PDA

View Full Version : /jail time countdown


mrxqware
28/12/2013, 06:51 PM
Dear Guys and Girls,


I'm working on the /jail command to admin-jail player who do not behave.
I would like to create a countdown so the player could see how long he needs to wait before he will be released after he has been jailed and when he relogs while he is still in jail.

I've tried to check other gamemodes but I don't know how to fix it.

Could someone help me please?




if(strcmp(cmd, "/jail", true) == 0)
{
if(IsPlayerConnected(playerid))
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /jail [playerid/PartOfName] [minutes] [reason]");
return 1;
}
new playa;
new time;
playa = ReturnUser(tmp);
tmp = strtok(cmdtext, idx);
time = strvalEx(tmp);
if(PlayerInfo[playerid][pAdmin] >= 2)
{
if(IsPlayerConnected(playa))
{
if(playa != INVALID_PLAYER_ID)
{
GetPlayerName(playa, giveplayer, sizeof(giveplayer));
GetPlayerName(playerid, sendername, sizeof(sendername));
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
new result[64];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
result[idx - offset] = EOS;
if(!strlen(result))
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /jail [playerid/PartOfName] [minutes] [reason]");
return 1;
}
format(string, sizeof(string), "{AA3333}AdmCmd{FFFF00}: %s has been jailed by an Admin, reason: %s", giveplayer, (result));
SendClientMessageToAll(COLOR_LIGHTRED, string);
ClearGuns(playa);
ResetPlayerWeapons(playa);
PlayerInfo[playa][pWantedLevel] = 0;
SetPlayerWantedLevel(playa, 0);
SetPlayerToTeamColor(playa);
PlayerInfo[playa][pJailed] = 1;
PlayerInfo[playa][pJailTime] = time*60;
SetPlayerInterior(playa, 6);
SetPlayerVirtualWorld(playerid, 0);
PlayerInfo[giveplayerid][pVirtualWorld] = 0;
SetPlayerPos(playa, 264.6288,77.5742,1001.0391);
SetPlayerFacingAngle(playa, -90);
format(string, sizeof(string), "You are jailed for %d minutes. Bail: Unable", time);
SendClientMessage(playa, COLOR_LIGHTBLUE, string);



}
}
}
else
{
SendClientMessage(playerid, COLOR_GRAD1, " You are not authorized to use that command !");
}
}
return 1;
}

mrxqware
29/12/2013, 12:26 AM
Could someone help me please?

Mattakil
29/12/2013, 02:17 AM
PlayerInfo[playa][pJailTime] = time*60; to PlayerInfo[playa][pJailTime] = time;

add unjail = SetTimerEx("OnPlayerJailUpdate", 1000, true, "i", playa); Don't forget to define unjail in your script!

forward OnPlayerJailUpdate(playerid);
public OnPlayerJailUpdate(playerid)
{
if(PlayerInfo[playerid][pJailTime] == 0)
{
KillTimer(unjail);
//unjail stuff here!
}
else
{
PlayerInfo[playerid][pJailTime] --;
return 1;
}
return 1;
}

mrxqware
29/12/2013, 08:54 AM
Thank you for your answer.

I have got the jail and unjail function already working, but I would like to have a textdraw/message in the top of the screen so the player can see 120 seconds left, 119 seconds left till 0 seconds left.

Could you help me with this please?

Mattakil
29/12/2013, 02:33 PM
GametextForPlayer