View unanswered posts | View active topics It is currently Fri Dec 27, 2024 8:45 am



Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
 Restricting weapon usage 
Author Message
User avatar

Joined: Wed Nov 22, 2006 3:19 pm
Posts: 2073
Reply with quote
Post 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
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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
Profile
User avatar

Joined: Wed Nov 22, 2006 3:19 pm
Posts: 2073
Reply with quote
Post 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
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post 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
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Restricting weapon usage
SceneMan:ShortestDistance(self.Pos,weapon.Pos,true).Magnitude

Much better.


Wed Jul 01, 2009 7:53 pm
Profile
User avatar

Joined: Wed Nov 22, 2006 3:19 pm
Posts: 2073
Reply with quote
Post 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
Profile
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1360
Location: USA
Reply with quote
Post 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
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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
Profile
User avatar

Joined: Wed Nov 22, 2006 3:19 pm
Posts: 2073
Reply with quote
Post 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
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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
Profile
User avatar

Joined: Wed Nov 22, 2006 3:19 pm
Posts: 2073
Reply with quote
Post 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
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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
Profile
User avatar

Joined: Wed Nov 22, 2006 3:19 pm
Posts: 2073
Reply with quote
Post 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
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 17 posts ]  Go to page 1, 2  Next

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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.079s | 14 Queries | GZIP : Off ]