SA-MP Forums Archive
zcmd and sscanf problem - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: zcmd and sscanf problem (/showthread.php?tid=170681)



zcmd and sscanf problem - mrcoolballs - 23.08.2010

Код:
CMD:pm(playerid, params[])
{
	new str[128], str2[128], id, Name1[MAX_PLAYER_NAME], Name2[MAX_PLAYER_NAME];
	if(sscanf(params, "us", id, str2))
	{
	    SendClientMessage(playerid, 0xFF0000FF, "Usage: /pm <id/name> <message>");
		return 1;
	}
	if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: That player is not connected!");
	if(playerid != id) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You cannot pm yourself!");
	GetPlayerName(playerid, Name1, sizeof(Name2)); //The Sender's Name so we use (playerid).
	GetPlayerName(id, Name2, sizeof(Name2)); //The Receiver's Name so we use (id).
	format(str, sizeof(str), "PM To %s(ID %d): %s", Name2, id, str2);
	SendClientMessage(playerid, 0xFF0000FF, str);
	format(str, sizeof(str), "PM From %s(ID %d): %s", Name1, playerid, str2);
	SendClientMessage(id, 0xFF0000FF, str);
 	return 1;
}
theres my code, but why doesnt it work when i type /pm it returns unknown command
am i suppose to put something under onplayercommand if so, what? nobody mentioned doing anything in the tutorials


Re: zcmd and sscanf problem - nemesis- - 23.08.2010

Is this sscanf 2.0? Also, where are you putting the code? It need not be under any callback.

On the part where you have if(player != id), it should be if(playerid == id).


Re: zcmd and sscanf problem - mrcoolballs - 23.08.2010

yes its sscanf2 and im not putting it under any callback just what do i have to put under onplayercommandtext


Re: zcmd and sscanf problem - nemesis- - 23.08.2010

Quote:
Originally Posted by mrcoolballs
Посмотреть сообщение
yes its sscanf2 and im not putting it under any callback just what do i have to put under onplayercommandtext
pawn Код:
if(sscanf(params, "us", id, str2))
Should be:
pawn Код:
if(sscanf(params, "us[128]", id, str2))
Zcmd commands behave like functions so they should not be under ANY callbacks. Correct the error I mentioned in sscanf and above and you should be fine.


Re: zcmd and sscanf problem - Sky4D - 23.08.2010

Well, since I need a PM command in my script anyway, let me create one real fast and you can edit it to your needs....

2 - 3 minutes later:

pawn Код:
COMMAND:pm(playerid, params[])
{
    new user, yourmessage[128], string[128];
    if(!sscanf(params, "us", user, yourmessage))
    {
        if(user != INVALID_PLAYER_ID)
        {
            format(string, sizeof(string), "[Private Message from %s]: %s", ReturnPlayerName(playerid), yourmessage);
            SendClientMessage(user, sc_Lime, string);
            format(string, sizeof(string), "[Private Message to %s]: %s", ReturnPlayerName(playerid), yourmessage);
            SendClientMessage(playerid, sc_Lime, string);
        }
        else return SendClientMessage(playerid, sc_LightRed, "ERROR: Invalid Player ID.");
    }
    else return SendClientMessage(playerid, sc_White, "COMMAND: /pm [playerid] [message]");
    return 1;
}
ReturnPlayerName:

pawn Код:
stock ReturnPlayerName(playerid)
{
    var1="Invalid_Player_ID";
    if(IsPlayerConnected(playerid))
    {
        GetPlayerName(playerid, var1, sizeof(var1));
        for(new i = 0; i < sizeof(var1); i++)
        { if(var1[i] == '_') { var1[i] = ' '; } }
    }
    return var1;
}



Re: zcmd and sscanf problem - FreshKilla - 23.08.2010

pawn Код:
CMD:pm(playerid, params[])
{
    new str[128], str2[128], id, Name1[MAX_PLAYER_NAME], Name2[MAX_PLAYER_NAME];
    if(sscanf(params, "us[128]", id, str2)) SendClientMessage(playerid, 0xFF0000FF, "Usage: /pm <id/name> <message>");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: That player is not connected!");
    if(playerid != id) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You cannot pm yourself!");
    GetPlayerName(playerid, Name1, sizeof(Name2)); //The Sender's Name so we use (playerid).
    GetPlayerName(id, Name2, sizeof(Name2)); //The Receiver's Name so we use (id).
    format(str, sizeof(str), "PM To %s(ID %d): %s", Name2, id, str2);
    SendClientMessage(playerid, 0xFF0000FF, str);
    format(str, sizeof(str), "PM From %s(ID %d): %s", Name1, playerid, str2);
    SendClientMessage(id, 0xFF0000FF, str);
    return 1;
}



Re: zcmd and sscanf problem - [L3th4l] - 23.08.2010

Ok Sky, since he said he is using sscanf2, your strings will be deprecated since you aren't assigning a size

pawn Код:
CMD:pm(playerid, params[])
{
    new ID, Message[128];
    if(sscanf(params, "us[128]", ID, params)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /PM < Player ID > < Message >");
    if(!IsPlayerConnected(ID)) return SendClientMessage(playerid, COLOR_RED, "ERROR: That user is offline!");
    format(Message, sizeof(Message), "PM From %s: %s", pName(playerid), params);
    SendClientMessage(playerid, GREEN, Message);
    format(Message, sizeof(Message), "PM To %s: %s", pName(ID), params);
    SendClientMessage(playerid, GREEN, Message);
    return 1;
}
Remeber that you will need to get the player's name, not sure if you use pName since thats the popular stock to use. But you can still use, GetPlayerName. Up to you, modify it to fit your needs.


Re: zcmd and sscanf problem - mrcoolballs - 23.08.2010

ok well i changed my code but how come when i test it out ingame, i will type /pm and it returns unknown command?
ive made a few commands and all of them return unknown command, and i dont have them under any callback

EDIT:::::


Okay i figured out the problem, i get the error runtime error 19 so thta means that the file is notproperly included if somebody could please tell me where to put the files of sscanf2 please, i already have it in my Pawno/includes
and it the plugins folder what else is there?


Re: zcmd and sscanf problem - nemesis- - 23.08.2010

Quote:
Originally Posted by Sky4D
Посмотреть сообщение
Well, since I need a PM command in my script anyway, let me create one real fast and you can edit it to your needs....

2 - 3 minutes later:

pawn Код:
COMMAND:pm(playerid, params[])
{
    new user, yourmessage[128], string[128];
    if(!sscanf(params, "us", user, yourmessage))
    {
        if(user != INVALID_PLAYER_ID)
        {
            format(string, sizeof(string), "[Private Message from %s]: %s", ReturnPlayerName(playerid), yourmessage);
            SendClientMessage(user, sc_Lime, string);
            format(string, sizeof(string), "[Private Message to %s]: %s", ReturnPlayerName(playerid), yourmessage);
            SendClientMessage(playerid, sc_Lime, string);
        }
        else return SendClientMessage(playerid, sc_LightRed, "ERROR: Invalid Player ID.");
    }
    else return SendClientMessage(playerid, sc_White, "COMMAND: /pm [playerid] [message]");
    return 1;
}
ReturnPlayerName:

pawn Код:
stock ReturnPlayerName(playerid)
{
    var1="Invalid_Player_ID";
    if(IsPlayerConnected(playerid))
    {
        GetPlayerName(playerid, var1, sizeof(var1));
        for(new i = 0; i < sizeof(var1); i++)
        { if(var1[i] == '_') { var1[i] = ' '; } }
    }
    return var1;
}
An entire function to return a silly player's name?

Quote:
Originally Posted by FreshKilla
Посмотреть сообщение
pawn Код:
CMD:pm(playerid, params[])
{
    new str[128], str2[128], id, Name1[MAX_PLAYER_NAME], Name2[MAX_PLAYER_NAME];
    if(sscanf(params, "us[128]", id, str2)) SendClientMessage(playerid, 0xFF0000FF, "Usage: /pm <id/name> <message>");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: That player is not connected!");
    if(playerid != id) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You cannot pm yourself!");
    GetPlayerName(playerid, Name1, sizeof(Name2)); //The Sender's Name so we use (playerid).
    GetPlayerName(id, Name2, sizeof(Name2)); //The Receiver's Name so we use (id).
    format(str, sizeof(str), "PM To %s(ID %d): %s", Name2, id, str2);
    SendClientMessage(playerid, 0xFF0000FF, str);
    format(str, sizeof(str), "PM From %s(ID %d): %s", Name1, playerid, str2);
    SendClientMessage(id, 0xFF0000FF, str);
    return 1;
}
Still not gunna work!

Quote:
Originally Posted by mrcoolballs
Посмотреть сообщение
ok well i changed my code but how come when i test it out ingame, i will type /pm and it returns unknown command?
ive made a few commands and all of them return unknown command, and i dont have them under any callback

EDIT:::::


Okay i figured out the problem, i get the error runtime error 19 so thta means that the file is notproperly included if somebody could please tell me where to put the files of sscanf2 please, i already have it in my Pawno/includes
and it the plugins folder what else is there?
Make sure you have the latest includes. Make sure the plugin is mentioned in server.cfg, make sure the include is mentioned at the top of your gamemode and make sure you're compiling with the latest includes.


Re: zcmd and sscanf problem - Sky4D - 23.08.2010

Quote:
Originally Posted by nemesis-
Посмотреть сообщение
An entire function to return a silly player's name?
Yes, because if they have a roleplay name such as 'Leroy_Jenkins' it returns it with 'Leroy Jenkins', and it's better than using GetPlayerName, ect, because it looks neater.