Jump to content
Sign in to follow this  
G4meM0ment

AI respawning - scripted coop mission

Recommended Posts

Hi again,

I've another question today :)

I wanted to write an AI respawn script, I already saw kind of Listener/Handler which deal with damage/death but I don't know how to check if a unit (not a vehicle) died...

My try would be some kind of "if(!alive _unit)".

Of course I would overgive _this from the init line of the AI to the script, I had the problem with Vehicles too but _unit1 = _this select 0; solved the problem, for soldiers it don't works...

I would continue the script by using an new thread which I send to sleep for an certain time and a the createUnit command to respawn it, would that work?

Thanks for helping me :)

Share this post


Link to post
Share on other sites

Your reasonings are correct. However if you need help, post your code, people will point problems out.

Share this post


Link to post
Share on other sites
Your reasonings are correct. However if you need help, post your code, people will point problems out.

OK so could you find the error here pls :P

if (!isServer) exitWith {};

_unit = _this select 0;
_delay = if (count _this > 1) then {_this select 1} else {300};
_marker = if (count _this > 2) then {_this select 2} else {"Spawn_west"};
_group = if (count _this > 3) then {_this select 3} else {"AI"};
_init = if (count _this > 4) then {_this select 4} else {""};
_skill = if (count _this > 5) then {_this select 5} else {0.5};
_rank = if (count _this > 6) then {_this select 6} else {"PRIVATE"};
_type = typeOf _unit;

hint "Debug 1";

while{_run} do {
hint "Debug 2";
sleep (2 + random 10);
if(!alive _unit) then {
	hint "Debug 3";
	[]spawn
       {
		hint "Debug 4";
        sleep _delay;
		_newUnit = _type createUnit[(getMarkerPos _marker), _group, _init, _skill, _rank];
		hint "Debug 5";
	};
};
};

And can you explain these groups to me? Because I dont know how to set a group and what a group is.

Share this post


Link to post
Share on other sites

Does no one see the error? Is there an error? Sorry for pushing here but I need this and google & co. just give me no useful anwser...

Share this post


Link to post
Share on other sites

Nothing should happen there since everything that happens is under a while check for _run but you don't declare _run anywhere.

Also this line will fail by default:

_group = if (count _this > 3) then {_this select 3} else {[color="#FF0000"]"AI"[/color]};

"AI" with quotes like that is a string, but when you use _group later in the createUnit array it's expecting a data type of Group, not a String.

You'd also need to privatize all your variables since they are later used in a spawn so I think they'd lose locality if you don't use private.

Share this post


Link to post
Share on other sites
Nothing should happen there since everything that happens is under a while check for _run but you don't declare _run anywhere.

Also this line will fail by default:

_group = if (count _this > 3) then {_this select 3} else {[color="#FF0000"]"AI"[/color]};

#

"AI" with quotes like that is a string, but when you use _group later in the createUnit array it's expecting a data type of Group, not a String.

You'd also need to privatize all your variables since they are later used in a spawn so I think they'd lose locality if you don't use private.

Would it work like this?

if (!isServer) exitWith {};

_unit = _this select 0;
_delay = if (count _this > 1) then {_this select 1} else {300};
_marker = if (count _this > 2) then {_this select 2} else {"Spawn_west"};
_group = (createGroup west);
_init = if (count _this > 4) then {_this select 4} else {""};
_skill = if (count _this > 5) then {_this select 5} else {0.5};
_rank = if (count _this > 6) then {_this select 6} else {"PRIVATE"};
_type = typeOf _unit;
_run = true;

hint "Debug 1";
while{_run} do {
if(!alive _unit) then {
	hint "Debug 2";
	[]spawn
	{
		hint "Debug 3";
		sleep _delay;
		_newUnit = _type createUnit[(getMarkerPos _marker), _group, _init, _skill, _rank];
		hint "Debug 4";
	};
};
sleep (2 + random 10);
};

---------- Post added at 20:36 ---------- Previous post was at 19:58 ----------

Would it work like this?

if (!isServer) exitWith {};

_unit = _this select 0;
_delay = if (count _this > 1) then {_this select 1} else {300};
_marker = if (count _this > 2) then {_this select 2} else {"Spawn_west"};
_group = (createGroup west);
_init = if (count _this > 4) then {_this select 4} else {""};
_skill = if (count _this > 5) then {_this select 5} else {0.5};
_rank = if (count _this > 6) then {_this select 6} else {"PRIVATE"};
_type = typeOf _unit;
_run = true;

hint "Debug 1";
while{_run} do {
if(!alive _unit) then {
	hint "Debug 2";
	[]spawn
	{
		hint "Debug 3";
		sleep _delay;
		_newUnit = _type createUnit[(getMarkerPos _marker), _group, _init, _skill, _rank];
		hint "Debug 4";
	};
};
sleep (2 + random 10);
};

I need tp add that it triggers "Debug 4" often so I think it dont sleeps and no solider spawns anyway....

---------- Post added at 20:42 ---------- Previous post was at 20:36 ----------

Ok I just tried it out now, pls help me :P

if (!isServer) exitWith {};
private["_unit", "_delay", "_marker", "_group", "_init", "_skill", "_rank", "_type", "_run"];
_unit = _this select 0;
_delay = if (count _this > 1) then {_this select 1} else {300};
_marker = if (count _this > 2) then {_this select 2} else {"Spawn_west"};
_group = (createGroup west);
_init = if (count _this > 4) then {_this select 4} else {""};
_skill = if (count _this > 5) then {_this select 5} else {0.5};
_rank = if (count _this > 6) then {_this select 6} else {"PRIVATE"};
_type = typeOf _unit;
_run = true;

hint "Debug 1";
while{_run} do {
if(!alive _unit) then {
	hint "Debug 2";
	[]spawn
	{
		hint "Debug 3";
		sleep _delay;
		_newUnit = _type createUnit[(getMarkerPos _marker), _group, _init, _skill, _rank];
		hint "Debug 4";
	};
};
sleep (2 + random 10);
};

Share this post


Link to post
Share on other sites

Hi mate... try this. Tested and working.

I changed a few things... like the delay so I could see the respawn happen in a few seconds.

Also changed the command for creating the unit (createUnit array). This is more efficient and the other command just plain didn't seem to work every time! Don't know why!

if (!isServer) exitWith {};

private ["_unit", "_delay", "_marker", "_group", "_init", "_skill", "_rank", "_type"];

_unit = _this select 0;
_delay = if (count _this > 1) then {_this select 1} else {5};
_marker = if (count _this > 2) then {_this select 2} else {"Spawn_West"};
_init = if (count _this > 3) then {_this select 4} else {""};
_skill = if (count _this > 4) then {_this select 5} else {0.5};
_rank = if (count _this > 5) then {_this select 6} else {"PRIVATE"};

_type = typeOf _unit;
_group = group _unit;

hint "Debug 1";

while {true} do {

if(!alive _unit) then {

	hint "Debug 2";
	sleep _delay;

	//uncomment the next line if you want the unit to be in a new group
	//_group = (createGroup west);

	_unit = _group createUnit [_type, getMarkerPos _marker, [], 0, "FORM"];
	_unit setrank _rank;
	_unit setskill _skill;
	_unit setvehicleinit _init;

	hint format ["All good!\n\n%1 created",_unit];

};

sleep 1;

};

Demo mission here if you need it.

Edited by twirly
Fixed link

Share this post


Link to post
Share on other sites
Hi mate... try this. Tested and working.

I changed a few things... like the delay so I could see the respawn happen in a few seconds.

Also changed the command for creating the unit (createUnit array). This is more efficient and the other command just plain didn't seem to work every time! Don't know why!

if (!isServer) exitWith {};

private ["_unit", "_delay", "_marker", "_group", "_init", "_skill", "_rank", "_type"];

_unit = _this select 0;
_delay = if (count _this > 1) then {_this select 1} else {5};
_marker = if (count _this > 2) then {_this select 2} else {"Spawn_West"};
_init = if (count _this > 3) then {_this select 4} else {""};
_skill = if (count _this > 4) then {_this select 5} else {0.5};
_rank = if (count _this > 5) then {_this select 6} else {"PRIVATE"};

_type = typeOf _unit;
_group = group _unit;

hint "Debug 1";

while {true} do {

if(!alive _unit) then {

	hint "Debug 2";
	sleep _delay;

	//uncomment the next line if you want the unit to be in a new group
	//_group = (createGroup west);

	_unit = _group createUnit [_type, getMarkerPos _marker, [], 0, "FORM"];
	_unit setrank _rank;
	_unit setskill _skill;
	_unit setvehicleinit _init;

	hint format ["All good!\n\n%1 created",_unit];

};

sleep 1;

};

Demo mission here if you need it.

Thank you very much :D now the AI in the camp will respawn :)

EDIT: Only init line doesn't work.

Edited by G4meM0ment

Share this post


Link to post
Share on other sites

Hey mate.... I was just looking at this again and the stuff in red needs fixing. That could be why the init didn't work.

_delay = if (count _this > 1) then {_this select 1} else {5};
_marker = if (count _this > 2) then {_this select 2} else {"Spawn_West"};
_init = if (count _this > 3) then {_this select [color="#FF0000"]3[/color]} else {""};
_skill = if (count _this > 4) then {_this select [color="#FF0000"]4[/color]} else {0.5};
_rank = if (count _this > 5) then {_this select [color="#FF0000"]5[/color]} else {"PRIVATE"};

My stuff up... I made a change on the left but not on the right and didn't test with an init line.

Share this post


Link to post
Share on other sites
Hey mate.... I was just looking at this again and the stuff in red needs fixing. That could be why the init didn't work.

_delay = if (count _this > 1) then {_this select 1} else {5};
_marker = if (count _this > 2) then {_this select 2} else {"Spawn_West"};
_init = if (count _this > 3) then {_this select [color="#FF0000"]3[/color]} else {""};
_skill = if (count _this > 4) then {_this select [color="#FF0000"]4[/color]} else {0.5};
_rank = if (count _this > 5) then {_this select [color="#FF0000"]5[/color]} else {"PRIVATE"};

My stuff up... I made a change on the left but not on the right and didn't test with an init line.

Ohh didn't noticed that, I'm sorry.

Share this post


Link to post
Share on other sites
Hey mate.... I was just looking at this again and the stuff in red needs fixing. That could be why the init didn't work.

_delay = if (count _this > 1) then {_this select 1} else {5};
_marker = if (count _this > 2) then {_this select 2} else {"Spawn_West"};
_init = if (count _this > 3) then {_this select [color="#FF0000"]3[/color]} else {""};
_skill = if (count _this > 4) then {_this select [color="#FF0000"]4[/color]} else {0.5};
_rank = if (count _this > 5) then {_this select [color="#FF0000"]5[/color]} else {"PRIVATE"};

My stuff up... I made a change on the left but not on the right and didn't test with an init line.

Ok I need to ask again, I've changed the code now to get the right array "part". But I dont know how I could edit it that the solider will have this in the right way, because he always need the script which tells him to execute the script (respawn scipt) and in my case some more stuff but it don't works :/ Could you help me out please? :p

Share this post


Link to post
Share on other sites

Hi.. I'm not following you exactly but you can execute this script from the soldiers init or from another script if you wanted.

To execute from the soldiers init add this text.

This is supplying all the paramaters for the script and the script is called "respawn.sqf".

nul = [this,300,"Spawn_West","",0.8,"PRIVATE"] execVM "respawn.sqf";

I have updated the little test mission to show you two ways to execute the script. Download it and have a look at it.

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  

×