View unanswered posts | View active topics It is currently Thu Dec 26, 2024 3:21 pm



Reply to topic  [ 134 posts ]  Go to page 1, 2, 3, 4, 5 ... 9  Next
 Lua based map objects, help! (BW related) 
Author Message

Joined: Sat Jan 13, 2007 11:04 pm
Posts: 2932
Reply with quote
Post Lua based map objects, help! (BW related)
I need some help on Lua code. There are 2 things:

Launch Pad

I just made an object with area that is supposed to launch items and/or actors at a certain speed and certain direction.


Code:
So the code would need to check if theres an actor/item inside its area and launch it at a predefined velocity and direction based on the angle of the "area object" which is an MOSR. Default launch direction would be up.




Teleporter

The teleporter is supposed to move a actor to any another teleporter on the map. Including itself (Incase its the only one, or youre just lucky to teleport nowhere :P ) When an actor enters a teleporter, it will teleport him after a 3 second delay. Another thing is, if there is someone already in a teleporter and someone from another teleporter was moved to this exact teleporter which is in use, it will instantly gib the actor (Telefrag).


Code:
The code would need to check if theres an actor within the area of the teleporter object and start a timer. After 3 seconds, the teleporter check for any other teleporter object in the scene and randomly move the actor to one of them.

If the actor leaves the area at any point before he is "teleported", everything will reset immediatly.

While another actor is being teleported, anyone who had teleported earlier and landed on that teleporter will be instantly gibbed. [optional]



Thanks in advance!


Sat Apr 18, 2009 9:39 pm
Profile
User avatar

Joined: Mon Jun 30, 2008 9:13 pm
Posts: 499
Location: Finland
Reply with quote
Post Re: Lua based map objects, help! (BW related)
Launch pad:
Code:
for actor in MovableMan.Actors do
   if SceneMan.Scene:WithinArea("name of area" , actor.Pos) then
      actor.Velocity = Vector(X , Y))
   end
end

Teleport:
Code:
for actor in MovableMan.Actors do
if SceneMan.Scene:WithinArea("ATeleportArea" , actor.Pos) then
   local area = SceneMan.Scene:GetArea(self.ListOfTeleports[math.random(#self.ListOfTeleports)])
   // insert code for 3 seconds delay here
   for actor2 in MovableMan.Actors do
      if  SceneMan.Scene:WithinArea(area.Name , actor2.Pos) then  // area.Name is just a guess at what would the area's name variable be. Just a plain area might do too.
         actor2:GibThis()
      end
   end
   actor.Pos = Vector( area:GetRandomPoint().X , area:GetRandomPoint().Y)  //possibly a  non-random way of doing this is possible
end
end

This requires a line around the start of the .lua:
Code:
self.ListOfTeleports = {"Area1" , "Area2" , ...}

You also have to check all different areas to see if someone is in them.


Last edited by piipu on Sat Apr 18, 2009 11:16 pm, edited 2 times in total.



Sat Apr 18, 2009 11:07 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Lua based map objects, help! (BW related)
You're also going to have to set areas manually in the scene code; you can't have placable bunkermodules or anything.


Sat Apr 18, 2009 11:15 pm
Profile
happy carebear mom
User avatar

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7096
Location: b8bbd5
Reply with quote
Post Re: Lua based map objects, help! (BW related)
Grif wrote:
you can't have placable bunkermodules or anything.

Depends on if nummy got his copy of the b23 beta.


Sat Apr 18, 2009 11:18 pm
Profile
User avatar

Joined: Mon Jun 30, 2008 9:13 pm
Posts: 499
Location: Finland
Reply with quote
Post Re: Lua based map objects, help! (BW related)
You could also check if there are any actors within a small square area above an object called Telepad but that would require quite some code.


Sat Apr 18, 2009 11:19 pm
Profile

Joined: Sat Jan 13, 2007 11:04 pm
Posts: 2932
Reply with quote
Post Re: Lua based map objects, help! (BW related)
Duh102 wrote:
Grif wrote:
you can't have placable bunkermodules or anything.

Depends on if nummy got his copy of the b23 beta.


Keep in mind that its for B23 and it does NOT use scene areas. It uses a blank MOSRotating object instead which acts as the "node of actions" or an "area" in the module.

The MOSRotating has a blank sprite with the same size of that module so you could consider the MOSR being the "area"

Anyways TLB did some code for another... object which will be available in B23 officially. I'm fairly sure some of this code could be used to make the systems work in the way I intended them.

Heres the Lua code: http://rafb.net/p/rNrLns78.html

Try using that to make the launcher/teleporter code. Please :)


Sun Apr 19, 2009 5:38 pm
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Lua based map objects, help! (BW related)
I'll give it a shot:
Launch Pad:
Code:
function Update(self)
for actor in MovableMan.actors do
if (actor.Pos.X >= self.Pos.X - distance) and (actor.Pos.X <= self.Pos.X + distance) and (actor.Pos.Y >= self.Pos.Y - distance) and (actor.Pos.Y <= self.Pos.Y + distance) and (actor.PinStrength <= 0)
then
actor.Velocity = Vector(X , Y)
end
end


Sun Apr 19, 2009 6:05 pm
Profile
User avatar

Joined: Fri Apr 27, 2007 4:55 pm
Posts: 1178
Location: America!
Reply with quote
Post Re: Lua based map objects, help! (BW related)
Depending on how Data is messing with loading the lua scripts, you should be able to do something like

Code:
function Create(self)
    if(!_teleporters) then
        _teleporters = {self}
    else
        table.insert(_teleporters,self)
    end
end

function Destroy(self)
    table.remove(_teleporters,self)
end


Which should put the table "_teleporters" into the global lua context. That way you will be able to have a list of all the available teleporters from any object. Then you could just go through the list of teleporters until you get to the one you're looking for(maybe just the one after the current teleporter) and sets the object to be teleported's position to the new teleporter position.

Code:
function Update(self)
    if(#_teleporters > 1) then
    for actor in MovableMan.Actors do
        --check if the actor is in the teleporter area
        if(above) then
            for i,j in ipairs(_teleporters) do
                if(j == self) then
                    if(_teleporters[j+1] == nil)
                        actor.Pos = _teleporters[0].Pos
                    else
                        actor.Pos = _teleporters[j+1].Pos
                    end
                end
            end
        end
    end
    end
end


EDIT: Also the three second delay can be done pretty easily by using timer objects and a boolean that gets set when an actor first enters the area.

Also, make Data allow us to add lua functions to the object.

I.E.
Quote:
function Create(self)
end
function Destroy(self)
end
function Update(self)
end
function DoStuff(self)
end


Sun Apr 19, 2009 6:42 pm
Profile

Joined: Sat Jan 13, 2007 11:04 pm
Posts: 2932
Reply with quote
Post Re: Lua based map objects, help! (BW related)
Lord Tim wrote:

EDIT: Also the three second delay can be done pretty easily by using timer objects and a boolean that gets set when an actor first enters the area.


How do I do that? I know next to nothing on how Lua works. :p


Quote:
Also, make Data allow us to add lua functions to the object.

I.E.
Quote:
function Create(self)
end
function Destroy(self)
end
function Update(self)
end
function DoStuff(self)
end


Those already exist. (In B23, that is.)
Check the link I posted: http://rafb.net/p/rNrLns78.html

That is an actual working object in B23 made by TheLastBanana.
I though it could be used to build the launcher.

I'll try out mail2345's code, I hope it works. :grin:


Sun Apr 19, 2009 6:59 pm
Profile
User avatar

Joined: Sun May 11, 2008 12:50 pm
Posts: 899
Reply with quote
Post Re: Lua based map objects, help! (BW related)
numgun wrote:
Check the link I posted: http://rafb.net/p/rNrLns78.html
That is an actual working object in B23 made by TheLastBanana.
I though it could be used to build the launcher.

Conveyor belts?


Sun Apr 19, 2009 7:28 pm
Profile WWW

Joined: Sat Jan 13, 2007 11:04 pm
Posts: 2932
Reply with quote
Post Re: Lua based map objects, help! (BW related)
Roon3 wrote:
Conveyor belts?


Wrong. Launch pad and a teleporter. :wink:


Sun Apr 19, 2009 8:36 pm
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post Re: Lua based map objects, help! (BW related)
Numgun, I think Roon3 means the script you posted that I made :P
If that's the case, yes.
Conveyor belts.
Also, those scripts aren't entirely finished. The ones you have right now will crash the game if it is restarted when any actors are still in play. Oh well :P


Sun Apr 19, 2009 11:21 pm
Profile WWW
User avatar

Joined: Fri Apr 27, 2007 4:55 pm
Posts: 1178
Location: America!
Reply with quote
Post Re: Lua based map objects, help! (BW related)
I already knew about the create, update, destroy ones, I was just wondering about the ability to add data to the objects themselves. Because as it is right now in B22, everything gets reset. If you can do the "self.speed" bit, it shouldn't be a problem. (That doesn't work in B22)


Sun Apr 19, 2009 11:54 pm
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post Re: Lua based map objects, help! (BW related)
Yep, you can declare functions and variables within an object and they'll stay there. You just can't access them from other objects.


Mon Apr 20, 2009 12:27 am
Profile WWW

Joined: Sat Jan 13, 2007 11:04 pm
Posts: 2932
Reply with quote
Post Re: Lua based map objects, help! (BW related)
It works!!!

Image

The launch pads are functional!
You can make hilarious a mercenary pinball with these! xD


The teleporter didnt work with the code Lord Tim suggested. I didnt get any errors, but the teleporters didnt teleport me anywhere. Would the script require that the teleporters were pre-placed on the scene?
Because I only tried them by putting them straight on the scene in skirmish.


Mon Apr 20, 2009 1:06 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 134 posts ]  Go to page 1, 2, 3, 4, 5 ... 9  Next

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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.047s | 14 Queries | GZIP : Off ]