OnPlayerDeath
#1

i wonder why is this not working !!!
when a cop kills a wanted player, the player will go to jail and will appear to him a clock time of how much time remaining till he released from jail.

everything is working but the time is moving quickly, not "seconds" ...here is the code: do i miss returns or something?!

Note: i tested this on /arrest command and worked perfect, but it's not working on "OnPlayerDeath"


pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    if(LawEnforcementMode[killerid] == true) //check if the killer is a cop or law enforcement
    {
        if(PlayerTeam[playerid] != TEAM_CIV || PlayerTeam[playerid] == TEAM_CIV && GetPlayerWantedLevel(playerid)<=3)
        { //if the player that has been killed is not civilian or civilian and his wanted level is less than 3
            DecreaseScore(killerid, 1); // it will decrease the killerid score by 1
            SendDeathMessage(killerid, playerid, reason);
        }
        else
        { //else if he is civilian and his wanted level is greater than 3
       
            PlayerInfo[playerid][pJailTime] = (GetPlayerWantedLevel(playerid)*60)/4;
            PutPlayerInJail(playerid); //will put the playerid in jail as a takendown (arrest)
            IncreaseScore(killerid, 1);
            SendDeathMessage(killerid, playerid, reason);
        }
    }
    return 1;
}

public PutPlayerInJail(playerid)
{
    new Random = random(sizeof(RandomJail));
    SetPlayerInterior(playerid,3);
    SetPlayerVirtualWorld(playerid,1);
    SetPlayerPos(playerid, RandomJail[Random][0], RandomJail[Random][1], RandomJail[Random][2]);
    SetPlayerFacingAngle(playerid, RandomJail[Random][3]);
    SetCameraBehindPlayer(playerid);
    SetPlayerWantedLevel(playerid, 0);
    SetPlayerHealth(playerid, 100);
   
    JailTimer[playerid] = SetTimerEx("UpdateJailSystem", 1000, true, "i", playerid);
    //jail timer is for showing the clock textdraw (how much time is remaining till release from jail)
    return 1;
}

public UpdateJailSystem(playerid)
{
    if(PlayerInfo[playerid][pJailTime] > 0)
    {
        new string[128], gseconds, gminutes;
        gseconds = PlayerInfo[playerid][pJailTime] % 60;
        gminutes = (PlayerInfo[playerid][pJailTime] - gseconds) / 60;
        PlayerInfo[playerid][pJailTime] --;
        format(string, sizeof string, "%d:%02d", gminutes, gseconds);
        TextDrawSetString(JailTimeClock[playerid], string);
        TextDrawShowForPlayer(playerid, JailTimeClock[playerid]);
    }
    else
    {
        ReleasePlayerFromJail(playerid);
    }
    return 1;
}
Reply
#2

anyone?>
Reply
#3

How quick? "Not Seconds" is not helpful
Reply
#4

Maybe with this code:
pawn Код:
JailTimer[playerid] = SetTimerEx("UpdateJailSystem", 1000, true, "i", playerid);
maybe with the seconds .. try more than 1000 ..
Reply
#5

1000 means decreasing the clock second by second,,, but it decreasing it so quickly like
pawn Код:
JailTimer[playerid] = SetTimerEx("UpdateJailSystem", 100, true, "i", playerid);
Reply
#6

You sould kill the timer, otherwise you will have the same timer executing over and over.
Reply
#7

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
You sould kill the timer, otherwise you will have the same timer executing over and over.
where should i kill the timer ? and why ?
Reply
#8

Timer needs to be killed so it won't be called more than once so that makes countdown much faster, to be honest I don't know where to kill that timer.
Reply
#9

worked, i killed it on OnPlayerDeath,, but why it worked ? o,o
Reply
#10

You can put it when the player dies, like below.
Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    if(LawEnforcementMode[killerid] == true) //check if the killer is a cop or law enforcement
    {
        if(PlayerTeam[playerid] != TEAM_CIV || PlayerTeam[playerid] == TEAM_CIV && GetPlayerWantedLevel(playerid)<=3)
        { //if the player that has been killed is not civilian or civilian and his wanted level is less than 3
            DecreaseScore(killerid, 1); // it will decrease the killerid score by 1
            SendDeathMessage(killerid, playerid, reason);
        }
        else
        { //else if he is civilian and his wanted level is greater than 3
        
            PlayerInfo[playerid][pJailTime] = (GetPlayerWantedLevel(playerid)*60)/4;
            KillTimer(JailTimer[playerid]);
            PutPlayerInJail(playerid); //will put the playerid in jail as a takendown (arrest)
            IncreaseScore(killerid, 1);
            SendDeathMessage(killerid, playerid, reason);
        }
    }
    return 1;
}
Quote:

worked, i killed it on OnPlayerDeath,, but why it worked ? o,o

^ It worked because you set the timer to repeat witch needs to be killed on different callbacks.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)