View unanswered posts | View active topics It is currently Sat Jan 11, 2025 10:19 am



Reply to topic  [ 4 posts ] 
 Lua module dump 
Author Message
happy carebear mom
User avatar

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7096
Location: b8bbd5
Reply with quote
Post 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 205 times


Fri May 22, 2009 10:08 pm
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post 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
Sat May 23, 2009 5:59 pm
Profile
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1360
Location: USA
Reply with quote
Post 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.


Wed Jun 10, 2009 6:49 pm
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post 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


Thu Jun 11, 2009 8:09 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.104s | 16 Queries | GZIP : Off ]