Help with dcmd and sscanf
#1

Since i've been having CPU usage problems with my gamemode. I'm re-writing a lot of it. i've removed lots of useless pieces of code, i probably wrote without even thinking.

Anyway im trying to re-write the commands using dcmd and sscanf.

This is an example command i've done, but its sending the message to ID 0 and not the intended id.

pawn Код:
dcmd_caps(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] < 1 && !PlayerTempMod[playerid] && !PlayerTempAdmin[playerid] && !IsPlayerAdmin(playerid)) return DenyMessage(playerid, 1);

    new giveplayerid;
    if(sscanf(params, "u", giveplayerid)) SendClientMessage(playerid, COLOR_WHITE, "USAGE: /caps [playerid]");
  else if(giveplayerid == INVALID_PLAYER_ID) SendClientMessage(playerid, COLOR_RED, "Invalid Player ID.");
  else
  {
    SendClientMessage(giveplayerid, COLOR_YELLOW, "Please DO NOT use CAPs on this server...Thank You!");
        PlayerPlaySound(giveplayerid, 1147, 0,0,0);
        SendClientMessage(playerid, COLOR_PINK, "Message Sent!");
    }
  return 1;
}
Reply
#2

Weird...
Try:
pawn Код:
dcmd_caps(playerid, params[])
{

new giveplayerid;
if(sscanf(params, "u", giveplayerid)) SendClientMessage(playerid, COLOR_WHITE, "USAGE: /caps [playerid]");
if(PlayerInfo[playerid][pAdmin] < 1 && !PlayerTempMod[playerid] && !PlayerTempAdmin[playerid] && !IsPlayerAdmin(playerid)) return DenyMessage(playerid, 1);

  else if(giveplayerid == INVALID_PLAYER_ID) SendClientMessage(playerid, COLOR_RED, "Invalid Player ID.");
  else
  {
  SendClientMessage(giveplayerid, COLOR_YELLOW, "Please DO NOT use CAPs on this server...Thank You!");
PlayerPlaySound(giveplayerid, 1147, 0,0,0);
SendClientMessage(playerid, COLOR_PINK, "Message Sent!");
}
  return 1;
}
Reply
#3

how did you defined dcmd(caps...... ?
Reply
#4

under OnPlayerCommandText

dcmd(caps,4,cmdtext);

Exactly like it shows on the wiki about dcmd and sscanf


Edit: Just tried using "i" instead of "u" and it works fine. Not sure why it says to use "u" on the examples but it didnt work with that for me.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)