Should this work?
#1

Hi all! I am not new now in the scripting hobby, so I think I should try different ways to script. Have a look at this command:

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(sethealth, 9, cmdtext);
    return 1;
}

dcmd_sethealth(playerid, params[]) {
    new pID, value;
    if(sscanf(params, "ui", pID, value)) {
        if(PlayerInfo[playerid][AdminLevel] >= 3) {
            if(pID != INVALID_PLAYER_ID) {
                new tName[MAX_PLAYER_NAME], string[128];
                GetPlayerName(pID, tName, MAX_PLAYER_NAME);
                format(string, sizeof(string), "You have set (%i) %s's health to %i", pID, tName, value);
                SetPlayerHealth(pID, value);
            }
            else return SendClientMessage(playerid, COLOR_GREEN, "Player Not Found");
        }
        else return SendClientMessage(playerid, COLOR_RED, "You have no acces to this command");
    }
    return SendClientMessage(playerid, COLOR_GOLD, "Syntax Error: /sethealth [playerid] [amount]");
}
No errors when I compile! Yeah, I know, the right way:

pawn Код:
dcmd_sethealth(playerid, params[]) {
    new pID, value, pName[MAX_PLAYER_NAME], string[128];
    if(sscanf(params, "ui", pID, value)) return SendClientMessage(playerid, COLOR_GOLD, "/sethealth [playerid] [amount]");
    else if(pID == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GREEN, "Player Not Found");
    else if(PlayerInfo[playerid][AdminLevel] <= 3) return SendClientMessage(playerid, COLOR_RED, "You have no access to this command");
    else {
        SetPlayerHealth(playerid, value);
        GetPlayerName(pID, pName, MAX_PLAYER_NAME);
        format(string, sizeof(string), "You changed (%i) %s's health to %i", pID, pName, value);
        SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
    }
    return 1;
}
But I tried the other way. Now, my question is:

1) Should the first way work IG?!
2) What way should I use to compile? I am for the first one. Dunno why, it seems more professional
Reply
#2

Use this:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(sethealth, 9, cmdtext);
    return 1;
}
pawn Код:
dcmd_sethealth(playerid, params[])
{
    new pID, value;
    if(PlayerInfo[playerid][AdminLevel] >= 3)
    {
        if(sscanf(params, "ud", pID, value)) return SendClientMessage(playerid, COLOR_GOLD, "Syntax Error: /sethealth [playerid] [amount]");
        if(pID == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GREEN, "Player Not Found");
        new tName[MAX_PLAYER_NAME], string[128];
        GetPlayerName(pID, tName, MAX_PLAYER_NAME);
        format(string, sizeof(string), "You have set (%d) %s's health to %d", pID, tName, value);
        SendClientMessage(playerid, -1,string);
        SetPlayerHealth(pID, value);
    }
    else return SendClientMessage(playerid, COLOR_RED, "You have no acces to this command");
    return 1;
}
Edit: use sscanf2.
Reply
#3

thanks bro. and yeah I use sscanf2

pawn Код:
#include <sscanf2>
Reply
#4

But if your learning try to learn an other better like zcmd, y_cmd or something....
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)