Help with command
#1

How can I fix this? look at screenshot for detail on the problem.

Код:
CMD:g2(playerid, params[])
{
    new string[256], text[100];
    if(sscanf(params, "s[100]", text)) return SendClientMessage(playerid, -1, "{6a696a}[cmd]: /g(lobalchat) {9c9a9c}[msg]");
    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
	    if(IsPlayerConnected(i))
	    {
	    
	    	if(pInfo[i][VIPlevel] == 0)
		    {
			    format(string, sizeof string, "{A9C4E4}[Global Chat] {EAEAEA}%s: %s", GetName(playerid), text);
			    SendClientMessageToAll(COLOR_SERVER, string);
		    }
	    	if(pInfo[i][VIPlevel] == 1)
		    {
			    format(string, sizeof string, "{A9C4E4}[Global Chat] {EAEAEA}VIP %s: %s", GetName(playerid), text);
			    SendClientMessageToAll(COLOR_SERVER, string);
		    }
		    if(pInfo[i][Adminlevel] == 1)
		    {
			    format(string, sizeof string, "{A9C4E4}[Global Chat] {EAEAEA}Trial Admin%s: %s", GetName(playerid), text);
			    SendClientMessageToAll(COLOR_SERVER, string);
		    }
		    if(pInfo[i][Adminlevel] == 2)
		    {
			    format(string, sizeof string, "{A9C4E4}[Global Chat] {EAEAEA}Basic Admin %s: %s", GetName(playerid), text);
			    SendClientMessageToAll(COLOR_SERVER, string);
		    }
		    if(pInfo[i][Adminlevel] == 3)
		    {
			    format(string, sizeof string, "{A9C4E4}[Global Chat] {EAEAEA}Senior Admin %s: %s", GetName(playerid), text);
			    SendClientMessageToAll(COLOR_SERVER, string);
		    }
		    if(pInfo[i][Adminlevel] == 4)
		    {
			    format(string, sizeof string, "{A9C4E4}[Global Chat] {EAEAEA}Anon: %s", text);
			    SendClientMessageToAll(COLOR_SERVER, string);
		    }
		    if(pInfo[i][Adminlevel] == 5)
		    {
			    format(string, sizeof string, "{A9C4E4}[Global Chat] {EAEAEA}Head Admin %s: %s", GetName(playerid), text);
			    SendClientMessageToAll(COLOR_SERVER, string);
		    }
		    if(pInfo[i][Adminlevel] == 6)
		    {
			    format(string, sizeof string, "{A9C4E4}[Global Chat] {EAEAEA}Anon: %s", text);
			    SendClientMessageToAll(COLOR_SERVER, string);
		    }
		    if(pInfo[i][Adminlevel] == 7)
		    {
			    format(string, sizeof string, "{A9C4E4}[Global Chat] {EAEAEA}Owner %s: %s", GetName(playerid), text);
			    SendClientMessageToAll(COLOR_SERVER, string);
		    }
	    }
    }
    return 1;
}
Reply
#2

add returns to every condition to make sure the next one wont execute.
Reply
#3

Make your checks by verse [ highest to lowest ] and after the first if(... use else if intead of only if.
I'm on phone now so can not fix only can suggest how to fix it xd.
Reply
#4

use switch
Reply
#5

but there are 2 different conditions
Reply
#6

PHP код:
#define MAX_ADMINLVL 8
new AdminRanks[MAX_ADMINLVL][13] = {
    
"Player",
    
"Trial Admin",
    
"Basic Admin",
    
"Senior Admin",
    
"Anon",
    
"Head Admin",
    
"Anon",
    
"Owner"
};
stock ServerStatus(playerid)
{
    new 
status[15] = "Player";
    if(
pInfo[playerid][Adminlevel] > && pInfo[playerid][Adminlevel] < MAX_ADMINLVL)
    {
        
status AdminRanks[pInfo[playerid][Adminlevel]]; //Admin -> First Priority
    
}
    else if(
pInfo[playerid][Adminlevel] >= MAX_ADMINLVL//Edited '>' -> '>='
    
{
        
status "Pro-Owner";
    }
    else if(
pInfo[playerid][VIPlevel] > 0// VIP -> Second
    
{
        
status "VIP";
    }
    return 
status;
}
CMD:g2(playeridparams[])
{
    new 
string[256], text[100];
    if(
sscanf(params"s[100]"text)) return SendClientMessage(playerid, -1"{6a696a}[cmd]: /g(lobalchat) {9c9a9c}[msg]");
    
format(stringsizeof(string), "{A9C4E4}[Global Chat] {EAEAEA}%s %s: %s"ServerStatus(playerid), GetName(playerid), text);
    
    
//foreach(Player, i)
    
for(new 0<= GetPlayerPoolSize(); i++) //Edited '<=', else the last guy won't get the message :P
    
{
        if(
IsPlayerConnected(i))
        {
            
SendClientMessage(iCOLOR_SERVERstring);
        }
    }
    
/*
    Mistakes:>
    1. You were sending to ALL players.... So 10 players IG = 10 messages..
    2. You were using Ifs, not if-else if.. = Messages have a chance of being sent 3-4Times i.e., if a player is a VIP, Admin.
    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
        if(IsPlayerConnected(i))
        {
        
            if(pInfo[i][VIPlevel] == 0)
            {
                format(string, sizeof string, "%s: %s", GetName(playerid), text);
            }
            if(pInfo[i][VIPlevel] == 1)
            {
                format(string, sizeof string, "{A9C4E4}[Global Chat] {EAEAEA}VIP %s: %s", GetName(playerid), text);
                SendClientMessageToAll(COLOR_SERVER, string);
            }
            if(pInfo[i][Adminlevel] == 1)
            {
                format(string, sizeof string, "{A9C4E4}[Global Chat] {EAEAEA}Trial Admin%s: %s", GetName(playerid), text);
                SendClientMessageToAll(COLOR_SERVER, string);
            }
            if(pInfo[i][Adminlevel] == 2)
            {
                format(string, sizeof string, "{}[Global Chat] {EAEAEA}Basic Admin %s: %s", GetName(playerid), text);
                SendClientMessageToAll(COLOR_SERVER, string);
            }
            if(pInfo[i][Adminlevel] == 3)
            {
                format(string, sizeof string, "{A9C4E4}[Global Chat] {EAEAEA}Senior Admin %s: %s", GetName(playerid), text);
                SendClientMessageToAll(COLOR_SERVER, string);
            }
            if(pInfo[i][Adminlevel] == 4)
            {
                format(string, sizeof string, "{A9C4E4}[Global Chat] {EAEAEA}Anon: %s", text);
                SendClientMessageToAll(COLOR_SERVER, string);
            }
            if(pInfo[i][Adminlevel] == 5)
            {
                format(string, sizeof string, "{A9C4E4}[Global Chat] {EAEAEA}Head Admin %s: %s", GetName(playerid), text);
                SendClientMessageToAll(COLOR_SERVER, string);
            }
            if(pInfo[i][Adminlevel] == 6)
            {
                format(string, sizeof string, "{A9C4E4}[Global Chat] {EAEAEA}Anon: %s", text);
                SendClientMessageToAll(COLOR_SERVER, string);
            }
            if(pInfo[i][Adminlevel] == 7)
            {
                format(string, sizeof string, "{A9C4E4}[Global Chat] {EAEAEA}Owner %s: %s", GetName(playerid), text);
                SendClientMessageToAll(COLOR_SERVER, string);
            }
        }
    }*/
    
return 1;

Reply
#7

Quote:
Originally Posted by Mic_H
Посмотреть сообщение
PHP код:
#define MAX_ADMINLVL 8
new AdminRanks[MAX_ADMINLVL][13] = {
    
"Player",
    
"Trial Admin",
    
"Basic Admin",
    
"Senior Admin",
    
"Anon",
    
"Head Admin",
    
"Anon",
    
"Owner"
};
stock ServerStatus(playerid)
{
    new 
status[15] = "Player";
    if(
pInfo[playerid][Adminlevel] > && pInfo[playerid][Adminlevel] < MAX_ADMINLVL)
    {
        
status AdminRanks[pInfo[playerid][Adminlevel]]; //Admin -> First Priority
    
}
    else if(
pInfo[playerid][Adminlevel] >= MAX_ADMINLVL//Edited '>' -> '>='
    
{
        
status "Pro-Owner";
    }
    else if(
pInfo[playerid][VIPlevel] > 0// VIP -> Second
    
{
        
status "VIP";
    }
    return 
status;
}
CMD:g2(playeridparams[])
{
    new 
string[256], text[100];
    if(
sscanf(params"s[100]"text)) return SendClientMessage(playerid, -1"{6a696a}[cmd]: /g(lobalchat) {9c9a9c}[msg]");
    
format(stringsizeof(string), "{A9C4E4}[Global Chat] {EAEAEA}%s %s: %s"ServerStatus(playerid), GetName(playerid), text);
    
    
//foreach(Player, i)
    
for(new 0<= GetPlayerPoolSize(); i++) //Edited '<=', else the last guy won't get the message :P
    
{
        if(
IsPlayerConnected(i))
        {
            
SendClientMessage(iCOLOR_SERVERstring);
        }
    }
    
/*
    Mistakes:>
    1. You were sending to ALL players.... So 10 players IG = 10 messages..
    2. You were using Ifs, not if-else if.. = Messages have a chance of being sent 3-4Times i.e., if a player is a VIP, Admin.
    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
        if(IsPlayerConnected(i))
        {
        
            if(pInfo[i][VIPlevel] == 0)
            {
                format(string, sizeof string, "%s: %s", GetName(playerid), text);
            }
            if(pInfo[i][VIPlevel] == 1)
            {
                format(string, sizeof string, "{A9C4E4}[Global Chat] {EAEAEA}VIP %s: %s", GetName(playerid), text);
                SendClientMessageToAll(COLOR_SERVER, string);
            }
            if(pInfo[i][Adminlevel] == 1)
            {
                format(string, sizeof string, "{A9C4E4}[Global Chat] {EAEAEA}Trial Admin%s: %s", GetName(playerid), text);
                SendClientMessageToAll(COLOR_SERVER, string);
            }
            if(pInfo[i][Adminlevel] == 2)
            {
                format(string, sizeof string, "{}[Global Chat] {EAEAEA}Basic Admin %s: %s", GetName(playerid), text);
                SendClientMessageToAll(COLOR_SERVER, string);
            }
            if(pInfo[i][Adminlevel] == 3)
            {
                format(string, sizeof string, "{A9C4E4}[Global Chat] {EAEAEA}Senior Admin %s: %s", GetName(playerid), text);
                SendClientMessageToAll(COLOR_SERVER, string);
            }
            if(pInfo[i][Adminlevel] == 4)
            {
                format(string, sizeof string, "{A9C4E4}[Global Chat] {EAEAEA}Anon: %s", text);
                SendClientMessageToAll(COLOR_SERVER, string);
            }
            if(pInfo[i][Adminlevel] == 5)
            {
                format(string, sizeof string, "{A9C4E4}[Global Chat] {EAEAEA}Head Admin %s: %s", GetName(playerid), text);
                SendClientMessageToAll(COLOR_SERVER, string);
            }
            if(pInfo[i][Adminlevel] == 6)
            {
                format(string, sizeof string, "{A9C4E4}[Global Chat] {EAEAEA}Anon: %s", text);
                SendClientMessageToAll(COLOR_SERVER, string);
            }
            if(pInfo[i][Adminlevel] == 7)
            {
                format(string, sizeof string, "{A9C4E4}[Global Chat] {EAEAEA}Owner %s: %s", GetName(playerid), text);
                SendClientMessageToAll(COLOR_SERVER, string);
            }
        }
    }*/
    
return 1;

error 017: undefined symbol "GetPlayerPoolSize"
Reply
#8

You don't have the latest sa-mp version
try " MAX_PLAYERS " rather than GetPlayerPoolSize
Reply
#9

Update your server to newest 0.3.7 correctly! (http://www.sa-mp.com/download.php)
Reply
#10

It's fixed! Thanks for the help everyone rep+
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)