17.04.2017, 03:32
Im making a jail command now i placed the timer to the unjail in ongamemodeinit but it only counts to negative numbers even if the player jailtime is 0, it still counts to negative numbers as long as the player connect to server...
PHP код:
//ongamemodeinit
SetTimer("PrisonTimer", 1000, true);
//the command
CMD:ajail(playerid, params[])
{
if(IsPlayerAdmin(playerid) || pInfo[playerid][Admin] >= 3)
{
new playerb, time, string[128], RandomCell;
if(sscanf(params, "uis[64]", playerb, time, params)) return SendClientMessage(playerid, error, "Usage: /ajail [playerid] [time] [reason]");
if(!IsPlayerConnected(playerb)) return SendClientMessage(playerid, error, "Player id not connected.");
if(time == 0)
{
if(!pInfo[playerb][Jailed]) return SendClientMessage(playerid, 0xFFFFFF, "Player is not prisoned.");
SetPlayerColor(playerb, error);
pInfo[playerb][Jailed] = 0;
pInfo[playerb][JailedTime] = time;
SetPlayerInterior(playerb, 0);
SetPlayerVirtualWorld(playerb, 0);
RandomCell = random(sizeof(RandomJails));
SetPlayerFacingAngle(playerb, 88.5042);
SetPlayerPos(playerb, 1548.8394,-1669.6111,13.5656);
SetCameraBehindPlayer(playerb);
format(string, sizeof(string), "[AdmCmd]: {FF6347}An Administrator has released %s from Jail. [Reason: %s]",GetName(playerb), params);
SendClientMessageToAll(red, string);
format(string, sizeof(string), "[AdmCmd]:{FF6347}You have been released by administrator %s.",GetName(playerid));
SendClientMessage(playerid,red, string);
TogglePlayerControllable(playerb, 1);
}
else
{
SetPlayerColor(playerb, error);
pInfo[playerb][Jailed] = 2;
pInfo[playerb][JailedTime] = time*60;
SetPlayerVirtualWorld(playerb, 1337);
SetPlayerInterior(playerb, 3);
ResetPlayerWeapons(playerb);
RandomCell = random(sizeof(RandomJails));
SetPlayerFacingAngle(playerb, RandomJails[RandomCell][3]);
TogglePlayerControllable(playerb, 0);
SetTimerEx("EnterExitTimer", 5000, false, "i", playerb);
SetPlayerPos(playerb, RandomJails[RandomCell][0], RandomJails[RandomCell][1], RandomJails[RandomCell][2]);
SetCameraBehindPlayer(playerb);
format(string, sizeof(string), "[AdmCmd]: {FF6347}An Administrator has jailed %s. [Reason: %s]", GetName(playerb), params);
SendClientMessageToAll(red, string);
format(string, sizeof(string), "[AdmCmd]: {FF6347}You have been jailed by administrator %s. Minutes: %d || Seconds: %d",GetName(playerid), pInfo[playerb][JailedTime]/60, pInfo[playerb][JailedTime]);
SendClientMessage(playerb, red, string);
GameTextForPlayer(playerb, "~w~Loading Objects", 3500, 3);
TogglePlayerControllable(playerb, 0);
SetTimerEx("EnterExitTimer", 5000, false, "i", playerb);
pInfo[playerb][pSpawnFreeze] = 1;
RemovePlayerAttachedObject(playerb, 0);
SetPlayerSpecialAction(playerb, SPECIAL_ACTION_NONE);
}
}
else return ShowMessage(playerid, error, 1);
return 1;
}
PHP код:
forward PrisonTimer();
public PrisonTimer()
{
foreach(Player, playerid)
{
if(pInfo[playerid][Jailed] == 2)
{
pInfo[playerid][Jailed] = 0;
pInfo[playerid][JailedTime] = 0;
SetPlayerInterior(playerid, 0);
SetPlayerVirtualWorld(playerid, 0);
SetPlayerFacingAngle(playerid, 88.5042);
SetPlayerColor(playerid, error);
SetPlayerPos(playerid, 1548.8394,-1669.6111,13.5656);
SetCameraBehindPlayer(playerid);
SendClientMessage(playerid, jblue, " Time Served. Be on your best behaviour now :) .");
}
else
{
new string[128];
pInfo[playerid][JailedTime] --;
format(string,sizeof(string),"~r~Jailed Time Left: ~w~%d ~r~seconds", pInfo[playerid][JailedTime]);
GameTextForPlayer(playerid, string, 1500, 3);
}
}
return 1;
}