Jump to content
Sign in to follow this  
Mike4010

Knocking down a player

Recommended Posts

Hey guys, so once again my noobie scripting skills make me fail miserably.

What i want to achieve is if i press the button 5 (on the numpad) i want the cursorTarget (a player) to get knocked down and after 5 seconds i want him to get back up. It works all well except the 5 seconds delay.

I have this in my init.sqf:

waituntil {!(IsNull (findDisplay 46))};
_keyDown = (findDisplay 46) displayAddEventHandler ["KeyDown", 
{if (_this select 1 == 76) then {
dude = cursorTarget; 
dude switchMove "AinjPpneMstpSnonWrflDnon"; 
sleep 5; 
dude playMove "AmovPercMstpSnonWnonDnon";}}];

When i run this it returns a generic error message, the cursorTarget gets "knocked down" and right back up.

Also i want to ask how to bind that code to a button combination? (Shift + F for example)

And would this whole thing work in multiplayer as well? If not, what would i have to change?

 

Excuse my pathetic problems, still quite new to scripting.

Thank you in advance! :thanx:

 

Share this post


Link to post
Share on other sites

You need to spawn your code to create a "scheduled" scope allowing suspensions like waitUntil or sleep. The inner code becomes:
 

{
  if (_this select 1 == 76 && cursorTarget isKindOf "CAManBase") then {
     cursorTarget spawn {
       _dude = _this;   
      _dude switchMove "AinjPpneMstpSnonWrflDnon";
      sleep 5;
      _dude playMove "AmovPercMstpSnonWnonDnon"
    };
  }
}

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×