Jump to content
  • 0

Passing variables to a script?


collumjiggas

Question

First of all this forum is great, I've learned so much just by reading. I'm a noob, so please go easy on me. I'm trying to reduce the number of duplicate scripts I have to get the mission file size down. Yes, apparently there's still scripting noobs out there, I feel like I should have taken this up years ago it's so much fun.

 

I have an extra_rc class set up like this

        class EvKobalt {
		class Kobalt5 {
		text = "Spawn OP AH6J";
		script = "execVM 'custom\admindeploy\opah6j.sqf'";
                };
	};

and opah6j.sqf looks like this:

_itemsPlayer = items player;
if (dayz_combat == 1) then { 
    cutText [format["You are in Combat and cannot build an AH6J."], "PLAIN DOWN"];
} else {

	player playActionNow "Medic";
	r_interrupt = false;
	_dis=10;	
	sleep 6;
	
	_object = "AH6J_EP1" createVehicle (position player);
	_object setVariable ["ObjectID", "1", true];
	_object setVariable ["ObjectUID", "1", true];
	_object setVariable ["MalSar",1,true];
	_object addWeapon "GAU8";
	_object addMagazine "1350Rnd_30mmAP_A10";
	_object addWeapon "HellfireLauncher";
	_object addMagazine "8Rnd_Hellfire";
	_object addWeapon "SidewinderLaucher_F35";
	_object addMagazine "2Rnd_Sidewinder_F35";
	_object addWeapon "BombLauncherF35";
	_object addMagazine "2Rnd_GBU12";
	
	_object attachto [player,[0.0,5.0,2]];
	_object setfuel 0.5;
	sleep 3;
	detach _object;
	player reveal _object;

	cutText [format["You've made a AH6J!"], "PLAIN DOWN"];
	
	r_interrupt = false;
	player switchMove "";
	player playActionNow "stop";
	
	sleep 10;
	
	cutText [format["Warning: Spawned AH6Js DO NOT SAVE after server restart!"], "PLAIN DOWN"];
	
};

What? Don't judge me. I pay the rent on the server, and if I decide I was a little bird with a Gau-8, helfire, and GBU-12s then I'mma spawn it!

 

What I'd like to do is convert this script so I can pass a vehicle classname to it in the extra rc file, but I'm not clear on how this works. I think what I need to do is something like this, but I can't get the syntax right.

 

script = [bAF_Apache_AH1_D] "execVM 'custom\admindeploy\opah6j.sqf'";

 

then

_itemsPlayer = items player;
if (dayz_combat == 1) then { 
    cutText [format["You are in Combat and cannot build an AH6J."], "PLAIN DOWN"];
} else {

	player playActionNow "Medic";
	r_interrupt = false;
	_dis=10;	
	sleep 6;
	
	_object = %1 createVehicle (position player);
	_object setVariable ["ObjectID", "1", true];
	_object setVariable ["ObjectUID", "1", true];
	_object setVariable ["MalSar",1,true];
	_object addWeapon "GAU8";
	_object addMagazine "1350Rnd_30mmAP_A10";
	_object addWeapon "HellfireLauncher";
	_object addMagazine "8Rnd_Hellfire";
	_object addWeapon "SidewinderLaucher_F35";
	_object addMagazine "2Rnd_Sidewinder_F35";
	_object addWeapon "BombLauncherF35";
	_object addMagazine "2Rnd_GBU12";
	
	_object attachto [player,[0.0,5.0,2]];
	_object setfuel 0.5;
	sleep 3;
	detach _object;
	player reveal _object;

	cutText [format["You've made a AH6J!"], "PLAIN DOWN"];
	
	r_interrupt = false;
	player switchMove "";
	player playActionNow "stop";
	
	sleep 10;
	
	cutText [format["Warning: Spawned AH6Js DO NOT SAVE after server restart!"], "PLAIN DOWN"];
	
};

But that doesn't work. Am I supposed to declare a private variable like this

 

private ["_spawnveh"]

 

and then

 

_spawnveh = %1

 

and then

 

_object = _spawnveh createVehicle (position player);

 

Or maybe I'm supposed to use the (to me) strange

 

_spawnveh = _this select 0

 

Another question I have is is it ok to move this script to server side? Is there any reason it woudln't work if I called it with

 

/z/dayz_server/script.sqf

 

Any guidance is appreciated. Thank you all.

 

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Love the heli spawn.  May have to try it just for the giggles :) .

 

Passing parameters is usually done via the _resultVariable = ["variable1", "variable2", "variable3"] spawn/execvm "script", options

 

They are then referenced in the script via the magic variable "_this" which is an array of the sent variables.

 

_this 0 = "variable1"

_this 1 = "variable2"

_this 3 = "variable3" etc

 

Alternatively, some of the scripts in Epoch are using global variables which are accessable to all scripts (not really recommended).  These are defined in the variables.sqf.

 

If you want ot get creative then you can pass sets of variables (as arrays) nested in variables that can then be extracted at the other end through _this and then put through other loops to split them out again (a vehicles inventory as a variable then split out in to weapons, ammo, backpacks in the script for example).

Link to comment
Share on other sites

  • 0

Hmmm, something's still not right. My extrarc file is broken, I'm sure my syntax sucks.

		class Kobalt5 {
		text = "Spawn OP AH6J";
		script = "["AH6J_EP1"] execVM ""custom\admindeploy\opheli.sqf"";";
                };

16:42:46 File mpmissions\dayz_Epoch_24.Napf\custom\extra_rc.hpp, line 38: '/ExtraRc/EvKobalt/Kobalt5.script': Missing ';' at the end of line
16:42:46 Error context ] execVM ""custom\admindeploy\opheli.sqf"";";
ErrorMessage: File mpmissions\dayz_Epoch_24.Napf\custom\extra_rc.hpp, line 38: '/ExtraRc/EvKobalt/Kobalt5.AH6J_EP1': '"' encountered instead of '='

 

If I ever get this working I'll happily polish it up and post it here, you know, for science.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...