Data Realms Fan Forums
http://45.55.195.193/

Restricting weapon usage
http://45.55.195.193/viewtopic.php?f=73&t=15665
Page 1 of 2

Author:  MaximDude [ Wed Jul 01, 2009 2:22 pm ]
Post subject:  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.

Author:  Grif [ Wed Jul 01, 2009 7:21 pm ]
Post subject:  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.

Author:  MaximDude [ Wed Jul 01, 2009 7:33 pm ]
Post subject:  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

Author:  mail2345 [ Wed Jul 01, 2009 7:39 pm ]
Post subject:  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

Author:  Grif [ Wed Jul 01, 2009 7:40 pm ]
Post subject:  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

Author:  mail2345 [ Wed Jul 01, 2009 7:53 pm ]
Post subject:  Re: Restricting weapon usage

SceneMan:ShortestDistance(self.Pos,weapon.Pos,true).Magnitude

Much better.

Author:  MaximDude [ Wed Jul 01, 2009 7:54 pm ]
Post subject:  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...

Author:  Mind [ Wed Jul 01, 2009 7:56 pm ]
Post subject:  Re: Restricting weapon usage

Mail's finding the shorttest distance between the two. Magnitude = Distance of the vector.

Author:  Grif [ Wed Jul 01, 2009 7:59 pm ]
Post subject:  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.

Author:  MaximDude [ Wed Jul 01, 2009 8:02 pm ]
Post subject:  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?

Author:  Grif [ Wed Jul 01, 2009 8:05 pm ]
Post subject:  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.

Author:  MaximDude [ Wed Jul 01, 2009 8:18 pm ]
Post subject:  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!!!??!?! >___<

Author:  Grif [ Wed Jul 01, 2009 8:25 pm ]
Post subject:  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.

Author:  MaximDude [ Wed Jul 01, 2009 8:43 pm ]
Post subject:  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

Author:  Grif [ Wed Jul 01, 2009 8:51 pm ]
Post subject:  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.

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