Need help w/ multiples of different enemies.

Blitz3D Forums/Blitz3D Programming/Need help w/ multiples of different enemies.

Guy Fawkes(Posted 2009) [#1]
Hi. :) I've been researching enemy spawning.

and i want to be able to control different enemies at different waypoints with the same array.

only problem is when i try to load the enemies, it only spawns 1 enemy..

code:

Dim enemymesh(1)

enemymesh(0) = LoadAnimMesh("media\ninja.b3d")
enemymesh(1) = LoadAnimMesh("markio\mariorun.x")

For x = 0 to 24
CreateHostile(enemymesh(Rnd(0,1)), Rnd(0,24), Rnd(25,50))
Next

Function CreateHostile.hostile(spec,x,z)
		A.hostile = New hostile
		
		Select spec
			Case 1
				A\model = enemymesh(0)
				A\hp = 5
				A\attack = 2
				A\attackrange = 20
				A\state = IDLE
				A\maxtime# = 5.0
				A\cooled = True
				A\current# = 0.0
		End Select
		
		A\ox = x
		A\oz = z
		A\fleepivot = CreatePivot()
		If A\model <> 0
        PositionEntity A\fleepivot,x,EntityY(t),z
;		PositionEntity A\fleepivot,x,TerrainY(t,x,0,z),z
		PositionEntity A\model,x,0,z
		EndIf
		Return A
				
End Function

Function UpdateHostile()
	
	For A.hostile = Each hostile
		A\current# = A\current# + 0.1
		If A\maxtime# <= A\current#
			A\cooled = True
			A\current# = 0.0
		EndIf
        PositionEntity A\model, EntityX(A\model),3+EntityY(T),EntityZ(A\model)
;		PositionEntity A\model,EntityX(A\model),3+TerrainY(T,EntityX(A\model),0,EntityZ(a\model)),EntityZ(A\model)
		If A\hp < 1
			A\state = DEAD
			For P.player = Each player
				P\experience = P\experience + 15
			Next
		EndIf
		Select A\state
			Case IDLE
				For P.player = Each player
					If EntityDistance(A\model,P\model) < A\attackrange And P\hp > 0
						A\target.player = P
						A\state = CONFRONT
					EndIf
				Next
			Case CONFRONT
				If EntityDistance(A\model,A\target\model) < 4
					If A\cooled = True
						A\target\hp = A\target\hp - A\attack
						A\cooled = False
					
							If A\target\hp < 1
								A\state = flee
							EndIf
					EndIf
				Else
					PointEntity A\model,A\target\model
					MoveEntity A\model,0,0,1
				EndIf
				
				If (Abs(EntityX(A\model) + EntityZ(A\model)- A\ox-A\oz)) > 120
					A\state = FLEE
				EndIf
			Case DEAD
;				Display("Gray Ball has died.",500,35,255,0,0,5)
				PlaySound deathsound
				CreateItem(Rand(1,2),EntityX(A\model),EntityZ(A\model))
				FreeEntity A\model
				Delete A
			Case FLEE
				PointEntity A\model,A\fleepivot
				MoveEntity A\model,0,0,1
				
				If EntityDistance(A\model,A\fleepivot) < 3
					A\state = IDLE
				EndIf
		End Select
		

		
		
	Next
	
End Function


~DS~


Guy Fawkes(Posted 2009) [#2]
i hope u can read it.

if not i can rewrite it


Guy Fawkes(Posted 2009) [#3]
anyone?


Flemmonk(Posted 2009) [#4]
What you should do is comment nearly every line of code (After you've written it), and then go through and read the comments and what you will find is a few that don't make sense. Those will be the lines you need to change (You would be working backwards compared to most of us though).

Even better! Scrap the code, write your comment first, explaining exactly what the code below it will do, then write the code.

Glancing at the code I can see 2 things that need changing.


Guy Fawkes(Posted 2009) [#5]
i know ur looking at this line:

for x = 1 to 25
CreateHostile(blah)
next

i shouldve realized a function cant repeat..


LineOf7s(Posted 2009) [#6]
o_O !!

For the record, a function can "repeat". Look elsewhere.


Guy Fawkes(Posted 2009) [#7]
a\model=enemymesh(0)


GIB3D(Posted 2009) [#8]
Do copyentity(enemymesh(0)) not just enemymesh(0)


Guy Fawkes(Posted 2009) [#9]
worked like a charm.

after i hid the entity from characreate

thanks again! :)

~DS~


Flemmonk(Posted 2009) [#10]
Your code will also spawn only 1 type of enemy model too. Seriously comment your code and tab it next time.


Guy Fawkes(Posted 2009) [#11]
ahaha.

i fixed that ;)

copyentity enemymesh(rnd(0,1)) ;)

~DS~


Flemmonk(Posted 2009) [#12]
Then you would need to change the function parameters.