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



Reply to topic  [ 6 posts ] 
 Minor help needed in fixing a gas script 
Author Message
User avatar

Joined: Mon Oct 11, 2010 1:15 pm
Posts: 594
Location: Finlandia
Reply with quote
Post Minor help needed in fixing a gas script
I've made a gas grenade into a mod of mine, and one of the features is ignoring actors with an attachable on the head with the work 'mask' in it, but so far it only scans for 1 masked actor to ignore, and sticks to that one. What I need is to make it ignore all 'masked' actors.

The script looks something like this:
Code:
function Create(self)
   self.gasTimer = Timer();
   self.gasInterval = 100;
end

function Update(self)
   if self.gasTimer:IsPastSimMS(self.gasInterval) then
      for i = 1,MovableMan:GetMOIDCount()-1 do
         local mask = MovableMan:GetMOFromID(i);
         if string.find(mask.PresetName, "Mask") and mask.ClassName == "Attachable" then
            local masked = MovableMan:GetMOFromID(mask.RootID);
            if MovableMan:IsActor(masked) and masked.ClassName == "AHuman" then
               self.nohurt = ToAHuman(masked);
            end
         end
      end
         for actor in MovableMan.Actors do
         if not string.find(actor.PresetName,"Robot") and not string.find(actor.PresetName,"Brain") and not string.find(actor.PresetName,"Drone") and not string.find(actor.PresetName,"Turret") and not string.find(actor.PresetName,"Dummy") and not string.find(actor.PresetName,"Dreadnought") and actor.PresetName ~= "Blast Runner" and actor.ClassName ~= "ACDropShip" and actor.ClassName ~= "ACRocket" and actor.ClassName ~= "ADoor" 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 < 50 then
               if actor.ID ~= self.nohurt.ID then
                  if actor.Health > 0 then
                     actor.Health = actor.Health - (40 / actor.Mass + 0.1) / 2
                  end
               end
            end
         end
      end
   self.gasTimer:Reset();
   end
end

It's mostly based on the medic drone script, and I've thrown some pieces here and there to make it, but I'm not skilled enough to exactly know what I should do.


Mon Jun 25, 2012 3:35 pm
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post Re: Minor help needed in fixing a gas script
See if this works, I just changed self.nohurt to a tabled value since you're iterating a lot of them.
Code:
function Create(self)
   self.gasTimer = Timer();
   self.gasInterval = 100;
end

function Update(self)
   if self.gasTimer:IsPastSimMS(self.gasInterval) then
      self.nohurt = {}
      for i = 1,MovableMan:GetMOIDCount()-1 do
         local mask = MovableMan:GetMOFromID(i);
         if string.find(mask.PresetName, "Mask") and mask.ClassName == "Attachable" then
            local masked = MovableMan:GetMOFromID(mask.RootID);
            if MovableMan:IsActor(masked) and masked.ClassName == "AHuman" then
               self.nohurt[#self.nohurt + 1] = ToAHuman(masked);
            end
         end
      end
         for actor in MovableMan.Actors do
         if not string.find(actor.PresetName,"Robot") and not string.find(actor.PresetName,"Brain") and not string.find(actor.PresetName,"Drone") and not string.find(actor.PresetName,"Turret") and not string.find(actor.PresetName,"Dummy") and not string.find(actor.PresetName,"Dreadnought") and actor.PresetName ~= "Blast Runner" and actor.ClassName ~= "ACDropShip" and actor.ClassName ~= "ACRocket" and actor.ClassName ~= "ADoor" 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 < 50 then
               for i = 1 , #self.nohurt
                  if actor.ID ~= self.nohurt[i].ID then
                     if actor.Health > 0 then
                        actor.Health = actor.Health - (40 / actor.Mass + 0.1) / 2
                     end
                  end
               end
            end
         end
      end
   self.gasTimer:Reset();
   end
end


If it doesn't work I'll take a closer look and actually test it but I'm busy right now and I think that should be your problem.


Mon Jun 25, 2012 4:56 pm
Profile
User avatar

Joined: Mon Oct 11, 2010 1:15 pm
Posts: 594
Location: Finlandia
Reply with quote
Post Re: Minor help needed in fixing a gas script
Bad Boy wrote:
See if this works.

Thank you for offering your helping hand! :) Even if it doesn't work as intended.

Tested it out, seems to ignore the masked actor, if there is only one of them. Tested it with 4 actors, all of them were affected, and after 3 of them died, the last one didn't get hurt anymore.

If you have the time, and are willing to help any more, it would be much appreciated!


Mon Jun 25, 2012 5:25 pm
Profile
Forum Moderator
User avatar

Joined: Fri Feb 02, 2007 3:53 pm
Posts: 1896
Location: in my little gay bunker
Reply with quote
Post Re: Minor help needed in fixing a gas script
You could alternatively go over every actor in create and add their actor IDs to a list and then not affect those. Depending on how long the gas lasts this could work. But you would end up with masked actors taking damage if they enter the fray after the nade was tossed.


Mon Jun 25, 2012 6:12 pm
Profile
User avatar

Joined: Mon Oct 11, 2010 1:15 pm
Posts: 594
Location: Finlandia
Reply with quote
Post Re: Minor help needed in fixing a gas script
The idea is to not affect the actor if it has the attachable on - only if it's shot off. That way it would appear prettier as the mask breaks. It would also mildly support other mods, ones that have actors that have masks on.


Mon Jun 25, 2012 6:16 pm
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post Re: Minor help needed in fixing a gas script
I'll take a proper look at it tomorrow or the day after. I've found myself suddenly very busy, I haven't had the chance to script a thing on my plate for the past couple of days, and there's a good deal on my plate.
So I'm happy to help but it may take me a little while to get to it I'm afraid. That said, it may not be too long, if I get frustrated with other things not working (or just finish them quickly) I may start this sooner rather than later. Expect later rather than sooner though :D


Edit: Oh and if someone else wants to help you don't feel bad about accepting it or anything, whatever gets things fixed for you soonest :)


Tue Jun 26, 2012 7:44 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.181s | 14 Queries | GZIP : Off ]