/unjail command doesn't kill jailtimer
#1

I scripted this little self-functioning jail filterscript and as title says, when i jail someone and in a few seconds unjail him with the command /unjail [ID], the timer still runs and trigers "public unjail()" lines. What do I do wrong?
pawn Код:
#include <a_samp>
#include <sscanf2>
#include <zcmd>


new bool: j12[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    j12[playerid]=false;
    return 0;
}


CMD:jail(playerid,params[])
{
    if (IsPlayerAdmin(playerid))
    {
        new id, time, admin[MAX_PLAYER_NAME], JailTimer[MAX_PLAYERS], Jailed[MAX_PLAYERS], str[128];
        if (!sscanf(params,"dd",id,time))
        {
            if (IsPlayerConnected(id))
            {
                if (j12[id]==false)
                {
                    GetPlayerName(playerid, admin, sizeof(admin));
                    GetPlayerName(id, Jailed, sizeof(Jailed));
                    format(str, sizeof(str), "Admin %s has put %s [%d] in jail for %d minutes.", admin, Jailed, id, time);
                    SendClientMessageToAll(0xFFA500FF, str);
                    SetPlayerInterior(id, 3);
                    SetPlayerFacingAngle(id, 360.0);
                    SetPlayerPos(id, 197.5662, 175.4800, 1004.0);
                    SetPlayerHealth(id, 9999999999.0);
                    ResetPlayerWeapons(id);
                    JailTimer[id] = SetTimerEx("unjail", time*60000, 0, "d", id);
                    j12[id] = true;
                }
                else SendClientMessage(playerid, 0xFF0000AA, "ERROR: Player is already in jail.");
            }
            else SendClientMessage(playerid, 0xFF0000AA, "ERROR: Player is not connected.");
        }
        else SendClientMessage(playerid, 0xFF0000AA, "USAGE: /jail [playerid] [minutes] ");
    }
    else SendClientMessage(playerid, 0xFF0000AA, "You must be Admin to use this command.");
    return 1;
}


forward unjail(id);

public unjail(id)
{
    new free[MAX_PLAYERS], str[128];
    SetPlayerInterior(id, 0);
    SpawnPlayer(id);
    GivePlayerWeapon(id, 4, 1);
    SetPlayerHealth(id,100.0);
    GameTextForPlayer(id, "~g~You are free",2500,3);
    GetPlayerName(id, free, sizeof(free));
    format(str, sizeof(str), "%s {FFFFFF}has been automatically released from jail.", free);
    SendClientMessageToAll(0x009DFFFF, str);
    PlayerPlaySound(id, 1137, 0.0, 0.0, 0.0);
    j12[id] = false;
    return 1;
}


CMD:unjail(playerid,params[])
{
    if (IsPlayerAdmin(playerid))
    {
        new id, admin[MAX_PLAYER_NAME], JailTimer[MAX_PLAYERS], free[MAX_PLAYERS], str[128];
        if(!sscanf(params,"d",id))
        {
            if (IsPlayerConnected(id))
            {
                if (j12[id]==true)
                {
                    GetPlayerName(playerid, admin, sizeof(admin));
                    GetPlayerName(id, free, sizeof(free));
                    j12[id] = false;
                    SetPlayerInterior(id, 0);
                    SpawnPlayer(id);
                    SetPlayerHealth(id, 100);
                    KillTimer(JailTimer[id]);
                    PlayerPlaySound(playerid, 1137, 0.0, 0.0, 0.0);
                    format(str, sizeof(str), "Admin %s has unjailed you.", admin);
                    SendClientMessage(id,0x00FF00AA, str);
                    format(str, sizeof(str), "You unjailed %s.", free);
                    SendClientMessage(id,0x00FF00AA, str);
                }
                else SendClientMessage(playerid, 0xFF0000AA, "ERROR: Player is not in jail.");
            }
            else SendClientMessage(playerid, 0xFF0000AA, "ERROR: Player is not connected.");
        }
        else SendClientMessage(playerid, 0xFF0000AA, "USAGE: /unjail [playerid]");
    }
    else SendClientMessage(playerid, 0xFF0000AA, "You must be Admin to use this command.");
    return 1;
}
Reply
#2

Try this
pawn Код:
new UnjailTimer[MAX_PLAYERS];
CMD:jail(playerid, params[])
{
 if (PlayerInfo[playerid][pAdmin] >= 4)
    {
        new targetid, name[MAX_PLAYER_NAME], tname[MAX_PLAYER_NAME], reason[128], time, string[128];
        if(sscanf(params, "uds[128]", targetid, time, reason)) return SendClientMessage(playerid, COLOR_YELLOW, "Correct Usage: /jail [playerid] [jailtime in minutes] [reason]");
        if(time >= 10 || time < 1) return SendClientMessage(playerid, COLOR_RED, "ERROR: minimum amount of time is 1 minute, maximum amount of time is 10 minutes");
        if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "ERROR: invalid playerid");
        SetPlayerPos(targetid, 197.6661,173.8179,1003.0234);
        PlayerInfo[targetid][Jailed] = true;
        SetPlayerInterior(targetid, 3);
        GetPlayerName(playerid, name, sizeof(name));
        new Minutes = time*1000*60;
        GetPlayerName(targetid, tname, sizeof(tname));
        format(string, sizeof(string), "ADMIN-JAIL: %s has been jailed by %s for %d Minutes(Reason: %s)", tname, name, time, reason);
        SendClientMessageToAll(COLOR_PURPLE, string);
        UnjailTimer[targetid] = SetTimerEx("UnjailPlayer",Minutes,0,"d",targetid);
    }
    else return SendClientMessage(playerid, COLOR_RED, "ERROR: you need to be atleast Admin Level 1 to use this command");
 return 1;
}
forward UnjailPlayer(targetid);
public UnjailPlayer(targetid)
{
    if(PlayerInfo[targetid][Jailed] == false) return 1;
    if(PlayerInfo[targetid][Jailed] == true)
    {
        SpawnPlayer(targetid);
        new tname[MAX_PLAYER_NAME], string[128];
        GetPlayerName(targetid, tname, sizeof(tname));
        format(string, sizeof(string), "SERVER-UNJAIL: %s has been automatically unjailed", tname);
        SendClientMessageToAll(COLOR_PURPLE, string);
        KillTimer(UnjailTimer[targetid]);
        PlayerInfo[targetid][Jailed] = false;
    }
    return 1;
}
Reply
#3

This is a joke, right? Don't post useless things man.
Reply
#4

try it will work
Reply
#5

Try to replace the
pawn Код:
KillTimer(JailTimer[id]);
from the command code to the
pawn Код:
public unjail(id) {    .....    }
Reply
#6

Of course that doesn't work.
Reply
#7

Add this to GM:

Код:
CMD:unjail(playerid, params[])
{
	if(PlayerInfo[playerid][pAdmin] >= 1)
	{
		new string[128], giveplayerid;
		if(sscanf(params, "us[64]", giveplayerid)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /unjail [playerid]");

		if(IsPlayerConnected(giveplayerid))
		{
			new year, month,day;
			getdate(year, month, day);
			format(string, sizeof(string), "%s has been released from prison by %s", GetPlayerNameEx(giveplayerid), GetPlayerNameEx(playerid));
			SendClientMessageToAllEx(COLOR_LIGHTRED, string);
			WantedPoints[giveplayerid] = 0;
			PlayerInfo[giveplayerid][pJailed] = 0;
			SetPlayerToTeamColor(giveplayerid);
			PlayerInfo[giveplayerid][pJailTime] = 0;
			SetPlayerPos(giveplayerid, 1529.6,-1691.2,13.3);
			SetPlayerInterior(giveplayerid,0);
			PlayerInfo[giveplayerid][pInt] = 0;
			SetPlayerVirtualWorld(giveplayerid, 0);
			PlayerInfo[giveplayerid][pVW] = 0;
			PlayerInfo[giveplayerid][pLocal] = 255;
		}
	}
	else
	{
		SendClientMessageEx(playerid, COLOR_GRAD1, "You are not authorized to use that command!");
	}
	return 1;
}
edit it as you wish
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)