SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 06/04/2019, 03:02 PM   #1
KamilPolska
Huge Clucker
 
Join Date: May 2016
Location: Poland
Posts: 494
Reputation: 5
Default Problem CMD

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 ================");
        }
    }
KamilPolska is offline   Reply With Quote
Old 06/04/2019, 03:32 PM   #2
Private200
High-roller
 
Private200's Avatar
 
Join Date: May 2012
Posts: 1,176
Reputation: 211
Default Re: Problem CMD

It's your sscanf that makes your command work as "giveleaderorg 45 0", check: https://forum.sa-mp.com/showthread.php?t=602923

It won't show the list because most likely, you are putting a valid player id?
Private200 is offline   Reply With Quote
Old 06/04/2019, 05:29 PM   #3
KamilPolska
Huge Clucker
 
Join Date: May 2016
Location: Poland
Posts: 494
Reputation: 5
Default Re: Problem CMD

Quote:
Originally Posted by Private200 View Post
It's your sscanf that makes your command work as "giveleaderorg 45 0", check: https://forum.sa-mp.com/showthread.php?t=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 ================");
        }
    }

Last edited by KamilPolska; 06/04/2019 at 06:08 PM.
KamilPolska is offline   Reply With Quote
Old 06/04/2019, 05:34 PM   #4
KamilPolska
Huge Clucker
 
Join Date: May 2016
Location: Poland
Posts: 494
Reputation: 5
Default Re: Problem CMD

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;
}
KamilPolska is offline   Reply With Quote
Old 06/04/2019, 07:07 PM   #5
TheToretto
Gangsta
 
TheToretto's Avatar
 
Join Date: Jul 2015
Posts: 584
Reputation: 66
Default Re: Problem CMD

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]"); 
__________________






Toretto#9902

Rest in peace grandpa, 03 November 2018
TheToretto is offline   Reply With Quote
Old 07/04/2019, 01:47 AM   #6
KamilPolska
Huge Clucker
 
Join Date: May 2016
Location: Poland
Posts: 494
Reputation: 5
Default Re: Problem CMD

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;
}
KamilPolska is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Password Hash Problem & MYSQL Saving Problem Faqahat Scripting Help 3 18/04/2016 11:54 AM
[SOLVED] 3 problem's! (1 problem still unsolved, but stopped solving.) Mechscape Help Archive 9 24/12/2009 08:47 PM


All times are GMT. The time now is 07:43 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.