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;
}
new countt[MAX_PLAYERS], counter[MAX_PLAYERS];
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;
}
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);
if(sscanf(params,"uis[124]",id, secconds, Reason)) return SendClientMessage(playerid,-1,"[Admin]: /jail [ID | Name] [secconds] [Reason]");
enum E_JAIL_DATA {
Float:posX,
Float:posY,
Float:posZ,
interior
};
new const gArr_RandomJail[][E_JAIL_DATA] = {
{ coord_posx, coord_posy, coord_posz, coord_interior } // replace these with the correct coordinates
};
enum E_PLAYER_DATA {
bool:Jailed,
JailTime
};
new Player[MAX_PLAYERS][E_PLAYER_DATA];
public OnGameModeInit() {
SetTimer("g_PlayerTimer", 1000, true);
return true;
}
forward g_PlayerTimer();
public g_PlayerTimer() {
foreach(new i : Player) {
if(Player[playerid][Jailed]) {
switch(--Player[playerid][JailTime]) {
case 0: {
// released
Player[playerid][Jailed] = false;
}
default: {
// Sentence not over yet
}
}
}
}
return true;
}
CMD:jail(playerid, params[]) {
new
targetid,
time;
if(sscanf(params, "ui", targetid, time)) {
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(playerid, gArr_RandomJail[randJail][posX], gArr_RandomJail[randJail][posY], gArr_RandomJail[randJail][posZ]);
SetPlayerInterior(playerid, gArr_RandomJail[randJail][interior]);
ResetPlayerWeapons(playerid);
return true;
}
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart) {
if(Player[playerid][Jailed]) {
SetPlayerHealth(playerid, 100.0);
}
return true;
}
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;
}
|
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;
}
|
|
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 } |