Problem with command
#1

Hello,
I have this command
Код:
			if(strcmp(cmd, "/setprefix", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_WHITE, "Usage: /setprefix [playerid] [Prefix text]");
				return 1;
			}
			new para1;
			new prefix;
			para1 = ReturnUser(tmp);
			tmp = strtok(cmdtext, idx);
			prefix = strval(tmp);
			if (pInfo[playerid][Adminlevel] >= 6 || IsPlayerAdmin(playerid))
			{
			    if(IsPlayerConnected(para1))
			    {
			        if(para1 != INVALID_PLAYER_ID)
			        {
						GetPlayerName(para1, giveplayer, sizeof(giveplayer));
						format(string, sizeof(string), "PREFIX: Administrator {FFFF00}%s {00FFFF} set you PREFIX {FFFF00}%s {00FFFF}. Congratulations!", PlayerName(playerid), prefix);
						SendClientMessage(para1, COLOR_ORANGE, string);
						pInfo[para1][Prefix] = prefix;
						format(string, sizeof(string), "PREFIX: {FFFF00}%s {00FFFF} now have PREFIX {FFFF00}%s{00FFFF}. Congratulations!", giveplayer, prefix);
						SendClientMessageToAll(COLOR_ORANGE, string);
					}
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_RED, "You have no access to this command!");
			}
		}
		return 1;
	}
The problem is with the variable "prefix". It's integer, but I want to be string.
How to fix this?
Reply
#2

Can we PLEASE update to something more advanced? Download ZCMD and sscanf:

Код:
CMD:setprefix(playerid, params[])
{
	new 
		prefix[100],
		id;

	if (sscanf(params, "us[100]", id, prefix))
	{
		SendClientMessage(playerid, COLOR_WHITE, "Usage: /setprefix [playerid/name] [Prefix text]");
		return 1;
	}

	if (pInfo[playerid][Adminlevel] >= 6 || IsPlayerAdmin(playerid))
	{
	    if(IsPlayerConnected(id))
	    {
			GetPlayerName(id, giveplayer, sizeof(giveplayer));

			format(string, sizeof(string), "PREFIX: Administrator {FFFF00}%s {00FFFF} set you PREFIX {FFFF00}%s {00FFFF}. Congratulations!", PlayerName(playerid), prefix);
			SendClientMessage(id, COLOR_ORANGE, string);

			pInfo[id][Prefix] = prefix;
			
			format(string, sizeof(string), "PREFIX: {FFFF00}%s {00FFFF} now have PREFIX {FFFF00}%s{00FFFF}. Congratulations!", giveplayer, prefix);
			SendClientMessageToAll(COLOR_ORANGE, string);
		}
	}
	else
	{
		SendClientMessage(playerid, COLOR_RED, "You have no access to this command!");
	}
	return 1;
}
How to use? https://sampforum.blast.hk/showthread.php?tid=300397
ZCMDS https://sampforum.blast.hk/showthread.php?tid=91354
sscanf https://sampforum.blast.hk/showthread.php?tid=570927
Reply
#3

Quote:
Originally Posted by Ralfie
Посмотреть сообщение
Can we PLEASE update to something more advanced? Download ZCMD and sscanf:

Код:
CMD:setprefix(playerid, params[])
{
	new 
		prefix[100],
		id;

	if (sscanf(params, "us[100]", id, prefix))
	{
		SendClientMessage(playerid, COLOR_WHITE, "Usage: /setprefix [playerid/name] [Prefix text]");
		return 1;
	}

	if (pInfo[playerid][Adminlevel] >= 6 || IsPlayerAdmin(playerid))
	{
	    if(IsPlayerConnected(id))
	    {
			GetPlayerName(id, giveplayer, sizeof(giveplayer));

			format(string, sizeof(string), "PREFIX: Administrator {FFFF00}%s {00FFFF} set you PREFIX {FFFF00}%s {00FFFF}. Congratulations!", PlayerName(playerid), prefix);
			SendClientMessage(id, COLOR_ORANGE, string);

			pInfo[id][Prefix] = prefix;
			
			format(string, sizeof(string), "PREFIX: {FFFF00}%s {00FFFF} now have PREFIX {FFFF00}%s{00FFFF}. Congratulations!", giveplayer, prefix);
			SendClientMessageToAll(COLOR_ORANGE, string);
		}
	}
	else
	{
		SendClientMessage(playerid, COLOR_RED, "You have no access to this command!");
	}
	return 1;
}
How to use? https://sampforum.blast.hk/showthread.php?tid=300397
ZCMDS https://sampforum.blast.hk/showthread.php?tid=91354
sscanf https://sampforum.blast.hk/showthread.php?tid=570927
I also use dcmd... can you help for dcmd in this case?
Reply
#4

Hello!

PHP код:
if(strcmp(cmd"/setprefix"true) == 0)
{
    if(
IsPlayerConnected(playerid))
     {
        
tmp strtok(cmdtextidx);
        if(!
strlen(tmp))
        {
            
SendClientMessage(playeridCOLOR_WHITE"Usage: /setprefix [playerid] [Prefix text]");
            return 
1;
        }
        new 
para1;
        new 
prefix[30];
        
para1 ReturnUser(tmp);
        
prefix strtok(cmdtextidx);
        if (
pInfo[playerid][Adminlevel] >= || IsPlayerAdmin(playerid))
        {
              if(
IsPlayerConnected(para1))
            {
                  if(
para1 != INVALID_PLAYER_ID)
                {
                    
GetPlayerName(para1giveplayersizeof(giveplayer));
                    
format(stringsizeof(string), "PREFIX: Administrator {FFFF00}%s {00FFFF} set you PREFIX {FFFF00}%s {00FFFF}. Congratulations!"PlayerName(playerid), prefix);
                    
SendClientMessage(para1COLOR_ORANGEstring);
                    
pInfo[para1][Prefix] = prefix;
                    
format(stringsizeof(string), "PREFIX: {FFFF00}%s {00FFFF} now have PREFIX {FFFF00}%s{00FFFF}. Congratulations!"giveplayerprefix);
                    
SendClientMessageToAll(COLOR_ORANGEstring);
                }
            }
        }
        else
        {
            
SendClientMessage(playeridCOLOR_RED"You have no access to this command!");
        }
    }
    return 
1;

Reply
#5

Quote:
Originally Posted by Mencent
Посмотреть сообщение
Hello!

PHP код:
if(strcmp(cmd"/setprefix"true) == 0)
{
    if(
IsPlayerConnected(playerid))
     {
        
tmp strtok(cmdtextidx);
        if(!
strlen(tmp))
        {
            
SendClientMessage(playeridCOLOR_WHITE"Usage: /setprefix [playerid] [Prefix text]");
            return 
1;
        }
        new 
para1;
        new 
prefix[30];
        
para1 ReturnUser(tmp);
        
prefix strtok(cmdtextidx);
        if (
pInfo[playerid][Adminlevel] >= || IsPlayerAdmin(playerid))
        {
              if(
IsPlayerConnected(para1))
            {
                  if(
para1 != INVALID_PLAYER_ID)
                {
                    
GetPlayerName(para1giveplayersizeof(giveplayer));
                    
format(stringsizeof(string), "PREFIX: Administrator {FFFF00}%s {00FFFF} set you PREFIX {FFFF00}%s {00FFFF}. Congratulations!"PlayerName(playerid), prefix);
                    
SendClientMessage(para1COLOR_ORANGEstring);
                    
pInfo[para1][Prefix] = prefix;
                    
format(stringsizeof(string), "PREFIX: {FFFF00}%s {00FFFF} now have PREFIX {FFFF00}%s{00FFFF}. Congratulations!"giveplayerprefix);
                    
SendClientMessageToAll(COLOR_ORANGEstring);
                }
            }
        }
        else
        {
            
SendClientMessage(playeridCOLOR_RED"You have no access to this command!");
        }
    }
    return 
1;

Thank you very much, man! This is the assistance that I expected.
May I ask one more thing?
I want the prefix to CAN contain spaces between the words.
In the moment if I type "Prefix with spaces", it will set only "Prefix" for prefix.
I also want to prefix must contain at least 1 character, because in the moment I can set empty prefix.
Reply
#6

Quote:
Originally Posted by bobsona
Посмотреть сообщение
Thank you very much, man! This is the assistance that I expected.
May I ask one more thing?
I want the prefix to CAN contain spaces between the words.
In the moment if I type "Prefix with spaces", it will set only "Prefix" for prefix.
I also want to prefix must contain at least 1 character, because in the moment I can set empty prefix.
Any ideas?
Reply
#7

MENCENT
Can you help me in my code i am waiting for you
Thanks
Reply
#8

Yep, I already have it included.
Reply


Forum Jump:


Users browsing this thread: