Jump to content
HatchetJesus

getpos player in multiplayer

Recommended Posts

I'm trying to get AI's to basically hunt players. I've been using getpos player to do this and it works very well in singleplayer.

But how would I go about to do it in multiplayer? I want the AI to move to a random player or alt -Random Bluefor unit.

(Also - What would actually happen if I used the getpos in multiplayer?

Share this post


Link to post
Share on other sites

getPos in multiplayer will work the same way as in single player. Now to move to a random Blufor unit. First you have to have an array of all the units of Blufor. Once you have that array use BIS_fnc_selectRandom to select a random unit. Once you have that unit you can tell the A.I. to move to that unit pos.

Share this post


Link to post
Share on other sites

Thanks for the answer. Question though...

You say that the getpos will work the same way in multiplayer. But when I use getpos player the AI will move to the player. What happens when there are multiple players? Who will the AI go to?

Share this post


Link to post
Share on other sites
Thanks for the answer. Question though...

You say that the getpos will work the same way in multiplayer. But when I use getpos player the AI will move to the player. What happens when there are multiple players? Who will the AI go to?

Seeing as to how the setPos will need to be done for isServer, you're right, it won't work for player. However, he never said to do it that way.

This is what he was getting at. This script assumes that all playable units are on one side (there is no PvP).

waitUntil {player == player};

playerarray = [];
{
playerarray = playerarray + [_x];
} forEach playableUnits; 

randomplayer = playerarray call BIS_fnc_selectRandom; 

randomplayerpos = getPos randomplayer; 
//Here, add a waypoint with the position being randomplayerpos

Share this post


Link to post
Share on other sites

Thanks. but if we make this more simplistic. Let's say I want a unit to move to an array with use of the bis_fnc_selectrandom.

Example: EnemyUnit Move getpos f_var_men_players bis_fnc_selectrandom... But how would I make that line into a working command?

Share this post


Link to post
Share on other sites

What you just said is what my lines do. You just need to add the waypoint in, which you need a group name for.

Share this post


Link to post
Share on other sites

Ok, so When trying it out I'm getting an error saying the array has no elements. What am I doing wrong?

Share this post


Link to post
Share on other sites

I already have it as an sqf. But when activated - I get the error.

waitUntil {player == player};

playerarray = [];

{

playerarray = playerarray + [_x];

} forEach playableUnits;

randomplayer = playerarray call BIS_fnc_selectRandom;

randomplayerpos = getPos randomplayer;

_wp = AS addWaypoint [position randomplayerpos, 0]

Is the waypoint added wrong?

Share this post


Link to post
Share on other sites
I'm trying to get AI's to basically hunt players. I've been using getpos player to do this and it works very well in singleplayer.

But how would I go about to do it in multiplayer? I want the AI to move to a random player or alt -Random Bluefor unit.

(Also - What would actually happen if I used the getpos in multiplayer?

You could do a loop like this (so if you have multiple hunters vs players then you can figure it out). Plus this will work in SP and MP and also has exception process if there are no players or if players are dead. It's only a framework so you have to fill in the blanks though.

private ["_sleep","_pos","_player","_players"];

_sleep = 5;	// change this number to alter rate of script.

while {true} do
{
_players = playableUnits + switchableUnits;

if (count _players > 0) then
{
	{
		_player = _x;
		if (not isNull _player) then
		{
			_pos = getPosATL _player;
			/* 				
				Now you know the player and his/her position,
				you can do your code here
			*/
		};
	} forEach _players;
	sleep _sleep;
}
else
{
	// exception code in case no players
	sleep _sleep;
};
};

Share this post


Link to post
Share on other sites
I already have it as an sqf. But when activated - I get the error.

waitUntil {player == player};

playerarray = [];

{

playerarray = playerarray + [_x];

} forEach playableUnits;

randomplayer = playerarray call BIS_fnc_selectRandom;

randomplayerpos = getPos randomplayer;

_wp = AS addWaypoint [position randomplayerpos, 0]

Is the waypoint added wrong?

Yessir, the waypoint is wrong. The "position" didn't need to be there, so it was assuming that "position" was an array, which it wasn't, thus it is empty. Plus you need to add a waypoint type.

_wp = AS addWaypoint [randomplayerpos, 0] 
_wp setWaypointType "MOVE"; 

Share this post


Link to post
Share on other sites

Hm.. Still getting the error though. So here's what I've done:

Placed down an enemy group and named them ( AS = Group this; )

Placed down Radio trigger with (Null = ExecVM "Hunt.sqf"; )

When I call the Radio in the editor I get the error.

waitUntil {player == player};

playerarray = [];

{

playerarray = playerarray + [_x];

} forEach playableUnits;

randomplayer = playerarray call BIS_fnc_selectRandom;

randomplayerpos = getPos randomplayer;

_wp = AS addWaypoint [randomplayerpos, 0]

_wp setWaypointType "MOVE";

Where Do I go wrong?

Share this post


Link to post
Share on other sites
What happens when there are multiple players? Who will the AI go to?

The player command returns the local player.

;2630387']Seeing as to how the setPos will need to be done for isServer' date=' you're right, it won't work for player.[/quote']

Eh, what? setPos has global effect and accepts global arguments. Any computer can move any unit, regardless of locality.

Share this post


Link to post
Share on other sites

Eh, what? setPos has global effect and accepts global arguments. Any computer can move any unit, regardless of locality.

Sorry, at that point I was referring to the fact that using "player" from a server, specifically a DS, won't accomplish anything. Which is why I posted the script.

@OP: You were missing a semi colon in the second to last line. Please be sure to read your errors, or at least post them, as no errors are "useless".

playerarray = [];
{
playerarray = playerarray + [_x];
} forEach playableUnits;

randomplayer = playerarray call BIS_fnc_selectRandom;

randomplayerpos = getPos randomplayer;
_wp = AS addWaypoint [randomplayerpos, 0];
_wp setWaypointType "MOVE"; 

Edited by Grimes [3rd ID]

Share this post


Link to post
Share on other sites

Works! Thanks for all the help. I have no previous experience with scripts or codes so thanks for being patient

Share this post


Link to post
Share on other sites
Works! Thanks for all the help. I have no previous experience with scripts or codes so thanks for being patient

No worries, sorry I wasn't as straight forward from the start. Keep scripting, feel free to ask more questions in a new thread.

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

×