Jump to content
Sign in to follow this  
skimmer8824

Client controlling AI local to server

Recommended Posts

Hi all, I just want to begin with that these forums and the BIS wiki have been a great resource to me in the past for SP missions; however, with the release of Arma3 I have just recently begun to take up scripting for MP compatible missions. What my problem comes down to is I am having trouble allowing a client to control an AI squad or vehicle that is local to the server. I have been trying numerous techniques with setVariable and publicVariable without any success. Below I have posted a simplified version of what I am trying to accomplish. The player has an action to move the AI unit to the player's current location. Testing this in SP, listen server, and dedicated, results in the AI unit's failure to move.

init.sqf

if (!isServer) then {waitUntil {!isNull player}};
showChat TRUE;

//Server
if (isServer) then
{
MOVEGROUP = createGroup WEST;
GUY = MOVEGROUP createUnit ["B_Helipilot_F", getPos cone,[],0,"NONE"]; 
publicVariable "GUY";
_null = [] execVM "loop.sqf";
};

//Client
if(!isDedicated) then
{
player addAction ["Move GUY","move.sqf"];
};

loop.sqf:

GUY setVariable ["GUYMOVETO",[], TRUE];
GUY setVariable ["GUYMOVE",FALSE, TRUE];

while {TRUE} do
{
if (GUY getVariable "GUYMOVE") then
{
	GUY move (GUY getVariable "GUYMOVETO");
	GUY setVariable["GUYMOVETO",[],TRUE];
	GUY setVariable["GUYMOVE",FALSE,TRUE];
	GUY globalChat "moving...";
	publicVariable "GUY";
};
sleep 0.5;
];	

move.sqf:

private ["_pos"];

if (GUY getVariable "GUYMOVE") exitWith {player globalChat "can't move";};

_pos = getPos player;
hint str _pos;

player globalChat "sending move order";
GUY setVariable["GUYMOVETO",_pos,TRUE];
GUY setVariable["GUYMOVE",TRUE,TRUE];
publicVariable "GUY";

I could be completely misunderstanding the usage of setVariable, but that's why I am posting this here. Thanks for any help!

Edited by skimmer8824

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  

×