sscanf problem
#1

Hey, I've got the latest includes and plugin for Streamer, but for some reason whenever I use a command, it uses it on the player typing the cmd... I'm pretty sure it's because I haven't assigned a value to "id" therefore it automatically assigns "id" the value of 0 (which is the id I am when I login, therefore it's kicking me). How can I assign a value to "id"? I'm trying to refresh my scripting memory and I'm not quiet sure how to do that.. Any help would be great thanks!

Example of commands that are kicking me when I type just "/kick" or or "/ban" etc...
pawn Код:
CMD:kick(playerid, params[])
{
    new string[128], id, reason[128];
    if(!IsPlayerAdmin(playerid)) SendClientMessage(playerid, -1, "Only administrators can use this command!");
    if(sscanf(params,"us[128]", id, reason)) SendClientMessage(playerid, -1, "USAGE: /kick [playerid] [reason]");
    if(!IsPlayerConnected(id)) SendClientMessage(playerid, -1, "That player isn't online!");
    format(string, sizeof(string), "%s has kicked %s. Reason %s.", GetICName(playerid), GetICName(id), reason);
    SendClientMessageToAll(YELLOW, string);
    Kick(id);
    return 1;
}


CMD:ban(playerid, params[])
{
    new str[128], id, reason[60];
    if(!IsPlayerAdmin(playerid)) SendClientMessage(playerid, -1, "You cannot use this command if you aren't an administrator!");
    if(sscanf(params,"us[60]", id, reason)) SendClientMessage(playerid, -1, "USAGE: /ban [playerid] [reason]");
    if(!IsPlayerConnected(id)) SendClientMessage(playerid, -1, "That player is not online!");
    new Day, Month, Year;
    getdate(Year, Month, Day);
    format(str, sizeof(str), "%s has banned %s, Date: %04d/%02d/%02d, Reason: %s.", GetICName(playerid), GetICName(id), Year, Month, Day, reason);
    SendClientMessageToAll(YELLOW, str);
    format(str, sizeof(str), "%s Banned.", GetICName(id));
    BanLog(str);
    Kick(id);
    return 1;
}

CMD:mute(playerid, params[])
{
    new id, reason[80], minutes, string[128];
    if(IsPlayerAdmin(playerid < 1 ))

    if(sscanf(params, "uis[80]", id, minutes, reason))  SendClientMessage(playerid,0xFFFF0000,"Usage: /mute [playerid/name] [time] [reason]");
    if(id == playerid) return SendClientMessage(playerid, GREY,"You cannot use this command on yourself!");
    if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, GREY,"That player is not connected!");
   
    if(minutes == 0) //perm mute
    {
        format(string, sizeof(string), "~ %s has been muted. Reason: '%s' ", GetICName(id), minutes, reason);
        PlayerStat[playerid][pMuted] = 0;
    }
    else
    {
        format(string, sizeof(string), "~ %s has been muted for %i minutes. Reason: '%s' ", GetICName(id), minutes, reason);
        PlayerStat[playerid][pMuted] = 0;
        SetTimerEx("unmuteTimer", 60*1000*minutes, false, "i", id);
    }
    SendClientMessageToAll(YELLOW, string);
    print(string);
    return 1;
}
Reply
#2

Change

Код:
if(sscanf(params,"us[60]", id, reason)) SendClientMessage(playerid, -1, "USAGE: /ban [playerid] [reason]");
To

Код:
if(sscanf(params,"us[60]", id, reason)) return SendClientMessage(playerid, -1, "USAGE: /ban [playerid] [reason]");
And your problem is fixed. It's because you weren't returning a value so it would continue through the command whether you entered a value or not and since the default value is 0 it kicked you

You should be doing that for all of these as well
Код:
  if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "Only administrators can use this command!");
    if(sscanf(params,"us[128]", id, reason)) return SendClientMessage(playerid, -1, "USAGE: /kick [playerid] [reason]");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "That player isn't online!");
Reply
#3

Thanks!!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)