SA-MP Forums Archive
aDuty Help - 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: aDuty Help (/showthread.php?tid=630139)



aDuty Help - silverms - 09.03.2017

hey so I have this command that should when player type the command to be view on the map all the players can see him but it isn't workin good here is the script
PHP код:
CMD:aduty(playeridparams[])
{
    if(
adlvl[playerid]<1) return 0;
    new 
pname[64], str[150];
    
GetPlayerName(playeridpnamesizeof(pname));
    for(new 
i=0iMAX_PLAYERSi++)
    {
        if(
aDuty[playerid]==0)
        {
            
SetPlayerMarkerForPlayer(playeridi, (GetPlayerColor(playerid)));
               
format(str,sizeof(str),"Admin[%s] Is Now [ON] Duty"pname);
            
SendClientMessageToAll(COLOR_GREEN,str);
            
aDuty[playerid]=1;
            return 
1;
        }
        if(
aDuty[playerid]==1)
        {
            
SetPlayerMarkerForPlayer(playeridi00);
               
format(str,sizeof(str),"Admin[%s] Is Now [OFF] Duty"pname);
            
SendClientMessageToAll(COLOR_GREEN,str);
            
SetPlayerHealth(playerid100);
            
SetPlayerArmour(playerid100);
            
aDuty[playerid]=0;
            return 
1;
        }
        return 
1;
        
    }
    return 
1;




Re: aDuty Help - Immortal99 - 10.03.2017

Firstly on top of ur script add:
new aDuty[MAX_PLAYERS];

Secondly Under OnPlayerConnect add:
aDuty[playerid] = 0; // This will set the players admin duty off when he connects
Do the same under OnPlayerDisconect


And then here is the code fixed:
PHP код:
.CMD:aduty(playeridparams[]) 

    if(
adlvl[playerid]<1) return 0
    new 
pname[64], str[150]; 
    
GetPlayerName(playeridpnamesizeof(pname)); 
    for(new 
i=0iMAX_PLAYERSi++) 
    { 
        if(
aDuty[playerid] == 0
        { 
            
SetPlayerMarkerForPlayer(playeridi, (GetPlayerColor(playerid))); 
               
format(str,sizeof(str),"Admin[%s] Is Now [ON] Duty"pname); 
            
SendClientMessageToAll(COLOR_GREEN,str); 
            
aDuty[playerid] = 1
            
//  You don't return 1 else it wouldn't set him on duty
        

        else if (
aDuty[playerid] == 1// This Will check if he's on duty
        

            
SetPlayerMarkerForPlayer(playeridi00); 
               
format(str,sizeof(str),"Admin[%s] Is Now [OFF] Duty"pname); 
            
SendClientMessageToAll(COLOR_GREEN,str); 
            
SetPlayerHealth(playerid100); 
            
SetPlayerArmour(playerid100); 
            
aDuty[playerid] = 0
            
// Again u don't return 1
        

        return 
1
         
    } 
    return 
1

I did this on my mobile so I didn't test it, but I think it should work


Re: aDuty Help - Toroi - 10.03.2017

Let me point out that you don't really want to use the SendClientMessageToAll function inside a player loop, or any other function beside SetPlayerMarkerForPlayer.

Also, remove the loop's return, as it will break the loop and its purpose.

You've to restructure it a lot for it to work efficiently.


Re: aDuty Help - silverms - 10.03.2017

Every thing is working fine he is go8ng on duty but ue isnt vuewing on the map like showplayermarkers


Re: aDuty Help - Toroi - 10.03.2017

It is not 'working fine' if it does not work.

The only thing you need the loop for is the SetPlayerMarkerForPlayer function. Instead, you're putting every function inside the loop, which will cause a massive function flood.

However, is not it easier to use the SetPlayerColor function? It does the same and it's for everyone, so you save a loop.