Jump to content
burdy

Check if object is alive as defined in a variable

Recommended Posts

Hey, 

So working on a rally script. Problem is, the script fails to detect the object being created, and thus wont recognize that the rally is down, allowing  the player to continuously make rally's.

_play = _this select 0;
_name = _this select 1;
_markname = _this select 2;


if ({alive _x } count [_name] > 1) then {
hint "Rally already placed!";

} else 
{ 

disableUserInput true;
sleep 5;
_name = "LIB_AmmoCrates_NoInteractive_Large" createVehicle position _play;
disableUserInput false;
_markname = createMarker ["_markname", position _name];
_markname setMarkerShape "ICON";
_markname setMarkerType "hd_dot";
_markname setMarkerText format ["%1 Rally", _play];
_name = _name addAction ["Destroy Rally", "Destroy.sqf", _name];
publicvariable "_name";
};




 

Share this post


Link to post
Share on other sites

What is "_play" and "_name" in this context? Share your executing line of code as well (i.e. [myParameters] execVM "myScript.sqf";)

 

EDIT: I see that _name is the actionID and _play is the player...

 

 

Your issue is that you need to make _name -> name. No underscore. I recommend you change the variable name to something like: rallyPointActionID

 

Actually, I just redid it to some degree:

 

_player = _this select 0;
_markname = _this select 1;
_rallyObj = _player getVariable ["rallyPointObj",objNull];
_rallyExists = !isNull _rallyObj;

if (_rallyExists) then 
{
    hint "Rally already placed!";
} else 
{ 
    disableUserInput true;
    sleep 5;
    _obj = "LIB_AmmoCrates_NoInteractive_Large" createVehicle position _play;
    disableUserInput false;
    _player setVariable ["rallyPointObj",_obj];
    _markname = createMarker [_markname, position _obj];
    _markname setMarkerShape "ICON";
    _markname setMarkerType "hd_dot";
    _markname setMarkerText format ["%1 Rally", _play];
    _obj addAction ["Destroy Rally", "Destroy.sqf", _obj];
};

With the above you need to pass in the player themselves and a marker name in the form of a string. You will need to go into your Destroy.sqf and add a line similar to the following:

_player setVariable ["rallyPointObj",objNull];

 

Share this post


Link to post
Share on other sites
[squad1, ["Build Rally Point", "RallyPoint.sqf", [squad1, rally1, west_rally_mark]]] remoteExec ["addAction", 0, true];

_name builds the physical rally, _markname puts a marker on the rally which will be used as a teleport, and _play gives the name of the player which lets the script know where to place the rally. So far, everything works up until the script not allowing me to build multiple (have not got to test the destroy addaction though).   

Share this post


Link to post
Share on other sites

Check my edit on my first post and see if that makes more sense to you, it avoids needing the actual name of the rally. Make sure west_rally_mark is the in the form of a string with my version.

Share this post


Link to post
Share on other sites
56 minutes ago, jshock said:

Check my edit on my first post and see if that makes more sense to you, it avoids needing the actual name of the rally. Make sure west_rally_mark is the in the form of a string with my version.


So cool, that works! I edited it a bit so I dont need to deal with making the marker names strings 

_play = _this select 0;
_name = _this select 1;
_markname = _this select 2;
ObjVar = _play getVariable ["ObjVar",objNull];
_rallyExists = !isNull ObjVar;

if (_rallyExists) then {
hint "Rally already placed!";

} else 
{ 

disableUserInput true;
sleep 5;
_name = "LIB_AmmoCrates_NoInteractive_Large" createVehicle position _play;
disableUserInput false;
_play setVariable ["ObjVar", _name];
_markname = createMarker ["_markname", position _name];
_markname setMarkerShape "ICON";
_markname setMarkerType "hd_dot";
_markname setMarkerText format ["%1 Rally", _play];
[_name, ["Destroy Rally Point", "Destroy.sqf", [_play, _name, _markname]]] remoteExec ["addAction", 0, true];
publicvariable "_name";
};


However, on to the Destroy script - for some reason everything in the script works (or I should say, the marker delete works) but destroying the object - it instead sets the players damage to 1.

 

_play = _this select 0;
_name = _this select 1;
_markname = _this select 2;

_name setdamage 1;
_play setVariable ["ObjVar", objNull];
deletemarker "_markname";

 

Share this post


Link to post
Share on other sites

Replace your destroy.sqf stuff with this:

 

(_this select 3) params ["_play","_name","_markname"];

_name setdamage 1;
_play setVariable ["ObjVar", objNull];
deletemarker "_markname";

 

Share this post


Link to post
Share on other sites

Okay that works - problem is, is that everything works but destroying the physical crate - presumably because the crate doesn't have a "name"?

Share this post


Link to post
Share on other sites

Try this instead of setDamage:

 

deleteVehicle _name;

Share this post


Link to post
Share on other sites

Works perfectly, thanks a lot

Share this post


Link to post
Share on other sites

Last thing,

So trying to add a "scanner" which detects enemies within a radius, preventing you from placing the Rally - this is not working. Suggestions?

 

_play = _this select 0;
_name = _this select 1;
_markname = _this select 2;
_Toclose = 0;
Close =  _play getVariable ["Close",objNull];
ObjVar = _play getVariable ["ObjVar",objNull];
_rallyExists = !isNull ObjVar;
_distanceExists = !isNull Close;
_distance = {if ((side _x == west) && (_x distance _play <= 700)) then { _play getVariable ["Close",_Toclose];} else { _play getVariable ["Close",objNull];}} foreach allunits;

if (_distanceExists) then {
hint "Enemy too close! Must not be within 700 meters of an enemy soldier"; } else {

if (_rallyExists) then {
hint "Rally already placed!";

} else 
{ 

disableUserInput true;
sleep 5;
_name = "LIB_AmmoCrates_NoInteractive_Large" createVehicle position _play;
disableUserInput false;
_play setVariable ["ObjVar", _name];
_markname = createMarker ["_markname", position _name];
_markname setMarkerShape "ICON";
_markname setMarkerType "hd_dot";
_markname setMarkerText format ["%1 Rally", _play];
[_name, ["Destroy Rally Point", "Destroy.sqf", [_play, _name, _markname]]] remoteExec ["addAction", 0, true];
publicvariable "_name";
}
};

 

Share this post


Link to post
Share on other sites
_play = _this select 0;
_name = _this select 1;
_markname = _this select 2;

ObjVar = _play getVariable ["ObjVar",objNull];
_rallyExists = !isNull ObjVar;

_distanceExists = count (allUnits select {side _x == west && _x distance _play <= 700}) > 0;

if (_distanceExists) then 
{
	hint "Enemy too close! Must not be within 700 meters of an enemy soldier"; 
} else 
{
	if (_rallyExists) then 
	{
		hint "Rally already placed!";
	} else 
	{ 
		disableUserInput true;
		sleep 5;
		_name = "LIB_AmmoCrates_NoInteractive_Large" createVehicle position _play;
		disableUserInput false;
		_play setVariable ["ObjVar", _name];
		_markname = createMarker ["_markname", position _name];
		_markname setMarkerShape "ICON";
		_markname setMarkerType "hd_dot";
		_markname setMarkerText format ["%1 Rally", _play];
		[_name, ["Destroy Rally Point", "Destroy.sqf", [_play, _name, _markname]]] remoteExec ["addAction", 0, true];
		publicvariable "_name";
	};
};

 

Share this post


Link to post
Share on other sites

Thank you, 

 

 

EDIT : Nevermind - figured out my last question -  didn't realize that (_this select) was referring to the sequence and should remain 3 (in the destroy.sqf).

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

×