Jump to content
Sign in to follow this  
Valfunction

cursorTarget help

Recommended Posts

I am trying to create a script where if you point at civilians with your weapon they stop moving. I have tested it with a couple mates in multiplayer (I'm the host) and it seems that I am the only one for whom the script works. When they point at the civilians nothing happens. I'm kinda stumped as to why. Code below:

while {alive player} do {
	if ( (side cursorTarget) == civilian ) then
		{
			_trg = cursorTarget;				
			_trg disableAI "MOVE";	

			sleep 5;

			_trg enableAI "MOVE";

   		}
};

Share this post


Link to post
Share on other sites

side cursorTarget? why side? If this script is running on the player client machine, you should say side player cursorTarget

actually, ignore that. I'm not near my gaming machine and can't check my code where it's working.

---------- Post added at 12:52 ---------- Previous post was at 12:46 ----------

Have you tried cursorTarget isKindOf "Civilian"

Share this post


Link to post
Share on other sites

Hi,

The main problem is that since you are the Host, the AI civilians are local to your machine (in this case the server) and disable/enableAI commands need to run where the units are local.

So, for the host it will work fine (yourself), but in the case of other players, it won't.

You will need to make sure other players disable/enableAi the units where they are local.

Share this post


Link to post
Share on other sites

cursorTarget is always for player so "player cursorTarget" would be incorrect syntax for it. Also it works fine for my so "side cursorTarget" seems to work fine the problem is it works only on the server (in this case me).

The main problem is that since you are the Host, the AI civilians are local to your machine (in this case the server) and disable/enableAI commands need to run where the units are local.

So, for the host it will work fine (yourself), but in the case of other players, it won't.

You will need to make sure other players disable/enableAi the units where they are local.

Ah ok. I didn't notice disableAI was local - oops. So I would need to run it through something like CBA_fnc_globalExecute.

Share this post


Link to post
Share on other sites
Ah ok. I didn't notice disableAI was local - oops. So I would need to run it through something like CBA_fnc_globalExecute.

Yes, that would be a way to do it. :)

Share this post


Link to post
Share on other sites

I have tried to do this with both globalExecute as well as creating event handlers. At the moment I am trying with event handlers. My two scripts are as such:

_land = nearestObject [player, "LandVehicle"];
_air = nearestObject [player, "Air"];
_ship = nearestObject [player, "Ship"];

while {alive player} do {
	if ( ((side cursorTarget) == civilian) AND (cursorTarget != _land) AND (cursorTarget != _air) AND (cursorTarget != _ship)) then
		{
			_trg = cursorTarget;				

			["Stop", [_trg]] call CBA_fnc_globalEvent;
   		}
};

This calls the event in the following script:

["Stop", {
_unit = _this select 0;
sleep 0.1;
_unit disableAI "MOVE";

escort1 = _unit addAction ["Escort", "CIS\escort.sqf"];
check1 = _unit addAction ["Check ID", "CIS\id.sqf"];

sleep 5;

_unit removeAction escort1;
_unit removeAction check1;

_unit enableAI "MOVE";
}] call CBA_fnc_addEventHandler;

The addactions work so I know that the event handlers is working but the disableAI does not work at all. The guy just keeps walking around.

I've also tried doing it with globalExecute but same thing the guy keeps walking around but I get the addactions.

Share this post


Link to post
Share on other sites
I have tried to do this with both globalExecute as well as creating event handlers. At the moment I am trying with event handlers. My two scripts are as such:

_land = nearestObject [player, "LandVehicle"];
_air = nearestObject [player, "Air"];
_ship = nearestObject [player, "Ship"];

while {alive player} do {
	if ( ((side cursorTarget) == civilian) AND (cursorTarget != _land) AND (cursorTarget != _air) AND (cursorTarget != _ship)) then
		{
			_trg = cursorTarget;				

			["Stop", [_trg]] call CBA_fnc_globalEvent;
   		}
};

This calls the event in the following script:

["Stop", {
_unit = _this select 0;
sleep 0.1;
_unit disableAI "MOVE";

escort1 = _unit addAction ["Escort", "CIS\escort.sqf"];
check1 = _unit addAction ["Check ID", "CIS\id.sqf"];

sleep 5;

_unit removeAction escort1;
_unit removeAction check1;

_unit enableAI "MOVE";
}] call CBA_fnc_addEventHandler;

The addactions work so I know that the event handlers is working but the disableAI does not work at all. The guy just keeps walking around.

I've also tried doing it with globalExecute but same thing the guy keeps walking around but I get the addactions.

addactions are local, so u have to execute your "escort" and "check id" scripts globaly when activated by someone..

you can also put your conditions directly into the addaction itself if u wanted. that way it will always be there but never show the addaction untill the conditions are met.. here;s an example of an addaction i've used.

animal = player addAction ["Gather Meat", "meat_value.sqf",true,0,false,true,"","Local player && vehicle player == player && cursorTarget isKindOf 'Animal' && !alive cursorTarget && (_target distance cursorTarget) < 2 && !(_target getVariable 'GutAnimal')"];

Edited by Nimrod_Z

Share this post


Link to post
Share on other sites

The addactions are executed globally thanks to the CBA_fnc_globalEvent and they work on a dedicated server. It's the disableAI which is the issue.

Share this post


Link to post
Share on other sites

You can't sleep in EV's you need to use spawn.

["Stop", {
_this spawn {
	_unit = _this select 0;
	sleep 0.1;
	_unit disableAI "MOVE";

	escort1 = _unit addAction ["Escort", "CIS\escort.sqf"];
	check1 = _unit addAction ["Check ID", "CIS\id.sqf"];

	sleep 5;

	_unit removeAction escort1;
	_unit removeAction check1;

	_unit enableAI "MOVE";
};
}] call CBA_fnc_addEventHandler;

And your vehicle check can be done a lot easier.


while {alive player} do {
	if ( ((side cursorTarget) == civilian) AND (vehicle cursorTarget == cursorTarget)) then
		{
			_trg = cursorTarget;				

			["Stop", [_trg]] call CBA_fnc_globalEvent;
   		}
};

Share this post


Link to post
Share on other sites

Did not know this. Using the spawn command created some really weird lag. What I ended up doing is creating an event for the disableAI and addActions and then a separate event for the enableAI and removeActions. I called the first then slept 5 then called the second.

Share this post


Link to post
Share on other sites

Using spawn should not create any lag. Use a sleep in the while loop as well, running forever-while loops without any sleep is rarely needed.

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  

×