Sscanf question
#1

Hello there,

I'm looking for a function that can help me by making commands like:

/give [playerid] [code] [amount]

CODES:
1: Weapon
2: Armour
3: Health

etc etc.

Anyone that can help me?

What I have for now is:

pawn Код:
CMD:give(playerid, params[])
{
    new membername, amount;
    if(sscanf(params, "uii", membername, params, amount))

    {
        SendClientMessage(playerid, COLOR_ORANGE, "[Set Player]{FFFFFF} /give[playerid] [code] [amount]");
        SendClientMessage(playerid, COLOR_GREY, "1) Health 2) Armour 3) Weapon");
        return 1;
    }

    else if(!strcmp(params, "1", true))
    {
        SetPlayerHealth(membername, amount);
        SendClientMessage(playerid, COLOR_GREEN, "Succeed");
        return 1;
    }

    else if(!strcmp(params, "2", true))
    {
        SetPlayerArmour(membername, amount);
        SendClientMessage(playerid, COLOR_GREEN, "Succeed");
        return 1;
    }

    return 1;
}
Reply
#2

pawn Код:
CMD:give(playerid, params[])
{
    new membername, code, amount;
    if(sscanf(params, "uii", membername, code, amount))
    {
        SendClientMessage(playerid, COLOR_ORANGE, "[Set Player]{FFFFFF} /give[playerid] [code] [amount]");
        SendClientMessage(playerid, COLOR_GREY, "1) Health 2) Armour 3) Weapon");
        return 1;
    }
    if(!IsPlayerConnected(membername)) return SendClientMessage(playerid, COLOR_GREY, "Invalid player");
   
    switch (code)
    {
        case 1:
        {
            SetPlayerHealth(membername, amount);
            SendClientMessage(playerid, COLOR_GREEN, "Succeed");
        }
        case 2:
        {
            SetPlayerArmour(membername, amount);
            SendClientMessage(playerid, COLOR_GREEN, "Succeed");
        }
        case 3:
        {
            // weapon..
        }
        default: SendClientMessage(playerid, COLOR_GREY, "Invalid option -> 1) Health 2) Armour 3) Weapon");
    }
    return 1;
}
Reply
#3

I suggest, health and Armour also and weapon to do like:
pawn Код:
case 1:
        {
            new Float:health; GetPlayerHealth(membername,health);
            SetPlayerHealth(membername,health+amount);
        }
        case 2:
        {
            new Float:armour; GetPlayerHealth(membername,armour);
            SetPlayerArmour(membername,armour+ amount);
        }
        case 3:
        {
            new playeridweapon;
            playeridweapon=GetPlayerWeapon(playerid);
            GivePlayerWeapon(membername, playeridweapon, amount);  
        }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)