SA-MP Forums Archive
[FilterScript] /god command for admins - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+--- Thread: [FilterScript] /god command for admins (/showthread.php?tid=422216)



/god command for admins - HurtLocker - 12.03.2013

A simple and useful command which allows you to manage gods in your server! I felt really good when I got it working. Oh yea.
pawn Code:
#include <a_samp>
#include <sscanf2>
#include <zcmd>

CMD:god(playerid, params[])
{
    //new str3[128];
    new str1[128], str2[128], admin[MAX_PLAYER_NAME], p[MAX_PLAYER_NAME], id, Float: health1, Float:health2;
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "You must be Admin to use this command");

//Make yourself god by typing only: /god
    GetPlayerHealth(playerid, health1);
    //format(str3, sizeof(str3), "health: %f.", health1); With these lines I found out that if you set a player's health to 9999~~.0,
    //SendClientMessage(playerid, COLOR_ORANGE, str3);    his health value becomes actually 0.0 and so I got the code working, took me hours, damn.
    if(sscanf(params, "d", id)) //do not change "d" with "u" or in /god [ID] format,
    {                         //you will receive message "ERROR: Player is not connected." even if you enter valid id.
        if (health1==0.0)
        {
        SetPlayerHealth(playerid, 100.0);
        return SendClientMessage(playerid,0x00FF00AA, "Back to mortality.");
        }

        if (health1>0.0)
        {
        SetPlayerHealth(playerid, 9999999999999999.0);
        return SendClientMessage(playerid, 0x00FF00AA, "You are god now!");
        }
    }
   
//Make a player of your server god with /god [ID]
    if(IsPlayerConnected(id))
    {
        GetPlayerName(playerid, admin, MAX_PLAYER_NAME);
        GetPlayerName(id, p, MAX_PLAYER_NAME);
        GetPlayerHealth(id, health2);

        if (health2>0.0)
        {
            SetPlayerHealth(id, 9999999999999999.0);
            format(str2, sizeof(str2), "You have successfully turned %s into god.", p);
            SendClientMessage(playerid, 0x00FF00AA, str2);
            format(str1, sizeof(str1), "Admin %s has turned you into god!", admin);
            SendClientMessage(id, 0x00FF00AA, str1);
        }

        if (health2==0)
        {
            SetPlayerHealth(id, 100.0);
            format(str2, sizeof(str2), "You have turned god %s into human.", p);
            SendClientMessage(playerid, 0x00FF00AA, str2);
            return SendClientMessage(id, 0x00FF00AA, "Back to mortality.");
        }
    }
    else SendClientMessage(playerid, 0xFF0000AA, "ERROR: Player is not connected.");
    return 1;
}
EDIT: update: using infinity instead of 999~~ --> scroll down.


Re: /god command for admins - Bicentric - 12.03.2013

Nicely done

Instead of setting their health to that extremely high number, why not just set it to infinity?

pawn Code:
#if !defined FLOAT_INFINITY
    #define FLOAT_INFINITY   (Float:0x7F800000)
#endif



Re: /god command for admins - HurtLocker - 12.03.2013

Quote:
Originally Posted by Bicentric
View Post
Nicely done

Instead of setting their health that that extremely high number, why not just set it to infinity?

pawn Code:
#if !defined FLOAT_INFINITY
    #define FLOAT_INFINITY   (Float:0x7F800000)
#endif
You are right buddy, here is the updated:
pawn Code:
#include <a_samp>
#include <sscanf2>
#include <zcmd>
#define FLOAT_INFINITY (Float:0x7F800000)

CMD:god(playerid, params[])
{
    //new str3[128];
    new str1[128], str2[128], admin[MAX_PLAYER_NAME], p[MAX_PLAYER_NAME], id, Float: health1, Float:health2;
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "You must be Admin to use this command");

//Make yourself god by typing only: /god
    GetPlayerHealth(playerid, health1);
    //format(str3, sizeof(str3), "health: %f.", health1); With these lines I found out that if you set a player's health to infinity,
    //SendClientMessage(playerid, COLOR_ORANGE, str3);    his health value becomes actually 0.0 and so I got the code working, took me hours, damn.
    if(sscanf(params, "d", id)) //do not change "d" with "u" or in /god [ID] format,
    {                         //you will receive message "ERROR: Player is not connected." even if you enter valid id.
        if (health1==0.0)
        {
        SetPlayerHealth(playerid, 100.0);
        return SendClientMessage(playerid,0x00FF00AA, "Back to mortality.");
        }

        if (health1>0.0)
        {
        SetPlayerHealth(playerid, FLOAT_INFINITY);
        return SendClientMessage(playerid, 0x00FF00AA, "You are god now!");
        }
    }
   
//Make a player of your server god with /god [ID]
    if(IsPlayerConnected(id))
    {
        GetPlayerName(playerid, admin, MAX_PLAYER_NAME);
        GetPlayerName(id, p, MAX_PLAYER_NAME);
        GetPlayerHealth(id, health2);

        if (health2>0.0)
        {
            SetPlayerHealth(id, FLOAT_INFINITY);
            format(str2, sizeof(str2), "You have successfully turned %s into god.", p);
            SendClientMessage(playerid, 0x00FF00AA, str2);
            format(str1, sizeof(str1), "Admin %s has turned you into god!", admin);
            SendClientMessage(id, 0x00FF00AA, str1);
        }

        if (health2==0)
        {
            SetPlayerHealth(id, 100.0);
            format(str2, sizeof(str2), "You have turned god %s into human.", p);
            SendClientMessage(playerid, 0x00FF00AA, str2);
            return SendClientMessage(id, 0x00FF00AA, "Back to mortality.");
        }
    }
    else SendClientMessage(playerid, 0xFF0000AA, "ERROR: Player is not connected.");
    return 1;
}



Re: /god command for admins - Private200 - 12.03.2013

You can't even call this filterscript, is this your first try? If yes, 7/10, not bad..


Re: /god command for admins - HurtLocker - 12.03.2013

Quote:
Originally Posted by Private200
View Post
You can't even call this filterscript, is this your first try? If yes, 7/10, not bad..
Sorry, but there's no prefix "command" so I put "filterscript".
This is just a command. I ve scripted some other commands (like /akill, /aslap, /goto, /getp, /pm, /heal) but they are even simpler so aren't worthy of being posted here.


Re: /god command for admins - iGetty - 12.03.2013

There's plenty different ways to create this, HurtLocker.

This is a good way, though. Well created.


Re: /god command for admins - Private200 - 13.03.2013

Quote:
Originally Posted by HurtLocker
View Post
Sorry, but there's no prefix "command" so I put "filterscript".
This is just a command. I ve scripted some other commands (like /akill, /aslap, /goto, /getp, /pm, /heal) but they are even simpler so aren't worthy of being posted here.
Put them all together then, it will be title "Admin commands" as I have mine, you'll have yours.


Re: /god command for admins - Djole1337 - 13.03.2013

Quote:
Originally Posted by iGetty
View Post
There's plenty different ways to create this
Yep. Here's an example:

pawn Code:
// Creating global player var. We'll use it later to check if player has god mode activated.
new
    bool: GodMode[MAX_PLAYERS char];
// Our timer
static
    GodTimer;
pawn Code:
// Simple god command
CMD:god(playerid, params[])
{
    if (!IsPlayerAdmin(playerid)) // Fixed typo
        return SendClientMessage(playerid, -1, "Nope.");
    GodMode{playerid} = !GodMode{playerid};
    SendClientMessage(playerid, -1, GodMode{playerid} ? ("God Mode activated!") : ("God Mode disabled!"));
    return 1;
}
pawn Code:
// Now we're gonna create 2 secs timer to check if player has god mode activated and fix their health.
// 2 secs timer is ok so don't worry, it's not gonna lag.

forward GodModeCheck();
public GodModeCheck()
{
    foreach(new i : Player)
    {
        if (GodMode{i} == true)
        {
            SetPlayerHealth(i, 100); // No need for 1k
        }
    }
    return 1;
}
// Now we're gonna place under OnGameModeInit()

public OnGameModeInit()
{
    GodTimer = SetTimer("GodModeCheck", 1000, true); // 1 sec timer.
    return 1;
}

public OnGameModeExit()
{
    KillTimer(GodTimer);
    return 1;
}



Re: /god command for admins - HurtLocker - 14.03.2013

Quote:
Originally Posted by Mr_DjolE
View Post
Quote:
Originally Posted by iGetty
View Post
There's plenty different ways to create this
Yep. Here's an example:
Your code doesn't even work, cannot be compiled. Reading your logic I see that an admin can make only himself god, and can't transform a non-admin player into god, as mine command can.


Re: /god command for admins - Djole1337 - 15.03.2013

Quote:
Originally Posted by HurtLocker
View Post
Your code doesn't even work, cannot be compiled. Reading your logic I see that an admin can make only himself god, and can't transform a non-admin player into god, as mine command can.
Since i codded it without testing it might have bugs. Also i only showed the "other" way.
Can you post errors please ?