Problem with robbery script
#1

Hello guys. I have a robbery script on my server. You can say like its working to 90%. The problem is, after I've robbed the bank once I need to restart the server to be able to rob the bank again. Here is my code.

pawn Код:
/*
    This script/application is created by UnlimitedDeveloper from SAMP forums
    and it's supposed to be shared only at SAMP forums, nowhere else!
    If any copy of this script is found on another forum, it will be taken down.
    */

    #include <a_samp>
    #include <zcmd>

    #define COLOR_WHITE 0xFFFFFFAA
    #define COLOR_RED 0xAA3333AA
    //Function forwarding
    /*
    Firstly we have to forward the functions that we are going
    to use later in our sript.
    */

    forward robtimer(playerid);
    forward waittimer();

    //Variables
    /*
    We are adding a NEW Variable so we can determine wether the bank
    can or cannot be robber at a certain time.
    */

    new robpossible;

    public OnFilterScriptInit()
    {
            /*
            When the filterscript executes itself it's setting the 'robpossible'
            variable to 1 which means that we can rob the bank right after we login.
            */

            robpossible = 1;
            return 1;
    }

    //Command(s)
    CMD:robbank(playerid, params[])
    {
            if(robpossible == 1) //If the bank can be robbed we continue below
            {
                    if(IsPlayerInRangeOfPoint(playerid, 3.0, 2315.952880,-1.618174,26.742187))
                    {//Next thing we do is, we check if we are at the bank interior ^^
                        robpossible = 0; //Then we set the bank so it cannot be robbed
                        SetTimer("waittimer", 300000, false); //Normal Mode 5 minutes
                        /*We run the timer(5 minutes) for the function that is going to make the
                        bank available for robbing again
                        */

                        //SetTimer("waittimer", 65000, false); //Test Mode 65 seconds
                        SetTimer("robtimer", 60000, false);
                        /* We also run another timer(1 minute) for the function that is
                        actually going to give us the money and a user friendly message.
                        */

                        /*
                        Add a function that would notify the police.
                        */

                        SendClientMessage(playerid, COLOR_WHITE, "You are robbing the bank, the police has been notified!");
                SendClientMessage(playerid, COLOR_WHITE, "You gotta stay 30 seconds in the bank in order to rob it!");
                SendClientMessageToAll(COLOR_RED, "Los Santos bank is being robbed!");
                     }
            } else {
                SendClientMessage(playerid, COLOR_WHITE, "The bank has already been robbed!");
            }
            return 1;
    }

    //Functions
    public robtimer(playerid)
    {
            new string[128];//We are defining a new string for the formatted message that we are displaying later on.
        new cash = random(200000);
            GivePlayerMoney(playerid, cash);
            /*
        With the fuction above 'new cash = random(200000);
            GivePlayerMoney(playerid, cash);' we give the player
        a random amount of money from $0 - $200,000
        */

        //Here below we use the string we defined above to format the message itself and display it to the player.
            format(string, sizeof(string), "You have successfully robbed $%d from the bank!", cash);
            SendClientMessage(playerid, COLOR_WHITE, string);
    }

    public waittimer()
    {
            robpossible = 1; //With this we make the bank available for robbery again, and we display a friendly message to all players.
            SendClientMessageToAll(COLOR_WHITE, "The bank is now available for robbery!");
    }
Please help me fix this!!
Reply
#2

And you dont understand this?

pawn Код:
SetTimer("waittimer", 300000, false); //Normal Mode 5 minutes
...
robpossible = 1; //With this we make the bank available for robbery again, and we display a friendly message to all players.
You must wait 5 minutes to next robbery
Reply
#3

Код:
SetTimer("waittimer", 300000, false); //Normal Mode 5 minutes
Change that to

Код:
SetTimer("waittimer", 30000, false); //Normal Mode 5 minutes
Reply
#4

Quote:
Originally Posted by Matess
Посмотреть сообщение
And you dont understand this?

pawn Код:
SetTimer("waittimer", 300000, false); //Normal Mode 5 minutes
...
robpossible = 1; //With this we make the bank available for robbery again, and we display a friendly message to all players.
You must wait 5 minutes to next robbery
I understand that -.- but it doesnt work to rob after 5 minutes..
Reply
#5

Quote:
Originally Posted by shahryar2
Посмотреть сообщение
Код:
SetTimer("waittimer", 300000, false); //Normal Mode 5 minutes
Change that to

Код:
SetTimer("waittimer", 30000, false); //Normal Mode 5 minutes
Testing right now
Reply
#6

You're not sending a playerid along with the 'robtimer' timer, which means you shouldn't be able to rob in the first place.

Change this:
pawn Код:
SetTimer("robtimer", 60000, false);
To this:
pawn Код:
SetTimerEx("robtimer", 60000, false, "d", playerid);
Also, in both your timer callbacks, add this to the bottom before the closing bracket:
pawn Код:
return 1;
Reply
#7

Quote:
Originally Posted by Ceathor
Посмотреть сообщение
You're not sending a playerid along with the 'robtimer' timer, which means you shouldn't be able to rob in the first place.

Change this:
pawn Код:
SetTimer("robtimer", 60000, false);
To this:
pawn Код:
SetTimerEx("robtimer", 60000, false, "d", playerid);
Well, its working the first time then it doesnt work anymore. Will also try this. Thanks
Reply
#8

Updated my post above, you need to add return 1;
Quote:
Originally Posted by AustinWeerdGuy
Посмотреть сообщение
Well, its working the first time then it doesnt work anymore. Will also try this. Thanks
Also, I'm sure you'll find it only worked for playerid = 0.
Reply
#9

Quote:
Originally Posted by shahryar2
Посмотреть сообщение
Код:
SetTimer("waittimer", 300000, false); //Normal Mode 5 minutes
Change that to

Код:
SetTimer("waittimer", 30000, false); //Normal Mode 5 minutes
Alright sorry for double posting here, but you just instructed him to change his timer from 5 minutes (300000 ms) to 30 seconds (300000 ms). I understand he wants it to be 5 minutes, which means this change should not be done to the script.
Reply
#10

Now it works to rob the bank over and over again. BUT, now the player doesnt get any money after the robbery... What should I do?

pawn Код:
/*
    This script/application is created by UnlimitedDeveloper from SAMP forums
    and it's supposed to be shared only at SAMP forums, nowhere else!
    If any copy of this script is found on another forum, it will be taken down.
    */

    #include <a_samp>
    #include <zcmd>

    #define COLOR_WHITE 0xFFFFFFAA
    #define COLOR_RED 0xAA3333AA
    //Function forwarding
    /*
    Firstly we have to forward the functions that we are going
    to use later in our sript.
    */

    forward robtimer(playerid);
    forward waittimer();

    //Variables
    /*
    We are adding a NEW Variable so we can determine wether the bank
    can or cannot be robber at a certain time.
    */

    new robpossible;

    public OnFilterScriptInit()
    {
            /*
            When the filterscript executes itself it's setting the 'robpossible'
            variable to 1 which means that we can rob the bank right after we login.
            */

            robpossible = 1;
            return 1;
    }

    //Command(s)
    CMD:robbank(playerid, params[])
    {
            if(robpossible == 1) //If the bank can be robbed we continue below
            {
                    if(IsPlayerInRangeOfPoint(playerid, 3.0, 2315.952880,-1.618174,26.742187))
                    {//Next thing we do is, we check if we are at the bank interior ^^
                        robpossible = 0; //Then we set the bank so it cannot be robbed
                        SetTimer("waittimer", 30000, false); //Normal Mode 5 minutes
                        /*We run the timer(5 minutes) for the function that is going to make the
                        bank available for robbing again
                        */

                        //SetTimer("waittimer", 65000, false); //Test Mode 65 seconds
                        SetTimer("robtimer", 60000, false);
                        /* We also run another timer(1 minute) for the function that is
                        actually going to give us the money and a user friendly message.
                        */

                        /*
                        Add a function that would notify the police.
                        */

                        SendClientMessage(playerid, COLOR_WHITE, "You are robbing the bank, the police has been notified!");
                SendClientMessage(playerid, COLOR_WHITE, "You gotta stay 30 seconds in the bank in order to rob it!");
                SendClientMessageToAll(COLOR_RED, "Los Santos bank is being robbed!");
                     }
            } else {
                SendClientMessage(playerid, COLOR_WHITE, "The bank has already been robbed!");
            }
            return 1;
    }

    //Functions
    public robtimer(playerid)
    {
            new string[128];//We are defining a new string for the formatted message that we are displaying later on.
        new cash = random(200000);
            GivePlayerMoney(playerid, cash);
            /*
        With the fuction above 'new cash = random(200000);
            GivePlayerMoney(playerid, cash);' we give the player
        a random amount of money from $0 - $200,000
        */

        //Here below we use the string we defined above to format the message itself and display it to the player.
            format(string, sizeof(string), "You have successfully robbed $%d from the bank!", cash);
            SendClientMessage(playerid, COLOR_WHITE, string);
    }

    public waittimer()
    {
            robpossible = 1; //With this we make the bank available for robbery again, and we display a friendly message to all players.
            SendClientMessageToAll(COLOR_WHITE, "The bank is now available for robbery!");
    }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)