Data Realms Fan Forums
http://45.55.195.193/

[Move me to LUA] Ignore player or players team.
http://45.55.195.193/viewtopic.php?f=73&t=18156
Page 1 of 1

Author:  ajlw [ Thu Mar 18, 2010 1:08 am ]
Post subject:  [Move me to LUA] Ignore player or players team.

I'm trying to make a script that attaches a remote detonate-able bomb to a surface.
I want the bomb to ignore the surface if it belongs to the actor that threw the bomb, or is part of the actor that threw the bomb (Say, his body.)

Right now when I walk over the bomb, it just latches onto the actor and eventually detonates.

Any ideas?

I tried using

Code:
    if MovableMan:IsActor(self.Sticky) and actor.team ~= 0 then


The Lua wiki isn't really helpfull at all... as it doesn't contain anything else other than the 'MovableMan:IsActor' function =.=

Author:  Abdul Alhazred [ Thu Mar 18, 2010 7:58 am ]
Post subject:  Re: [LUA] Ignore player or players team.

Code:
MovableMan:IsActor(self.Sticky)
You want to use MovableMan:ValidMO or MovableMan:IsParticle if self.Sticky is not an actor.

Code:
actor.team ~= 0
'0' is the red team, so the weapon will not be usable for the green team. You could simply store which team the grenade belongs to and compare this value to the target actor's team (one primitive way of doing this can be found in the Coalition Homing Missile Launcher). The code you posted does not make much sense since we cannot see all of it. If you need any more help, consider uploading the weapon in an rte.

Did this answer your question?

Author:  Shook [ Thu Mar 18, 2010 7:19 pm ]
Post subject:  Re: [LUA] Ignore player or players team.

This may sound silly, but i think capitalizing the T in "team" might solve your problem. Cortex Command is very strict about capitalization.

Author:  ajlw [ Thu Mar 18, 2010 7:41 pm ]
Post subject:  Re: [LUA] Ignore player or players team.

Code:
function Create(self)
    self.minDist = 40
    self.parentDist = 10
    self.hasStuck = 0 
    print("Red C-4 planted!");
    --Make sure the red C-4 list exists.
    if c4ListA == nil then
   --If not, create it.
   c4ListA = { };
    end
    --Add this C-4 to the list.
    c4ListA[#c4ListA + 1] = self;
end

function Update(self)
   StickOn(self)
end

function StickOn(self)
    if self.Vel.X <= 5 and self.Vel.X >= -5 and self.hasStuck == 0 then
        for actor in MovableMan.Actors do
            local distx = actor.Pos.X - self.Pos.X;
            local disty = actor.Pos.Y - self.Pos.Y;
            local dist = math.sqrt(distx ^ 2 + disty ^ 2);
            if dist < self.minDist then
                self.stickTo = actor
                self.stickOffset = self.Pos - self.stickTo.Pos
                self.hasStuck = 1
            end
        end
    end
    if MovableMan:IsActor(self.stickTo) and actor.Team ~= 0 then
        self.AngularVel = 0
        self.Pos = self.stickTo.Pos + self.stickOffset
    end   
end

function Destroy(self)
end


I found the biggest part of this code by googling (no idea who's it is), and just switched it up a little bit with already existing lua in the original CC files.

Not sure what I should change. The wiki really isn't helping anyone is it?

EDIT:

Logically it would be from this forum, but I don't know who it came from.

Author:  Abdul Alhazred [ Thu Mar 18, 2010 10:17 pm ]
Post subject:  Re: [LUA] Ignore player or players team.

It looks like parts of your the code is from the Coalition.rte.

I'm not sure how much this helps but you can use the code below as a starting point.
Code:
function Create(self)
   self.Team = -1   -- Find out who fired the weapon by finding the closest actor here
end

function Update(self)
   if not self.stickTo then   -- If no target "self.stickTo" will be nil and evaluate to false
      if self.Vel.Magnitude < 5 then
         local min = 40
         local distance
         -- Find the closest actor
         for actor in MovableMan.Actors do
            if actor.Team ~= self.Team then
               distance = SceneMan:ShortestDistance(self.Pos, actor.Pos, false).Magnitude   -- Check distance and compensate for wrapping maps
               if distance < min then
                  min = distance
                  self.stickTo = actor
                  self.stickOffset = SceneMan:ShortestDistance(actor.Pos, self.Pos, false)
               end
            end
         end
      end
   elseif MovableMan:IsActor(self.stickTo) then
      self.AngularVel = 0
      self.Pos = self.stickTo.Pos + self.stickOffset
   end
end

function Destroy(self)
end

Author:  ajlw [ Thu Mar 18, 2010 10:25 pm ]
Post subject:  Re: [LUA] Ignore player or players team.

Well, actually, I just got into LUA coding... and that just looks like it's not going to work...

Author:  Lizardheim [ Fri Mar 19, 2010 12:39 pm ]
Post subject:  Re: [Move me to LUA] Ignore player or players team.

BLASPHEMY!

Abdul is one of the finest Lua scripters on this forum.

Author:  ajlw [ Fri Mar 19, 2010 7:32 pm ]
Post subject:  Re: [Move me to LUA] Ignore player or players team.

Oh, I thought he meant I wa- okay.

Author:  ajlw [ Sat Mar 20, 2010 1:13 pm ]
Post subject:  Re: [Move me to LUA] Ignore player or players team.

DOUBLE POST: (It wouldn't let me edit.)

Well, it worked, after a bit of tinkering about.


The only problem is, now when it attaches to something it tries to drag it into the floor or a wall.


ALSO, how do you make a dropped magazine dissapear?
I kinda want to make the entire weapon dissapear when fired...

oh wait, I think I got an idea.

Author:  411570N3 [ Sat Mar 20, 2010 1:21 pm ]
Post subject:  Re: [Move me to LUA] Ignore player or players team.

Make the magazine Discardable = 0.

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