Home   Help Search Login Register  

Author Topic: Passing Variables into Addaction command  (Read 1766 times)

0 Members and 1 Guest are viewing this topic.

Offline sardaukar17

  • Members
  • *
Passing Variables into Addaction command
« on: 04 Aug 2009, 03:10:33 »
Alright here is a good one. Hardest thing I have tried to tackle so far.
I am trying to build a set of scripts that allows a truck to be given the ability to create another unit near it. I need the truck to be able to repspawn and I need the vehical it creates to respawn. Both exist on the map at start of the mission. All the create option does is move the unit near the truck from another location. This is the script in question. What I need to do is have these local variables passed with the execution of the "Artillary.sqs" script. "Artaction.sqs" is executed as follows.

[Truck,Art] exec "Artaction.sqs"

Code: [Select]
_truck = _this select 0
_art = _this select 1

artaction=_truck addaction ["Build Arillary","Artillary.sqs";
_truck is the vehical that the action is being added to and _art is the actual artillary piece. These 2 variables need to be passed in much the same way the "artaction.sqs" script was executed

Now I have done some reading and I read that it can be done but maybe I mss understood or the info I read is wrong. Or it doesn't work for local variables just global which ofcourse won't work but according to this site
 http://community.bistudio.com/wiki/addAction
if I understand it correctly I should be able to simply do this:
Code: [Select]
artaction=_truck addaction ["Build Arillary","Artillary.sqs",(_truck,_art)];
Natuarally it doesn't work. So any ideas?

Offline Inkompetent

  • Members
  • *
Re: Passing Variables into Addaction command
« Reply #1 on: 04 Aug 2009, 03:35:17 »
How about using artAction=_truck addAction ["Build Artillery","Artillary.sqs",[_truck,_art]];

Offline sardaukar17

  • Members
  • *
Re: Passing Variables into Addaction command
« Reply #2 on: 05 Aug 2009, 02:12:46 »
No dice. The script fails to execute completly

Offline F2kSel

  • Members
  • *
Re: Passing Variables into Addaction command
« Reply #3 on: 05 Aug 2009, 14:46:32 »
You need to combine the variables into an array.

Code: [Select]
_temp = [_truck,_art]
artAction=_truck addAction ["Build Artillery","Artillary.sqs",_temp]


to retrieve the info

in the the script  it would be something like this

Code: [Select]
_array = _this select 3;

_newtruck = _array select 0;
_newart    =  _array select 1;

Inkompetent was on the right track but I don't know a way of doing it in the addaction command.
« Last Edit: 05 Aug 2009, 14:48:27 by F2kSel »

Offline Pirin

  • Members
  • *
Re: Passing Variables into Addaction command
« Reply #4 on: 05 Aug 2009, 20:37:38 »
I'd do it this way myself:

Code: [Select]
artAction = _truck addAction ["Build Artillery","Artillary.sqf",[art]];

Code: [Select]
_truck = _this select 0;
_art = (_this select 3) select 0;

_art setPos (getPos _truck);

or something.


Offline sardaukar17

  • Members
  • *
Re: Passing Variables into Addaction command
« Reply #5 on: 06 Aug 2009, 03:39:42 »
F2kSel that worked perfectly. I ofcourse got what you were trying to tell me wrong about as many possible combinations of wrong I could have but in the end it did infact work like a charm.

The problem now lol.. And this is the beaughty of the whole thing. It didn't even occur to me that after the artillary piece is destroyed and recreated it is no longer in sync with the Artillary Module and thus unusable. I'll have to go and experitment with ways of reconnecting it or reconnecting a new one. But I do appriciate the help. This is what I have thus far. And it is not perfect but could be helpful to anyone out there trying the same thing. You will have to forgive the ancient sqs files. But they are all I know :(


This is "artaction.sqs"
Code: [Select]
_truck=_this select 0
_art=_this select 1
_temp=[_truck,_art]
artaction=_truck addaction ["Build Arillary","Artillary.sqs",_temp];

exit


This next part is "artillary.sqs"
Code: [Select]
_array=_this select 3
_truck = _array select 0
_art= _array select 1
_loc= getpos _truck

~5

?!(alive _art): goto "dead";

_art setpos [_loc select 0,(_loc select 1)-9,_loc select 2];
_art setdir -120;
_truck removeAction artaction;

~10

[_truck,_art] exec "artaction.sqs";
goto "exit"


#dead
_truck removeAction artaction
[_art,artrespawn,-120,"m119",10,_truck] exec "vcl_respawnart.sqs"
goto "exit"

#exit
exit

This next one is "Vcl_respawnart.sqs" This one someone else wrote and I borrowed and modified minimaly.
Code: [Select]
?!(local Server): Goto "end"
_art = _this select 0
_respawnpoint = _this select 1
_azimut = _this select 2
_class = _this select 3
_respawndelay = _this select 4
_truck = _this select 5

#start
~1

~_respawndelay
deleteVehicle _art
_art = _class createVehicle getpos _respawnpoint
_art setdir _azimut

[_truck,_art] exec "artaction.sqs"
#end
Exit
« Last Edit: 06 Aug 2009, 03:43:53 by sardaukar17 »

Offline Trexian

  • Members
  • *
Re: Passing Variables into Addaction command
« Reply #6 on: 06 Aug 2009, 14:29:57 »
According to the Biki, the synch has to happen within .5 sec. of initialization of the mission (IIRC).  You may need to work out something that allows you to track the damage of the arty (damaged eventhandler perhaps), and if it gets below a certain amount, immediately repair it, but take it "offline" for awhile (maybe even move it somewhere temporarily).

Here's hoping your irritability has been alleviated. ;)
Sic semper tyrannosauro.