Jump to content
Sign in to follow this  
calculor

Help with addaction

Recommended Posts

Sorry for the vague title but I couldn't really describe it in such small space.

My problem is with the addaction command. I was wondering if there some way to send a custom variable to the script that gets executed.

For instance I have

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

unit addaction [ "Test Action" , "testscript.sqf" ]

The thing is that I want to use the same action for various other units and execute the same script. However, I want to be able to send a custom variable to the script depending on which unit has the action.

For a little insight what I am trying to do is create an array to store a number variable for specific units' inventory size. The number that would be sent to the script would be used to find out which part of the array that units inventory is stored.

I have some coding experience in basic and c++ but I'm fairly new to scripting for Ofp/Arma so I am not entirely sure about all the ways I can manipulate arrays.

I've tried to search all over the forums and biki but I'm not really sure what to look for and I've spent a lot of time without any results. So please dont hate me if the answer was right under my nose. I tried !

Anyway, sorry for the long winded post and thanks in advance for any support.

p.s. Can anyone point me in the direction of a good editing resources site? I guess ofpec switched hosts.

Share this post


Link to post
Share on other sites

From the wiki

Quote[/b] ]Note:In ArmA the script file can be sqs or sqf, in OFP it can only be a sqs file.

Parameters of the called script:

An array of parameters is passed to the called script:

[unit, caller, ID]

unit: Object - the unit which the action is assigned to

caller: Object - the unit that activated the action

ID: Integer - ID of the activated action

If i understood correctly you want a player to execute the script in a certain place.

I´ve come across with that same problem in my map "Weird Things".

Suggestion: place a trigger over the action area where u want the "addaction" to happen and in condition type in: Player in thislist. Set the trigger to repeat the action and on activion field execute the script you want to.

Unpbo the mission and check the map to see how i´ve done it. (Im at work cant remember exactly the syntax now).

Share this post


Link to post
Share on other sites

Im not sure if thats it. I want the player to be able to "use" certain objects. I have that part working so far. i use addaction and once the player uses that option on an item it runs the script. The problem is that I have an array in the script and I can't access it the way I want to. for instance in the script i want to set the value of one of the elements. However the element number is going to be unique depending on which object the player is using the action on.

So what I was trying to do is find out if there is a way to change a variable as the addaction command gets executed so I can use the set command on the array.

Hope the makes sense. Thanks in advance

Share this post


Link to post
Share on other sites

I did found a way actually, but it multiplayer and JIP it only gave me problems.

At a certain point i intended to reuse a script depending on the location of players on the map. For that i placed in the trigger where the addaction would pop up as usuable:

[0] exec "Sciptname.sqs"

When the script started with

_this = _this select 0;

it would pickup the variable of the current location (since the location would depend on the number). Maybe you can workaround picking the idea from here. After i got this part working was quite easy in single player / non JIP.

_array = [object1, object2, object3];

_array select _this;

Hope i could help.

Share this post


Link to post
Share on other sites
Quote[/b] ]The thing is that I want to use the same action for various other units and execute the same script. However, I want to be able to send a custom variable to the script depending on which unit has the action.

Depending on what units your using you could use typeOf. But thats assuming they are all different types, but anything that can distinguish them would be ok.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Unit=_This Select 0;

_Param=-1;

Switch (TypeOf _Unit) Do

       {

       Case "SoldierWB":

               {

               _Param=0;

               };

       Case "SoldierWSniper":

               {

               _Param=1;

               };

       };

If (_Param!=-1) Then

       {

       ........

       };

Or embed the parameter into each unit using this in the units init fields:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">This setVariable ["MyParam",AnObject]

And your action calls:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Unit=_This Select 0;

_Param=_Unit GetVariable "MyParam";

If !(IsNull _Param) Then

       {

       ........

       };

If you want you can also use vehicleVarName.

Give them all unique names in the editor like Unit01....Unit09 then use:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Unit=_This Select 0;

_Param=-1;

Switch (VehicleVarName _Unit) Do

       {

       Case "Unit01":

               {

               _Param=0;

               };

       Case "Unit02":

               {

               _Param=1;

               };

       };

It all depends on the parameter your trying to pass and the units your using.

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  

×