loop two team of players
#1

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
Reply
#2

help help help help im trying to use foreach include but it doesnt work !
Reply
#3

what do you want to do ?

Do you want to find the two closest players from the teams ?
Reply
#4

yes.... 1st player that is near 2nd player from another team with distance of 10 will do something... like print ok
Reply
#5

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]);
            }
        }
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)