Can anyone tell me why this doesnt work? It says object doesnt exist at a certain spot, i will capitalize the spot.
MAIN.bb
Graphics3D 800,800,900
SetBuffer FrontBuffer()
;=============
;CustomFunctions:
;Walk(unit,pointx,pointz,ID) id is usually 1
;AIwander(unit)
;AIflee(unit,attacker) unit to flee,attacker to flee from
;Kill(unit)
;AIattack(attacker,target)
;
;=============
;Models
;=============
zombieB3D = LoadMesh("zombie.b3d")
;=============
;Types
;=============
;Unit Type
Type unit
Field roll,yaw,pitch
Field r,g,b,a
Field maxhitpoints
Field UnitType$
Field ent
Field walkframe1
Field walkframe2
Field attackframe1
Field attackframe2
Field state
Field x,y,z
Field hitpoints
Field damage
Field attackcool,speed
End Type
;Hero Type
Type player
Field playername$
Field playernum
End Type
;Preset Zombie Unit
zombie.unit = New unit
zombie\r = 255
zombie\maxhitpoints = 25
zombie\hitpoints = 25
zombie\g = 255
zombie\unittype$ = "zombie"
zombie\ent = zombieB3D
zombie\b = 255
zombie\walkframe1 = 0
zombie\walkframe2 = 0
zombie\a = 0
zombie\attackframe1 = 0
zombie\attackframe2 = 0
zombie\state = 4
zombie\x = 0
zombie\y = 0
zombie\z = 0
zombie\damage = 5
zombie\speed = 0.6
zombie\attackcool = 2
;Player Unit
player1.unit = New unit
CopyUnit(zombie,player1)
player1\maxhitpoints = 50
player1\hitpoints = 50
player1\unittype$ = "player"
player1\damage = 10
player1\attackcool = 1
;===============
;Globals
;===============
Global FLEE = 0
Global DEAD = 1
Global DEFEND = 2
Global IDLE = 3
Global gravity = .5
;=======-
;Texturing
;=======-
;=============
;Includes and Variables that have to be placed after include
;=============
Include "functions1.bb"
Global a.unit
;=======-
;Monsters
;=======-
;Zombies
.FixAI
AI("zombie")
;=======-
;Player
;=======-
;=================
;Main Program Loop
;=================
light = CreateLight()
camera = CreateCamera()
CameraViewport camera,0,0,800,800
While True
PositionEntity zombie\ent,0,0,0
PositionEntity player1\ent,-15,0,-15
UpdateWorld
RenderWorld
Flip
Wend
functions1.bb
Function UpdateUnit(unitstype$)
For a.unit = Each unit
If a\unittype$ = unitstype$
a\x = EntityX(a\ent)
a\y = EntityY(a\ent)
a\z = EntityZ(a\ent)
EntityColor a\ent,a\r,a\g,a\b
EntityAlpha a\ent,a\a
a\roll = EntityRoll(a\ent)
a\yaw = EntityYaw(a\ent)
a\pitch = EntityPitch(a\ent)
EndIf
Next
End Function
Function Walk(walker.unit,x,z,ID)
pivot1 = CreatePivot()
PositionEntity pivot1,x,y,z
PointEntity walker\ent,pivot1
If ID = 1
While (EntityX(walker\ent) <= x) = False And (EntityZ(walker\ent) <= z) = False
MoveEntity walker\ent,walker\speed,0,walker\speed
Wend
EndIf
End Function
Function AIwander(wanderer.unit)
Walk(wanderer,Rand(EntityX(wanderer\ent),EntityX(wanderer\ent) + 10) + Rand(2,10),Rand(EntityZ(wanderer\ent),EntityZ(wanderer\ent)+ 10) + Rand(2,10),1)
End Function
Function AIflee(fleer.unit,attacker.unit)
Walk(fleer,EntityX(attacker\ent) - Rand(0,25),EntityZ(attacker\ent) - Rand(0,25),1)
End Function
Function Kill(entity.unit)
EntityAlpha entity\ent,0.1
Delay(200)
EntityAlpha entity\ent,0.2
Delay(200)
EntityAlpha entity\ent,0.3
Delay(200)
EntityAlpha entity\ent,0.4
Delay(200)
EntityAlpha entity\ent,0.5
Delay(200)
EntityAlpha entity\ent,0.6
Delay(200)
EntityAlpha entity\ent,0.7
Delay(200)
EntityAlpha entity\ent,0.8
Delay(200)
EntityAlpha entity\ent,0.9
Delay(200)
EntityAlpha entity\ent,1.0
Delay(200)
FreeEntity entity\ent
End Function
Function AIattack(unit.unit,target.unit)
WALK(UNIT,TARGET\X,TARGET\Z,1) ; HERE!
While Abs(unit\x - target\x) <= 10 And Abs(unit\z - target\z) <= 10
target\hitpoints = target\hitpoints - unit\damage
Delay(unit\attackcool * 1000)
Wend
End Function
Function AI(unittype$)
For a.unit = Each unit
If a\unittype$ = unittype$
If a\hitpoints < .25 * maxhitpoints
a\state = 0
EndIf
If a\hitpoints <= 0
a\state = 1
EndIf
Select a\state
Case 0
AIflee(a.unit,player1.unit)
Case 2
Kill(a)
Delete a
Case 4
AIwander(a)
End Select
AIattack(a,player1)
UpdateUnit(unitname$)
EndIf
Next
End Function
Function CopyUnit(unit1.unit,copied.unit)
copied\r = unit1\r
copied\maxhitpoints = unit1\hitpoints
copied\hitpoints = unit1\hitpoints
copied\g = unit1\g
copied\unittype$ = unit1\unittype$
copied\ent = unit1\ent
copied\b = unit1\b
copied\walkframe1 = unit1\walkframe1
copied\walkframe2 = unit1\walkframe2
copied\a = unit1\a
copied\attackframe1 = unit1\attackframe1
copied\attackframe2 = unit1\attackframe2
copied\state = unit1\state
copied\x = unit1\x
copied\y = unit1\y
copied\z = unit1\z
copied\damage = unit1\damage
copied\speed = unit1\speed
copied\attackcool = unit1\attackcool
End Function
MAIN.bb
Graphics3D 800,800,900
SetBuffer FrontBuffer()
;=============
;CustomFunctions:
;Walk(unit,pointx,pointz,ID) id is usually 1
;AIwander(unit)
;AIflee(unit,attacker) unit to flee,attacker to flee from
;Kill(unit)
;AIattack(attacker,target)
;
;=============
;Models
;=============
zombieB3D = LoadMesh("zombie.b3d")
;=============
;Types
;=============
;Unit Type
Type unit
Field roll,yaw,pitch
Field r,g,b,a
Field maxhitpoints
Field UnitType$
Field ent
Field walkframe1
Field walkframe2
Field attackframe1
Field attackframe2
Field state
Field x,y,z
Field hitpoints
Field damage
Field attackcool,speed
End Type
;Hero Type
Type player
Field playername$
Field playernum
End Type
;Preset Zombie Unit
zombie.unit = New unit
zombie\r = 255
zombie\maxhitpoints = 25
zombie\hitpoints = 25
zombie\g = 255
zombie\unittype$ = "zombie"
zombie\ent = zombieB3D
zombie\b = 255
zombie\walkframe1 = 0
zombie\walkframe2 = 0
zombie\a = 0
zombie\attackframe1 = 0
zombie\attackframe2 = 0
zombie\state = 4
zombie\x = 0
zombie\y = 0
zombie\z = 0
zombie\damage = 5
zombie\speed = 0.6
zombie\attackcool = 2
;Player Unit
player1.unit = New unit
CopyUnit(zombie,player1)
player1\maxhitpoints = 50
player1\hitpoints = 50
player1\unittype$ = "player"
player1\damage = 10
player1\attackcool = 1
;===============
;Globals
;===============
Global FLEE = 0
Global DEAD = 1
Global DEFEND = 2
Global IDLE = 3
Global gravity = .5
;=======-
;Texturing
;=======-
;=============
;Includes and Variables that have to be placed after include
;=============
Include "functions1.bb"
Global a.unit
;=======-
;Monsters
;=======-
;Zombies
.FixAI
AI("zombie")
;=======-
;Player
;=======-
;=================
;Main Program Loop
;=================
light = CreateLight()
camera = CreateCamera()
CameraViewport camera,0,0,800,800
While True
PositionEntity zombie\ent,0,0,0
PositionEntity player1\ent,-15,0,-15
UpdateWorld
RenderWorld
Flip
Wend
functions1.bb
Function UpdateUnit(unitstype$)
For a.unit = Each unit
If a\unittype$ = unitstype$
a\x = EntityX(a\ent)
a\y = EntityY(a\ent)
a\z = EntityZ(a\ent)
EntityColor a\ent,a\r,a\g,a\b
EntityAlpha a\ent,a\a
a\roll = EntityRoll(a\ent)
a\yaw = EntityYaw(a\ent)
a\pitch = EntityPitch(a\ent)
EndIf
Next
End Function
Function Walk(walker.unit,x,z,ID)
pivot1 = CreatePivot()
PositionEntity pivot1,x,y,z
PointEntity walker\ent,pivot1
If ID = 1
While (EntityX(walker\ent) <= x) = False And (EntityZ(walker\ent) <= z) = False
MoveEntity walker\ent,walker\speed,0,walker\speed
Wend
EndIf
End Function
Function AIwander(wanderer.unit)
Walk(wanderer,Rand(EntityX(wanderer\ent),EntityX(wanderer\ent) + 10) + Rand(2,10),Rand(EntityZ(wanderer\ent),EntityZ(wanderer\ent)+ 10) + Rand(2,10),1)
End Function
Function AIflee(fleer.unit,attacker.unit)
Walk(fleer,EntityX(attacker\ent) - Rand(0,25),EntityZ(attacker\ent) - Rand(0,25),1)
End Function
Function Kill(entity.unit)
EntityAlpha entity\ent,0.1
Delay(200)
EntityAlpha entity\ent,0.2
Delay(200)
EntityAlpha entity\ent,0.3
Delay(200)
EntityAlpha entity\ent,0.4
Delay(200)
EntityAlpha entity\ent,0.5
Delay(200)
EntityAlpha entity\ent,0.6
Delay(200)
EntityAlpha entity\ent,0.7
Delay(200)
EntityAlpha entity\ent,0.8
Delay(200)
EntityAlpha entity\ent,0.9
Delay(200)
EntityAlpha entity\ent,1.0
Delay(200)
FreeEntity entity\ent
End Function
Function AIattack(unit.unit,target.unit)
WALK(UNIT,TARGET\X,TARGET\Z,1) ; HERE!
While Abs(unit\x - target\x) <= 10 And Abs(unit\z - target\z) <= 10
target\hitpoints = target\hitpoints - unit\damage
Delay(unit\attackcool * 1000)
Wend
End Function
Function AI(unittype$)
For a.unit = Each unit
If a\unittype$ = unittype$
If a\hitpoints < .25 * maxhitpoints
a\state = 0
EndIf
If a\hitpoints <= 0
a\state = 1
EndIf
Select a\state
Case 0
AIflee(a.unit,player1.unit)
Case 2
Kill(a)
Delete a
Case 4
AIwander(a)
End Select
AIattack(a,player1)
UpdateUnit(unitname$)
EndIf
Next
End Function
Function CopyUnit(unit1.unit,copied.unit)
copied\r = unit1\r
copied\maxhitpoints = unit1\hitpoints
copied\hitpoints = unit1\hitpoints
copied\g = unit1\g
copied\unittype$ = unit1\unittype$
copied\ent = unit1\ent
copied\b = unit1\b
copied\walkframe1 = unit1\walkframe1
copied\walkframe2 = unit1\walkframe2
copied\a = unit1\a
copied\attackframe1 = unit1\attackframe1
copied\attackframe2 = unit1\attackframe2
copied\state = unit1\state
copied\x = unit1\x
copied\y = unit1\y
copied\z = unit1\z
copied\damage = unit1\damage
copied\speed = unit1\speed
copied\attackcool = unit1\attackcool
End Function