SA-MP Forums Archive
Problem CMD - 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: Problem CMD (/showthread.php?tid=665497)



Problem CMD - KamilPolska - 06.04.2019

Hello. I have a question.
Code:
CMD:giveleaderorg(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return 1;
    new id=-1, family;
	if( sscanf(params, "dK<fix>(-1)", family, id)) return SendClientMessage(playerid, -1, "USAGE /giveleaderorg [ORG ID] [ID]");
    if(family < 0 || family > MAX_ORG-1) return 1;
    if(id != -1)
    {
        if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "No such player!");
        if(GetPlayerFraction(id) != 0 || GetPlayerOrg(id) != 0) return SendClientMessage(playerid, -1, "This player has factions or family!");
        orgInvitePlayer(id, family);
        gPlayerOrgLeader[id] = true;
    }
    new str[128];
    if(id != -1)
    {
		new orgUID = orgID(family);
		if(orgUID != 0xFFFF)
		{
			format(str, sizeof(str), "%s give control over family to %d player %s", GetNick(playerid), family, GetNick(id));
			SendClientMessageToAll(-1, str);
			
			PlayerInfo[id][pTeam] = 5;
			gTeam[id] = 5;
		}
		else
		{
			SendClientMessage(playerid, -1, "ERROR! An error occured.");
		}
    }
    else
    {
        SendClientMessage(playerid, -1, "================ LIST OF LEADERS ================");

        format(str, 128, "SELECT `Nick` FROM `accounts` WHERE `FMember`='%d' AND `Rank`>1000", family);
        mysql_query(g_SQL, str);

        new nick[24];
        new results = cache_num_rows();

		if(results > 0)
		{
			for(new i = 0; i < results; i++)
			{
				cache_get_value_name(i, "Nick", nick);

            	sscanf(str, "p<|>s[24]", nick);

            	SendClientMessage(playerid, -1, nick);
        	}
        	SendClientMessage(playerid, -1, "================ END ================");
        }
    }
    return 1;
}
The command works as an entry /giveleaderorg 45 0
What is this all about? Why he does not work or show me the list.
Code:
    else
    {
        SendClientMessage(playerid, -1, "================ LIST OF LEADERS ================");

        format(str, 128, "SELECT `Nick` FROM `accounts` WHERE `FMember`='%d' AND `Rank`>1000", family);
        mysql_query(g_SQL, str);

        new nick[24];
        new results = cache_num_rows();

		if(results > 0)
		{
			for(new i = 0; i < results; i++)
			{
				cache_get_value_name(i, "Nick", nick);

            	sscanf(str, "p<|>s[24]", nick);

            	SendClientMessage(playerid, -1, nick);
        	}
        	SendClientMessage(playerid, -1, "================ END ================");
        }
    }



Re: Problem CMD - Private200 - 06.04.2019

It's your sscanf that makes your command work as "giveleaderorg 45 0", check: https://sampforum.blast.hk/showthread.php?tid=602923

It won't show the list because most likely, you are putting a valid player id?


Re: Problem CMD - KamilPolska - 06.04.2019

Quote:
Originally Posted by Private200
View Post
It's your sscanf that makes your command work as "giveleaderorg 45 0", check: https://sampforum.blast.hk/showthread.php?tid=602923

It won't show the list because most likely, you are putting a valid player id?
I think so. The command works nicely and gives me the leader of the organization only I do not know what's going on in this code what I showed. It does not show me messages, for example SendClientMessage(playerid, -1, "================ LIST OF LEADERS ================");
Code:
    else
    {
        SendClientMessage(playerid, -1, "================ LIST OF LEADERS ================");

        format(str, 128, "SELECT `Nick` FROM `accounts` WHERE `FMember`='%d' AND `Rank`>1000", family);
        mysql_query(g_SQL, str);

        new nick[24];
        new results = cache_num_rows();

		if(results > 0)
		{
			for(new i = 0; i < results; i++)
			{
				cache_get_value_name(i, "Nick", nick);

            	sscanf(str, "p<|>s[24]", nick);

            	SendClientMessage(playerid, -1, nick);
        	}
        	SendClientMessage(playerid, -1, "================ END ================");
        }
    }



Re: Problem CMD - KamilPolska - 06.04.2019

Quote:
Originally Posted by ******
View Post
What is `k<fix>`?
Eg.
CMD:makeleader - k<fix>d - para1, level
CMD:giveleaderorg - dK<fix>(-1) - family, id
Code:
SSCANF:fix(string[])
{
	new ret = INVALID_PLAYER_ID;
	
	if(IsNumeric(string))
	{
		new p = strval(string);
		if(IsPlayerConnected(p))
			ret = p;
	}
	else 
	{
		foreach(Player, p)
		{
			if(strfind(GetNick(p), string, true) != -1)
			{
				ret = p;
				break;
			}
		}
	}
	
	return ret;
}



Re: Problem CMD - TheToretto - 06.04.2019

Quote:
Originally Posted by KamilPolska
View Post
Eg.
CMD:makeleader - k<fix>d - para1, level
CMD:giveleaderorg - dK<fix>(-1) - family, id
Code:
SSCANF:fix(string[])
{
	new ret = INVALID_PLAYER_ID;
	
	if(IsNumeric(string))
	{
		new p = strval(string);
		if(IsPlayerConnected(p))
			ret = p;
	}
	else 
	{
		foreach(Player, p)
		{
			if(strfind(GetNick(p), string, true) != -1)
			{
				ret = p;
				break;
			}
		}
	}
	
	return ret;
}
Have you ever heard of the specifier "u"?

EDIT:
PHP Code:
    new targetid;
    if(
sscanf(params"du"familytargetid)) 
        return 
SendClientMessage(playerid, -1"USAGE /giveleaderorg [ORG ID] [ID]"); 



Re: Problem CMD - KamilPolska - 07.04.2019

Yes, I know rarely use "u". I can not fix the list of leaders. Only one message shows SendClientMessage(playerid, -1, "================ LIST OF LEADERS ================");.
And the rest of the message does not show, for example SendClientMessage(playerid, -1, PlayerInfo[id][Nick]); and SendClientMessage(playerid, -1, "================ END ================");
Code:
CMD:giveleaderorg(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return 1;
    new id = -1, family;
	if( sscanf(params, "du", family, id)) return SendClientMessage(playerid, -1, "USAGE /giveleaderorg [ORG ID] [ID]");
    if(family < 0 || family > MAX_ORG-1) return 1;
    if(id != -1)
    {
        if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "No such player!");
        if(GetPlayerFraction(id) != 0 || GetPlayerOrg(id) != 0) return SendClientMessage(playerid, -1, "This player has factions or family!");
        orgInvitePlayer(id, family);
        gPlayerOrgLeader[id] = true;
    }
    new str[128];
    if(id == 9)
    {
		new orgUID = orgID(family);
		if(orgUID != 0xFFFF)
		{
			format(str, sizeof(str), "%s give control over family to %d player %s", GetNick(playerid), family, GetNick(id));
			SendClientMessageToAll(-1, str);
			
			PlayerInfo[id][pTeam] = 5;
			gTeam[id] = 5;
		}
		else
		{
			SendClientMessage(playerid, -1, "ERROR! An error occured.");
		}
    }
    else
    {
		new query[500];
		//new nick[24];
	    //new results = cache_num_rows();

		mysql_format(g_SQL, query, sizeof(query), "SELECT `Nick` FROM `accounts` WHERE `FMember`='%d' AND `Rank`>1000", family);
		mysql_query(g_SQL, query);

    	new rows;
    	cache_get_row_count(rows);

	    GetPlayerName(id, PlayerInfo[id][Nick], MAX_PLAYER_NAME);

    	SendClientMessage(playerid, -1, "================ LIST OF LEADERS ================");

	    if(rows)
	    {
	        new loaded;
	        while(loaded < rows)
	        {
				cache_get_value_name(loaded, "Nick", PlayerInfo[id][Nick], 24);

				sscanf(str, "p<|>s[24]", PlayerInfo[id][Nick]);

				SendClientMessage(playerid, -1, PlayerInfo[id][Nick]);
	            loaded++; 
	        }
	        SendClientMessage(playerid, -1, "================ END ================");
	    }

	    /*
	    GetPlayerName(id, PlayerInfo[id][Nick], MAX_PLAYER_NAME);

		mysql_format(g_SQL, query, sizeof(query), "SELECT `Nick` FROM `accounts` WHERE `FMember`='%d' AND `Rank`>1000", family);
		mysql_query(g_SQL, query);

	    SendClientMessage(playerid, -1, "================ LIST OF LEADERS ================");

		if(results > 0)
		{
			for(new i = 0; i < results; i++)
			{
				cache_get_value_name(i, "Nick", PlayerInfo[id][Nick], 24);

				sscanf(str, "p<|>s[24]", PlayerInfo[id][Nick]);

				SendClientMessage(playerid, -1, PlayerInfo[id][Nick]);
			}
			SendClientMessage(playerid, -1, "================ END ================");
		}
		*/
    }
    return 1;
}