Rogu3 H1Z1Stakes.com 0 Posted May 25, 2018 I am trying to make a script where I can teleport a whole unit "BLUFOR" or "OPFOR" which are players to a specific marker through an addAction. Here is my code, this links to an object, which is a flag pole. _players = allPlayers; { if(side _x == west) then { player SetPos getMarkerPos "marker1"; } } foreach _players; Can anyone help me fix my code so that it works? Share this post Link to post Share on other sites
AZCoder 921 Posted May 25, 2018 { if(side _x == west) then { _x SetPos getMarkerPos "marker1"; } } foreach allPlayers; 3 Share this post Link to post Share on other sites
gokitty1199 225 Posted May 25, 2018 read the comment _players = allPlayers; { if(side _x == west) then { player SetPos getMarkerPos "marker1";//THIS LINE IS THE ERROR WHERE IT SAYS player } } foreach _players; _players is an array that holds every player on the server, so lets say theres 3 people on the server when this runs. p1, p2, p3 the forEach command uses the magic variable _x as a pointer to each element in the array. think of an element as a slot in the array, so element 0 is p1 and element 1 is p2 and element 2 is p3. so in your if statement(which is correct) it is checking the side of element 0/p1 and if it is equal to west then it sets player to the markers position, this is where the issue is. if you were to run just player setPos getMarkerPos "marker1"; in the players initPlayerLocal for example, this would work because its running on the client of the player so it teleports him and him only. since your using forEach you need to use the magic variable _x just like you did in the if statement to check the side of the player. remember _x is pointing to a slot in the _players array which holds the information of the players on the server so you need to do this _x setPos getMarkerPos "marker1"; so that it sets the position of each player inside _players to the markers location. so in the end it should look like this _players = allPlayers; { if(side _x == west) then { _x SetPos getMarkerPos "marker1";//THIS LINE IS THE ERROR WHERE IT SAYS player } } foreach _players; 2 Share this post Link to post Share on other sites
gokitty1199 225 Posted May 25, 2018 1 minute ago, AZCoder said: { if(side _x == west) then { _x SetPos getMarkerPos "marker1"; } } foreach allPlayers; awww man i just typed up a response :( you win 1 1 Share this post Link to post Share on other sites
AZCoder 921 Posted May 25, 2018 1 minute ago, gokitty1199 said: awww man i just typed up a response :( you win You pointed out the specific problem though, so we both win 1 1 Share this post Link to post Share on other sites
Rogu3 H1Z1Stakes.com 0 Posted May 25, 2018 10 minutes ago, AZCoder said: { if(side _x == west) then { _x SetPos getMarkerPos "marker1"; } } foreach allPlayers; 9 minutes ago, gokitty1199 said: read the comment _players = allPlayers; { if(side _x == west) then { player SetPos getMarkerPos "marker1";//THIS LINE IS THE ERROR WHERE IT SAYS player } } foreach _players; _players is an array that holds every player on the server, so lets say theres 3 people on the server when this runs. p1, p2, p3 the forEach command uses the magic variable _x as a pointer to each element in the array. think of an element as a slot in the array, so element 0 is p1 and element 1 is p2 and element 2 is p3. so in your if statement(which is correct) it is checking the side of element 0/p1 and if it is equal to west then it sets player to the markers position, this is where the issue is. if you were to run just player setPos getMarkerPos "marker1"; in the players initPlayerLocal for example, this would work because its running on the client of the player so it teleports him and him only. since your using forEach you need to use the magic variable _x just like you did in the if statement to check the side of the player. remember _x is pointing to a slot in the _players array which holds the information of the players on the server so you need to do this _x setPos getMarkerPos "marker1"; so that it sets the position of each player inside _players to the markers location. so in the end it should look like this _players = allPlayers; { if(side _x == west) then { _x SetPos getMarkerPos "marker1";//THIS LINE IS THE ERROR WHERE IT SAYS player } } foreach _players; I have done both of these, but it still doesn't work? It only teleports me, and not my friend who is in the same faction??? Share this post Link to post Share on other sites
AZCoder 921 Posted May 25, 2018 Looking at https://community.bistudio.com/wiki/allPlayers The 2nd example can be used to verify total number of all blufor players (should be 2+ in your case): hint str(west countSide allPlayers) Once it's working, you might want to add an "alive" check so you don't teleport dead bodies to your marker. But why it's not working, not sure, I don't really code for multiplayer. It looks right. Make sure everyone is joined before executing the script. 2 Share this post Link to post Share on other sites
Harzach 2517 Posted May 25, 2018 10 minutes ago, Rogu3 H1Z1Stakes.com said: I have done both of these, but it still doesn't work? It only teleports me, and not my friend who is in the same faction??? NOTES: In player hosted game, the complete array of allPlayers may get delayed at the start. Use BIS_fnc_listPlayers if you need it earlier Although since you are calling this from an addAction, this is probably not the issue. 4 Share this post Link to post Share on other sites