Why is it saying object don't exist in the SetWeapon() function?
`-------- Title: My First FPS
`-------- Author: Krimzon DestinE
`-------- Date: October 15, 2005
`Setup Client Options
SYNC ON:SYNC RATE 0:HIDE MOUSE: AUTOCAM OFF:RANDOMIZE TIMER()
`---------------------------------------------------------------
`------------------Main Variables-------------------------------
`---------------------------------------------------------------
` CWeapon = Current Weapon
global CWeapon=0
`weapon
type weapon
name as string
ammo as integer
maxammo as integer
clips as integer
maxclips as integer
speed as integer
delay as integer
damage as integer
endtype
`setup arrays
dim weapon(4) as weapon
weapon(0).name="Unarmed"
weapon(1).name="Sniper Rifle"
weapon(1).ammo=1000
weapon(1).maxammo=1000
weapon(1).clips=3
weapon(1).maxclips=3
weapon(1).speed=0
weapon(1).delay=0
weapon(1).damage=0
weapon(2).name="Shotgun"
weapon(2).ammo=8000
weapon(2).maxammo=8000
weapon(2).clips=3
weapon(2).maxclips=3
weapon(2).speed=00
weapon(2).delay=0
weapon(2).damage=0
weapon(3).name="Tommygun"
weapon(3).ammo=5000
weapon(3).maxammo=5000
weapon(3).clips=3
weapon(3).maxclips=3
weapon(3).speed=0
weapon(3).delay=0
weapon(3).damage=0
weapon(4).name="RocketLauncher"
weapon(4).ammo=1000
weapon(4).maxammo=1000
weapon(4).clips=3
weapon(4).maxclips=3
weapon(4).speed=0
weapon(4).delay=0
weapon(4).damage=0
`Define the main variables needed
PlayerHP=2000`-----Player's Health
MaxPlayerHP=2000`--Player's Max Health
EnemyHP=2000`------Enemy's Health
MaxEnemyHP=2000`---Enemy's Max Health
ArmorHP=500`-------Armor Health
play_out = 0`------Tells when player has gone off matrix
firing=0`----------tells when weapon is being fired
`---------------------------------------------------------------
`------------------In Game Objects------------------------------
`---------------------------------------------------------------
`Create Main Player
MAKE OBJECT SPHERE 1,50:COLOR OBJECT 1,RGB(000,255,000):POSITION OBJECT 1,RND(1000),Ground#,RND(1000)
`Create Enemy Player
MAKE OBJECT SPHERE 2,50:COLOR OBJECT 2,RGB(255,000,000):POSITION OBJECT 2,RND(1000),Ground#,RND(1000)
`create sniper rifle
MAKE OBJECT CUBE 3,10:COLOR OBJECT 3,RGB(13,234,132):POSITION OBJECT 3,100,Ground#,160
`create rocket launcher
MAKE OBJECT CUBE 4,10:COLOR OBJECT 4,RGB(58,220,76):POSITION OBJECT 4,100,Ground#,190
`create shotgun
MAKE OBJECT CUBE 5,10:COLOR OBJECT 5,RGB(33,0,13):POSITION OBJECT 5,100,Ground#,210
`create tommy gun
MAKE OBJECT CUBE 6,10:COLOR OBJECT 6,RGB(67,16,190):POSITION OBJECT 6,100,Ground#,250
`create armor
MAKE OBJECT CUBE 7,10:COLOR OBJECT 7,RGB(167,176,10):POSITION OBJECT 7,100,Ground#,100
`create ammo crate
MAKE OBJECT CUBE 8,10:COLOR OBJECT 8,RGB(20,250,75):POSITION OBJECT 8,100,Ground#,130
`create health crate
MAKE OBJECT CUBE 9,10:COLOR OBJECT 9,RGB(70,10,200):POSITION OBJECT 9,100,Ground#,230
`create bullet
for bullet = 10 to weapon(CWeapon).ammo
make object sphere bullet, 1
Position Object bullet, Camera Position X(), Camera Position Y(), Camera Position Z()
Hide Object bullet
next bullet
`create playing field
MAKE MATRIX 1,1000,1000,50,50
`make matrix the ground
Ground#=GET GROUND HEIGHT(1,0,0)
`---------------------------------------------------------------
`------------------Player Limbs---------------------------------
`---------------------------------------------------------------
`Add limb for intersection checks
MAKE OBJECT SPHERE 9999,10
MAKE MESH FROM OBJECT 1,9999
DELETE OBJECT 9999
ADD LIMB 1,1,1
HIDE LIMB 1,1
`Add a second limb for ground checks
ADD LIMB 1,2,1
OFFSET LIMB 1,2,0,-50,0
DELETE MESH 1
HIDE LIMB 1,2
`---------------------------------------------------------------
`------------------Main Do/Loop---------------------------------
`---------------------------------------------------------------
DO
`---------------------------------------------------------------
`------------------Info Display---------------------------------
`---------------------------------------------------------------
display_items()
`display text enemyhp above enemy
IF OBJECT EXIST(2)=1
IF OBJECT IN SCREEN(2)=1
CENTER TEXT OBJECT SCREEN X(2),OBJECT SCREEN Y(2)-70,"Enemy Health: "+str$(EnemyHP)
ENDIF
ENDIF
`Display our Ammo, Clips, Health, and Armor on-screen
TEXT 0,SCREEN HEIGHT()-80,"Health: "+str$(PlayerHP)
if CWeapon > 0
`TEXT 0,SCREEN HEIGHT()-60,"Current Weapon: "+weapon(CWeapon).name
TEXT 0,SCREEN HEIGHT()-50,"Ammo: "+str$(weapon(CWeapon).ammo)
TEXT 0,SCREEN HEIGHT()-40,"Clips: "+str$(weapon(CWeapon).clips)
endif
`Show that we're reloading
IF Reload=1 THEN CENTER TEXT SCREEN WIDTH()/2,SCREEN HEIGHT()/2,"Reloading..."
`Add a target reticule to the screen
CIRCLE SCREEN WIDTH()/2,SCREEN HEIGHT()/2,5
`Fix player moving through the matrix
if Play_y# < Ground#
Play_y# = Ground#
position object 1, Play_x#, Play_y#, Play_z#
endif
`Screen FPS
FPS#=SCREEN FPS()
TEXT 500,0,"FPS: "+STR$(FPS#)
`Camera Positioning
POSITION CAMERA OBJECT POSITION X(1),OBJECT POSITION Y(1)+10,OBJECT POSITION Z(1)
`---------------------------------------------------------------
`------------------Movement Settings----------------------------
`---------------------------------------------------------------
`stop player from flying
xrotate object 1, 0
`Movement Controls
IF KEYSTATE(17)=1 THEN MOVE OBJECT 1,.9
IF KEYSTATE(31)=1 THEN MOVE OBJECT 1,-.9
IF KEYSTATE(30)=1 THEN MOVE OBJECT LEFT 1,.8
IF KEYSTATE(32)=1 THEN MOVE OBJECT RIGHT 1,.8
`Use variables to make code easier to read (shorter lines)
Play_x# = object position x(1)
Play_y# = object position y(1)
Play_z# = object position z(1)
Leg_x# = LIMB POSITION X(1,2)
Leg_y# = LIMB POSITION Y(1,2)
Leg_z# = LIMB POSITION Z(1,2)
enemy_x# = object position x(2)
enemy_y# = object position y(2)
enemy_z# = object position z(2)
`prevent player from moving off matrix
if Play_x# < 0 then Play_x# = 0 : play_out = 1
if Play_x# > 1000 then Play_x# = 1000 : play_out = 1
if Play_z# < 0 then Play_z# = 0 : play_out = 1
if Play_z# > 1000 then Play_z# = 1000 : play_out = 1
if play_out = 1
position object 1, Play_x#, Play_y# , Play_z#
play_out = 0
endif
`Space key Controls
IF SPACEKEY()=1 AND JUMPING=0
JUMP_SPEED#=1
JUMPING=1
ENDIF
`Jumping
IF JUMPING=1
DEC JUMP_SPEED#,.005
POSITION OBJECT 1,Play_x#,Play_y#+JUMP_SPEED#, Play_z#
IF Play_y#<=Ground# THEN JUMPING=0
ENDIF
`Put player direction back to mouselook angle
xrotate object 1, CAMX#
`Mouse Camera Movement
CAMY#=CAMY#+MOUSEMOVEX()*.1
CAMX#=CAMX#+MOUSEMOVEY()*.1
IF CAMX#>90 AND CAMX#<135 THEN CAMX#=90
IF CAMX#>270 AND CAMX#<225 THEN CAMX#=90
YROTATE CAMERA CAMY#
XROTATE CAMERA CAMX#
YROTATE OBJECT 1,CAMY#
XROTATE OBJECT 1,CAMX#
`enemy death, deletions, and regeneration
if EnemyHP=0 AND OBJECT EXIST(2)=1
DELETE OBJECT 2
MAKE OBJECT SPHERE 2,50: COLOR OBJECT 2,RGB(255,000,000): POSITION OBJECT 2,RND(600),Ground#,RND(600)
EnemyHP=2000
endif
`Reloading (press R)
IF MOUSECLICK()=0 AND KEYSTATE(19)=1 AND weapon(CWeapon).ammo<weapon(CWeapon).maxammo AND weapon(CWeapon).clips>0
Reload=1
ENDIF
`Reloading Part 2 (delay)
IF Reload=1 THEN INC Time#,.005
IF Time#>=1 THEN weapon(CWeapon).ammo=weapon(CWeapon).maxammo:DEC weapon(CWeapon).clips,1:Time#=0:Reload=0
`Ammo Crate code (obtain ammo from ground)
IF OBJECT EXIST(4)=1
IF weapon(CWeapon).ammo<weapon(CWeapon).maxammo AND INTERSECT OBJECT (4, Leg_x#, Leg_y#, Leg_z#, Play_x#,Play_y#, Play_z#)>0
INC weapon(CWeapon).clips,(weapon(CWeapon).maxclips-weapon(CWeapon).clips)
INC weapon(CWeapon).ammo,(weapon(CWeapon).maxammo-weapon(CWeapon).ammo)
DELETE OBJECT 4
ENDIF
ENDIF
`Armor crate code A (obtain armor from ground)
IF OBJECT EXIST(3)=1
IF INTERSECT OBJECT (3, Leg_x#, Leg_y#, Leg_z#, Play_x#,Play_y#, Play_z#)>0
DELETE OBJECT 3
ENDIF
ENDIF
`Armor crate code B (display armor and reduce armor health when shot
IF OBJECT EXIST(3)=0
TEXT 0,SCREEN HEIGHT()-70,"Armor: "+str$(ArmorHP)
ENDIF
`health crate code
If PlayerHP<MaxPlayerHP and intersect object (9, Leg_x#, Leg_y#, Leg_z#, Play_x#, Play_y#, Play_z#)>0
inc PlayerHP,(MaxPlayerHP-PlayerHP)
delete object 9
endif
`---------------------------------------------------------------
`------------------Shooting Code--------------------------------
`---------------------------------------------------------------
`Mouseclick Shooting
if keystate(19)=0 AND mouseclick()=1
IF weapon(CWeapon).ammo>0 THEN DEC weapon(CWeapon).ammo,1
If intersect object (2, limb position x(1,1), limb position y(1,1), limb position z(1,1), play_x#, Play_y#, PLay_z#)>0 then dec enemyhp,1
TEXT 0,SCREEN HEIGHT()-50,"Ammo: "+str$(weapon(CWeapon).ammo)
TEXT 0,SCREEN HEIGHT()-40,"Clips: "+str$(weapon(CWeapon).clips)
ENDIF
`---------------------------------------------------------------
`------------------Weapons Code---------------------------------
`---------------------------------------------------------------
`Get Sniper Rifle
IF OBJECT EXIST(1)=1
IF INTERSECT OBJECT (1, Leg_x#, Leg_y#, Leg_z#, Play_x#,Play_y#, Play_z#)>0
DELETE OBJECT 1
CWeapon=1
SetWeapon()
ENDIF
ENDIF
`Get Rocket Launcher
IF OBJECT EXIST(2)=1
IF INTERSECT OBJECT (2, Leg_x#, Leg_y#, Leg_z#, Play_x#,Play_y#, Play_z#)>0
DELETE OBJECT 2
CWeapon=2
SetWeapon()
ENDIF
ENDIF
`Get Shotgun
IF OBJECT EXIST(3)=1
IF INTERSECT OBJECT (3, Leg_x#, Leg_y#, Leg_z#, Play_x#,Play_y#, Play_z#)>0
DELETE OBJECT 3
CWeapon=3
SetWeapon()
ENDIF
ENDIF
`Get Tommygun
IF OBJECT EXIST(4)=1
IF INTERSECT OBJECT (4, Leg_x#, Leg_y#, Leg_z#, Play_x#,Play_y#, Play_z#)>0
DELETE OBJECT 4
CWeapon=4
SetWeapon()
ENDIF
ENDIF
SYNC
LOOP
function SetWeapon()
select CWeapon
case 0
offset limb 1,1,0,0,10
endcase
case 1
offset limb 1,1,0,0,10000
endcase
case 2
offset limb 1,1,0,0,10000
endcase
case 3
offset limb 1,1,0,0,450
endcase
case 4
offset limb 1,1,0,0,400
endcase
endselect
endfunction
function display_items()
IF OBJECT EXIST(3)=1
IF OBJECT IN SCREEN(3)=1
CENTER TEXT OBJECT SCREEN X(3),OBJECT SCREEN Y(3)-20,"Snper Rifle"
ENDIF
ENDIF
IF OBJECT EXIST(4)=1
IF OBJECT IN SCREEN(4)=1
CENTER TEXT OBJECT SCREEN X(4),OBJECT SCREEN Y(4)-20,"Rocket Launcher"
ENDIF
ENDIF
IF OBJECT EXIST(5)=1
IF OBJECT IN SCREEN(5)=1
CENTER TEXT OBJECT SCREEN X(5),OBJECT SCREEN Y(5)-20,"Shot Gun"
ENDIF
ENDIF
IF OBJECT EXIST(6)=1
IF OBJECT IN SCREEN(6)=1
CENTER TEXT OBJECT SCREEN X(6),OBJECT SCREEN Y(6)-20,"Tommy Gun"
ENDIF
ENDIF
IF OBJECT EXIST(7)=1
IF OBJECT IN SCREEN(7)=1
CENTER TEXT OBJECT SCREEN X(7),OBJECT SCREEN Y(7)-20,"Armor"
ENDIF
ENDIF
IF OBJECT EXIST(8)=1
IF OBJECT IN SCREEN(8)=1
CENTER TEXT OBJECT SCREEN X(8),OBJECT SCREEN Y(8)-20,"Ammo Crate"
ENDIF
ENDIF
IF OBJECT EXIST(9)=1
IF OBJECT IN SCREEN(9)=1
CENTER TEXT OBJECT SCREEN X(9),OBJECT SCREEN Y(9)-20,"Helath"
ENDIF
ENDIF
endfunction