View unanswered posts | View active topics It is currently Mon Jan 13, 2025 5:39 pm



Reply to topic  [ 8 posts ] 
 Held weapons? 
Author Message
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post Held weapons?
I've used the search option, but had no luck finding any answers to this. So, here it comes: is there any way to check if an actor is holding a specific weapon? Because, as far as I know, held weapons are classified as attachables, and don't appear in the inventory.
I could use alternate ways to check that, such as giving the weapon an AEmitter that emitted a specific particle, and having the script check if such particle was within a certain radius of the actor on which the the script will be run, but that would add a lot of unneeded complexity ( and lag thereof ) to the system.
Thanks in advance.


Tue Jun 23, 2009 11:00 pm
Profile WWW
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Held weapons?
I would iterate though all MOIDs and check the rootID and presetname for the actors ID and the name of the weapon.


Tue Jun 23, 2009 11:06 pm
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post Re: Held weapons?
Tried that, but doesn't seem to work. Here's the script I'm using:

Code:
function Create(self)
-- The variables:
   self.timer1 = Timer();
   
end

function Update(self)

      for RedSaw in MovableMan.Items do
            if RedSaw.PresetName == "Red's Saw"  then
            if RedSaw:IsAttachedTo(self) then
               print ("It works!")
            end
         end
      end


Is there anything wrong with it?


Tue Jun 23, 2009 11:51 pm
Profile WWW
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Held weapons?
Code:
local mo = self
for i = 1, MovableMan:GetMOIDCount() do
 mo = MovableMan:GetMOFromID(i)
  if mo.RootID == self.ID and mo.PresetName == "Red Saw" then
print ("It works!")
  end
end


Wed Jun 24, 2009 12:01 am
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post Re: Held weapons?
1. post
Uh, tried that, but it still doesn't work. The console just gives error messages and says that it's "attempting to index a nil value: mo".

2. post
Sorry for the double post, but weird stuff has happened. Trying to make the code mail2345 gave me work, I messed around with some variables, and what happens now is that the code works just as it should. If the actor is holding the said weapon, the console prints that it works. There is one little problem, though: it keeps spamming error messages! Every frame a new " attempting to index a nil value! " appears. Even though this is not a big problem, I would really like to know what's happening has the code seems ok now.

Anyone can explain?

Code:
function Create(self)
-- The variables:
   self.timer1 = Timer();
   
end

function Update(self)

--local mo = 0
for mo in MovableMan.Particles do
for i = 1, MovableMan:GetMOIDCount() do
mo = MovableMan:GetMOFromID(i)
  if mo.RootID == self.ID and mo.PresetName == "Red's Saw" then
print ("It works!")
  end
end
end
end


merged


Wed Jun 24, 2009 2:31 am
Profile WWW
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Held weapons?
Oh, right, I forgot about what TLB said:
Code:
function Create(self)
-- The variables:
   self.timer1 = Timer();
   
end

function Update(self)

--local mo = 0
for mo in MovableMan.Particles do
for i = 1, MovableMan:GetMOIDCount() - 1 do
mo = MovableMan:GetMOFromID(i)
  if mo.RootID == self.ID and mo.PresetName == "Red's Saw" then
print ("It works!")
  end
end
end
end



Wed Jun 24, 2009 2:39 am
Profile
User avatar

Joined: Mon Jun 30, 2008 9:13 pm
Posts: 499
Location: Finland
Reply with quote
Post Re: Held weapons?
You'll want to drop that for loop. There's no need to do this 100 times a frame.


Wed Jun 24, 2009 9:12 am
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post Re: Held weapons?
I do believe so. Even if I make the script only check that every 15ms, it still generates unholy amounts of lag.

EDIT: No, forget what I said. By making the script only check if the actor has the weapon when a specific key is pressed, I managed to circumvent the lag issue.


P.S. : See, Thor? I used the edit function this time! :grin:


Wed Jun 24, 2009 2:59 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

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.092s | 13 Queries | GZIP : Off ]