SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 27/07/2016, 10:51 PM   #1
yvoms
Huge Clucker
 
yvoms's Avatar
 
Join Date: Nov 2009
Location: Las Venturas
Posts: 454
Reputation: 26
Default Jail Command - Saving + shown

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.
__________________

yvoms is offline   Reply With Quote
Old 27/07/2016, 11:21 PM   #2
Shinja
Gangsta
 
Shinja's Avatar
 
Join Date: Jan 2016
Posts: 972
Reputation: 107
Default Re: Jail Command - Saving + shown

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]");
Shinja is offline   Reply With Quote
Old 27/07/2016, 11:34 PM   #3
yvoms
Huge Clucker
 
yvoms's Avatar
 
Join Date: Nov 2009
Location: Las Venturas
Posts: 454
Reputation: 26
Default Re: Jail Command - Saving + shown

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
__________________

yvoms is offline   Reply With Quote
Old 27/07/2016, 11:34 PM   #4
AndySedeyn
High-roller
 
AndySedeyn's Avatar
 
Join Date: Feb 2014
Location: Belgium
Posts: 1,207
Reputation: 681
Default Re: Jail Command - Saving + shown

> 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

Last edited by AndySedeyn; 28/07/2016 at 01:33 AM.
AndySedeyn is offline   Reply With Quote
Old 28/07/2016, 08:07 AM   #5
yvoms
Huge Clucker
 
yvoms's Avatar
 
Join Date: Nov 2009
Location: Las Venturas
Posts: 454
Reputation: 26
Default Re: Jail Command - Saving + shown

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;
}
?
__________________

yvoms is offline   Reply With Quote
Old 28/07/2016, 09:06 AM   #6
AndySedeyn
High-roller
 
AndySedeyn's Avatar
 
Join Date: Feb 2014
Location: Belgium
Posts: 1,207
Reputation: 681
Default Re: Jail Command - Saving + shown

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.
AndySedeyn is offline   Reply With Quote
Old 28/07/2016, 09:11 AM   #7
yvoms
Huge Clucker
 
yvoms's Avatar
 
Join Date: Nov 2009
Location: Las Venturas
Posts: 454
Reputation: 26
Default Re: Jail Command - Saving + shown

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
}
__________________

yvoms is offline   Reply With Quote
Old 28/07/2016, 09:15 AM   #8
AndySedeyn
High-roller
 
AndySedeyn's Avatar
 
Join Date: Feb 2014
Location: Belgium
Posts: 1,207
Reputation: 681
Default Re: Jail Command - Saving + shown

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.
AndySedeyn is offline   Reply With Quote
Old 28/07/2016, 09:30 AM   #9
yvoms
Huge Clucker
 
yvoms's Avatar
 
Join Date: Nov 2009
Location: Las Venturas
Posts: 454
Reputation: 26
Default Re: Jail Command - Saving + shown

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
__________________

yvoms is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving admin jail to mysql Zeus666 Scripting Help 1 03/07/2016 03:53 PM
Saving a jail timer?? stuoyto Scripting Help 2 20/05/2012 05:22 PM
[FilterScript] [FS] Jail area and Jail command PinkFloydLover Filterscripts 13 05/08/2009 06:11 AM


All times are GMT. The time now is 08:13 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.