Data Realms Fan Forums
http://45.55.195.193/

Code activation problems
http://45.55.195.193/viewtopic.php?f=73&t=15452
Page 1 of 1

Author:  Areku [ Sat Jun 20, 2009 9:05 pm ]
Post subject:  Code activation problems

Decided to script some more. Here's what I've got so far:

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

function Update(self)
   
   if self.AmIHere == false then
      for actor in MovableMan.Actors do
            if not actor.PresetName == "Red" 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 dist > 5 and dist < 1000 and actor.Pos.X > self.Pos.X then
                     self.Pos.X = self.Pos.X - 1;
            end
            if dist > 5 and dist < 1000 and actor.Pos.X < self.Pos.X then
                     self.Pos.X = self.Pos.X + 1;
            end
            if dist > 5 and dist < 1000 and actor.Pos.Y > self.Pos.Y then
                     self.Pos.Y = self.Pos.Y - 1;
            end
            if dist > 5 and dist < 1000 and actor.Pos.Y < self.Pos.Y then
                     self.Pos.Y = self.Pos.Y + 1;
            end
            if dist < 5 then
               actor:GibThis();
               self.AmIHere = true;
            end
            
               
         
            
            end
      end
   end

   if self.AmIHere == true then
      for ridinghood in MovableMan.Actors do
            if actor.PresetName == "Red" then
            local avgx = ridinghood.Pos.X - self.Pos.X;
            local avgy = ridinghood.Pos.Y - self.Pos.Y;
            local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
            if dist > 5 and dist < 1000 and ridinghood.Pos.X > self.Pos.X then
                     self.Pos.X = self.Pos.X - 1;
            end
            if dist > 5 and dist < 1000 and ridinghood.Pos.X < self.Pos.X then
                     self.Pos.X = self.Pos.X + 1;
            end
            if dist > 5 and dist < 1000 and ridinghood.Pos.Y > self.Pos.Y then
                     self.Pos.Y = self.Pos.Y - 1;
            end
            if dist > 5 and dist < 1000 and ridinghood.Pos.Y < self.Pos.Y then
                     self.Pos.Y = self.Pos.Y + 1;
            end
            if dist < 5 then
               gimmeasaw = CreateHDFirearm("Red's Saw","NotGonnaTellYouTheModsName.rte");
               ridinghood:AddInventoryItem(gimmeasaw);
               self.AmIHere = false;
               self:GibThis();
               
            end
         end
      end
   end
      

end


It should work like this: an actor, called "red", holds the weapon. As it is considered an attachable while held, the code does nothing. When the weapon ( it's a sword ) is dropped, however, the code should start working, moving it to the nearest non-red actor, killing the said actor, going back to Red, giving it another sword and then gibbing itself. Should work.
However, after rewriting the script about five times and solving a plethora of error messages, I still can't get this to work. To put it simply, it does nothing. At all. Does anyone know why? Thanks in advance.

Author:  mail2345 [ Sat Jun 20, 2009 9:08 pm ]
Post subject:  Re: Code activation problems

Add some debug print lines.

Author:  Areku [ Sat Jun 20, 2009 9:10 pm ]
Post subject:  Re: Code activation problems

I added them. One right before the actor.gibthis, and the other one before the self.amihere = false in the end. None of 'em printed anything.

Author:  piipu [ Sat Jun 20, 2009 10:54 pm ]
Post subject:  Re: Code activation problems

Try removing the Create function and replacing
Code:
   if self.AmIHere == false then
from the beginning with
Code:
   if self.AmIHere ~= true then
I'm not sure if the create function is gone through when the weapon is dropped. If that's the case, this should solve it.

Author:  mail2345 [ Sat Jun 20, 2009 10:59 pm ]
Post subject:  Re: Code activation problems

Or preferably
Code:
 if not(self.AmIHere) then


But create does activate on grnade throw.

Author:  Areku [ Sun Jun 21, 2009 12:00 am ]
Post subject:  Re: Code activation problems

Tried both, and it still doesn't work. By the way, the problem is not on dropping the weapon: the code doesn't work even if I just place it in the map with a dropship.

Author:  TheLastBanana [ Sun Jun 21, 2009 12:21 am ]
Post subject:  Re: Code activation problems

Code:
            if dist < 5 then
               actor:GibThis();
               self.AmIHere = true;
            end

If you're doing this with a drop ship, of course it isn't going to work. Your body would have to be exactly on center with the drop ship. Make the 5 a bigger number, that's a very small range.

Author:  Areku [ Sun Jun 21, 2009 3:50 am ]
Post subject:  Re: Code activation problems

Yeah, I think I will change it to 15 or something like that. But that's not the main problem. What happens is that the weapon does not follow actors as it was supposed to do. It just stays motionless on the floor.

Author:  mail2345 [ Sun Jun 21, 2009 3:52 am ]
Post subject:  Re: Code activation problems

I would subtract the two pos vectors and set the magnitude of the created vector.

Author:  Areku [ Sun Jun 21, 2009 2:17 pm ]
Post subject:  Re: Code activation problems

Uh, could you explain how to do that? I'm not really good in understanding lua programming... :???:

Author:  Grif [ Sun Jun 21, 2009 6:42 pm ]
Post subject:  Re: Code activation problems

createdvector.Magnitude = (vector1.X - vector2.X, vector1.Y - vector2.Y);

Author:  mail2345 [ Sun Jun 21, 2009 7:13 pm ]
Post subject:  Re: Code activation problems

Ahh clarify.

I meant more like

self.vel = self.pos - actor.pos
self.vel:SetMagnitude(whatever)

Author:  Areku [ Mon Jun 22, 2009 11:41 pm ]
Post subject:  Re: Code activation problems

Ah, I see. I'll try that. Thanks!

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