Problem with /energy command
#1

Hi I made this command for energy while playing, but I got problems! Only admins can use this command!

pawn Код:
CMD:energy(playerid, params[])
{
    if(IsPlayerAdmin(playerid)) {
        new ID;
        if(sscanf(params, "u", ID)) return SendClientMessage(playerid, COLOR_BLUE, "USAGE: /energy"); //errorline
        SetPlayerHealth(SetPlayerHealth +100);    //errorline
    }
    else
    {
        SendClientMessage(playerid, COLOR_BLUE, "You are not an administrator, so you can't use this command!"); //errorline
    }
    return 1;
}
I got 3 error while compiling:

Код:
D:\Program Files\Rockstar Games\GTA San Andreas\eigener SAMP\gamemodes\deathmatch.pwn(64) : error 035: argument type mismatch (argument 2)
D:\Program Files\Rockstar Games\GTA San Andreas\eigener SAMP\gamemodes\deathmatch.pwn(65) : error 076: syntax error in the expression, or invalid function call
D:\Program Files\Rockstar Games\GTA San Andreas\eigener SAMP\gamemodes\deathmatch.pwn(69) : error 035: argument type mismatch (argument 2)
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


3 Errors.
Reply
#2

pawn Код:
CMD:energy(playerid, params[])
{
    if(IsPlayerAdmin(playerid)) {
        new ID;
        if(sscanf(params, "u", ID)) return SendClientMessage(playerid, 0x0022FFFF, "USAGE: /energy");
        SetPlayerHealth(ID, 100);
    }
    else
    {
        SendClientMessage(playerid, 0x0022FFFF, "You are not an administrator, so you can't use this command!");
    }
    return 1;
}

Check your COLOR_BLUE define, it probably isn't correct.
And for SetPlayerHealth, it has 2 parameters, playerid and Float:Health...
Reply
#3

It's not SetPlayerHealth(SetPlayerHealth +100);
It's SetPlayerHealth(ID, 100);
ID, is the params of that cmd (i guess)
Reply
#4

That is possibly the most bizzare function usage I have ever seen! You haven't even fufilled the required amount of parameters for the function, you should take a look at them on the SA-MP Wiki for more information and examples that may help you.

https://sampwiki.blast.hk/wiki/SetPlayerHealth
https://sampwiki.blast.hk/wiki/GetPlayerHealth

Here is an example:

pawn Код:
CMD:energy(playerid, params[])
{
    if(IsPlayerAdmin(playerid)) {
        new ID, Float:health;
        if(sscanf(params, "u", ID)) return SendClientMessage(playerid, COLOR_BLUE, "USAGE: /energy"); //errorline
        GetPlayerHealth(ID, health);
        SetPlayerHealth(ID, health + 100);    //errorline
    }
    else
    {
        SendClientMessage(playerid, COLOR_BLUE, "You are not an administrator, so you can't use this command!"); //errorline
    }
    return 1;
}
Now there's a problem with that, it will end up setting the players health above 100 in most circumstances, if you meant to actually just set their health to 100 instead of incrementing it by +100 like you indicated in your code, then you would just use:

pawn Код:
SetPlayerHealth(ID, 100);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)