SA-MP Forums Archive
[Tutorial] How to make /godon and /godoff commands. (Explaining) - 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: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] How to make /godon and /godoff commands. (Explaining) (/showthread.php?tid=417450)



How to make /godon and /godoff commands. (Explaining) - Goldino - 21.02.2013

How to make /godon and /godoff commands. (Explaining)

What you will need:

zCmd - Zeex - Click me!


Getting started:

Lets start off by defining this color:

pawn Код:
#define RED 0xFF0000FF
And including zCmd once you have downloaded the include.

pawn Код:
#include <zcmd>
We will now start off the tutorial.


The main Subject:

We will use a bool. The bool is used to check if the player already has godmode on or already has godmode off!

Add this to the top of your script, under the includes:

pawn Код:
new
    bool: playerGod[ MAX_PLAYERS ];
Now lets move onto the command. You can either change the line which checks if the player is an Admin, or you can use one of your own which you have defined in your Admin system.

pawn Код:
CMD:godon( playerid, params[] )
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED, "You are not authorised to use this command");
    if ( playerGod{ playerid } )
        return SendClientMessage(playerid, RED, "ERROR:{FFFFFF} You already have god mode on!");
    SetPlayerHealth(playerid, 9999999999.0);
    SetPlayerArmour(playerid, 9999999999.0);
    new
        str[ 128 ];
    format( str, sizeof ( str ), "[GODMODE - ON] Administrator %s has turned on his Godmode.", GetName( playerid ) );
    SendClientMessageToAll(RED, str);

    playerGod{ playerid } = true;
    return 1;
}


pawn Код:
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED, "You are not authorised to use this command");
This checks if the player is an Rcon Admin. If he is not, it will return a message to the player.

pawn Код:
if ( playerGod{ playerid } )
        return SendClientMessage(playerid, RED, "ERROR:{FFFFFF} You already have god mode on!");
This checks if the Player already has godmode on, if he does, it will return a message.

pawn Код:
SetPlayerHealth(playerid, 9999999999.0);
    SetPlayerArmour(playerid, 9999999999.0);
This sets the Player's health so he can not be killed by another person.


pawn Код:
new
        str[ 128 ];
    format( str, sizeof ( str ), "[GODMODE - ON] Administrator %s has turned on his Godmode.", GetName( playerid ) );
    SendClientMessageToAll(RED, str);
This is a string which sends out a message to the whole server saying that the Administrator has turned on his godmode.

pawn Код:
playerGod{ playerid } = true;
This line turns it to true, so when the player does /godon or /godoff, it can check if he already has it on/off.

pawn Код:
CMD:godoff( playerid, params[] )
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED, "You are not authorised to use this command");
    if ( !playerGod{ playerid } )
        return SendClientMessage(playerid, RED, "ERROR:{FFFFFF} You already have god mode off!");
    SetPlayerHealth(playerid, 100);
    SetPlayerArmour(playerid, 100);
   
    new
        str[ 128 ];
    format( str, sizeof ( str ), "[GODMODE - OFF] Administrator %s has turned off his Godmode.", GetName( playerid ) );
    SendClientMessageToAll(RED, str);
   
    playerGod{ playerid } = false;
    return 1;
}
I have explained the exact thing above, this turns his godmode off. Read above, if you do not understand.


I hope you have learned something from this - if you would like to request a new tutorial, just PM me or comment. Thanks


Re: How to make /godon and /godoff commands. (Explaining) - faiznurfaza - 21.02.2013

Nice Sir, But use this
PHP код:
#include <a_samp>
#include <zcmd>
new god[MAX_PLAYERS];
public 
OnPlayerConnect(playerid)
{
    
god[playerid] = 0;
    return 
1;
}
public 
OnPlayerDisconnect(playeridreason)
{
    
god[playerid] = 0;
    return 
1;
}
CMD:god(playeridparams[])
{
    if(
IsPlayerAdmin(playerid) || god[playerid] == 0)
    {
        
god[playerid] = 1;
        
SetPlayerHealth(playerid99999999);
        
SetPlayerArmour(playerid99999999);
        
SendClientMessage(playerid, -1"You Turn Godmode To ON!");
    }
    if(
IsPlayerAdmin(playerid) || god[playerid] == 1)
    {
        
god[playerid] = 0;
        
SetPlayerHealth(playerid100);
        
SetPlayerArmour(playerid0);
        
SendClientMessage(playerid, -1"You Turn Godmode To OFF!");
    }
    return 
1;




Re: How to make /godon and /godoff commands. (Explaining) - RajatPawar - 21.02.2013

Good explanation! And yes, instead of two different commands, try using just one bool (as you have), one command, and one switch statement ! Otherwise, it's cool.


Re: How to make /godon and /godoff commands. (Explaining) - Goldino - 21.02.2013

Ok, thanks man. I'll try to make one next time.