/badge for factions
#1

Код:
CMD:badge(playerid, params[])
{

	if(pInfo[playerid][Faction] == 0 || pInfo[playerid][Faction] >=3) return SendClientMessage(playerid, 0x46E850FF, "SERVER:{FFFFFF} You're not authorized to use this command!");

 	switch (pInfo[playerid][Faction])
    {
        case 1:
        {
	if(pInfo[playerid][Faction] == 1)
	if(pDuty[playerid] == 0)
	{
	    pDuty[playerid] = 1;
	    SendClientMessage(playerid, COLOR_WHITE, "You are now on Duty");
		SetPlayerColor(playerid, COLOR_PDRAD);
        }
        case 2:
        {
	if(pInfo[playerid][Faction] == 2)
	if(pDuty[playerid] == 0)
	{
	    pDuty[playerid] = 1;
	    SendClientMessage(playerid, COLOR_WHITE, "You are now on Duty");
		SetPlayerColor(playerid, COLOR_RED);
        }
	case 3:
	{
	if(pInfo[playerid][Faction] >= 1)
	if(pDuty[playerid] == 1)
	{
	    pDuty[playerid] = 0;
	    SendClientMessage(playerid, COLOR_WHITE, "You are now off Duty");
		SetPlayerColor(playerid, COLOR_WHITE);
        }
	return 1;
}
When i do this in my script it comes up with loads of errors

Код:
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(282) : error 017: undefined symbol "ReloadLabels"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(283) : error 017: undefined symbol "LoadVehicles"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(378) : error 017: undefined symbol "UserPath"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(380) : error 017: undefined symbol "UserPath"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(386) : error 017: undefined symbol "PreloadAnimLib"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(387) : error 017: undefined symbol "PreloadAnimLib"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(406) : error 017: undefined symbol "UserPath"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(516) : error 017: undefined symbol "RegisterFix"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(535) : error 017: undefined symbol "SendNearbyMessage"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(555) : error 017: undefined symbol "UserPath"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(561) : error 017: undefined symbol "udb_hash"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(627) : error 017: undefined symbol "udb_hash"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(629) : error 017: undefined symbol "UserPath"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(681) : error 017: undefined symbol "CreatePlayerVehicle"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(690) : error 017: undefined symbol "CreatePlayerVehicle"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(699) : error 017: undefined symbol "CreatePlayerVehicle"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(708) : error 017: undefined symbol "CreatePlayerVehicle"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(717) : error 017: undefined symbol "CreatePlayerVehicle"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(726) : error 017: undefined symbol "CreatePlayerVehicle"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(735) : error 017: undefined symbol "CreatePlayerVehicle"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(744) : error 017: undefined symbol "CreatePlayerVehicle"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(753) : error 017: undefined symbol "CreatePlayerVehicle"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(762) : error 017: undefined symbol "CreatePlayerVehicle"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(771) : error 017: undefined symbol "CreatePlayerVehicle"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(780) : error 017: undefined symbol "CreatePlayerVehicle"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\gamemodes\core.pwn(789) : error 017: undefined symbol "CreatePlayerVehicle"

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


26 Errors.
Reply
#2

Anyone know why this happens or able to tell me how to fix it?
Reply
#3

Opened brackets do not match with the closed. Next time, try to indent your code properly so it'll be easier readable and avoids these issues:
PHP код:
CMD:badge(playeridparams[])
{
    if(
pInfo[playerid][Faction] == || pInfo[playerid][Faction] >= 3) return SendClientMessage(playerid0x46E850FF"SERVER:{FFFFFF} You're not authorized to use this command!");
    switch(
pInfo[playerid][Faction])
    {
        case 
1:
        {
            if(
pInfo[playerid][Faction] == && pDuty[playerid] == 0)
            {
                
pDuty[playerid] = 1;
                
SendClientMessage(playeridCOLOR_WHITE"You are now on Duty");
                
SetPlayerColor(playeridCOLOR_PDRAD);
            }
        }
        case 
2:
        {
            if(
pInfo[playerid][Faction] == && pDuty[playerid] == 0)
            {
                
pDuty[playerid] = 1;
                
SendClientMessage(playeridCOLOR_WHITE"You are now on Duty");
                
SetPlayerColor(playeridCOLOR_RED);
            }
        }
        case 
3:
        {
            if(
pInfo[playerid][Faction] >= && pDuty[playerid] == 1)
            {
                
pDuty[playerid] = 0;
                
SendClientMessage(playeridCOLOR_WHITE"You are now off Duty");
                
SetPlayerColor(playeridCOLOR_WHITE);
            }
        }
    }
    return 
1;

Reply
#4

Tried it but the only thing that works in the game then is the cop /badge to go on duty, they cant go off duty and ems cant go on or off duty... but thanks for trying
Reply
#5

I actually didn't bother to check the code, I just fixed the indentation. Using "else" statement will solve it:
PHP код:
CMD:badge(playeridparams[])
{
    if(
pInfo[playerid][Faction] == || pInfo[playerid][Faction] >= 3) return SendClientMessage(playerid0x46E850FF"SERVER:{FFFFFF} You're not authorized to use this command!");
    
pDuty[playerid] = !pDuty[playerid];
    switch(
pInfo[playerid][Faction])
    {
        case 
1:
        {
            if(
pDuty[playerid])
            {
                
SendClientMessage(playeridCOLOR_WHITE"You are now on Duty");
                
SetPlayerColor(playeridCOLOR_PDRAD);
            }
            else
            {
                
// off duty
            
}
        }
        case 
2:
        {
            if(
pDuty[playerid])
            {
                
SendClientMessage(playeridCOLOR_WHITE"You are now on Duty");
                
SetPlayerColor(playeridCOLOR_RED);
            }
            else
            {
                
// off duty
            
}
        }
        case 
3:
        {
            if(!
pDuty[playerid])
            {
                
SendClientMessage(playeridCOLOR_WHITE"You are now off Duty");
                
SetPlayerColor(playeridCOLOR_WHITE);
            }
            else
            {
                
// on duty
            
}
        }
    }
    return 
1;

EDIT: Updated because setting the value before the switch.
Reply
#6

EDIT: Too slow, GG Konstantinos... GG.
Код:
CMD:badge(playerid, params[]) 
{ 
    if(pInfo[playerid][Faction] == 0 || pInfo[playerid][Faction] >= 3) return SendClientMessage(playerid, 0x46E850FF, "SERVER:{FFFFFF} You're not authorized to use this command!"); 

    switch(pInfo[playerid][Faction]) 
    { 
        case 1:
        { 
            if(pInfo[playerid][Faction] == 1 && pDuty[playerid] == 0) 
            { 
                pDuty[playerid] = 1; 
                SendClientMessage(playerid, COLOR_WHITE, "You are now on Duty"); 
                SetPlayerColor(playerid, COLOR_PDRAD); 
            } 
            else if(pDuty[playerid] == 1)
            {
                pDuty[playerid] = 0; 
                SendClientMessage(playerid, COLOR_WHITE, "You are now off Duty"); 
                SetPlayerColor(playerid, COLOR_WHITE); 
             }
        } 
        case 2: 
        { 
            if(pInfo[playerid][Faction] == 2 && pDuty[playerid] == 0) 
            { 
                pDuty[playerid] = 1; 
                SendClientMessage(playerid, COLOR_WHITE, "You are now on Duty"); 
                SetPlayerColor(playerid, COLOR_RED); 
            } 
            else if(pDuty[playerid] == 1)
            {
                pDuty[playerid] = 0; 
                SendClientMessage(playerid, COLOR_WHITE, "You are now off Duty"); 
                SetPlayerColor(playerid, COLOR_WHITE); 
             }
        } 
    }
    return 1; 
}
Try this, what i saw was only faction id 3 could go off duty due to it only working in the case 3: instruction.
Reply
#7

Some nasty ass code above.
PHP код:
CMD:badge(playeridparams[]) {
    if(
pInfo[playerid][Faction] != || pInfo[playerid][Faction] != 2) {
        return 
SendClientMessage(playerid0x46E850FF"SERVER:{FFFFFF} You're not authorized to use this command!");
    }
    if(
pDuty[playerid] == 0) {
        
pDuty[playerid] = 1;
        
SendClientMessage(playeridCOLOR_WHITE"You are now on Duty");
        
SetPlayerColor(playeridCOLOR_RED);        
    } else {
        
pDuty[playerid] = 0;
        
SendClientMessage(playeridCOLOR_WHITE"You are now off Duty");
        
SetPlayerColor(playeridCOLOR_WHITE);
    }
    return 
1;

You're making a switch which isn't even needed..
Above code will do the exact same.. Just shorter and cleaner
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)