[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
#2

That's nice man. and only for rcon admins ? so how about this ?
pawn Код:
if(IsPlayerAdmin(playerid)) == 2)
new isplayeradmin [MAX_PLAYERS] // you'll need this too
And in your last FULL CODE you missed " (playerid) " on isplayeradmin and this will be the write one
pawn Код:
CMD:unjail(playerid,params[]) {
    new id;
     if(IsPlayerAdmin(playerid)) // some fixed :
        if(sscanf(params,"d",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);// you had missed ) here .
        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;
}
Reply
#3

Quote:
Originally Posted by мυ∂υℓ_вacнα
Посмотреть сообщение
That's nice man. and only for rcon admins ? so how about this ?
pawn Код:
if(IsPlayerAdmin(playerid) == 2)
new isplayeradmin [MAX_PLAYERS] // you'll need this too
And in your last FULL CODE you missed " (playerid) " on isplayeradmin
ouh yea edited thanks !
and yea i just made it for rcon because i didnt mean to make an admin system on here xd
Reply
#4

Quote:
Originally Posted by BlacK_RiDeR
View Post
Good Tutorial
thanks glade it helped you
Reply
#5

I think there's a mistake on your code.
Sscanf has some fixed specifiers.

And specifier "d" is used for integer.

How come this be right if you're using "d" for id.
Here id refers to player2.

Specifier "u" must be used for id.
Reply
#6

your right xLords , another mistake sorry ill fix it.
Reply
#7

Good tut for the newbies ;P
Reply
#8

Quote:
Originally Posted by VladCanarez
Посмотреть сообщение
Good tut for the newbies ;P
thanks ;P
Reply
#9

Looks good,keep it up.
Reply
#10

Quote:
Originally Posted by TaLhA XIV
Посмотреть сообщение
Looks good,keep it up.
Thanks
Reply
#11

Im aware that I'm bumping a very old topic lol but it's useful atleast for those who use the Search Button but also you gotta define the colours, and the 'SzString" and It'd be cool if you making it saves incase the player relogs, etc.
Reply
#12

Nice work, +rep to you.
Reply
#13

1. You dont need 2 variables.
2. If you are using only 0-1 ( new Jailed[MAX_PLAYERS]; ), use bool: and char ( new bool:Jailed[MAX_PLAYERS char]; )

connect/disconnect
pawn Code:
if(JailTimer[playerid] > -1)
    KillTimer(JailTimer[playerid]);

JailTimer[playerid] = -1;
pawn Code:
CMD:jail(playerid,params[])
{
    if(!IsPlayerAdmin(playerid)) return 0;

    new id,time,reason[100];
    if(sscanf(params,"udS(No Reason)[100]",id,time,reason)) SendClientMessage(playerid, lb, "USAGE: /jail <playerid / Part of Name> <time> <reason>");// this is sscanf routine , d=integer and s= string
    else if(id == INVALID_PLAYER_ID || !IsPlayerConnected(id)) 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
    else if(JailTimer[id] > -1) SendClientMessage(playerid, red, "ERROR: Player is already jailed.");// 1 jailed 0 is not jailed
    else{
        new szPlayerName[MAX_PLAYER_NAME + 1];
        GetPlayerName(id, szPlayerName, MAX_PLAYER_NAME);// the jailed person id
        SetPlayerInterior(id, 3);//sets player interior
        SetPlayerVirtualWorld(id, 10);//sets player vw
        SetPlayerPos(id, 197.5662, 175.4800, 1004.0);//player pos
        SetPlayerFacingAngle(id, 360.0);//player angle
        SetPlayerHealth(id, 9999999999.0);//player cannot be killed
        ResetPlayerWeapons(id);//resets his weapons
        JailTimer[id] = SetTimerEx("Unjail", time*60000, false, "i", id);//jail timer
        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
    }
    return 1;
}

CMD:unjail(playerid,params[])
{
    if(!IsPlayerAdmin(playerid)) return 0;
    new id;
    if(sscanf(params,"u",id)) SendClientMessage(playerid, lb, "USAGE: /unjail <playerid / Part of Name>"); //sscanf routine
    else if(id == INVALID_PLAYER_ID || !IsPlayerConnected(id)) SendClientMessage(playerid, red, "ERROR: Player is not connected."); //checks if the targetid is connected
    else if(JailTimer[id] < 0) SendClientMessage(playerid, red, "ERROR: Player is not jailed."); //checks if the id is jailed and if he isnt it will send an error.
    else{
        KillTimer(JailTimer[id]);//kills the timer
        JailTimer[id] = -1;
        SetPlayerInterior(id, 0);//normal int
        SetPlayerVirtualWorld(id, 0);//normal vw
        SetPlayerHealth(id, 100);//sets his health back as 100
        SpawnPlayer(id);//respawns player
    }
    return 1;
}
Reply
#14

Code:
D:\Desktop\jdfreeroam\gamemodes\jdfreeroam.pwn(2834) : error 017: undefined symbol "szString"
D:\Desktop\jdfreeroam\gamemodes\jdfreeroam.pwn(2834) : error 017: undefined symbol "szString"
D:\Desktop\jdfreeroam\gamemodes\jdfreeroam.pwn(2834) : error 029: invalid expression, assumed zero
line 2834:

Code:
format(szString, sizeof(szString), "AdmSys-: %s (ID:%d) has been jailed for %d minutes; Reason: %s", PlayerName, id, time, reason);
help
Reply
#15

Quote:
Originally Posted by iamjems
View Post
Code:
D:\Desktop\jdfreeroam\gamemodes\jdfreeroam.pwn(2834) : error 017: undefined symbol "szString"
D:\Desktop\jdfreeroam\gamemodes\jdfreeroam.pwn(2834) : error 017: undefined symbol "szString"
D:\Desktop\jdfreeroam\gamemodes\jdfreeroam.pwn(2834) : error 029: invalid expression, assumed zero
line 2834:

Code:
format(szString, sizeof(szString), "AdmSys-: %s (ID:%d) has been jailed for %d minutes; Reason: %s", PlayerName, id, time, reason);
help
Here is a fix

Check the date when this tutorial was released..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)