Author |
Message |
ajlw
Joined: Mon Mar 15, 2010 11:46 pm Posts: 67
|
[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 =.=
Last edited by ajlw on Thu Mar 18, 2010 11:36 pm, edited 1 time in total.
|
Thu Mar 18, 2010 1:08 am |
|
|
Abdul Alhazred
DRL Developer
Joined: Tue Aug 11, 2009 5:09 am Posts: 395
|
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. '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?
|
Thu Mar 18, 2010 7:58 am |
|
|
Shook
Joined: Fri Feb 16, 2007 8:43 pm Posts: 1695 Location: AH SHIT FUCK AUGH
|
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.
|
Thu Mar 18, 2010 7:19 pm |
|
|
ajlw
Joined: Mon Mar 15, 2010 11:46 pm Posts: 67
|
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.
|
Thu Mar 18, 2010 7:41 pm |
|
|
Abdul Alhazred
DRL Developer
Joined: Tue Aug 11, 2009 5:09 am Posts: 395
|
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
|
Thu Mar 18, 2010 10:17 pm |
|
|
ajlw
Joined: Mon Mar 15, 2010 11:46 pm Posts: 67
|
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...
|
Thu Mar 18, 2010 10:25 pm |
|
|
Lizardheim
DRL Developer
Joined: Fri May 15, 2009 10:29 am Posts: 4107 Location: Russia
|
Re: [Move me to LUA] Ignore player or players team.
BLASPHEMY!
Abdul is one of the finest Lua scripters on this forum.
|
Fri Mar 19, 2010 12:39 pm |
|
|
ajlw
Joined: Mon Mar 15, 2010 11:46 pm Posts: 67
|
Re: [Move me to LUA] Ignore player or players team.
Oh, I thought he meant I wa- okay.
|
Fri Mar 19, 2010 7:32 pm |
|
|
ajlw
Joined: Mon Mar 15, 2010 11:46 pm Posts: 67
|
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.
|
Sat Mar 20, 2010 1:13 pm |
|
|
411570N3
Joined: Wed Jan 07, 2009 10:26 am Posts: 4074 Location: That quaint little British colony down south
|
Re: [Move me to LUA] Ignore player or players team.
Make the magazine Discardable = 0.
|
Sat Mar 20, 2010 1:21 pm |
|
|
|