[Tutorial] How to make /freeze & /unfreeze command
#1

Hello,

I have known that some of the people is complaining about the commands bugs.

So i decided to make a small tutorial with /freeze /unfreeze command so you can work with it easily.

Let's make /freeze & /unfreeze command.

First of all you need to define & Include your includes
Like:
PHP Code:
#include <a_samp>
#include <zcmd>
#include <sscanf2> 
PHP Code:
CMD:freeze(playerid,params[])
{
    if(
PlayerInfo[playerid][Admin] >= 1)
    {
        new 
id;
        if(
sscanf(params,"u",id)) return SendClientMessage(playerid,0xFF0000AA,"USAGE: /freeze [playerid]");
        if(!
IsPlayerConnected(id)) return SendClientMessage(playerid,0xFF0000AA,"ERROR: Invalid playerid");
        
TogglePlayerControllable(id,0);
        
SendClientMessage(playerid,0xFF0000AA,"( ! ) You are frozen by an Admin ! ");
    }
    return 
1;

Ok let's explain

PHP Code:
CMD:Unfreeze (playeridparams[]) 
This line is very important, Cause you can't make any command without putting
PHP Code:
"CMD:Unfreeze(playerid,params[])" 
Or you can replace it with the SAMP normal command function.
PHP Code:
if (strcmpcmd"/freeze"true ) == 
Then you need to put "{" to open the section for the script so you can continue script
PS: If you didn't open after making the command line with this "{" and end with this "}" Your codes will get a lot of warnings/errors. So take care.

PHP Code:
if(PlayerInfo[playerid][Admin] >= 1
This line to get the player info, Cause if he is an Admin he can use it.
Or you can remove this line if you want it for Normal players

Also ">= 1)" this is the Admin level you can set it as you wish so the level you will put only the Admins +X Can you use the command. 1-2-3-4-5-6-7-8-9-10 etc.

You need to put another "{" cause you opened new section.

PHP Code:
if(!IsPlayerConnected(id)) 
This line to check if the player connected or not online.

PHP Code:
return SendClientMessage(playerid,0xFF0000AA,"ERROR: Invalid playerid"); 
This is the message when the Admin types the command /freeze, If the player isn't connected then this is the client message that the Admin will get so he will be notified that the player isn't connected.

PHP Code:
TogglePlayerControllable(id,0); 
/freeze command depends on this line.

This line makes the player Frozen/Unfrozen

If you typed (id,0) then the player will be frozen
If you typed (id,1) then the player will be unfrozen

PHP Code:
SendClientMessage(playerid,0xFF0000AA,"( ! ) You are frozen by an Admin ! "); 
This is the message the player will get when you make /freeze command on him

As you see the "}" we closed it after we finished the command.

But its not finished yet.

You need to put "return 1;" in any command at THE LAST DON'T PUT IT ON THE FIRST CAUSE IT WILL BUG YOUR COMMAND.

Also you must close the second "}" after you finish "return 1;"

But be careful don't put { } in anything, Just put it when we open new section then you need to close the
second section

But its still in the first section

Then close the first
}

Then you're done with /freeze command.

Now /unfreeze
PHP Code:
CMD:unfreeze(playerid,params[])
{
    if(
PlayerInfo[playerid][Admin] >= 1)
    {
        new 
id;
        if(
sscanf(params,"u",id)) return SendClientMessage(playerid,0xFF0000AA,"USAGE: /unfreeze [playerid]");
        if(!
IsPlayerConnected(id)) return SendClientMessage(playerid,0xFF0000AA,"ERROR: Invalid playerid");
        
TogglePlayerControllable(id,1);
        
SendClientMessage(playerid,0xFF0000AA,"( ! ) You are unfrozen by an Admin ");
    }
    return 
1;

All same but you change
PHP Code:
TogglePlayerControllable(id,0); 
With
PHP Code:
TogglePlayerControllable(id,1); 
As i said in the first its for freeze/unfreeze

So, We are done

Hope you learned something from me
Reply
#2

Need opinions
Reply
#3

You shouldn't have used PlayerInfo[playerid][Admin] at all because if beginners "copy-paste" it, they will be confused about the errors. Another thing is that you send the message "You are (un)frozen by an Admin" to the player who typed the command and not the id was given.
Reply
#4

I'll fix it, Thanks for your reply
Reply
#5

you can change
Code:
if(PlayerInfo[playerid][Admin] >= 1)
to
Code:
if(IsPlayerAdmin(playerid))
coz not all server use "PlayerInfo[playerid][Admin]" Variable
Reply
#6

But it will be for RCON only, So I made it if you have Admin levels too.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)