[Tutorial] How to make a God Mode command.
#1

How to create a GodMode Command using ZCMD

Hello, In this tutorial, we'll be learning how to create a /godmode command using ZCMD.

We will need ZCMD.ini which could be found here: https://sampforum.blast.hk/showthread.php?tid=91354

Step 1: Including ZCMD

All you have to do here is:
pawn Код:
#include <zcmd>
Step 2: Defining

This is just a simple step, we're going to define Godmode to have control of how its going to work and when
pawn Код:
new GodMode[MAX_PLAYER_NAME];
In my opinion, its better to keep it after ' #endif '

Step 3: Adding the command
Since we have ZCMD now we just simply type CMD: to create a command so
pawn Код:
CMD:godmode(playerid, params[])
{
    SetPlayerHealth(playerid, Float:0x7F800000 );
    GodeMode[playerid] = 1;
}
Modifying your script

Since we only have /gm to turn your godmode, and you dont want it on or you dont know wether it works or not, then lets add something to turn it off and send a message to you!

pawn Код:
CMD:godmode(playerid, params[])
{
    if(GodMode[playerid] == 0)          //If godMode is not on
    {                                            //then
        SetPlayerHealth(playerid, Float:0x7F800000 );   //Float:0x7F800000 Means infinite health.
        SendClientMessage(0x24FF0AB9,playerid,"God Mode has been turned on! Type /godmode again if you want to turn it off!");
        GodeMode[playerid] = 1;         //Turn godmode on
    }
    else if(GodMode[playerid] == 1)   // Else if its on
    {                                           //then
        SetPlayerHealth(playerid, 100);
        SendClientMessage(0xFF0000AA ,playerid,"God Mode has been turned off! Type /godmode again if you want to turn it on!");
        GodMode[playerid] = 0;           //Turn godmode off
    }
}
__________________________________________________ _______________________________________________

THIS WAS SCRIPTED IN THIS BROWSER ITSELF AND HAS NOT BEEN TESTED, LET ME KNOW IF THERE ARE ANY BUGGS, Thank you

Since this is my First Tutorial, I'd like feedbacks from you guys, and I hope you have understood how this has been created.

Reply
#2

Good work man, rep +
edit: it should not be on OnPlayerUpdate
Reply
#3

I would recommend not using "OnPlayerUpdate" since it is called many times in a second, and it will become bad practice to do so since it will create lag/unefficient code.
Reply
#4

Yeah, or you could do this.
Код:
CMD:godmode(playerid, params[])
{
    SetPlayerHealth(playerid, 999999999);
}
It would save everyone a lot of time and server resources.

Edit: Here's a way you could do it using your method.

Код:
#include ZCMD
new godmode[MAX_PLAYERS];

CMD:godmode(playerid, params[])
{
    if(godmode[playerid] == 0)
    {
    SetPlayerHealth(playerid, 100);
    godmode[playerid] = 1;
    SendClientMessage(playerid, -1, "Your godmode has been enabled. You cannot die.");
    }
    else if(godmode[playerid] == 1)
    {
     godmode[playerid] = 0;
     SetPlayerHealth(playerid, 100); //In case he takes damage right as he disables godmode.
     SendClientMessage(playerid, -1, "Your godmode has been disabled. You may now die.");
    }
}

public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
    if(godmode[playerid]==1)
    {
    SetPlayerHealth(playerid, 100);
    }
    else if(godmode[issureid]==1)
    {
    SetPlayerHealth(playerid, 100);
    SendClientMessage(issuerid, -1, "You can't shoot other players while in godmode.");
    }
    else
    {
     //other codes and stuffs.
    }
    return 1;
}
Reply
#5

Try when you do godmode health = Float:999999999999 And fall from the sky, you would for sure die.

You need to set health to this Float:0x7F800000
pawn Код:
SetPlayerHealth(playerid, 0x7F800000);
to have a real godmode.
Reply
#6

Updated, Remove the onplayerupdate because it creates lag, thank you guys
Reply
#7

Hey why did i got this when i compile my script?

Код:
E:\Server\SAMP\Aero Team Deathmatch\gamemodes\Gangwar.pwn(2) : fatal error 100: cannot read from file: "zcmd"

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
i already put my zcmd at the include, thx.. sorry im still a newbie
Reply
#8

Bump.
Reply
#9

SendClientMessage(0x24FF0AB9,playerid,"God Mode has been turned on! Type /godmode again if you want to turn it off!");

Should be,

SendClientMessage(playerid,0x24FF0AB9,"God Mode has been turned on! Type /godmode again if you want to turn it off!");

Also, you don't really explain everything in detail. This is more of a FS than a tutorial.
Reply
#10

Quote:
Originally Posted by JevieraJehan
Посмотреть сообщение
Hey why did i got this when i compile my script?

Код:
E:\Server\SAMP\Aero Team Deathmatch\gamemodes\Gangwar.pwn(2) : fatal error 100: cannot read from file: "zcmd"

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
i already put my zcmd at the include, thx.. sorry im still a newbie
You need to actually add in the plugin to your pawno folder.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)