Home   Help Search Login Register  

Author Topic: Addaction script help please!  (Read 4278 times)

0 Members and 1 Guest are viewing this topic.

Offline crushpanzer

  • Members
  • *
Addaction script help please!
« on: 11 Apr 2010, 21:17:05 »
Hi!

I am making an Iraq war mission where you play as a US army soldier who is hunting down several targets and can arrest them... The soldier is supposed to be able to restrain the subject until the cavalry arrive...

The soldier kinda plays cops and robbers making him able to cuff anyone but I need a hand with the scripting...

My plan was to be able to take down the subject using the "AddAction" script along with the "ArrestingMan" script... It sorta looked like this:

player addAction ["Restrain", "ActsPercMstpSnonWnonDnon_ArrestingManLoop"]]

But for some reason, it makes ArmA crash when i play it.

If you could change it to the correct script so that it's will work and If you could add an "free target" ability, I'll be most greatful!

Thanks!

/josh

Offline Krieg

  • Mission Maker
  • Members
  • *
  • Who dares wins.
Re: Addaction script help please!
« Reply #1 on: 11 Apr 2010, 21:54:45 »
Hmm... Beyond my OFP realm once more.

ArmA addAction, to my knowledge, works exactly the same as in OFP.
Try:

Code: [Select]
youraction = player addAction ["Restrain", "ActsPercMstpSnonWnonDnon_ArrestingManLoop.sqs"]]

If that does not work, then problem is with your script.

If you see a light at the end of the tunnel, then it's probably an enemy tank.

Offline crushpanzer

  • Members
  • *
Re: Addaction script help please!
« Reply #2 on: 11 Apr 2010, 22:00:03 »
Hi,

i put it in and it came up with "ActsPercMstpSnonWnonDnon_ArrestingManLoop.sqs" not found...

What can I do?

/Josh

Offline Loyalguard

  • Former Staff
  • ****
Re: Addaction script help please!
« Reply #3 on: 12 Apr 2010, 07:22:31 »
I believe the problem is that you are trying to put code directly in the addAction parameters. You can only put a script name to execute the code you want. Try this instead ( untested and typed on a phone so excuse typos):

First, The easiest way to implement would probably add the action to the units you are going to arrest instead of the player. The reason being is that you can pass the "target" of an addAction (which is the object/unit that the action is attached to) to the script. If I understand correclty you want the unit restrained to play that animation. So,  in the editor put this ithe init line of every unit you want to be able to restrain:

Code: [Select]
this addAction ["Restrain", "restrain.sqf"];
Now create a new script in your mission file called restrain.sqf:

Code: [Select]
// restrain.sqf

private ["_target", "_id"];

_target = _this select 0;  // The unit to be restrained.
_id = _this select 2; // The index number of the action.  

// Make the be bound to the ground.
_target playMove "ActsPercMstpSnonWnonDnon_ArrestingManLoop";

// Remove the "Restrain" action so you don't restrain a unit more than omce at a time.
_target removeAction _id;

// Add an action to free the target.
_target addAction ["Free Target", "release.sqf"];

Then add one more script callef release.sqf:

Code: [Select]
// release.sqf

private ["_target", "_id"];

_target = _this select 0;  // The unit to be freed
_id = _this select 2; // The index number of the action.  

// Make the unit stand normally.  
_target playMove "AmovPercMstpSnonWnonDnon";

// Remove the "Free Target" action so you don't free a unit more than omce at a time.
_target removeAction _id;

// Add an action to restrain the target again if needed.
_target addAction ["Restrain", "restrain.sqf"];

Good luck!  If you don't like the release animation substitute it with one that works for you.
« Last Edit: 12 Apr 2010, 07:28:47 by Loyalguard »

Offline crushpanzer

  • Members
  • *
Re: Addaction script help please!
« Reply #4 on: 12 Apr 2010, 10:43:26 »
Hi, I don't have any idea on how to add this, I got the mission file but I don't know where to add it... Also, is this stuff in the box just raw stuff that needs slight editing before adding or is it complete?

/Josh

« Last Edit: 12 Apr 2010, 11:37:48 by crushpanzer »

Offline Krieg

  • Mission Maker
  • Members
  • *
  • Who dares wins.
Re: Addaction script help please!
« Reply #5 on: 12 Apr 2010, 17:46:31 »
Hmm... That might be your problem of "scriptname.sqs not found".

The only modifying the scripts in box needs is to be saved to "what-ever-name-you-want.sqs" using either Notepad or tools like ArmAEdit. Save it to:

My Documents - ArmA - Missions - YourMissionName folder.

Open up your mission in editor, and add script code Loyalguard already posted wherever you need it.
Code: [Select]
this addAction ["Restrain", "restrain.sqf"]
Hope that helps,
Krieg
If you see a light at the end of the tunnel, then it's probably an enemy tank.

Offline Loyalguard

  • Former Staff
  • ****
Re: Addaction script help please!
« Reply #6 on: 12 Apr 2010, 20:05:38 »
As Krieg pointed out, for the init line.  Opent the editor, click on your unit and paste that one line in the init line.

For the scripts, they are complete code and should all be ready to (unless I have made a typo or other syntax error or have a wring animation name, but I don't currently have ArmA installed and so I can't test it).  To create a new script file open notepad, paste the contents of restrain.sqf into it.  Save it in your mission filed but rename it restrain.sqf (not.txt).  Do the same for release.sqf in a new document.

Offline crushpanzer

  • Members
  • *
Re: Addaction script help please!
« Reply #7 on: 12 Apr 2010, 21:23:07 »
Hi!

I tried it but it restrained the player, I can't actually cuff the target...

But it did work but I just need to know how to perform the action on the AI target..

Thanks for the help so far!

Just need to know this to finish off with it!

/Josh

Offline Loyalguard

  • Former Staff
  • ****
Re: Addaction script help please!
« Reply #8 on: 13 Apr 2010, 00:11:26 »
Did you add:

Code: [Select]
this addAction ["Restrain", "restrain.sqf"];
to the player's or the AI target's init line?  It needs to go in the target's init (and repeat it for any other AI target you want arrested).  It does NOT go in the player's init line.

If you did put it in the the AI unit's init line and it still restrained the player let me know.

Offline crushpanzer

  • Members
  • *
Re: Addaction script help please!
« Reply #9 on: 13 Apr 2010, 10:57:40 »
Hi,

It works but he dosen't stay down, he just keeps getting up and I can't stop him. Could you show me where to put the DisableAI "Anim" script? And on the release one EnableAI "Anim"?

Thanks!

/Josh
« Last Edit: 13 Apr 2010, 11:26:50 by crushpanzer »

Offline Loyalguard

  • Former Staff
  • ****
Re: Addaction script help please!
« Reply #10 on: 13 Apr 2010, 17:37:58 »
Ok. Here is some modified code below. But, this may only work in single player.  I believe disableAI/enableAI only works where the unit is local.  If the AI is not in a human player's group it is local to the server only and this command will not work in MP (I think).  So, if you intend this for MP and it doesn't work we have to look at a way to get the unit local (make him part of the human player's group), getting the script to run on the server, or possibly looping the restrained animation until released.  All three are possible but let's not put the cart before the horse.  Try this first and see how it works.  As you can see, I only added one line of new code to each script.  Two caveats:  In restrain.sqf Hopefully the restrained animation kicks in fully before the disableAI command or it will lock out the change.  If it doesn't, you might need to add a sleep command or other safety catch between the playMove and disableAI command.  Also for release.sqf once enableAI runs it maybe unnecessary to use the playMove command if you say that not he gets up as soon as he goes down.  If so, you can just remove the code.  Play with it and see.  Good luck!

Code: [Select]
// restrain.sqf

private ["_target", "_id"];

_target = _this select 0; // The unit to be restrained.
_id = _this select 2; // The index number of the action.

// Make the target be bound to the ground.
_target playMove "ActsPercMstpSnonWnonDnon_ArrestingManLoop";

// Prevent the target from changing animation states.
_target disableAI "ANIM";

// Remove the "Restrain" action so you don't restrain a unit more than omce at a time.
_target removeAction _id;

// Add an action to free the target.
_target addAction ["Free Target", "release.sqf"];

Code: [Select]
// release.sqf

private ["_target", "_id"];

_target = _this select 0; // The unit to be freed
_id = _this select 2; // The index number of the action.

// Enable the target to change animation states.
_target enableAI "ANIM";

// Make the unit stand normally.
_target playMove "AmovPercMstpSnonWnonDnon"; // This may not be needed anymore.

// Remove the "Free Target" action so you don't free a unit more than omce at a time.
_target removeAction _id;

// Add an action to restrain the target again if needed.
_target addAction ["Restrain", "restrain.sqf"];

Offline crushpanzer

  • Members
  • *
Re: Addaction script help please!
« Reply #11 on: 13 Apr 2010, 18:48:52 »
Hi!

Thanks, no it is only a SP mission so, I don't need to worry..

I am probarbly getting a bit annoying by saying this but, could you write one on the disarming the unit action... I tried to do this but I can't actually seem to get it to work...

I put instead of the Anim script: _Removeallweapons Target

But, with my luck, or lack of it, it didn't work...

If you could do this one more thing, I will be able to crack on with finishing the mission!

You have been a great help so far and I am glad I came to the OFPEC forums!

Thanks for everything so far!

Offline Loyalguard

  • Former Staff
  • ****
Re: Addaction script help please!
« Reply #12 on: 13 Apr 2010, 21:46:41 »
No problem!  We're here to help!  If you would like to be even more self-sufficient, check out Cheetah's basic SQF tutorial here at OFPEC: Basic SQF by Cheetah

So to remove weapons, you have the right command but your syntax is a little off.  Try this instead inside restrain.sqf (before the playMove line probably)

Code: [Select]
// Remove all weapons from the target.
removeAllWeapons _target;

Offline crushpanzer

  • Members
  • *
Re: Addaction script help please!
« Reply #13 on: 13 Apr 2010, 23:18:58 »
Ahh! Thanks you guys!

You are the best! My problems are that I have the stuff but never know where to put it!

Thanks!

/Josh