View unanswered posts | View active topics It is currently Thu Jan 16, 2025 8:38 am



Reply to topic  [ 17 posts ]  Go to page Previous  1, 2
 Bullet Suggestion 
Author Message
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: Bullet Suggestion
Geti, that script won't work, mostly because SetWhichMOToNotHit can only be called once per particle per frame. That's the main reason nobody has made a friendly fire mod.


Thu Aug 05, 2010 6:36 am
Profile WWW
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Bullet Suggestion
That's a daft limitation. I seem to remember that being a nuisance at some point though.
Code:
function Create(self)
   self.table = {};
   function self:PutActorList(pointer, Team)
      for actor in MovableMan.Actors do
         if actor.Team == Team then
            table.insert(pointer,actor);
         end
      end
   end
end

function Update(self)
   for k,v in ipairs(self.table) do
      if MoveableMan:ValidMO(v[1]) and v[3]:ElapsedSimTimeMS() < v[4] then --double safeguard.
         if #v[2] == 0 then
            v = nil;
         else
            v[1]:SetWhichMOToNotHit(table.remove(v[2]),-1);
         end
      else
         v = nil;
      end
   end
   for particle in MovableMan.Particles do
      if particle.Age <= TimerMan.DeltaTimeMS then
      --if that doesn't work, delete it and uncomment the following. Not sure when age is applied.
      --[[if particle.PresetName ~= "FRIENDLY FIRE ON" then
         particle.PresetName = "FRIENDLY FIRE ON"; ]]--
         if particle.HitsMOs and particle.Lifetime > 60 then
            local index = (math.random(1000000)); --it's only a temporary thing anyway
            self.table[index] = {particle, {}, Timer(), particle.Lifetime};
            local curdist = 50
            local friendlyactor = "a"
            local sd = SceneMan:ShortestDistance;
            for actor in MovableMan.Actors do
               local dist = sd(actor.Pos,particle.Pos,true);
               if dist < curdist then
                  curdist = dist;
                  friendlyactor = actor;
               end
            end
            if friendlyactor ~= "a" then
               self:PutActorList(self.table[index][2],friendlyactor.Team);
            end
         end
      end
   end
end

not sure I can do that with indexes and particle pointers, considering how finicky CC's lua implementation is, but unless I've made some idiot typo like in the previous version (HitsMOs vs particle.HitsMOs) it should work.

EDIT: hold on, reworking it, forgot to add a handler for when the particles don't exist anymore. *idiotidiotidiot*
EDIT2: done, hopefully ValidMO works for pointers. That should be a sufficient framework for someone to debug in any case.


Thu Aug 05, 2010 7:34 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 17 posts ]  Go to page Previous  1, 2

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.067s | 13 Queries | GZIP : Off ]