invalid player id
#1

hey guys, i'm making a command that shows how noob a player is in percentage.
it's just a random command that is used for fun.

command: /hownoob -id-

in chat: OMG! Player(1) is 94 Percent Noob!


I have ran into a little problem though, if I put in an invalid id, it says: OMG! (65535) is 10 Percent Noob!

i'm pretty sure i've made it so that if an invalid id is used, it should send back an error message, but that doesnt seem to be the case, also i get sscanf invalid parameter errors in my server console :/

here is my code

PHP код:
CMD:hownoob(playeridparams[])
{
    new 
pname[MAX_PLAYER_NAME];
    new 
noob random(101);
    new 
string[64];
    if(!
IsPlayerConnected(playerid)) return SendClientMessage(playeridRED"Invalid ID.");
    if(
sscanf(params"us[128]"playerid)) return SendClientMessage(playeridRED"Syntax: /hownoob (id)");
    if(
GetPVarInt(playerid,"HOWNOOB_TIMER")>GetTickCount())return SendClientMessage(playerid,0xFFFFFFFF,"Please Wait Before Being Noob Again!");
    
SetPVarInt(playerid,"HOWNOOB_TIMER",GetTickCount()+60000);
    
GetPlayerName(playeridpnamesizeof(pname));
    
format(stringsizeof(string), "OMG! %s(%d) is %i Percent Noob!"pnameplayeridnoob);
    
SendClientMessageToAll(PINKstring);
    return 
1;

Reply
#2

pawn Код:
CMD:hownoob(playerid, params[])
{
    new pname[MAX_PLAYER_NAME];
    new noob = random(101);
    new string[64];
    new id; // the target
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, RED, "Invalid ID."); // You had IsPlayerConnected(playerid)
    if(sscanf(params, "us[64]", id, string)) return SendClientMessage(playerid, RED, "Syntax: /hownoob (id)"); // You had "us[128]" yet you defined string as 64, and you forgot to include string after ID

    // Change the rest of the stuff id = target, playerid = YOU
    if(GetPVarInt(playerid,"HOWNOOB_TIMER")>GetTickCount())return SendClientMessage(playerid,0xFFFFFFFF,"Please Wait Before Being Noob Again!");
    SetPVarInt(playerid,"HOWNOOB_TIMER",GetTickCount()+60000);
    GetPlayerName(playerid, pname, sizeof(pname));
    format(string, sizeof(string), "OMG! %s(%d) is %i Percent Noob!", pname, playerid, noob);
    SendClientMessageToAll(PINK, string);
    return 1;
}
Reply
#3

i keep getting "Syntax: /hownoob (id)" in the chatbox, even if i put in the correct id
Reply
#4

pawn Код:
if(sscanf(params, "us[64]", id, string)) return SendClientMessage(playerid, RED, "Syntax: /hownoob (id)"); // Maybe this should be above
if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, RED, "Invalid ID."); // Lets try change is player connected to invalid player id
Reply
#5

code looks like this now

PHP код:
CMD:hownoob(playeridparams[])
{
    new 
id;
    new 
pname[MAX_PLAYER_NAME];
    new 
noob random(101);
    new 
string[64];
    if(
sscanf(params"us[64]"idstring)) return SendClientMessage(playeridRED"Syntax: /hownoob (id)");
    if(
id == INVALID_PLAYER_ID) return SendClientMessage(playeridRED"Invalid ID.");
    if(
GetPVarInt(playerid,"HOWNOOB_TIMER")>GetTickCount())return SendClientMessage(playerid,0xFFFFFFFF,"Please Wait Before Being Noob Again!");
    
SetPVarInt(playerid,"HOWNOOB_TIMER",GetTickCount()+60000);
    
GetPlayerName(idpnamesizeof(pname));
    
format(stringsizeof(string), "OMG! %s(%d) is %i Percent Noob!"pnameidnoob);
    
SendClientMessageToAll(PINKstring);
    return 
1;

still get the Syntax error when using /hownoob
Reply
#6

You're checking if id is connected before using sscanf to get the id.

And why are you splitting params into id and string, while you're just using id?

pawn Код:
CMD:hownoob(playerid, params[])
{
    new id;
    new pname[MAX_PLAYER_NAME];
    new noob = random(101);
    new string[64];
    if(sscanf(params, "u", id)) return SendClientMessage(playerid, RED, "Syntax: /hownoob (id)");
    if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, RED, "Invalid ID.");
    if(GetPVarInt(playerid,"HOWNOOB_TIMER")>GetTickCount())return SendClientMessage(playerid,0xFFFFFFFF,"Please Wait Before Being Noob Again!");
    SetPVarInt(playerid,"HOWNOOB_TIMER",GetTickCount()+60000);
    GetPlayerName(id, pname, sizeof(pname));
    format(string, sizeof(string), "OMG! %s(%d) is %i Percent Noob!", pname, id, noob);
    SendClientMessageToAll(PINK, string);
    return 1;
}
Reply
#7

That's because you're parsing two parameters and only seem to use one for the command.

pawn Код:
CMD:hownoob(playerid, params[])
{
    new pname[MAX_PLAYER_NAME];
    new noob = random(101);
    new string[64];
    if(!IsPlayerConnected(playerid)) return SendClientMessage(playerid, RED, "Invalid ID.");
    if(sscanf(params, "u", playerid)) return SendClientMessage(playerid, RED, "Syntax: /hownoob (id)");
    if(id = INVALID_PLAYER_ID)return SendClientMessage(playerid, RED, "Player isn't connected. ");
    if(GetPVarInt(playerid,"HOWNOOB_TIMER")>GetTickCount())return SendClientMessage(playerid,0xFFFFFFFF,"Please Wait Before Being Noob Again!");
    SetPVarInt(playerid,"HOWNOOB_TIMER",GetTickCount()+60000);
    GetPlayerName(playerid, pname, sizeof(pname));
    format(string, sizeof(string), "OMG! %s(%d) is %i Percent Noob!", pname, playerid, noob);
    SendClientMessageToAll(PINK, string);
    return 1;
}
Reply
#8

ahh, no wonder -.-

thanks for the help guys, problem is solved !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)