loop two team of players - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: loop two team of players (
/showthread.php?tid=267417)
loop two team of players -
jamesbond007 - 08.07.2011
how to loop two team of players then compare if are close to each other?
like
pawn Код:
new team1[MAX_PLAYERS],team2[MAX_PLAYERS];
for(new x=0; x<MAX_PLAYERS;x++)
{
// if is player connected && team 1
x = team1[x];
}
for (new y=0; y<MAX_PLAYESR;y++)
{
// if is player connected && is team 2
y = team2[y];
}
if(Getdistancebetweenplayers(team1,team2)< 10)
{
print("ok.");
}
somehow like this
Re: loop two team of players -
jamesbond007 - 08.07.2011
help help help help im trying to use foreach include but it doesnt work !
AW: loop two team of players -
Nero_3D - 08.07.2011
what do you want to do ?
Do you want to find the two closest players from the teams ?
Re: loop two team of players -
jamesbond007 - 08.07.2011
yes.... 1st player that is near 2nd player from another team with distance of 10 will do something... like print ok
AW: loop two team of players -
Nero_3D - 08.07.2011
If you got an exact range just use IsPlayerInRangeOfPoint
pawn Код:
new
i,
j,
left,
Float: X,
Float: Y,
Float: Z,
team[MAX_PLAYERS],
right = sizeof team - 1;
// saves the playerids in an array for faster looping
for(i = 0; i != MAX_PLAYERS; ++i) {
switch(GetPlayerTeam(playerid)) { // use here your team variable
case Team1: team[left++] = playerid;
case Team2: team[right--] = playerid;
}
}
// the actual loop
for(i = 0; i != left; ++i) {
if(GetPlayerPos(team[i], X, Y, Z)) {
for(j = sizeof team - 1; j != right; --j) {
if(IsPlayerInRangeOfPoint(team[j], 10.0, X, Y, Z)) {
printf("Distance between %d and %d is less than 10.0", team[i], team[j]);
}
}
}
}