Jail Command - Saving + shown
#1

Greetings,
i'm trying to create a /jail command with the prefix /jail playername secconds reason,
The player should be jailed in a random cell (3 existing), His weapons should be reset, and his health should be unlimited to prevent him being killed, also if a player leaves the server, the remaining secconds he should spend in the jail cell should be saved in the database, i already created the database column.

Code:
CMD:jail(playerid, params[])
{
	new id, aname[MAX_PLAYER_NAME], name[MAX_PLAYER_NAME], Reason[120], secconds[120], string[128];
	if(pData[playerid][Admin] < 1) return SendClientMessage(playerid, COLOR_WHITE, "[Error]: You are not authorized to use this command.");
	if(sscanf(params,"uds[128]",id, Reason)) return SendClientMessage(playerid,-1,"[Admin]: /jail [ID | Name] [secconds] [Reason]");
	if(pData[playerid][Admin] < pData[id][Admin]) return SendClientMessage(playerid, COLOR_WHITE, "[Error]:You are not authorized to use this command on a higher level administrator.");
	if(id == playerid) return SendClientMessage(playerid, COLOR_WHITE,"[Error]:You can not perform this command on yourself.");
    else if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid,-1,"[Error]:This player is not connected.");
	return 1;
}
So basically when a player gets jailed i would like to display the time left in jail at the top of the screen in the center, i have no idea on how to do this, so i would really really appreciate it if someone could help me with this.
Reply
#2

Code:
new countt[MAX_PLAYERS], counter[MAX_PLAYERS];
Code:
forward JailCount(playerid);
public JailCount(playerid)
{
    new string[55];
    counter[playerid]--;
    format(string, sizeof(string),"~b~%d Second remaining", counter[playerid]);
    GameTextForPlayer(playerid, string, 990, 3);
    if(counter[playerid] <= 0)
    {
        format( string, sizeof(string), "~g~Released from jail");
        GameTextForPlayer(playerid, string, 990, 3);
        KillTimer(countt[playerid]);
        Jailed[playerid] = 0;
		SpawnPlayer(playerid);
		SetPlayerVirtualWorld(playerid, 0);
		SetPlayerInterior(playerid, 0);
		new Float: PPos[3];
		GetPlayerPos(playerid, PPos[0], PPos[1], PPos[2]);
		PlayerPlaySound(playerid, 1058, PPos[0], PPos[1], PPos[2]);
    }
    return 1;
}
and add to your command
Code:
RemovePlayerFromVehicle(id);
ResetPlayerWeapons(id);
SetPlayerPos(id, 264.8763, 77.8042, 1001.0391);//jail pos
SetPlayerInterior(id, 6);//jail interior
Jailed[id] = 1;//jailed variable
new time = secconds*1000
counter[id] = 60;
countt[id] = SetTimerEx("Count", time, true, "i", id);
By the way, your sccanf doesn't contain time

Code:
if(sscanf(params,"uis[124]",id, secconds, Reason)) return SendClientMessage(playerid,-1,"[Admin]: /jail [ID | Name] [secconds] [Reason]");
Reply
#3

I meant something like the screenshot i provided,
http://puu.sh/qgNFE/2e653654d4.jpg
also, if a player exits the game or crashes i would like to save the remaining time left
Reply
#4

> Create an array for the random jails.
PHP Code:
enum E_JAIL_DATA {
    
Float:posX,
    
Float:posY,
    
Float:posZ,
    
interior
};
new const 
gArr_RandomJail[][E_JAIL_DATA] = {
    { 
coord_posxcoord_posycoord_poszcoord_interior // replace these with the correct coordinates
}; 
> Create a player variable which will hold the amount of jail time in seconds.
> Create a boolean player variable which will be true when the player is jailed and false when not
PHP Code:
enum E_PLAYER_DATA {
    
bool:Jailed,
    
JailTime
};
new 
Player[MAX_PLAYERS][E_PLAYER_DATA]; 
> Create a timer that reduces this variable by 1 (if the timer loops with a 1 second delay). I advise having one global player timer. Use this timer for multiple scripts and not only this one.
PHP Code:
public OnGameModeInit() {
    
SetTimer("g_PlayerTimer"1000true);
    return 
true;
}
forward g_PlayerTimer();
public 
g_PlayerTimer() {
    foreach(new 
Player) {
        if(
Player[playerid][Jailed]) {
            switch(--
Player[playerid][JailTime]) {
                case 
0: {
                    
// released
                    
Player[playerid][Jailed] = false;
                }
                default: {
                    
// Sentence not over yet
                
}
            }
        }
    }
    return 
true;

> Upon jailing the player, set the boolean variable to true
> Send player to one of the random jails
> Reset their weapons

PHP Code:
CMD:jail(playeridparams[]) {
    new
        
targetid,
        
time;
    if(
sscanf(params"ui"targetidtime)) {
        return 
SendClientMessage(playerid, -1"USAGE: /jail <targetid/partofname> <time (seconds)>");
    }
    
// ...
    // Error checks
    // ...
    
Player[targetid][Jailed] = true;
    
Player[targetid][JailTime] = (time 1000);
    new
        
randJail sizeof(gArr_RandomJail);
    
SetPlayerPos(playeridgArr_RandomJail[randJail][posX], gArr_RandomJail[randJail][posY], gArr_RandomJail[randJail][posZ]);
    
SetPlayerInterior(playeridgArr_RandomJail[randJail][interior]);  
    
ResetPlayerWeapons(playerid);
    return 
true;

> Set the player's health to a high number to represent 'god mode' or use OnPlayerTakeDamage to set the player's health back to 100

PHP Code:
public OnPlayerTakeDamage(playeridissueridFloat:amountweaponidbodypart) {
    if(
Player[playerid][Jailed]) {
        
SetPlayerHealth(playerid100.0);
    }
    return 
true;

> Save the value of both variables to the database
> Send the player back to jail and resume the timer after loading the data (and if the boolean is set to true)
> Create a textdraw which you will update in the timer
Reply
#5

Thank you andy, however the player is not being sent to jail when he Reconnects, also the textdraw is not updating.
Fixed the textdraw, however when i reconnect i do get the Textdraw saying im jailed, but it does not send back to jail.

Is it because im randomly spawning the player after i spawned him in the jail?
Code:
public OnPlayerSpawn(playerid)
{   
    if(pData[playerid][JailTime] > 0) {

        // Player was in jail before logging off
        Player_SendToJail(playerid);
        }

    new Random = random(sizeof(RandomSpawns));
    SetPlayerPos(playerid, RandomSpawns[Random][0], RandomSpawns[Random][1], RandomSpawns[Random][2]);
    SetPlayerFacingAngle(playerid, RandomSpawns[Random][3]); 

    return 1;
}
?
Reply
#6

Quote:
Originally Posted by yvoms
View Post
Thank you andy, however the player is not being sent to jail when he Reconnects, also the textdraw is not updating.
Fixed the textdraw, however when i reconnect i do get the Textdraw saying im jailed, but it does not send back to jail.

Is it because im randomly spawning the player after i spawned him in the jail?
Code:
public OnPlayerSpawn(playerid)
{   
    if(pData[playerid][JailTime] > 0) {

        // Player was in jail before logging off
        Player_SendToJail(playerid);
        }

    new Random = random(sizeof(RandomSpawns));
    SetPlayerPos(playerid, RandomSpawns[Random][0], RandomSpawns[Random][1], RandomSpawns[Random][2]);
    SetPlayerFacingAngle(playerid, RandomSpawns[Random][3]); 

    return 1;
}
?
Yes. Don't change the spawn coordinates of the player after sending them to the jail.
Reply
#7

Hmm, i'm having some issues with that, would it work if i'd do it like this?
if(pData[playerid][JailTime] > 0){
PlayerSendToJail)PLayerid)
} Else {
Playerspawningstuff
}
Reply
#8

Quote:
Originally Posted by yvoms
View Post
Hmm, i'm having some issues with that, would it work if i'd do it like this?
if(pData[playerid][JailTime] > 0){
PlayerSendToJail)PLayerid)
} Else {
Playerspawningstuff
}
That should work. I would personally use 'Jailed' in if-statements. It was initially created to be used in if-statements.
Reply
#9

yeah the method i said is not really working hehe,

It spawns the player in one of the random spawnpoints, and the timer keeps running saying he is jailed
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)