Jump to content
Sign in to follow this  
nullsystems

Vehicle Rembering its "Name" after respawn...

Recommended Posts

ello,

Im using a simple respawn script.

How can I get the vehicle to remember its original name ( set from the editor ) after it respawns?

I tried:

_vcl = _type createVehicle _pos;

_vcl setVehicleVarName _name_vcl;

publicVariable "_name_vcl";

call compile format["%1 = _vcl", _name_vcl];

hint format["%1",vehicleVarname _vcl];

But this does not work.

The hint comes up with the name I want, but when I try and do anything by calling that name, it doesnt identify it.

Edited by nullsystems

Share this post


Link to post
Share on other sites

You can probably do it with a "killed" event handler.

Try and find scripts which retain non-standard weapon loadouts - like this old sqs script I just happen to have:

<code>

;Universal Weapons Respawn Script v1.04 (March 31, 2003) revised (February 1, 2007)

;Required Version: ArmA

;original by toadlife revised by norrin for ArmA

;toadlife@toadlife.net

;intialize like this: ["unitname",0] exec "weapons_respawn.sqs"

; Or this: ["unitname",1] exec "weapons_respawn.sqs"

;

; * "unitname" = The name of the player the script runs on (must be enclosed by quotes!)

; * 0/1 = method of repleneshing weapons

; **if method is 0, the player gets the same weapons he started out with every time

; **if method is 1, the player gets the same weapons he had when he died

;

; Advanced example method of initializing script - put the following lines in your init.sqs,

; and replce the unit names with your own:

;_units = ["w1","w2","w3","w4","w5","w6","w7","w8","w9","w10","w11","w12","w13","w14","w15","w16","w17","w18"]

;{[_x,0] exec "weapons_respawn.sqs"} foreach _units

;

;

~(random 0.3)

_name = _this select 0

_method = _this select 1

_hasrifle = false

_unit = call compile format["%1",_name]

?(_method == 0):_return = "checklocal";goto "guncheck"

#checklocal

_unit = call compile format["%1",_name]

?(local _unit):goto "respawnloop"

~(1 + (random 3))

goto "checklocal"

#respawnloop

@!alive _unit

#checkmethod

?(_method == 1):_return = "waitforlife";goto "guncheck"

#waitforlife

@alive call compile format["%1",_name]

_unit = call compile format["%1",_name]

removeAllWeapons _unit

?_hasrifle:_guns = _guns - [_prigun];_guncount = count _guns

_c = 0

while {_c <= (_magcount - 1)} do {_unit addmagazine (_mags select _c); _c = _c + 1}

_c = 0

while {_c <= (_guncount - 1)} do {_unit addweapon (_guns select _c); _c = _c + 1}

?_hasrifle:_unit addweapon _prigun;_gun = _guns + [_prigun]

;//If unit has a rifle select it

?_hasrifle:goto "selectrifle"

;//No rifle - if unit has a pistol, select it

?_unit hasweapon ((weapons _unit - [secondaryweapon _unit,"Binocular","NVGoggles"]) select 0):_unit selectweapon ((weapons _unit - [secondaryweapon _unit,"Binocular","NVGoggles"]) select 0);goto "respawnloop"

;//No rifle or pistol, select secondary weapon

_unit selectweapon secondaryweapon _unit

goto "respawnloop"

#selectrifle

;// BUG WORKAROUND! - Added to compensate for selectweapon bug

;// Any gun with more than one muzzle (grenadelaunchers) cannot be selected with selectweapon!

;// Default Grenadelaunchers supported - Add your own types if you need to.

_unit selectweapon _prigun

?_prigun == "M16A2GL":_unit selectweapon "M16Muzzle"

?_prigun == "M16A4GL":_unit selectweapon "M16Muzzle"

?_prigun == "M16A4_ACG_GL":_unit selectweapon "M16Muzzle"

?_prigun == "M4GL":_unit selectweapon "M4Muzzle"

?_prigun == "M4A1GL":_unit selectweapon "M4Muzzle"

?_prigun == "AK74GL":_unit selectweapon "AK74Muzzle"

goto "respawnloop"

#guncheck

_guns = weapons _unit

_mags = magazines _unit

~(random 0.5)

_guncount = count _guns

_magcount = count _mags

?_unit hasweapon (primaryweapon _unit):_hasrifle = true;_prigun = primaryweapon _unit;goto _return

_hasrifle = false

goto _return

</code>

you might be able to reverse engineer some of the ideas from there in order to pass a variable to object on respawn?

PS - sorry if that script just scared the bejesus out of you =]

Share this post


Link to post
Share on other sites

Here's the code I use, but using your variable names, maybe it'll work? :)

_vcl SetVehicleVarName _name_vcl;
_vcl Call Compile Format ["%1=_This ; PublicVariable ""%1""",_name_vcl];

Share this post


Link to post
Share on other sites

Nope, didnt work.

Also, I dont see any connection between what im trying to do an that script.

Share this post


Link to post
Share on other sites

Adapt this. Kudos to Sickboy and Spooner. :bounce3:

{
if (local _x) then
{
	_x setVariable ["proper_name",vehicleVarname _x]; // format["%1",_x] should work aswell
};
} forEach playableUnits;

	private ["_unitName","_newUnit"];
_unitName = _this getVariable "proper_name";
waitUntil {alive (call compile _unitName)};
_newUnit = (call compile _unitName);
_newUnit setVariable ["proper_name",vehicleVarname _newUnit]; // format["%1",_newUnit] should work aswell

Share this post


Link to post
Share on other sites

But this does not work.

The hint comes up with the name I want, but when I try and do anything by calling that name, it doesnt identify it.

You can't publicVariable a local variable, in your case _name_vcl.

So this is wrong:

publicVariable "_name_vcl";

How about this one:

_vcl = _type createVehicle _pos;
call compile format ["
   %1 = _vcl;
   publicVariable '%1';
", _name_vcl];

The advantage is that it is also JIP aware. I've never used setVehicleVarname, no need for it.

Xeno

Edited by Xeno

Share this post


Link to post
Share on other sites

Thanks guys, going to test :)

Edited by nullsystems

Share this post


Link to post
Share on other sites

alternatively you can set the vehiclevarname with setvehicleinit, which is how i do it. ie

_veh setvehicleinit
'
name = this;
this setvehiclevarname "name";
';
processinitcommands;

this has full jip support and broadcasts to all clients etc.

Share this post


Link to post
Share on other sites
alternatively you can set the vehiclevarname with setvehicleinit, which is how i do it. ie
_veh setvehicleinit
'
name = this;
this setvehiclevarname "name";
';
processinitcommands;

this has full jip support and broadcasts to all clients etc.

how would I use this code if I already have code to execute a respawn script in the vehicle's init line? Should this be written into another script that I should also execute in the init line? How exactly would that script be written? I'm not a scripter (yet).

I am finishing up a big CTF "war" map with respawning vehicles and AI that is triggered and scripted to behave like a human might while playing CTF. But, because of the way I have the AI commanded to enter a vehicle if the vehicle is present at the time they are near it, I need the vehicle to remember it's name.

Thanks in advance!

Share this post


Link to post
Share on other sites

you can setvehicleinit as much as you want and they will all work as long as you processinitcommands straight after each one. so if you had a respawn script in the vehicles initline previously it doesnt matter as it has already been processed.

Share this post


Link to post
Share on other sites
alternatively you can set the vehiclevarname with setvehicleinit, which is how i do it. ie
_veh setvehicleinit
'
name = this;
this setvehiclevarname "name";
';
processinitcommands;

this has full jip support and broadcasts to all clients etc.

So this string of text just gets entered into the init line for the vehicle? I am guessing I would just put a ";" after the line that executes the respawn script, then add this line of code, followed by it's ";" as in:

"line of code"; "other line of code"; <---entered in the init field

Right? Thanks a lot guys!

Share this post


Link to post
Share on other sites

Noob here, but I'm trying to do something similar to Eclipse. When I put this code in the vehicle's initialization box I get a "Local Variable in Global Space" error.

@Eclipse, did you figure this out?

Thanks in advance.

Share this post


Link to post
Share on other sites

use this respawn script, it works great, and all the parameters can be edited according to how you want it to work.

Good luck!

Share this post


Link to post
Share on other sites

Thanks for the quick reply. Didn't see the script though. :)

Share this post


Link to post
Share on other sites

Once your unit is killed, just take the initial location. I made this for one of my missions.

!alive blablabla
deleteVehicle [i]nameofyourvehicle[/i];
[i]nameofyourvehicle[/i] = "[i]classnameofyouvehicle[/i]" createVehicle [[i]position,ofyour,vehicle[/i]];

U may also use

[i]nameofyourvehicle[/i] setdir [i]azimut[/i];

Edited by Ashka

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  

×