I do the lua file like this
Items{
Item[1] =
{
name= "backpack"
x= 223,
y= 223,
z= 0,
3D_File= BackPack.x,
Rotating= true
BackPackItems {
Item[1] {
name= "lunchbox",
3D_File= LunchBox.x
}
}
}
Item[2] =
{
name= "missile pack"
x= 123,
y= 123,
z= 0,
3D_File= MissilePack.x,
Rotating= true
}
}
I send data to a lua file like this
REM not saved the item name because it probably wont change!
REM the item moved better save its new location for next time
r=lua execute ("Items->Item[1]->x=124.5")
r=lua execute ("Items->Item[1]->y=124.5")
r=lua execute ("Items->Item[1]->z=0")
REM the item has stopped rotating for some reason maybe sum1 pulled a switch?
r=lua execute ("Items->Item[1]->z=flase")
I read data from a file like this..
r = load lua("c:/item.lua")
function LoadItem (max_items)
for key = 1 to max_items
REM probably better use a flexible list rather than a fixed array
itemnamearray[key] = LUA ARRAY STRING (Items->Item[key]->name)
itemrotatingarray[key] = LUA ARRAY STRING (Items->Item[key]->rotating)
loadobject key,LUA ARRAY STRING ("Items->Item[key]->3D_File")
postitionobject key,LUA ARRAY STRING ("Items->Item[key]->x"), LUA ARRAY STRING ("Items->Item[key]->y"),LUA ARRAY STRING ("Items->Item[key]->z")
next
end
You can check out a little lua sample I wrote here
http://www.freewebs.com/sang33ta/LuaExample.rar
OK here is a little upgrade you can make to the Amazon.lua we will re-program the AI without needing DBP to recompile the software!!!
add these three lines...
spotPlayerDistance = 20
if dist > attackDistance and dist < spotPlayerDistance then
if timer > (oldTimer + attackTimer) and dist < attackDistance then
..now the monster only comes after you if you get too close to her.
Your full Amazon.lua file should looks as below...
oldTimer = 0
function moveAmazon (objnum,timer,dist)
monsterName = "Amazon"
attackDistance = 3
spotPlayerDistance = 20
moveSpeed = 0.2
attackStrength = 10
-- 1000 = 1 second
attackTimer = 3*1000
-- Get the position of the camera
cx,cy,cz = CamInfo()
-- Keep the Amazon on the floor
cy = 0
-- Move the Amazon if she is not yet at the camera
if dist > attackDistance and dist < spotPlayerDistance then
PointObject(objnum,cx,cy,cz)
MoveObject(objnum,moveSpeed)
else
-- Do an attack if we are at the camera position and the timer allows it
if timer > (oldTimer + attackTimer) and dist < attackDistance then
oldTimer = timer
return attackStrength,monsterName
else
return 0,monsterName
end
end
end
http://www.KumKie.com http://bulldog.servegame.com