What's goin on with my shooting/killing code? It's not decreasing the enemies' health at all. not sure why, i don't recall changing anything to make i not work but it doesn't.
`-------- 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
`delaying the bullets
`weapon
type weapon
name as string
ammo as integer
maxammo as integer
clips as integer
maxclips as integer
bspeed as integer
blife as integer
bdamage as integer
endtype
`weapon array
dim weapon(3) as weapon
weapon(0).name="Unarmed"
weapon(1).name="Machinegun"
weapon(1).ammo=10000
weapon(1).maxammo=10000
weapon(1).clips=5
weapon(1).maxclips=5
weapon(1).bspeed=5
weapon(1).blife=10000
weapon(1).bdamage=100
weapon(2).name="Shotgun"
weapon(2).ammo=1000
weapon(2).maxammo=1000
weapon(2).clips=6
weapon(2).maxclips=6
weapon(2).bspeed=4
weapon(2).blife=10000
weapon(2).bdamage=1000
weapon(3).name="Rocket Launcher"
weapon(3).ammo=1000
weapon(3).maxammo=1000
weapon(3).clips=3
weapon(3).maxclips=3
weapon(3).bspeed=10
weapon(3).blife=5000
weapon(3).bdamage=2000
`Define the main variables needed
playerhp=2000`----------Player's Health
maxplayerhp=2000`-------Player's Max Health
ArmorHP=500`------------Armor Health
play_out = 0`-----------Tells when player has gone off matrix
enemies = 5`------------Number of enemies
`makes health for each enemy
dim enemy_health(enemies)
`makes states for each enemy
dim enemy_state(enemies)
`Initial enemy properties
for e=1 to enemies
enemy_health(e)=2000
enemy_state(e)=1
next e
`---------------------------------------------------------------
`------------------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 machinegun
make object cube 2,10:color object 2,rgb(000,000,255):position object 2,100,Ground#+5,160
`create shotgun
make object cube 3,10:color object 3,rgb(000,000,255):position object 3,100,Ground#+5,190
`create rocketlauncher
make object cube 4,10:color object 4,rgb(000,000,255):position object 4,100,Ground#+5,220
`create armor
make object cube 5,10:color object 5,rgb(000,255,000):position object 5,100,Ground#+5,250
`create ammo crate
make object cube 6,10:color object 6,rgb(000,255,000):position object 6,100,Ground#+5,280
`create health crate
make object cube 7,10:color object 7,rgb(000,255,000):position object 7,100,Ground#+5,310
`create enemies
for e=1 to enemies: make object sphere 10+e,50 : color object 10+e,rgb(255,000,000): next e
`distance between player and enemy
dim enemy_dist#(enemies)
`enemy position type
Type enemy
x as float
y as float
z as float
endtype
dim enemy_position(enemies) as enemy
`Randomise positions
for e=1 to enemies
enemy_position(e).x=rnd(1000)
enemy_position(e).z=rnd(1000)
next e
dim enemy_angle(enemies) :`Array for the enemies' angles
`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
for e = 1 to enemies
if object exist(10+e)=1
if object in screen(10+e)=1
center text object screen x(10+e),object screen y(10+e)-70,"Enemy Health: "+str$(enemy_health(e))
endif
endif
next e
`Display health on-screen
text 525,450,"Health: "+str$(PlayerHP)
if CWeapon > 0
text 0,screen height()-55,weapon(CWeapon).name
text 0,screen height()-40,"Ammo: "+str$(weapon(CWeapon).ammo)
text 0,screen height()-30,"Clips: "+str$(weapon(CWeapon).clips)
endif
if CWeapon=0
text 0,screen height()-55,weapon(CWeapon).name
endif
`Add a target reticule to the screen
circle screen width()/2,screen height()/2,5
`Screen FPS
FPS#=screen fps()
text 500,0,"FPS: "+str$(FPS#)
`---------------------------------------------------------------
`------------------Movement Settings----------------------------
`---------------------------------------------------------------
`Fix player moving through the matrix
if posy# < ground#+25
posy# = ground#+25
position object 1,posx#, posy#, posz#
endif
`Camera Positioning
position camera object position x(1),object position y(1)+10,object position z(1)
`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
`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)
`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,posx#,posy#+JUMP_SPEED#, posz#
IF posy#<=ground#+25 THEN JUMPING=0
ENDIF
`Put player direction back to mouselook angle
xrotate object 1, CAMX#
`prevent player from moving off matrix
if posx# < 0 then posx# = 0 : play_out = 1
if posx# > 1000 then posx# = 1000 : play_out = 1
if posz# < 0 then posz# = 0 : play_out = 1
if posz# > 1000 then posz# = 1000 : play_out = 1
if play_out = 1
position object 1, posx#, posy# , posz#
play_out = 0
endif
`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-----------------------------------
`---------------------------------------------------------------
`**********AI**********
`Select all enemies
for e=1 to enemies
enemy_dist#(e)=sqrt((posx#-enemy_position(e).x)^2+(posy#-enemy_position(e).y)^2+(posz#-enemy_position(e).z)^2)
if enemy_state(e)=1
enemy_angle(e)=wrapvalue(enemy_angle(e)+rnd(3))
endif
if enemy_state(e)=2
enemy_angle(e)=atanfull(posx#-enemy_position(e).x,posz#-enemy_position(e).z)
endif
enemy_position(e).x=newxvalue(enemy_position(e).x,enemy_angle(e),2.0)
enemy_position(e).z=newzvalue(enemy_position(e).z,enemy_angle(e),2.0)
if enemy_dist#(e)<250 then enemy_state(e)=2 else enemy_state(e)=1
enemy_position(e).y=get ground height(1,enemy_position(e).x,enemy_position(e).z)+25
position object 10+e,enemy_position(e).x,enemy_position(e).y,enemy_position(e).z
yrotate object 10+e,enemy_angle(e)
next e
`************killing************************
for e = 1 to enemies
if object exist (10+e)=1
if enemy_health(e)<=0
delete object 10 + e
make object sphere 10+e,50
color object 10+e,rgb(255,000,000)
enemy_position(e).x=rnd(1000)
enemy_position(e).z=rnd(1000)
enemy_health(e)=2000
endif
endif
next e
`---------------------------------------------------------------
`------------------Weapons/Items--------------------------------
`---------------------------------------------------------------
`create machinegun
if object exist(2)=1
if intersect object (2, legx#,legy#,legz#,posx#,posy#,posz#)>0
delete object 2
SetWeapon()
CWeapon=1
endif
endif
`create shogun
if object exist(3)=1
if intersect object (3, legx#,legy#,legz#,posx#,posy#,posz#)>0
delete object 3
SetWeapon()
CWeapon=2
endif
endif
`create rocketlauncher
if object exist(4)=1
if intersect object (4, legx#,legy#,legz#,posx#,posy#,posz#)>0
delete object 4
SetWeapon()
CWeapon=3
endif
endif
`Get Armor
IF OBJECT EXIST(5)=1
IF INTERSECT OBJECT (5, legx#, legy#, legz#, posx#,posy#, posz#)>0
DELETE OBJECT 5
ENDIF
ENDIF
if object exist(5)=0
TEXT 0,SCREEN HEIGHT()-100,"Armor: "+str$(ArmorHP)
endif
`Ammo Crate code A (ammo increase)
IF OBJECT EXIST(6)=1
IF weapon(CWeapon).ammo<weapon(CWeapon).maxammo AND INTERSECT OBJECT (6, legx#, legy#, legz#, posx#,posy#,posz#)>0
INC weapon(CWeapon).ammo,(weapon(CWeapon).maxammo-weapon(CWeapon).ammo)
DELETE OBJECT 6
ENDIF
ENDIF
`ammo crate code B (clips increase)
if object exist(6)=1
If weapon(CWeapon).clips<weapon(CWeapon).maxclips and weapon(Cweapon).ammo>= weapon(Cweapon).maxammo
if INTERSECT OBJECT (6, legx#, legy#, legz#, posx#,posy#, posz#)>0
INC weapon(Cweapon).clips,1
delete object 6
endif
endif
endif
`health crate code
If PlayerHP<MaxPlayerHP and intersect object (7, legx#, legy#, legz#, posx#, posy#, posz#)>0
inc PlayerHP,(MaxPlayerHP-PlayerHP)
delete object 7
endif
`---------------------------------------------------------------
`------------------Shooting-------------------------------------
`---------------------------------------------------------------
``Mouseclick Shooting
for e = 1 to enemies
if keystate(19)=0 and mouseclick()=1
if weapon(CWeapon).ammo > 0 then dec weapon(CWeapon).ammo,1
if object exist(10+e)=1
if intersect object (10+e, limb position x(1,1), limb position y(1,1), limb position z(1,1), posx#, posy#, posz#)>0 then dec enemy_health(e),1
endif
endif
next e
`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
`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: endcase
case 1: offset limb 1,1,0,0,10000: endcase
case 2: offset limb 1,1,0,0,450: endcase
case 3: offset limb 1,1,0,0,400: endcase
endselect
endfunction
function display_items()
IF OBJECT EXIST(2)=1
IF OBJECT IN SCREEN(2)=1
CENTER TEXT OBJECT SCREEN X(2),OBJECT SCREEN Y(2)-20,"Machinegun"
ENDIF
ENDIF
IF OBJECT EXIST(3)=1
IF OBJECT IN SCREEN(3)=1
CENTER TEXT OBJECT SCREEN X(3),OBJECT SCREEN Y(3)-20,"Shotgun"
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,"Armor"
ENDIF
ENDIF
if object exist(6)=1
if object in screen(6)=1
center text object screen x(6),object screen y (6)-20,"Ammo"
endif
endif
IF OBJECT EXIST(7)=1
IF OBJECT IN SCREEN(7)=1
CENTER TEXT OBJECT SCREEN X(7),OBJECT SCREEN Y(7)-20,"Health"
ENDIF
ENDIF
endfunction