This is one from an RPG sample I've made for the plugin. It defines all the behaviours for an entity labelled "Bob".
Ignore all the functions towards the end, for level loading. All they do is send hte relevant bits to DBPro so it can load the 3d models, etc. Then each loop DBPro invokes Bob_Tick() to update everything.
If I was smarter
, and had more time, I'd OOP-ify all this so when loading a level you'd just write
Bob = new EntityBob(0.0,10.0,0.0,"Hello!")
instead of the current level data file which is
-- Level data file
-- Paths
MakePath("bob1")
AddWaypoint("bob1",100,0,100)
AddWaypoint("bob1",-100,0,-100)
MakePath("bob2")
AddWaypoint("bob2",45,0,150)
AddWaypoint("bob2",-76,0,12)
AddWaypoint("bob2",0,0,120)
-- Entities
Bob_Create(0,0,0)
Bob_GivePath("bob1")
Bob_End()
Bob_Create(-40,0,2)
Bob_End()
Bob_Create(69,0,96)
Bob_GivePath("bob2")
Bob_End()
Bob_Create(75,0,75)
Bob_End()
-- This script defines all the behaviours for the entity 'Bob'
bob_IDLE = 0
bob_WALK = 1
bob_CHAT = 2
bob_WALKSPEED = 0.2
Bob_Scale = {x=300,y=300,z=300}
-- ================= CALLED BY ENGINE =================
-- Constructor
-- one param: the obj num ent is going to have
function Bob_Init(objnum)
Entities[objnum] = { obj = objnum, type="Bob", speech="Good day Sir.", haspath = NO, state=bob_IDLE }
end
-- Attach this Bob to a path
function Bob_AttachToPath(objnum,path)
AddObject(objnum,path,bob_WALKSPEED)
Entities[objnum]['state'] = bob_WALK
Entities[objnum]['haspath'] = YES
end
-- Update what this Bob is doing
function Bob_Tick(objnum)
-- Get the object data
this = Entities[objnum]
-- Two simple states. Either player within 20 units of Bob, or Bob gets on with doing something
if(Obj2Pt(objnum,CAMPOSX,0,CAMPOSZ)<20) then
-- Point us at the cam
PointObject(objnum,CAMPOSX,0,CAMPOSZ)
-- Make us idle
LoopObject(objnum,291,359)
if MOUSECLICK==1 then
SendMessageS("ChatWindow",this['speech'])
else
SendMessage("Click2Talk")
end
else
if this['haspath'] == YES then
LoopObject(objnum,1,13)
UpdateObject(objnum)
else
LoopObject(objnum,291,359)
end
end
end
-- ================= FOR LEVEL LOADING =================
-- A quick function that places the correct messages on the stack when a level is loaded
function Bob_Create(x,y,z)
SendMessageS("Create","Bob")
SendMessageF("Pos:X",x)
SendMessageF("Pos:Y",y)
SendMessageF("Pos:Z",z)
end
-- This may seem to echo an above function, but it's here to maintain the strict [Level load => Engine => Entity functions] workflow
function Bob_GivePath(pathid)
SendMessageS("Path",pathid)
end
-- Finish bob segment
function Bob_End()
SendMessage("End")
end
"A book. If u know something why cant u make a kool game or prog.
come on now. A book. I hate books. book is stupid. I know that I need codes but I dont know the codes"