SA-MP Forums Archive
help with small code - 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)
+--- Thread: help with small code (/showthread.php?tid=545528)



help with small code - Onfroi - 09.11.2014

Just because I'm awful at finding small errors, can anyone tell me what's wrong with the following code..
pawn Код:
new pTeam = GetPlayerTeam(playerid);
    foreach(Player, i)
    {
        if(GetPlayerTeam(i) != pTeam)
        {
            SetPlayerMarkerForPlayer(playerid, i, (GetPlayerColor(i) & 0xFFFFFF00));
            SetPlayerMarkerForPlayer(i, playerid, (GetPlayerColor(playerid) & 0xFFFFFF00));
        }
        else
        {
            SetPlayerMarkerForPlayer(playerid, i, GetPlayerColor(playerid));
            SetPlayerMarkerForPlayer(i, playerid, GetPlayerColor(i));
        }
    }
I don't get any errors or anything but the purpose of the code is failing. It's supposed to show players in the radar only if they're in the same team.

Thanks in advance.


Re: help with small code - MD5 - 09.11.2014

Make it a stock.


Re: help with small code - Eth - 09.11.2014

I am not sure what's wrong but try this:
pawn Код:
new pTeam = GetPlayerTeam(playerid);
    for(new i =0; i < MAX_PLAYERS;i++)
   {
   if(IsPlayerConnected(i))
    {
        if(GetPlayerTeam(i) == pTeam)
        {
            SetPlayerMarkerForPlayer(playerid, i, (GetPlayerColor(i) & 0xFFFFFF00));
            SetPlayerMarkerForPlayer(i, playerid, (GetPlayerColor(playerid) & 0xFFFFFF00));
        }
        else
        {
            SetPlayerMarkerForPlayer(playerid, i, GetPlayerColor(playerid));
            SetPlayerMarkerForPlayer(i, playerid, GetPlayerColor(i));
        }
    }
}



Re: help with small code - Abagail - 09.11.2014

pawn Код:
foreach(Player, i)
    {
        if(GetPlayerTeam(i) != pTeam)
        {
          SetPlayerMarkerForPlayer(playerid, i, GetPlayerColor(playerid));
            SetPlayerMarkerForPlayer(i, playerid, GetPlayerColor(i));
        }
        else
        {
             SetPlayerMarkerForPlayer(playerid, i, (GetPlayerColor(i) & 0xFFFFFF00));
            SetPlayerMarkerForPlayer(i, playerid, (GetPlayerColor(playerid) & 0xFFFFFF00));
        }
    }
Try this.


Re: help with small code - Onfroi - 09.11.2014

Quote:
Originally Posted by MD5
Посмотреть сообщение
Make it a stock.
I don't see how that would fix the code
I'm using it OnPlayerSpawn.
Quote:
Originally Posted by Eth
Посмотреть сообщение
I am not sure what's wrong but try this:
pawn Код:
new pTeam = GetPlayerTeam(playerid);
    for(new i =0; i < MAX_PLAYERS;i++)
   {
   if(IsPlayerConnected(i))
    {
        if(GetPlayerTeam(i) == pTeam)
        {
            SetPlayerMarkerForPlayer(playerid, i, (GetPlayerColor(i) & 0xFFFFFF00));
            SetPlayerMarkerForPlayer(i, playerid, (GetPlayerColor(playerid) & 0xFFFFFF00));
        }
        else
        {
            SetPlayerMarkerForPlayer(playerid, i, GetPlayerColor(playerid));
            SetPlayerMarkerForPlayer(i, playerid, GetPlayerColor(i));
        }
    }
}
I don't think foreach is the problem and this "if(GetPlayerTeam(i) == pTeam)" is wrong because that would make players in the same team invisible in the radar, won't it?
Quote:
Originally Posted by Abagail
Посмотреть сообщение
pawn Код:
foreach(Player, i)
    {
        if(GetPlayerTeam(i) != pTeam)
        {
          SetPlayerMarkerForPlayer(playerid, i, GetPlayerColor(playerid));
            SetPlayerMarkerForPlayer(i, playerid, GetPlayerColor(i));
        }
        else
        {
             SetPlayerMarkerForPlayer(playerid, i, (GetPlayerColor(i) & 0xFFFFFF00));
            SetPlayerMarkerForPlayer(i, playerid, (GetPlayerColor(playerid) & 0xFFFFFF00));
        }
    }
That would make the enemy visible in the radar

Just to clear up, what I want is for only players in the same team to be visible in the radar. Enemies will be invisible.

But thanks all for trying to help, really appreciate it


Re: help with small code - Eth - 09.11.2014

try this:
pawn Код:
foreach(Player, i)
    {
        if(GetPlayerTeam(i) == pTeam)
        {
          SetPlayerMarkerForPlayer(playerid, i, GetPlayerColor(playerid));
            SetPlayerMarkerForPlayer(i, playerid, GetPlayerColor(i));
        }
        else
        {
             SetPlayerMarkerForPlayer(playerid, i,0xFFFFFF00);
             SetPlayerMarkerForPlayer(i, playerid,0xFFFFFF00);
        }
    }
I never give up!
also it should be == pTeam not !+ pteam because at the else it will set the color of the player to 0xFFFFFF00 which is invisible try it and tell me if it worked

Second Edit: just for Curiosity What is the GM you are making now??