Data Realms Fan Forums
http://45.55.195.193/

Lua module dump
http://45.55.195.193/viewtopic.php?f=73&t=14874
Page 1 of 1

Author:  Duh102 [ Fri May 22, 2009 10:08 pm ]
Post subject:  Lua module dump

After Daman's suggestion, this is for .lua files that do one thing and do it well, IE, modules. Post whatever you like here, but you must be willing to let others use it without permission. Also, you must document your code for ease of use.

I'll start with my homing missile code.
To use, somewhere in the Create() in the .lua for your projectile put
Code:
self.LTimer = Timer();
dofile("*RTE name*/missile.lua");

and when you want your projectile to home in, put
Code:
HomeInOn(self, self.target, 0.5, 30, 200, 600);

The parameters are
Code:
HomeInOn(projectile, target, turnspeed, maxspeed, lagtime, radius)

projectile to home in (usually self) which must have the above timer LTimer
target actor
turnspeed in arbitrary value, 0.5 is pretty fast
maxspeed in another arbitrary value, a bit less than normal CC m/s
lagtime from when the projectile is created until it activates
radius to search for a target when activating

Pic:
Image
And DL:
Mediafire
OR
Attachment:
HomingMissile.rar [872 Bytes]
Downloaded 206 times

Author:  mail2345 [ Sat May 23, 2009 5:59 pm ]
Post subject:  Re: Lua module dump

Here is some code for easily making a global actor controller, used to fake ability to inject functions.
Like in my infection zombie and health implant mods.
actorupdatefunc has to return either true are false. Returning true deletes the actor from the table(like the disease being cured). The function has to have one argument - the actor. actordestroyfunc will not have it's return value read, and is send the actor.
If you only want one, just have the other be a blank function, like
Code:
function actordestroyfunc(actor)

end


In create put:
Code:
dofile("Module.rte/GlobalControl.lua")
local ti = controlerinit(self, thetablewhichyouwishtoprocess, anunusedglobalvariable)
self.DNS = ti[1] -- Copy back variables
thetablewhichyouwishtoprocess = ti[2]
self.Lifetime = ti[3]
anunusedglobalvariable = true


In destroy put:
Code:
if self.DNS == 0 then -- Check if it's the real controller
thetablewhichyouwishtoprocess = nil -- Clear variables
anunusedglobalvariable = false
end


In update put:
Code:
thetablewhichyouwishtoprocess = controller-work(thetablewhichyouwishtoprocess, actorupdatefunc, actordestroyfunc)


EDIT: Example:
Code:


function actorupdatefunc(actor)
actor.Health = math.random(0,200)
if actor.Health == 0 then
return true
else
return false
end
end

function actordestroyfunc(acotr)
end

function Create(self)
dofile("Module.rte/GlobalControl.lua")
local ti = controlerinit(self, thetablewhichyouwishtoprocess, anunusedglobalvariable)
self.DNS = ti[1] -- Copy back variables
thetablewhichyouwishtoprocess = ti[2]
self.Lifetime = ti[3]
anunusedglobalvariable = true
end

function Destroy(self)
local ti = controlerend(self, thetablewhichyouwishtoprocess, anunusedglobalvariable)
thetablewhichyouwishtoprocess = ti[1] -- Copy back
anunusedglobalvariable = ti[2]
end

function Update(self)
thetablewhichyouwishtoprocess = controlerupdate(thetablewhichyouwishtoprocess, actorupdatefunc, actordestroyfunc)
end

Randomizes health of actors in list.

Attachments:
Module.rte.7z [851 Bytes]
Downloaded 192 times

Author:  Mind [ Wed Jun 10, 2009 6:49 pm ]
Post subject:  Lua Module Dump

Code:
function Create(self)
end

function Update(self)
   for actor in MovableMan.Actors do
      local diff = math.sqrt(math.pow((actor.Pos.X-self.Pos.X),2) + math.pow((actor.Pos.Y - self.Pos.Y),2))
            if (diff < 200) and actor.Team ~= self.Team then
         actor:DropAllInventory();
         for item in MovableMan.Items do
            if (diff < 200) then
               item.Pos.X = self.Pos.X + math.random(-10,10)
               item.Pos.Y = self.Pos.Y + math.random(-10,10)
               if item.ClassName == "TDExplosive" then
                  item.Pos.X = self.Pos.X - 40
                  item.Pos.Y = self.Pos.Y
               end
            end
         end
      end
   end
end


This will take your enemies items and place them within a 10 pixel range of you, but if it is a bomb, it will discard it 40 pixels to the right.

Author:  mail2345 [ Thu Jun 11, 2009 8:09 pm ]
Post subject:  Re: Lua module dump

I think it needs to be in a lua file, as a function like:
Code:
function StealStuff(self)
   for actor in MovableMan.Actors do
      local diff = math.sqrt(math.pow((actor.Pos.X-self.Pos.X),2) + math.pow((actor.Pos.Y - self.Pos.Y),2))
            if (diff < 200) and actor.Team ~= self.Team then
         actor:DropAllInventory();
         for item in MovableMan.Items do
            if (diff < 200) then
               item.Pos.X = self.Pos.X + math.random(-10,10)
               item.Pos.Y = self.Pos.Y + math.random(-10,10)
               if item.ClassName == "TDExplosive" then
                  item.Pos.X = self.Pos.X - 40
                  item.Pos.Y = self.Pos.Y
               end
            end
         end
      end
   end
end

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/