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:
And including zCmd once you have downloaded the include.
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(playerid, reason)
{
god[playerid] = 0;
return 1;
}
CMD:god(playerid, params[])
{
if(IsPlayerAdmin(playerid) || god[playerid] == 0)
{
god[playerid] = 1;
SetPlayerHealth(playerid, 99999999);
SetPlayerArmour(playerid, 99999999);
SendClientMessage(playerid, -1, "You Turn Godmode To ON!");
}
if(IsPlayerAdmin(playerid) || god[playerid] == 1)
{
god[playerid] = 0;
SetPlayerHealth(playerid, 100);
SetPlayerArmour(playerid, 0);
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.