/god command problem.
#1

Here is my /god cmd code, i have put some // to help you get faster into my thinking.
pawn Код:
CMD:god(playerid, params[])
{
new str1[128], str2[128], str3[128], admin[MAX_PLAYER_NAME], p[MAX_PLAYER_NAME], id, Float: health;
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "You must be Admin to use this command");//
if(sscanf(params, "d", id) && playerid==id) return SetPlayerHealth(playerid, 9999999999999999.0);//if you type /god, instead of getting message about correct usage, you trigger the command on yourself.
GetPlayerName(playerid, admin, MAX_PLAYER_NAME);
GetPlayerName(id, p, MAX_PLAYER_NAME);
GetPlayerHealth(id,health);
if(IsPlayerConnected(id) && health<101.0)
{
    SetPlayerHealth(id, 9999999999999999.0);
    format(str1, sizeof(str1), "Admin %s has turned you into god!", admin);
    SendClientMessage(id, 0x00FF00AA, str1);
    format(str2, sizeof(str2), "You have successfully turned %s into god.", p);
    SendClientMessage(playerid, 0x00FF00AA, str2);
}
else if (IsPlayerConnected(id) && health>100.0);//
{                                                     //
    SetPlayerHealth(id, 100.0);                       //          here, you get back to normal
    format(str3, sizeof(str3), "Back to mortality.");//
    SendClientMessage(playerid, 0x00FF00AA, str3);//
}                                                       //
else return SendClientMessage(playerid, 0xFF0000AA, "ERROR: Player is not connected.");
return 1;
}
Errors in lines: else if: "empty statement"
else return: invalid expression ,assumed zero
same line: warning: expression has no effect
same line: expected token: ";", but found "return"
return 1;: unreachable code.
Notice that if i put in /* --- */ the whole "else if" statement, the code gets sucessfully compiled. So there is something I do wrong in "else if" area. Of cource i have my includes in pawno and written upper in code, not here. Help!
Reply
#2

pawn Код:
CMD:god(playerid, params[])
{
    new str[128], admin[MAX_PLAYER_NAME + 1], p[MAX_PLAYER_NAME + 1], id, Float:health;
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "You must be Admin to use this command");

    if(sscanf(params, "u", id) || playerid == id) return SetPlayerHealth(playerid, 9999999999999999.0);
   
    GetPlayerName(playerid, admin, MAX_PLAYER_NAME);
    GetPlayerName(id, p, MAX_PLAYER_NAME);
    GetPlayerHealth(id, health);
    if(IsPlayerConnected(id) && health <= 100.0)
    {
        SetPlayerHealth(id, 9999999999999999.0);
        format(str, sizeof(str), "Admin %s has turned you into god!", admin);
        SendClientMessage(id, 0x00FF00AA, str);
        format(str, sizeof(str), "You have successfully turned %s into god.", p);
        return SendClientMessage(playerid, 0x00FF00AA, str);
    }
    else if (IsPlayerConnected(id) && health > 100.0)
    {                                                    
        SetPlayerHealth(id, 100.0);                      
        format(str, sizeof(str), "Back to mortality.");//
        return SendClientMessage(playerid, 0x00FF00AA, str);
    }                                                      
    else return SendClientMessage(playerid, 0xFF0000AA, "ERROR: Player is not connected.");
}
Empty statement occurs usually because of stray ";". Don't create so many str variables when all you need is one.
Reply
#3

Thank you a lot buddy! Rep+!

------------

New problem: I succesfully turn my self into god with /god. But I can't disable god by typing /god. Instead of sayg "back to mortality", gives message that I turned into god. More specifically, lines "if(sscanf(params, "d", id) && health > 100.0) return SetPlayerHealth(playerid, 100.0);"
and "else if (IsPlayerConnected(id) && health > 100.0)" do not get triggered. Any ideas?
pawn Код:
CMD:god(playerid, params[])
{
    new str[128], admin[MAX_PLAYER_NAME], p[MAX_PLAYER_NAME], id, Float:health;
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "You must be Admin to use this command");
    GetPlayerHealth(id, health);
    if(sscanf(params, "d", id) && playerid == id) return SetPlayerHealth(playerid, 9999999999999999.0);
    if(sscanf(params, "d", id) && health > 100.0) return SetPlayerHealth(playerid, 100.0);
    GetPlayerName(playerid, admin, MAX_PLAYER_NAME);
    GetPlayerName(id, p, MAX_PLAYER_NAME);
   
    if(IsPlayerConnected(id) && health <= 100.0)
    {
        SetPlayerHealth(id, 9999999999999999.0);
        format(str, sizeof(str), "Admin %s has turned you into god!", admin);
        SendClientMessage(id, 0x00FF00AA, str);
        format(str, sizeof(str), "You have successfully turned %s into god.", p);
        return SendClientMessage(playerid, 0x00FF00AA, str);
    }
    else if (IsPlayerConnected(id) && health > 100.0)
    {
        SetPlayerHealth(id, 100.0);
        format(str, sizeof(str), "Back to mortality.");
        SendClientMessage(id, 0x00FF00AA, str);
        format(str, sizeof(str), "Back to mortality.");
        return SendClientMessage(playerid, 0x00FF00AA, str);
    }
    else return SendClientMessage(playerid, 0xFF0000AA, "ERROR: Player is not connected.");
}
SOLVED
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)