View unanswered posts | View active topics It is currently Mon Jan 13, 2025 6:20 am



Reply to topic  [ 13 posts ] 
 Code activation problems 
Author Message
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post 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.


Sat Jun 20, 2009 9:05 pm
Profile WWW
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Code activation problems
Add some debug print lines.


Sat Jun 20, 2009 9:08 pm
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post 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.


Sat Jun 20, 2009 9:10 pm
Profile WWW
User avatar

Joined: Mon Jun 30, 2008 9:13 pm
Posts: 499
Location: Finland
Reply with quote
Post 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.


Sat Jun 20, 2009 10:54 pm
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Code activation problems
Or preferably
Code:
 if not(self.AmIHere) then


But create does activate on grnade throw.


Sat Jun 20, 2009 10:59 pm
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post 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.


Sun Jun 21, 2009 12:00 am
Profile WWW
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: 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.


Sun Jun 21, 2009 12:21 am
Profile WWW
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post 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.


Sun Jun 21, 2009 3:50 am
Profile WWW
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Code activation problems
I would subtract the two pos vectors and set the magnitude of the created vector.


Sun Jun 21, 2009 3:52 am
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post Re: Code activation problems
Uh, could you explain how to do that? I'm not really good in understanding lua programming... :???:


Sun Jun 21, 2009 2:17 pm
Profile WWW
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Code activation problems
createdvector.Magnitude = (vector1.X - vector2.X, vector1.Y - vector2.Y);


Sun Jun 21, 2009 6:42 pm
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Code activation problems
Ahh clarify.

I meant more like

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


Sun Jun 21, 2009 7:13 pm
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post Re: Code activation problems
Ah, I see. I'll try that. Thanks!


Mon Jun 22, 2009 11:41 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 13 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.038s | 13 Queries | GZIP : Off ]