SA-MP Forums Archive
Bank rob with escape timer. - 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: Bank rob with escape timer. (/showthread.php?tid=623793)



Bank rob with escape timer. - Djumza - 05.12.2016

Hello guys today i'm making bank rob system with timer for : rob,escape and new rob possibility.
I used these lines.. i don't get any pawn errors but i get some bugs in game. :
pawn Код:
CMD:rob(playerid,params[])
{
    if(gTeam[playerid] == TEAM_CIVIL)
    {
        if(robpossible == 1)
        {
            if(IsPlayerInRangeOfPoint(playerid,5.0,-26.691598,-55.714897,1003.546875))
            {
                robpossible = 0;
                SetTimer("timer1", 120000 , false);
                SetTimer("timer2", 5000, false);
                SendClientMessage(playerid,-1,"[SERVER]: You are robbing the store,the police has been notified !");
                SendClientMessage(playerid,-1,"[SERVER]: You have to stay 5 sec in the store in order to rob it.");
                TogglePlayerControllable(playerid,0);
            }
            else return SendClientMessage(playerid,-1,"[SERVER]: You must be in store");
        }
        else return SendClientMessage(playerid,-1,"[SERVER]: Store cant be robbed right now!");
    }
    else return SendClientMessage(playerid,-1,"[SERVER]: As cop u cant use rob cmd!");
    return 1;
}
public timer1()
{
    robpossible = 1;
    SendClientMessageToAll(COLOR_YELLOW,"[SERVER]: Store is now available for robbery!");
}
public timer2(playerid)
{
    new msg[128];
    robmoney = random(10000);
    format(msg,sizeof(msg),"You have successfully robbed $%d from the store,now escape,if u die u lose it",robmoney);
    SendClientMessage(playerid,COLOR_GREEN,msg);
    TogglePlayerControllable(playerid,1);
    SetPlayerWantedLevel(playerid,6);
    SetTimer("escape",30000,false);
    IsBankRobber[playerid] = 1;
}
public escape(playerid)
{
    GivePlayerMoney(playerid,robmoney);
    SendClientMessage(playerid,-1,"You have successfully escaped with money");
    IsBankRobber[playerid] = 0;
}
//==========on top=============//
forward timer1();
forward timer2(playerid);
forward escape(playerid);
new robpossible;
new robmoney;
new gTeam[MAX_PLAYERS];
new pClass[MAX_PLAYERS];
new IsBankRobber[MAX_PLAYERS];
public OnGameModeInit()
{
    DisableInteriorEnterExits();
    robpossible = 1;
    robmoney = 0;
//======= death ===========//
public OnPlayerDeath(playerid, killerid, reason)
{
    if(IsBankRobber[playerid] == 1)
    {
        GivePlayerMoney(killerid,robmoney);
        SendClientMessageToAll(COLOR_GREEN," TEST ");
        IsBankRobber[playerid] = 0;
    }
    else
    {
While i was writhing this i figured out i forgot to kill timer when bank robber is dead. That's why i was getting ingame bug where both of guys bank robber and killer would get money.
Anyway there is a bug where i use /rob cmd and all things from "timer2" are done to my friend who is out of bank doing his thing.
I get only msgs that i have to wait 5 sec and i stay freeze forever.
Sorry for bad english i could explain better if u ask me to.


Re: Bank rob with escape timer. - GoldenLion - 05.12.2016

Use SetTimerEx so you can pass the playerid. Like that:
Код:
SetTimerEx("timer2", 5000, false, "i", playerid);
Right now you are setting a timer without any parameters and that means playerid is 0.


Re: Bank rob with escape timer. - Djumza - 05.12.2016

Oh ! Okey.. thanks.. should i use SetTimerEx for escape timer too ?


Re: Bank rob with escape timer. - GoldenLion - 05.12.2016

Of course as you need to pass playerid.


Re: Bank rob with escape timer. - Djumza - 05.12.2016

Thanks !