View unanswered posts | View active topics It is currently Tue Apr 23, 2024 8:10 am



Reply to topic  [ 5 posts ] 
 If holding this and person fires then crouch. 
Author Message
User avatar

Joined: Mon Oct 25, 2010 5:51 am
Posts: 1198
Location: Sydney
Reply with quote
Post If holding this and person fires then crouch.
I need a reliable script for a weapon that forces the actor holding it to crouch when it fires. I was playing around with the shovel script to find the device, but I don't know what do do from there on...
Please?


Sun May 29, 2011 4:11 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: If holding this and person fires then crouch.
EDIT:

Code:

function Create(self)

local curdist = 70 -- Change this distance based on your own gun
  for actor in MovableMan.Actors 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 then
         curdist = dist;
         self.parent = actor;
    self.parent:GetController():SetState(10, true)
      end
end
end

function Update(self)
self.parent:GetController():SetState(10, true)
end



This should work fine.


Sun May 29, 2011 5:00 am
Profile
User avatar

Joined: Sat Feb 26, 2011 10:29 am
Posts: 163
Reply with quote
Post Re: If holding this and person fires then crouch.
You should first make sure the actor is not walking(MOVE_RIGHT or MOVE_LEFT) or in the air(actor:GetAltitude(0,0) < ?), then lock the state to 10(BODY_CROUCH) about the whole process(not only in function Create). Give the gun an ActivationDelay, leaving actor some time to crouch down, or, I donno if there's a method to judge whether the actor is already crouch down.


Sun May 29, 2011 5:37 am
Profile
User avatar

Joined: Mon Oct 25, 2010 5:51 am
Posts: 1198
Location: Sydney
Reply with quote
Post Re: If holding this and person fires then crouch.
lol, I attached it to the fired particle, and it was created when it fired, about every second. It made the actor bum shuffle his was across the tutorial bunker :P

Any way to enforce the crouch as long as the actor holds fire?

EDIT: nvm, increased lifetime

Thanks for the help guys :grin:

EDITEDIT: what about a .lua controlled hinge, just to make something dangle?


Last edited by Kettenkrad on Sun May 29, 2011 10:51 am, edited 1 time in total.



Sun May 29, 2011 7:40 am
Profile
User avatar

Joined: Sat Feb 26, 2011 10:29 am
Posts: 163
Reply with quote
Post Re: If holding this and person fires then crouch.
Kettenkrad wrote:
lol, I attached it to the fired particle, and it was created when it fired, about every second. It made the actor bum shuffle his was across the tutorial bunker :P
Any way to enforce the crouch as long as the actor holds fire?
EDIT: nvm, increased lifetime
Thanks guys :grin:
EDITEDIT: what about a .lua controlled hinge, just to make something dangle?


eh, I'll suggest you to attach a lua-attached particle to the gun.
the lua code:when create. look for its parent gun, then keep checking whether there's a actor hold the weapon.(If you don't keep checking in the function Update, the lua will not work right after you drop it or change user of it)

after that:


Sun May 29, 2011 10:27 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 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.049s | 15 Queries | GZIP : Off ]