View unanswered posts | View active topics It is currently Fri Dec 27, 2024 5:49 am



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

Joined: Wed Jan 07, 2009 10:26 am
Posts: 4074
Location: That quaint little British colony down south
Reply with quote
Post Re: Lua based map objects, help! (BW related)
Does it work with anything or just actors? It'd be interesting to stand next to one firing so as to accelerate your bullets...


Mon Apr 20, 2009 1:09 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)
No I dont think it will affect MOPixels, but it should throw guns and other items like actors.

Im just thinking is a teleporter even possible if an object cant access another. Can it atleast check if there are objects that are the same as the teleporter?


Mon Apr 20, 2009 1:14 pm
Profile

Joined: Sat Jan 13, 2007 11:04 pm
Posts: 2932
Reply with quote
Post Re: Lua based map objects, help! (BW related)
piipu wrote:
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.


This is a very good method, but its tied to scene pre-placed and pre-defined areas.
Is there a way that this code could be converted to use MOSR objects as the areas?

And how do I do a 3 second delay with a boolean to check is there an actor inside the teleporter? : /


Mon Apr 20, 2009 1:50 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)
Code:
function Update(self)
for actor in MovableMan.actors do
  if (actor.Pos.X >= Teleporter.Pos.X - self.distance) and (Teleporter.Pos.X <= Teleporter.Pos.X + self.distance)
  and (actor.Pos.Y >= Teleporter.Pos.Y - self.distance) and (actor.Pos.Y <= Teleporter.Pos.Y + self.distance) then // set self.distance to some nice value beforehand
    if not(Teleporter.activated == 1) then
      Teleporter.Timer = Timer()
      Teleporter.Timer:Reset();
      Teleporter.activated = 1
    else
      if Teleporter.Timer:IsPastSimMS(3000) then
        if [copypaste the first if statement here to see if the actor has stepped out of the area] then
         for actor2 in MovableMan.Actors do
           if  [insert long if thingy here, replace actor with actor2] then
             actor2:GibThis()
           end
         end
        Teleporter.activated = 0
        end
      end
    end
  end
end

I think you can modify that to make it work.
edit: added a check to see that the actor hasn't stepped out.
Problems I can think of: Actor doesn't have to be in the teleporter for the 3 seconds, just the ending and start.
If there are more actors in the teleporter, they will all be teleported. This may not be a problem.
Teleporter.Timer may not work. You could change it to self.Timer, but then the whole network would activate and reset at once.
editedit: added some more. This is getting messy.


Last edited by piipu on Mon Apr 20, 2009 2:35 pm, edited 1 time in total.



Mon Apr 20, 2009 2:20 pm
Profile

Joined: Sat Jan 13, 2007 11:04 pm
Posts: 2932
Reply with quote
Post Re: Lua based map objects, help! (BW related)
Code:
//do that stuff in the other post


What do I do here? : S
Which post are you talking about? LordTim's or yours?


piipu wrote:
Code:
// set self.distance to some nice value beforehand


What is this for? : 0


Code:
        if [copypaste the first if statement here to see if the actor has stepped out of the area] then


Buh? What statement? = I


Last edited by numgun on Mon Apr 20, 2009 2:37 pm, edited 1 time in total.



Mon Apr 20, 2009 2:31 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)
Fixed that.


Mon Apr 20, 2009 2:36 pm
Profile

Joined: Sat Jan 13, 2007 11:04 pm
Posts: 2932
Reply with quote
Post Re: Lua based map objects, help! (BW related)
Gah my head is going to explode. ;_;
I barely understand anything from the code. *Bangs head against wall*

Someone help! :roll:


EDIT: Am I doing this right? : O

Code:
function Create(self)
    self.distance = 10
end


function Destroy(self)

end


function Update(self)
for actor in MovableMan.actors do
  if (actor.Pos.X >= Teleporter.Pos.X - self.distance) and (Teleporter.Pos.X <= Teleporter.Pos.X + self.distance)
  and (actor.Pos.Y >= Teleporter.Pos.Y - self.distance) and (actor.Pos.Y <= Teleporter.Pos.Y + self.distance) then
    if not(Teleporter.activated == 1) then
      Teleporter.Timer = Timer()
      Teleporter.Timer:Reset();
      Teleporter.activated = 1
    else
      if Teleporter.Timer:IsPastSimMS(3000) then
        if (actor.Pos.X >= Teleporter.Pos.X - self.distance) and (Teleporter.Pos.X <= Teleporter.Pos.X + self.distance)
        and (actor.Pos.Y >= Teleporter.Pos.Y - self.distance) and (actor.Pos.Y <= Teleporter.Pos.Y + self.distance) then
         for actor2 in MovableMan.Actors do
           if  (actor.Pos.X >= Teleporter.Pos.X - self.distance) and (Teleporter.Pos.X <= Teleporter.Pos.X + self.distance)
           and (actor.Pos.Y >= Teleporter.Pos.Y - self.distance) and (actor.Pos.Y <= Teleporter.Pos.Y + self.distance) then
             actor2:GibThis()
           end
         end
        Teleporter.activated = 0
        end
      end
    end
  end
end




EDIT2: dont know if its revelant, but heres what the object the Lua code is tied to:

Code:
AddActor = MOSRotating
   PresetName = Teleporter Node


Mon Apr 20, 2009 2:41 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)
Code:
function Update(self)
for actor in MovableMan.actors do
  if (actor.Pos.X >= Teleporter.Pos.X - self.distance) and (Teleporter.Pos.X <= Teleporter.Pos.X + self.distance)
  and (actor.Pos.Y >= Teleporter.Pos.Y - self.distance) and (actor.Pos.Y <= Teleporter.Pos.Y + self.distance) then // This checks if any actor is within a square the size of self.distance of the teleporter.
    if not(Teleporter.activated == 1) then // see if teleporter is activated
      Teleporter.Timer = Timer() // if not, set a timer for the teleporter, reset it just to
      Teleporter.Timer:Reset();  // be sure and set the teleporter activated
      Teleporter.activated = 1
    else // if it is activated, wait until the timer has been on for 3 seconds, then check if the actor is
      if Teleporter.Timer:IsPastSimMS(3000) then  //still in the teleporter.
        if [copypaste the first if statement here to see if the actor has stepped out of the area] then
         Teleporter2 =              //whoops, there's a hole here! maybe LordTim can help with this.
// if the actor is still in the area, select a random teleporter to be the target.
         for actor2 in MovableMan.Actors do  // go through all actors on the map, see if anyone is inside the target.
           if  [insert long if thingy here, replace actor with actor2 and Teleporter with Teleporter2] then
             actor2:GibThis()  // if there's anyone in the target teleporter, gib them.
           end
         end
        Teleporter.activated = 0  // deactivate the teleporter so the delay will happen again.
        end
      end
    end
  end
end

That should clear it up some. This method needs some way of setting Teleporter2 as a random teleporter on the scene, but I can't think of a way right now. Maybe LordTim knows.

edit: this way, your actor will get gibbed if you end up in the same teleport you started from.


Mon Apr 20, 2009 2:54 pm
Profile

Joined: Sat Jan 13, 2007 11:04 pm
Posts: 2932
Reply with quote
Post Re: Lua based map objects, help! (BW related)
After some copy pasta and elaborate thinking, I came up with this:

Code:
function Create(self)
    if(! _teleporters) then --ERROR HERE, UNEXPECTED SYMBOL AFTER !
         _teleporters = {self}
    else
        table.insert(_teleporters,self)
    end
    self.teledelaytimer = Timer();
   self.teleactivate = nil;
end

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


function Update(self)
   if(#_teleporters > 1) then
    for actor in MovableMan.Actors do
      if (actor.Pos.X >= self.Pos.X - 24) and (actor.Pos.X <= self.Pos.X + 24) and (actor.Pos.Y >= self.Pos.Y - 25) and (actor.Pos.Y <= self.Pos.Y + 25) and (actor.PinStrength <= 0) then // This checks if any actor is within a square the size of self.distance of the teleporter.

         if MovableMan:IsParticle(self.teleactivate) == false then
            self.teleactivate = CreateAEmitter("Teleport Activation");
            self.teleactivate:EnableEmission(true);
            self.teleactivate.Pos = Vector(0,0);
            MovableMan:AddParticle(self.teleactivate);
         end
         if self.teledelaytimer:LeftTillSimMS(3000) > 0 then
            self:AddObjectivePoint("Teleporting: " .. math.ceil(self.teleactivate:LeftTillSimMS(3000)/1000) .. " sec", Vector(0, 0),  GameActivity.ARROWDOWN); --Removed "Activity.TEAM_1," from here.
         end
         if -self.teledelaytimer:LeftTillSimMS(0) > 3000 then
         --TELEPORTATION HAPPENS HERE
            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
      else
         self.teledelaytimer:Reset();
         if MovableMan:IsParticle(self.teleactivate) then
            self.teleactivate.Lifetime = 1;
         end
      end



Contains part of code from LordTim's code, but it has an error on line 2 and it says "UNEXPECTED SYMBOL AFTER "!"".

Whats wrong with that?

And how would I incorporate telefragging with this?


Mon Apr 20, 2009 8:16 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)
Thats an intresting method :P Anyway, that error line should maybe be
Code:
if not(_teleporters) then

Not sure about that tho'.
Telefrag:
Code:
            for i,j in ipairs(_teleporters) do
               if(j == self) then
                  if(_teleporters[j+1] == nil)
                    for actor2 in MovableMan.Actors do
                      if ((actor2.Pos.X >= _teleporters[0].Pos.X - 24) and (actor2.Pos.X <= _teleporters[0].Pos.X + 24) and (actor2.Pos.Y >= _teleporters[0].Pos.Y - 25) and (actor2.Pos.Y <= _teleporters[0].Pos.Y + 25) then
                        actor2:GibThis();
                      end
                    end
                    actor.Pos = _teleporters[0].Pos
                  else
                    for actor2 in MovableMan.Actors do
                      if ((actor2.Pos.X >= _teleporters[j+1].Pos.X - 24) and (actor2.Pos.X <= _teleporters[j+1].Pos.X + 24) and (actor2.Pos.Y >= _teleporters[j+1].Pos.Y - 25) and (actor2.Pos.Y <= _teleporters[j+1].Pos.Y + 25) then
                        actor2:GibThis();
                      end
                    end
                     actor.Pos = _teleporters[j+1].Pos
                  end
               end
            end

edit: fixed wrong teleporter from telefragging
edit2: Looking at LordTim's post, it's
Code:
if (!_teleporters) then

without the space. Try that too. I have no idea about table syntax.


Mon Apr 20, 2009 9:03 pm
Profile

Joined: Sat Jan 13, 2007 11:04 pm
Posts: 2932
Reply with quote
Post Re: Lua based map objects, help! (BW related)
Heres an updated code. It gives no errors, but it doesnt work either. Nothing happens when I get an actor inside a teleporter. : /

Wierd stuff. I added the telefrag you made anyways.

Code:
function Create(self)
    if not(_teleporters) then --I think that not must be inside the brackets, not sure : S
         _teleporters = {self}
    else
        table.insert(_teleporters,self)
    end
    self.teledelaytimer = Timer();
   self.teleactivate = nil;
end

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


function Update(self)
   if(#_teleporters > 1) then
    for actor in MovableMan.Actors do
      if (actor.Pos.X >= self.Pos.X - 24) and (actor.Pos.X <= self.Pos.X + 24) and (actor.Pos.Y >= self.Pos.Y - 25) and (actor.Pos.Y <= self.Pos.Y + 25) and (actor.PinStrength <= 0) then

         if MovableMan:IsParticle(self.teleactivate) == false then
            self.teleactivate = CreateAEmitter("Teleport Activation");
            self.teleactivate:EnableEmission(true);
            self.teleactivate.Pos = Vector(0,0);
            MovableMan:AddParticle(self.teleactivate);
         end
         --if self.teledelaytimer:LeftTillSimMS(3000) > 0 then
            --self:AddObjectivePoint("Teleporting: " .. math.ceil(self.teleactivate:LeftTillSimMS(3000)/1000) .. " sec", Vector(0, 0),  GameActivity.ARROWDOWN); --Removed "Activity.TEAM_1," from here.
         --end
         if -self.teledelaytimer:LeftTillSimMS(0) > 3000 then
         --TELEPORTATION HAPPENS HERE
            for i,j in ipairs(_teleporters) do
            if(j == self) then
               if(_teleporters[j+1] == nil)
               for actor2 in MovableMan.Actors do
                  if ((actor2.Pos.X >= _teleporters[0].Pos.X - 24) and (actor2.Pos.X <= _teleporters[0].Pos.X + 24) and (actor2.Pos.Y >= _teleporters[0].Pos.Y - 25) and (actor2.Pos.Y <= _teleporters[0].Pos.Y + 25) then
                  actor2:GibThis();
                  end
                    end
                    actor.Pos = _teleporters[0].Pos
               else
               for actor2 in MovableMan.Actors do
                  if ((actor2.Pos.X >= _teleporters[j+1].Pos.X - 24) and (actor2.Pos.X <= _teleporters[j+1].Pos.X + 24) and (actor2.Pos.Y >= _teleporters[j+1].Pos.Y - 25) and (actor2.Pos.Y <= _teleporters[j+1].Pos.Y + 25) then
                  actor2:GibThis();
                  end
                    end
                     actor.Pos = _teleporters[j+1].Pos
               end
               end
            end
         end
      else
         self.teledelaytimer:Reset();
         if MovableMan:IsParticle(self.teleactivate) then
            self.teleactivate.Lifetime = 1;
         end
      end
   end   
   end
end


Mon Apr 20, 2009 9:13 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)
See if console gives any errors during playing. And try that
Code:
if (!_teleporters) then
stuff


Mon Apr 20, 2009 9:35 pm
Profile

Joined: Sat Jan 13, 2007 11:04 pm
Posts: 2932
Reply with quote
Post Re: Lua based map objects, help! (BW related)
Your telefrag code had some extra "(" symbols at some parts that caused errors.

Now I dont know if this is even right, but I re-did the "not" part on line 2.
Heres the latest code, now with no special effects and much more simple.
No errors, but teleporters dont work. :-(

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

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


function Update(self)
   if(#_teleporters > 1) then
    for actor in MovableMan.Actors do
      if (actor.Pos.X >= self.Pos.X - 24) and (actor.Pos.X <= self.Pos.X + 24) and (actor.Pos.Y >= self.Pos.Y - 25) and (actor.Pos.Y <= self.Pos.Y + 25) and (actor.PinStrength <= 0) then
            for i,j in ipairs(_teleporters) do
            if(j == self) then
               if(_teleporters[j+1] == nil) then
               for actor2 in MovableMan.Actors do
                  if (actor2.Pos.X >= _teleporters[0].Pos.X - 24) and (actor2.Pos.X <= _teleporters[0].Pos.X + 24) and (actor2.Pos.Y >= _teleporters[0].Pos.Y - 25) and (actor2.Pos.Y <= _teleporters[0].Pos.Y + 25) then
                  actor2:GibThis();
                  end
                    end
                    actor.Pos = _teleporters[0].Pos
               else
               for actor2 in MovableMan.Actors do
                  if (actor2.Pos.X >= _teleporters[j+1].Pos.X - 24) and (actor2.Pos.X <= _teleporters[j+1].Pos.X + 24) and (actor2.Pos.Y >= _teleporters[j+1].Pos.Y - 25) and (actor2.Pos.Y <= _teleporters[j+1].Pos.Y + 25) then
                  actor2:GibThis();
                  end
                    end
                     actor.Pos = _teleporters[j+1].Pos
               end
               end
            end
      end
   end   
   end
end


Mon Apr 20, 2009 9:52 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)
Right, I should explain what I did.

First of all, the code I wrote, I did directly into the browser, with no tests whatsoever. I forgot that Lua doesn't use "!". Instead you should be able to use either "not _teleporters" or "_teleporters == nil". Both should return true when the table has not yet been initialized.

The "_teleporters" is designed to be a global table that will just be sitting in the Lua context. So every object with a Lua script will be able to access that table. Essentially, you don't want to be doing the _teleporters = 0 bit, because that will reset the table every time a new teleporter is added.

The thing that could potentially happen if you haven't added the delay code is that instantly after teleporting your actor, it teleports him right back. You should notice this, though, since the actor won't be able to move anymore.

There should always be at least two teleporters because of the check "if(#_teleporters > 1) then", where "#" is just the operator that gets the size of the table.

The bit with
Code:
for i,j in ipairs(_teleporters) do
if(j == self) then
if(_teleporters[j+1] == nil) then
--etc
else
--etc
end

is just going through the global list of teleporters one by one until it gets to the current teleporter. When it finds that, it attempts to teleport to the next one in that global list. If that one doesn't exist (your teleporter is at the end of the list), then it tries to teleport to the first one in the list, which I just realized will be at [1] instead of [0], because Lua arrays always start at 1, so that needs to be fixed too.

I'll think about the timing bit and post later.


Tue Apr 21, 2009 2:11 am
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 cut half the code off just by using _teleporter[math.rand(1,#_teleporter)] as the target. I'll see about that after school, I don't have time right now.


Tue Apr 21, 2009 6:56 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 134 posts ]  Go to page Previous  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.032s | 14 Queries | GZIP : Off ]