SA-MP Forums Archive
OnPlayerDeath - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: OnPlayerDeath (/showthread.php?tid=488675)



OnPlayerDeath - AnonScripter - 18.01.2014

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;
}



Re: OnPlayerDeath - AnonScripter - 19.01.2014

anyone?>


Re: OnPlayerDeath - Smally - 19.01.2014

How quick? "Not Seconds" is not helpful


Re: OnPlayerDeath - Sawalha - 19.01.2014

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


Re: OnPlayerDeath - AnonScripter - 19.01.2014

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



Re: OnPlayerDeath - SickAttack - 19.01.2014

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


Re: OnPlayerDeath - AnonScripter - 19.01.2014

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 ?


Re: OnPlayerDeath - Lajko1 - 19.01.2014

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.


Re: OnPlayerDeath - AnonScripter - 19.01.2014

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


Re: OnPlayerDeath - SickAttack - 19.01.2014

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.