/smokeweed crashing game
#1

Hey I made a simple weed system, does anyone know why when the player uses /smokeweed and has 0 weed, it says you have no weed... but then when the player does have weed (after an admin /agiveweed's the player), they use /smokeweed and it crashes the game. The server console says "sscanf warning: Format specifier does not match parameter count." This is my code
pawn Код:
CMD:agiveweed(playerid, params[])
{
    new targetid, string[128], amount;
    if(PlayerStat[playerid] [AdminLevel] < 2) return SendClientMessage(playerid, GREY, "You don't have access to this command!");
    if(sscanf(params, "ud[128]", targetid, amount)) return SendClientMessage(playerid, GREY, "USAGE: /agiveweed [playerid] [amount]");
    if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, GREY, "That player is not connected!");
    else
    {
        PlayerStat[targetid][HasWeed] = amount++;
        format(string, sizeof(string), "You have given %s %d gram(s) of weed!", GetOOCName(targetid), amount);
        SendClientMessage(playerid, WHITE, string);
        format(string, sizeof(string), "Administrator %s has given you %d gram(s) of weed!", GetOOCName(playerid), amount);
        SendClientMessage(targetid, WHITE, string);
        AdminActionLog(string);
    }
    return 1;
}


CMD:smokeweed(playerid, params[])
{
    new Float:health, string[128];
    if(PlayerStat[playerid][HasWeed] >= 1)
    {
        if(GetPlayerHealth(playerid, health) < 75)                
        {
            ApplyAnimation(playerid, "JST_BUSINESS", "smoke_01", 4.1, 1, 1, 1, 0, 1, 1);
            SetPlayerHealth(playerid, health+25);
            format(string, sizeof(string), "%s takes out a joint and smokes some weed.", GetICName(playerid));
            SendNearByMessage(playerid, ACTION_COLOR, string, 4);
            PlayerStat[playerid][HasWeed] -= 1;
        }
        else
        {
            SendClientMessage(playerid, GREY, "Your health must be below 75 to smoke weed!");
        }
    }
    else
    {
        SendClientMessage(playerid, GREY, "You don't have any weed left!");
    }
    return 1;
 }
I've got
pawn Код:
enum PlayerInfo
{
            HasWeed,
}
etc

Any help would be appreciated. Thank you!
Reply
#2

if(sscanf(params, "ud", targetid, amount))
Reply
#3

only [128] is used when letter

pawn Код:
if(sscanf(params, "us[128]", targetid, amount))
in your bag so serious

pawn Код:
if(sscanf(params, "ud", targetid, amount))
and you put it up mate
Reply
#4

Thanks for your help, but I tried that and it's still crashing my game
Reply
#5

It is crashing the player because you are using an invalid animation library.

This line of code:

Код:
ApplyAnimation(playerid, "JST_BUSINESS", "smoke_01", 4.1, 1, 1, 1, 0, 1, 1);
Should be this:

Код:
ApplyAnimation(playerid, "JST_BUISNESS", "smoke_01", 4.1, 1, 1, 1, 0, 1, 1);
Weird how the animation library needs to be spelled incorrectly to work properly. You can find all the correct animation libraries here: https://sampwiki.blast.hk/wiki/Animations
Reply
#6

This is not the reason for your crash,but still this needs to be corrected

Change
pawn Код:
if(GetPlayerHealth(playerid,health)<75)
To

pawn Код:
GetPlayerHealth(playerid,health);
if(health<75)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)