[Tutorial] How to make [Jail/unjail] admin commands with ZCMD+SSCANF
#1

Beginning
This tutorial as the title says about making " jail and unjail" commands for admins, its quite simple but useful
Requirements:
1-
sscanf here
zcmd here
2-
general knowledge of these two.

Lets start

use zcmd command style,
pawn Код:
CMD:mycmd(playerid,params[])
or [pawn]COMMAND:mycmd(playerid,params[])[/pawno]

so now:
on the top of the script add:
pawn Код:
new JailTimer[MAX_PLAYERS];// for the timer
new Jailed[MAX_PLAYERS];//for the players in jail
pawn Код:
CMD:jail(playerid,params[]){// we opened a bracket here
after that we need to check if the player is an admin, because this command is only for admins so, here we go:
pawn Код:
if(IsPlayerAdmin(playerid)) {// we closed 2 brackets 1 for the player id and the other for the IsPlayerAdmin
now we need to define new things as the id the time and the reason,:
pawn Код:
new id,time,reason[100],PlayerName[MAX_PLAYER_NAME],GPlayerName[MAX_PLAYER_NAME];//id = the targetid, time = the jailing time, reason[100]= the reason string in this tutorial i think you know about strings,playername and Gplayername for the jailing names ill explain later
now lets start in the deep!
pawn Код:
if(sscanf(params,"dds",id,time,reason)) return SendClientMessage(playerid, lb, "USAGE: /jail <playerid> <time> <reason>");// this is sscanf routine , d=integer and s= string
pawn Код:
if (!IsPlayerConnected(id)) return SendClientMessage(playerid, red, "ERROR: Player is not connected.");// now we are checking if the targetid is online ! = not and id= targetid and if the id isnt on will send the message etc
we need to check if the player already jailed or not so we do:
pawn Код:
if(Jailed[id] == 1) return SendClientMessage(playerid, red, "ERROR: Player is already jailed.");// 1 jailed 0 is not jailed
now we need to send a message to all players saying that admin[name] has jailed[name]!
pawn Код:
GetPlayerName(id, PlayerName, sizeof(PlayerName));// the jailed person id
     GetPlayerName(playerid, GPlayerName, sizeof(GPlayerName));// the admin id
pawn Код:
format(szString, sizeof(szString), "AdmSys-: %s (ID:%d) has been jailed for %d minutes; Reason: %s", PlayerName, id, time, reason);
        SendClientMessageToAll(color, szString);//%s = name . %d = number
now we need to set the player pos in the jail and take his gun!
pawn Код:
SetPlayerInterior(id, 3);//sets player interior
        SetPlayerVirtualWorld(id, 10);//sets player vw
        SetPlayerFacingAngle(id, 360.0);//player angle
        SetPlayerPos(id, 197.5662, 175.4800, 1004.0);//player pos
        SetPlayerHealth(id, 9999999999.0);//player cannot be killed
        ResetPlayerWeapons(id);//resets his weapons
        JailTimer[id] = SetTimerEx("Unjail",time*60000, false, "i", id);//jail timer
    }
    else {
        return 0;//sends : Server:Unknown Command.
    }
    return 1;
}
now we finished the jail command lets start with the unjail.ill explain it in a fast way
pawn Код:
CMD:unjail(playerid,params[]) {
    new id;
     if(IsPlayerAdmin(playerid)) {//checks if the player is admin
        if(sscanf(params,"u",id)) return SendClientMessage(playerid, lb, "USAGE: /unjail <playerid>");//sscanf routine
        if (!IsPlayerConnected(id)) return SendClientMessage(playerid, red, "ERROR: Player is not connected.");//checks if the targetid is connected
        if(Jailed[id] == 0) return SendClientMessage(playerid, red, "ERROR: Player is not jailed.");//checks if the id is jailed and if he isnt it will send an error.
                Jailed[id] = 0;// sets his jail to 0 = unjailed
        SetPlayerInterior(id, 0);//normal int
        SetPlayerVirtualWorld(id, 0);//normal vw
        SpawnPlayer(id);//respawns player
        SetPlayerHealth(id, 100);//sets his health back as 100
        KillTimer(JailTimer[id]);//kills the timer
    }
    else {
        return 0;// sends: Server:Unknown Command.
    }
    return 1;
}
and we are done , i hope i explained it in a good way ive learned this recently so i wanted to share it, dont be tough with comments , hope i helped you!
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 3 Guest(s)