View unanswered posts | View active topics It is currently Thu Dec 26, 2024 5:36 am



Reply to topic  [ 7 posts ] 
 Attached AHumans? 
Author Message
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post Attached AHumans?
I'm trying to make an actor that uses lua to set its position according to another actor's, like the dreadnought with turrets that P3lbox made. The difference is, I want the actors to attach or detach from each other based on a variable set by a pressed key. I've made this chunk of code: ( pasting it here messed it up a little)

Code:
function Create(self)
-- The variables:
   self.LilBusters = false;
   
end

function Update(self)
   for actor in MovableMan.Actors do
         if actor:IsInGroup("LowLegs") then
         local avgx = actor.Pos.X - self.Pos.X;
         local avgy = actor.Pos.Y - self.Pos.Y;
         local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
            if self:IsPlayerControlled() and UInputMan:KeyPressed(18) and self.LilBusters == false then
               if dist < 50 then
                        self.LilBusters = true;   
                  print ("LilBusters is ON");   
                  end
            if self:IsPlayerControlled() and UInputMan:KeyPressed(18) and self.LilBusters == true then
               if dist < 50 then
                        self.LilBusters = false;
                  print ("LilBusters is OFF");      
                  end
            end
            if self.LilBusters == true then
               self.Pos.X = actor.Pos.X;
               self.Pos.Y = actor.Pos.Y;
            end
         end
      end
   end
end


It doesn't work, for no apparent reason. No error messages appear, the actors don't attach, nothing happens at all. I know that the script is active, as I tried typing some random values between the variables, and that made error messages appear.
Can anyone explain me what's wrong?


Mon May 25, 2009 4:20 pm
Profile WWW
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Attached AHumans?
If it doesn't print then something's wrong with your logic statements.


Mon May 25, 2009 6:56 pm
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post Re: Attached AHumans?
After following Grif's advice and reviewing the statements, I came up with this much shorter and neater piece of code:
Code:
function Create(self)
-- The variables:
   self.LilBusters = false;
   
end

function Update(self)
   for actor in MovableMan.Actors do
      local avgx = actor.Pos.X - self.Pos.X;
      local avgy = actor.Pos.Y - self.Pos.Y;
      local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
      if not actor.IsActor then
         if self.LilBusters == true then
            self.LilBusters = false;
            print ("LilBusters is OFF due to destruction");
         end
      end
--      if dist > 50 and self.LilBusters == true then
--         self.LilBusters = false;
--         print ("LilBusters is OFF due to distance");
--      end
      if actor:IsInGroup("LowLegs") and dist < 50 then
         if self:IsPlayerControlled() and self.LilBusters == false and UInputMan:KeyPressed(18) then
            self.LilBusters = true;   
            print ("LilBusters is ON");
         end
         if self:IsPlayerControlled() and self.LilBusters == true and UInputMan:KeyPressed(20) then
            self.LilBusters = false;   
            print ("LilBusters is OFF due to manual activation");
         end
         if self.LilBusters == true then
            self.Pos.X = actor.Pos.X;
            self.Pos.Y = actor.Pos.Y - 50;
         end
      end
   end
end

 


Then I put the two actors close to each other, pressed the "R" key and, surprisingly enough, it worked. The actors attached to each other. There was one... minor problem, though. The attached actor's limbs started to slowly descend, like gooey jelly dripping out from a dark green ice cube. While I was puzzled trying to decipher where that disgusting comparison I made originated itself, the upper actor's arm touched the lower actor's head. On less time that it takes to wink an eye, both actors accelerated to velocities rarely seen by human eyes, immediately covering the surrounding terrain with their blood and mutilated guts.

As entertaining as that may be, it is not, by any means, what I intended them to do. Does someone know what is causing such effect? Any help is appreciated.

(By the way, I made some experiments, and discovered that the farther one actor is from the other, the longer they take to explode, and the faster their body parts fly.)


Mon May 25, 2009 9:58 pm
Profile WWW
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Attached AHumans?
That sounds hilarious, I'd say release it like that.


Mon May 25, 2009 10:05 pm
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post Re: Attached AHumans?
Sure, if you say so. :)

To activate it, you have to buy the upper and lower parts, get them close to each other, select the upper part and then press R.


Attachments:
File comment: The prototype!
2InOne.rte.rar [59.33 KiB]
Downloaded 217 times
Mon May 25, 2009 10:18 pm
Profile WWW
User avatar

Joined: Thu May 15, 2008 11:40 am
Posts: 1527
Location: In heaven, everything is fine.
Reply with quote
Post Re: Attached AHumans?
Very buggy. That poor guy is crushed after a few seconds after combination.


Tue Jun 02, 2009 6:19 am
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Attached AHumans?
The Decaying Soldat wrote:
Very buggy. That poor guy is crushed after a few seconds after combination.


Awesome job reading there el capitan.


Tue Jun 02, 2009 3:06 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.092s | 14 Queries | GZIP : Off ]