Author |
Message |
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
Restricting weapon usage
I want my clone to not be able to pick up or use any 2 handed devices (Assault rifles, etc.) exept his own pre-equipped weapon. And if he has something 2 handed (Except own weapon) in his inventory, he would auto-drop it once its equipped. He should end up being able to use/pick up his pre-equipped weapon and other one handed sidearms.
How would I do that? If there is already an answer somewhere, please point me to it because I was unable to find anything.
|
Wed Jul 01, 2009 2:22 pm |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: Restricting weapon usage
for weapon in MovableMan.Items do if weapon:IsOneHanded() == false then if <insert proximity check of choice, there's dozens of them> < <distance desired, 40's probably good> then weapon.GetsHitByMOs = false; end end end
On the actor, in update. Should work, unless someone wants to point out an easier way to make it not pick up items.
|
Wed Jul 01, 2009 7:21 pm |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
Re: Restricting weapon usage
So something like this should work? Code: function Update(self) for weapon in MovableMan.Items do if weapon:IsOneHanded() == false and weapon.PresetName ~= "weapon name" then -- *weapon name* being the actors pre-equipped weapon if (actor.Pos.X >= self.Pos.X - 40) and (actor.Pos.X <= self.Pos.X + 40) and (actor.Pos.Y >= self.Pos.Y - 40) and (actor.Pos.Y <= self.Pos.Y + 40) then weapon.GetsHitByMOs = false; end end end
|
Wed Jul 01, 2009 7:33 pm |
|
|
mail2345
Joined: Tue Nov 06, 2007 6:58 am Posts: 2054
|
Re: Restricting weapon usage
You need to enable GetHitsByMOs. Change this: Code: weapon.GetsHitByMOs = false; end To this and add tabs: Code: weapon.GetsHitByMOs = false; else weapon.GetsHitByMOs = true end
|
Wed Jul 01, 2009 7:39 pm |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: Restricting weapon usage
if (actor.Pos.X >= self.Pos.X - 40) and (actor.Pos.X <= self.Pos.X + 40) and (actor.Pos.Y >= self.Pos.Y - 40) and (actor.Pos.Y <= self.Pos.Y + 40) then
That's bad code for two reasons.
1: you haven't defined actor. But even if you replace that with weapon (which you need to do) 2: that's going to give a badly defined rectangle.
I'd recommend using the pythagorean theorem; use math.sqrt(math.pow(weapon.pos.x - self.pos.x,2) + etc etc
|
Wed Jul 01, 2009 7:40 pm |
|
|
mail2345
Joined: Tue Nov 06, 2007 6:58 am Posts: 2054
|
Re: Restricting weapon usage
SceneMan:ShortestDistance(self.Pos,weapon.Pos,true).Magnitude
Much better.
|
Wed Jul 01, 2009 7:53 pm |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
Re: Restricting weapon usage
Grif wrote: That's bad code for two reasons.
1: you haven't defined actor. But even if you replace that with weapon (which you need to do) 2: that's going to give a badly defined rectangle.
I'd recommend using the pythagorean theorem; use math.sqrt(math.pow(weapon.pos.x - self.pos.x,2) + etc etc >_< I didn't notice that... So, I should use this? Code: local curdist = 40; for weapon in MovableMan.Items do 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 < curdist and weapon:IsOneHanded() == false then weapon.GetsHitByMOs = false;
@ mail That one confuses me...
|
Wed Jul 01, 2009 7:54 pm |
|
|
Mind
Joined: Thu Mar 06, 2008 10:54 pm Posts: 1360 Location: USA
|
Re: Restricting weapon usage
Mail's finding the shorttest distance between the two. Magnitude = Distance of the vector.
|
Wed Jul 01, 2009 7:56 pm |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: Restricting weapon usage
Mail's code is actually just about the most efficient, because then the game itself is doing the distance checking, rather than reporting variables to lua which then acts on them and returns them.
In-engine methods are virtually always the fastest.
|
Wed Jul 01, 2009 7:59 pm |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
Re: Restricting weapon usage
So how do I actually use it?
Like if the magnitude is smaller then 40, the weapon isn't one handed and is not the pre-equipped weapon then make it GHBM=0, and then else is GHBM=1?
|
Wed Jul 01, 2009 8:02 pm |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: Restricting weapon usage
You had the right statements above, just use SceneMan:ShortestDistance(self.Pos,weapon.Pos,true).Magnitude < 40 as your distance check.
|
Wed Jul 01, 2009 8:05 pm |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
Re: Restricting weapon usage
ARGH!!! It doesn't work! Code: function Update(self) local curdist = 40; for weapon in MovableMan.Items do SceneMan:ShortestDistance(self.Pos,weapon.Pos,true).Magnitude if Magnitude < curdist and weapon:IsOneHanded() == false then weapon.GetsHitByMOs = false; else weapon.GetsHitByMOs = true; end end end WHY MUST THIS Lua BE SO COMPLICATED!!!??!?! >___<
|
Wed Jul 01, 2009 8:18 pm |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: Restricting weapon usage
Because magnitude isn't a variable, it's a property. Of a vector, specifically. Code: function Update(self) for weapon in MovableMan.Items do local curdist = 40; local vector = SceneMan:ShortestDistance(self.Pos,weapon.Pos,true) if vector.Magnitude < curdist and weapon:IsOneHanded() == false then weapon.GetsHitByMOs = false; else weapon.GetsHitByMOs = true; end end end Use that.
|
Wed Jul 01, 2009 8:25 pm |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
Re: Restricting weapon usage
Ohhh...
There's one little, tiny, insignificant problem though... He can still pick up weapons... What the hell can be wrong?
The code itself can't be wrong, cause I copypasted it. I thought maybe it was because it isn't tabbed, but that didn't seem to change anything.
And I made sure I didn't forget to define the script to the actor (Like I did one time -___-;)
Curse you CC and your unfriendly-ness to me and my mod! >:C
|
Wed Jul 01, 2009 8:43 pm |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: Restricting weapon usage
Replace it with weapon:GibThis instead of getshitbymos. If that doesn't work, then there's something wrong with the script itself.
|
Wed Jul 01, 2009 8:51 pm |
|
|
|