Jump to content
Sign in to follow this  
Tajin

Vehicle Respawn with Name & Init

Recommended Posts

I've noticed that the respawnscripts used in most of the threads here are pretty basic and not useful if you have running scripts, that a) need to be executed again after respawn or b) rely on a correct vehicleVarName.

If that is the case for you, have a look at this script.

It also takes an somewhat different, point-based approach on deciding when the respawn should come active.

t-respawn.sqf

if (isServer) then {
_obj = _this select 0;
_time = _this select 1;
_delay = _this select 2;
_times = _this select 3;
_vinit = _this select 4;

_pos = getPos _obj;
_dmg = getDammage _obj;
_vup = vectorUp _obj;
_vdir = vectorDir _obj;
_fuel = fuel _obj;
_fire = canFire _obj;
_type = typeOf _obj;

_count = 0;

for [{_loop=0},{(_count <= _delay)},{_loop=_loop}] do 
{

	if ({alive _x} count crew _obj > 0) then {
		_count = 0;
	} else {
		if (!canMove _obj) then {
			_count = _count + 2;
		};
		if ((getPos _obj distance _pos) > 10) then {
			_count = _count + 1;
		};
		if (_fire && !canFire _obj) then {
			_count = _count + 1;
		};
		if (damage _obj > 0.95) then {
			_count = _count + 3;
		};
	};
	sleep 1;
};

_name = vehicleVarName _obj;
if (_name == "") then {
	_name = "nul";
};
deleteVehicle _obj;
sleep _time;

if (_times != 0) then {
	_times = _times - 1;
	_new = _type createVehicle _pos;
	_new setPos _pos;
	_new setVectorDirAndUp [_vdir,_vup];
	_new setDamage _dmg;
	_new setFuel _fuel;
	nul=[_new,_time,_delay,_times,_vinit] execVM "t-respawn.sqf";
	_new setVehicleInit format["%1 = this;%2;this setVehicleVarName '%1'",_name,_vinit];
	processInitCommands;
};
};

Execute it like this (init line) but change the values:

nul=[this,respawntime,spawndelay,spawncount,init] execVM "t-respawn.sqf";

respawntime simple, the delay between the removal of the old vehicle and the spawning of the new one.

spawndelay this is the tolerance the object has, it defines how long certain conditions have to be met for the respawn to kick in. These conditions are the following: unable to fire, unable to move, damaged to 95%, not at its starting position. The more of these conditions are met, the sooner the vehicle will respawn. All this only has an effect if the vehicle is empty.

spawncount how often will it respawn ? A negative value equals unlimited times.

init If you need any scriptcommands to be executed after the respawn, type them "here".

Enjoy.

Edited by Tajin

Share this post


Link to post
Share on other sites

Should work now, just tested it a bit and updated.

Share this post


Link to post
Share on other sites

Will be putting it to my test as well, a little later. I may need ONE more piece of script to make things work the way I have it envisioned. Thank you for the script!

Share this post


Link to post
Share on other sites

The conditions for spawndelay would be made more flexible if they were seperate. For example: You want the vehicle to respawn with a short delay if it is destroyed but not if the vehicle is left somewhere (or you want a diferent value for this condition).

Question: Why do you check both canMove and damage? If the vehicle is 95% damaged it wont be able to move, wright?

if (_fire && !canFire _obj)

I got stuck at this part :( , i'd be gratefull if you could explain it.

Nice script, thank you for sharing it :) .

Share this post


Link to post
Share on other sites

Right now it spaws where it was, that can be added though.

Regarding flexibility of the spawndelay, you can easily alter that in the script.:

			if (!canMove _obj) then {
			_count = _count + 2;
		};
		if ((getPos _obj distance _pos) > 10) then {
			_count = _count + 1;
		};
		if (_fire && !canFire _obj) then {
			_count = _count + 1;
		};
		if (damage _obj > 0.95) then {
			_count = _count + 3;
		};

For example if you want the distance condition to have an higher impact you could change the + 1 to + 5 or so. I've set these values from scratch, feel free to tweak them as you see fit.

canMove is very different to the damage condition.

An vehicle can have lets say 20% damage and still be unable to move if the engine is damaged.

			if (_fire && !canFire _obj) then {
			_count = _count + 1;
		};

This part checks if the vehicle was able to fire when it spawned and if it is still able to fire. (wouldn't make much sense to add a point for not beeing able to fire on a vehicle that has no weapons)

Share this post


Link to post
Share on other sites

Ahh yes everything seems to make more sense this morning :D .

You could submit it to ofpec, Armaholic, etc, im sure it would get plenty of hits.

Nice work :) .

Share this post


Link to post
Share on other sites

:happy: Thanks, I'll consider that. :hmmm:

- offtopic, since I was just thinking about it: What would you say, if we had sticky satchel charges ?

Tried the basics of it yesterday and it works like a charm.

Edited by Tajin

Share this post


Link to post
Share on other sites

So, this script works great, but I have one question about the count when a vehicle is empty. I see that the vehicle being empty and unable to fire adds to the count value, as well as being damaged over 95%, etc etc. If you add up all these values that add to the count, if comes out to 7. Would putting a value higher than what these numbers add up to make it so that the vehicle would never respawn until it was fully destroyed? I don't want the vehicle to disappear as soon as people leave it, whether it is able to fire, disabled, damaged over 95% or not. I want them to be able to use it for cover, at least for a while. Maybe have a minute or 2 before it catches fire, is detroyed, then respawns. How would I accomplish this using this script?

Thanks!

After reading through the script again, I think I see that the spawn delay variables are looping once a second. So, if the vehicle was disabled, but otherwise ok, and being disabled counted as a "1", and I had the respawndelay set to 20 in the vehicle's init line to execute the script, then it would take 20 seconds before the vehicle was removed, then whatever the spawn time was set to before it respawned, correct?

Edited by Eclipse4349
just noticed something... I think...

Share this post


Link to post
Share on other sites

Exactly, thats the whole Idea behind it. :)

If the vehicle is disabled (unable to move), with a delay of 20 it would take 10 seconds before the respawn kicks in.

If it is disabled and unable to fire, it takes 7 seconds.

The more useless it is, the sooner it'll be removed.

You might want to lower the points for the 95% damaged-condition though, right now it'll spawn really fast in this case, because if its 95% damaged, it is completely fubar and therefor also not able to move or fire.

Well.. people would use that for VBIED's :eek: .

Yup, no more scripts needed for that then (except for the AI). :D

Edited by Tajin

Share this post


Link to post
Share on other sites

NICE WORK!

Now, if I could just get my AI units to respawn with their names intact so my triggers work to get them to use the vehicles after the units have respawned, and not just at the start of the round while they are still named, I will be all set, and my big CTF warzone will be ready to test in MP! Or, I need to change the way I order them into vehicles. But, since I cannot group an empty vehicle to a group of Blufor or Opfor units, I can't use a "get in" trigger. Any ideas? Is there a way to create a Blufor or Opfor vehicle with 0 crew members?

Share this post


Link to post
Share on other sites

Provide some more detail on how they respawn and how they're ordered to board vehicles. Or even better: what you need them for.

edit.: nevermind, just noticed your other thread.

Edited by Tajin

Share this post


Link to post
Share on other sites

Thanks a lot, you have no idea how bad I want to get this mission finished and posted on the User Mission section!

I explained the situation in detial here:

http://forums.bistudio.com/showthread.php?t=79179

Thank you so much for all the support. If you have xfire, please feel free to add me, or on Steam. I can give you my name via PM if you want it.

Share this post


Link to post
Share on other sites

I would like to run this script or functions when a vehicle respawns :

this removeMagazine "14Rnd_FFAR";
this addMagazine "4000Rnd_762x51_M134";

How can I make this happen? I dont get along with the init parameter very well, thought it should be entered there but how?

Share this post


Link to post
Share on other sites
I would like to run this script or functions when a vehicle respawns :

this removeMagazine "14Rnd_FFAR";
this addMagazine "4000Rnd_762x51_M134";

How can I make this happen? I dont get along with the init parameter very well, thought it should be entered there but how?

Like it says in the first post, write in the script call the commands you wrote in the vehicle's init box:

nul=[this,respawntime,spawndelay,spawncount,init] execVM "t-respawn.sqf"; replace init with the commands you posted.

Share this post


Link to post
Share on other sites
Like it says in the first post, write in the script call the commands you wrote in the vehicle's init box:

nul=[this,respawntime,spawndelay,spawncount,init] execVM "t-respawn.sqf"; replace init with the commands you posted.

Just for my own education, to add more than one extra init command in the above line of code, would those commands have to be enclosed by () or ""? As in:

nul=[this,respawntime,spawndelay,spawncount,(command1, command2)] execVM "t-respawn.sqf" or

nul=[this,respawntime,spawndelay,spawncount,"command1, command2"] execVM "t-respawn.sqf"

Or could they just be listed, as in:

nul=[this,respawntime,spawndelay,spawncount,command1, command2] execVM "t-respawn.sqf"

Would they need commas after each command, like the other parameters, or would they have to have a semicolon after each of them since they are commands?

---------- Post added at 03:33 PM ---------- Previous post was at 03:10 PM ----------

And one more question about the script...

If I was to change:

_name = vehicleVarName _obj;

if (_name == "") then {

_name = "nul";

};

deleteVehicle _obj;

sleep _time;

to

_name = vehicleVarName _obj;

if (_name == "") then {

_name = "nul";

};

_obj setvehicledamage 1;

sleep _time;

would that make it so the vehicle caught fire and was destroyed, but stayed on the map as a destroyed husk, and the new one would still properly be created and named the same as the original?

Edited by Eclipse4349

Share this post


Link to post
Share on other sites
would that make it so the vehicle caught fire and was destroyed, but stayed on the map as a destroyed husk

yes. However it'll make abandoned vehicles explode instead of just removing them, which can result in collateral damage. Also I prefer cleaning up the wrecks, atleast after a while.

About the commands, yes they are seperated by semicolons and yes, put them in "".

Share this post


Link to post
Share on other sites

Im using this on a few vehicles, however there is one vehicle that i dont want to respawn if it is left empty somewhere.

Can i do this with this script? Would be a bit of a waste to run another script just for a single vehicle.

Share this post


Link to post
Share on other sites

If you use this modified version, you can set the points given for certain conditions in your init.

Init would now look like this:

nul=[this,respawntime,spawndelay,spawncount,init,[canmove,distance,canfire,damage]] execVM "t-respawn.sqf"

or in your specific case for that one vehicle:

nul=[this,respawntime,spawndelay,spawncount,init,[2,1,0,3]] execVM "t-respawn.sqf"

Script here:

if (isServer) then {
_obj = _this select 0;
_time = _this select 1;
_delay = _this select 2;
_times = _this select 3;
_vinit = _this select 4;
_points = _this select 5;

_pos = getPos _obj;
_dmg = getDammage _obj;
_vup = vectorUp _obj;
_vdir = vectorDir _obj;
_fuel = fuel _obj;
_fire = canFire _obj;
_type = typeOf _obj;

_count = 0;

for [{_loop=0},{(_count <= _delay)},{_loop=_loop}] do 
{

	if ({alive _x} count crew _obj > 0) then {
		_count = 0;
	} else {
		if (!canMove _obj) then {
			_count = _count + _points select 0;
		};
		if ((getPos _obj distance _pos) > 10) then {
			_count = _count + _points select 1;
		};
		if (_fire && !canFire _obj) then {
			_count = _count + _points select 2;
		};
		if (damage _obj > 0.95) then {
			_count = _count + _points select 3;
		};
	};
	sleep 1;
};

_name = vehicleVarName _obj;
if (_name == "") then {
	_name = "nul";
};
deleteVehicle _obj;
sleep _time;

if (_times != 0) then {
	_times = _times - 1;
	_new = _type createVehicle _pos;
	_new setPos _pos;
	_new setVectorDirAndUp [_vdir,_vup];
	_new setDamage _dmg;
	_new setFuel _fuel;
	nul=[_new,_time,_delay,_times,_vinit,_points] execVM "t-respawn.sqf";
	_new setVehicleInit format["%1 = this;%2;this setVehicleVarName '%1'",_name,_vinit];
	processInitCommands;
};
};

Share this post


Link to post
Share on other sites

I got it now working :D

Important thing was to convert the double quotes to single quotes when calling:

"this removeMagazine '14Rnd_FFAR'; this addMagazine '4000Rnd_762x51_M134'"

^^ This is the init parameter having two calls.

Having a concrete example of how this had looked would have saved me a lot of time actually ;)

---------- Post added at 12:30 PM ---------- Previous post was at 12:07 PM ----------

Instead of using parameters for the init I would like to define config or class files where startup attributes for certain types of vehicles are defined, is it possible to include a call to a config for the init parameter?

Share this post


Link to post
Share on other sites

You could use something like this instead:

"nul = [this] execVM 'somescript.sqf'"

and put all the settings you need in somescript.sqf

(handle for the vehicle would be _this select 0)

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  

×