[FilterScript] /god command for admins
#1

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.
Reply
#2

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
Reply
#3

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;
}
Reply
#4

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

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.
Reply
#6

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

This is a good way, though. Well created.
Reply
#7

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.
Reply
#8

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;
}
Reply
#9

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.
Reply
#10

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 ?
Reply


Forum Jump:


Users browsing this thread: 6 Guest(s)