HatchetJesus 1 Posted February 24, 2014 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
Johnson11B2P 3 Posted February 24, 2014 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
HatchetJesus 1 Posted February 24, 2014 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
KC Grimes 79 Posted February 24, 2014 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
HatchetJesus 1 Posted February 24, 2014 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
KC Grimes 79 Posted February 24, 2014 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
HatchetJesus 1 Posted February 24, 2014 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
fight9 14 Posted February 24, 2014 You'll need to do it from an external SQF file. Share this post Link to post Share on other sites
Blake ST2 11 Posted February 24, 2014 Do it externally Share this post Link to post Share on other sites
HatchetJesus 1 Posted February 24, 2014 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
das attorney 858 Posted February 25, 2014 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
KC Grimes 79 Posted February 25, 2014 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
HatchetJesus 1 Posted February 25, 2014 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
MulleDK19 21 Posted February 25, 2014 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
KC Grimes 79 Posted February 25, 2014 (edited) 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 February 25, 2014 by Grimes [3rd ID] Share this post Link to post Share on other sites
HatchetJesus 1 Posted February 25, 2014 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
KC Grimes 79 Posted February 26, 2014 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