remember when you told me this?
Quote: "I would use select/case. Anything that has to do with the weapons like the max ammo for each weapon could also be included."
Well, I used to have a type array for the weapons containing all the weapon info and a case/select fucntion for offsetting the limb. Now, I want to do away with the weapon type array and just use the case/select function. However, the weapon name is not displayed when a weapon is picked up and the ammo and clips is always 0.
`-------- 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-------------------------------
`---------------------------------------------------------------
`make initial weapon Unarmed
global CWeapon=0
`Define the main variables needed
global playerhp=2000`----------Player's Health
global maxplayerhp=2000`-------Player's Max Health
global enemyhp=2000`-----------Enemy's Health
global MaxEnemyHP=2000`--------Enemy's Max Health
global ArmorHP=500`------------Armor Health
play_out = 0`-----------Tells when player has gone off matrix
`---------------------------------------------------------------
`------------------In Game Objects------------------------------
`---------------------------------------------------------------
`Create Main Player
MAKE OBJECT SPHERE 1,50:COLOR OBJECT 1,RGB(255,000,000):POSITION OBJECT 1,RND(1000),Ground#+25,RND(1000)
`Create Enemy Player
MAKE OBJECT SPHERE 2,50:COLOR OBJECT 2,RGB(255,000,000):POSITION OBJECT 2,RND(1000),Ground#+25,RND(1000)
`create machinegun
MAKE OBJECT CUBE 3,10:COLOR OBJECT 3,RGB(000,000,255):POSITION OBJECT 3,100,Ground#+5,160
`create shotgun
MAKE OBJECT CUBE 4,10:COLOR OBJECT 4,RGB(000,000,255):POSITION OBJECT 4,100,Ground#+5,190
`create rocketlauncher
MAKE OBJECT CUBE 5,10:COLOR OBJECT 5,RGB(000,000,255):POSITION OBJECT 5,100,Ground#+5,220
`create armor
MAKE OBJECT CUBE 6,10:COLOR OBJECT 6,RGB(000,255,000):POSITION OBJECT 6,100,Ground#+5,250
`create ammo crate
MAKE OBJECT CUBE 7,10:COLOR OBJECT 7,RGB(000,255,000):POSITION OBJECT 7,100,Ground#+5,280
`create health crate
MAKE OBJECT CUBE 8,10:COLOR OBJECT 8,RGB(000,255,000):POSITION OBJECT 8,100,Ground#+5,310
`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
SetWeapon()
`---------------------------------------------------------------
`------------------Info Display---------------------------------
`---------------------------------------------------------------
`Screen FPS
FPS#=SCREEN FPS()
TEXT 500,0,"FPS: "+STR$(FPS#)
display()
`display weapon info
if CWeapon > 0
TEXT 0,SCREEN HEIGHT()-55,name$
TEXT 0,SCREEN HEIGHT()-40,"Ammo: "+str$(ammo)
TEXT 0,SCREEN HEIGHT()-30,"Clips: "+str$(clips)
endif
`Camera Positioning
POSITION CAMERA OBJECT POSITION X(1),OBJECT POSITION Y(1)+10,OBJECT POSITION Z(1)
`---------------------------------------------------------------
`------------------Movement Settings----------------------------
`---------------------------------------------------------------
`Use variables to make code easier to read (shorter lines)
posx# = object position x(1)
posy# = object position y(1)
posz# = object position z(1)
legx# = LIMB POSITION X(1,2)
legy# = LIMB POSITION Y(1,2)
legz# = LIMB POSITION Z(1,2)
eposx# = object position x(2)
eposy# = object position y(2)
eposz# = object position z(2)
`Fix player moving through the matrix
if pposy# < ground#+25
pposy# = ground#+25
position object 1,pposx#, pposy#, pposz#
endif
`stop player from flying
xrotate object 1, 0
`Movement Controls
IF KEYSTATE(17)=1 THEN MOVE OBJECT 1,1
IF KEYSTATE(31)=1 THEN MOVE OBJECT 1,-1
IF KEYSTATE(30)=1 THEN MOVE OBJECT LEFT 1,1.5
IF KEYSTATE(32)=1 THEN MOVE OBJECT RIGHT 1,1.5
`prevent player from moving off matrix
if pposx# < 0 then pposx# = 0 : play_out = 1
if pposx# > 1000 then pposx# = 1000 : play_out = 1
if pposz# < 0 then pposz# = 0 : play_out = 1
if pposz# > 1000 then pposz# = 1000 : play_out = 1
if play_out = 1
position object 1, pposx#, pposy# , pposz#
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#,.009
POSITION OBJECT 1,pposx#,pposy#+JUMP_SPEED#, pposz#
IF posy#<=ground#+25 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 Code-----------------------------------
`---------------------------------------------------------------
`unintelligent artificial intelligence
if object exist(2)=1
point object 2,pposx#,pposy#,pposz#
move object 2, .8
endif
`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
`---------------------------------------------------------------
`------------------Weapons/Items--------------------------------
`---------------------------------------------------------------
`machinegun
if object exist(3)=1
if intersect object (3, legx#,legy#,legz#,pposx#,pposy#,pposz#)>0
delete object 3
CWeapon=1
SetWeapon()
endif
endif
`shogun
if object exist(4)=1
if intersect object (4, legx#,legy#,legz#,pposx#,pposy#,pposz#)>0
delete object 4
CWeapon=2
SetWeapon()
endif
endif
`rocketlauncher
if object exist(5)=1
if intersect object (5, legx#,legy#,legz#,pposx#,pposy#,pposz#)>0
delete object 5
CWeapon=3
SetWeapon()
endif
endif
`Get Armor
IF OBJECT EXIST(6)=1
IF INTERSECT OBJECT (6, legx#, legy#, legz#, pposx#,pposy#, pposz#)>0
DELETE OBJECT 6
ENDIF
ENDIF
if object exist(6)=0
TEXT 0,SCREEN HEIGHT()-100,"Armor: "+str$(ArmorHP)
endif
`Ammo Crate code A (ammo increase)
IF OBJECT EXIST(7)=1
IF ammo<maxammo AND INTERSECT OBJECT (7, legx#, legy#, legz#, pposx#,pposy#,pposz#)>0
INC ammo,(maxammo-ammo)
DELETE OBJECT 7
ENDIF
ENDIF
`ammo crate code B (clips increase)
if object exist(7)=1
If clips<maxclips and ammo>= maxammo
if INTERSECT OBJECT (7, legx#, legy#, legz#, pposx#,pposy#, pposz#)>0
INC clips,1
delete object 7
endif
endif
endif
`health crate code
If PlayerHP<MaxPlayerHP and intersect object (8, legx#, legy#, legz#, pposx#, pposy#, pposz#)>0
inc PlayerHP,(MaxPlayerHP-PlayerHP)
delete object 8
endif
`---------------------------------------------------------------
`------------------Shooting-------------------------------------
`---------------------------------------------------------------
`Mouseclick Shooting
if keystate(19)=0 AND mouseclick()=1
If ammo > 0
dec ammo,1
if object exist(2)=1
If intersect object (2, limb position x(1,1), limb position y(1,1), limb position z(1,1), posx#, posy#, posz#)>0 then dec EnemyHP,1
endif
endif
endif
`Reloading (press R)
IF MOUSECLICK()=0 AND KEYSTATE(19)=1 AND ammo<maxammo AND clips>0
Reload=1
ENDIF
`Reloading Part 2 (delay)
IF Reload=1 THEN INC Time#,.005
IF Time#>=1 THEN ammo=maxammo:DEC clips,1:Time#=0:Reload=0
`reloading part 3 (Show that we're reloading)
IF Reload=1 THEN CENTER TEXT SCREEN WIDTH()/2,SCREEN HEIGHT()/2,"Reloading..."
SYNC
LOOP
function SetWeapon()
select CWeapon
case 0
offset limb 1,1,0,0,10
name$ = "Unarmed"
endcase
case 1
offset limb 1,1,0,0,500
name$ = "Machinegun"
ammo = 200
maxammo = 200
clips = 5
maxclips = 5
endcase
case 2
offset limb 1,1,0,0,600
name$ = "Shotgun"
ammo = 8
maxammo = 8
clips = 6
maxclips = 6
endcase
case 3
offset limb 1,1,0,0,10000
name$ = "Rocket Launcher"
ammo = 2000
maxammo = 2000
clips = 3
maxclips = 3
endcase
endselect
endfunction
function display()
`display item names
IF OBJECT EXIST(3)=1
IF OBJECT IN SCREEN(3)=1
CENTER TEXT OBJECT SCREEN X(3),OBJECT SCREEN Y(3)-20,"Machinegun"
ENDIF
ENDIF
IF OBJECT EXIST(4)=1
IF OBJECT IN SCREEN(4)=1
CENTER TEXT OBJECT SCREEN X(4),OBJECT SCREEN Y(4)-20,"Shotgun"
ENDIF
ENDIF
IF OBJECT EXIST(5)=1
IF OBJECT IN SCREEN(5)=1
CENTER TEXT OBJECT SCREEN X(5),OBJECT SCREEN Y(5)-20,"Rocket Launcher"
ENDIF
ENDIF
IF OBJECT EXIST(6)=1
IF OBJECT IN SCREEN(6)=1
CENTER TEXT OBJECT SCREEN X(6),OBJECT SCREEN Y(6)-20,"Armor"
ENDIF
ENDIF
IF OBJECT EXIST(7)=1
IF OBJECT IN SCREEN(7)=1
CENTER TEXT OBJECT SCREEN X(7),OBJECT SCREEN Y(7)-20,"Ammo"
ENDIF
ENDIF
IF OBJECT EXIST(8)=1
IF OBJECT IN SCREEN(8)=1
CENTER TEXT OBJECT SCREEN X(8),OBJECT SCREEN Y(8)-20,"Health"
ENDIF
ENDIF
`display 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 playerhp on-screen
TEXT 0,SCREEN HEIGHT()-80,"Health: "+str$(PlayerHP)
`Add a target reticule to the screen
CIRCLE SCREEN WIDTH()/2,SCREEN HEIGHT()/2,5
endfunction
I thought maybe all of those had to be global but then I remember that global variables are defined at the beginning of the code and functions are defined at the bottom of the code so that can't be it.