SA-MP Forums Archive
Help with command - 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 command (/showthread.php?tid=630733)



Help with command - Zmith - 18.03.2017

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;
}



Re: Help with command - Toroi - 18.03.2017

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


Re: Help with command - jlalt - 18.03.2017

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.


Re: Help with command - SyS - 18.03.2017

use switch


Re: Help with command - Toroi - 18.03.2017

but there are 2 different conditions


Re: Help with command - Mic_H - 18.03.2017

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;




Re: Help with command - Zmith - 18.03.2017

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"


Re: Help with command - coool - 18.03.2017

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


Re: Help with command - Bolex_ - 18.03.2017

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


Re: Help with command - Zmith - 18.03.2017

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