Killing a timer
#1

Hello, how can I kill my timer for robbing the bank when a player is being shot at and has less than 20hp, KillTimer(robtimer); gives me an error

pawn Код:
C:\Users\Josh\Desktop\DEVIL NPC BUS\filterscripts\robb.pwn(115) : warning 202: number of arguments does not match definition
C:\Users\Josh\Desktop\DEVIL NPC BUS\filterscripts\robb.pwn(117) : error 076: syntax error in the expression, or invalid function call
Here is my full 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_PURPLE 0xC2A2DAAA
#define DIALOGITEMS 1
#define DIALOGITEMS2 2

//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, 2144.2012,1640.6323,993.5761))
        {
            robpossible = 0;
            //SetTimer("waittimer",  5000, false); //for testing
           
            //SetTimer("robtimer", 5000, false); //Test Mode 6 seconds
            SetTimer("waittimer", 5500000, false);
            SetTimer("robtimer", 300000, false);
           
            SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid)+4);
            TogglePlayerControllable(playerid, 0);
            SendClientMessage(playerid, COLOR_WHITE, "You are now robbing the bank, the police have been notified!");
            SendClientMessage(playerid, COLOR_WHITE, "You must stay in the bank for 5 minutes in order to rob it!");
            SendClientMessageToAll(COLOR_PURPLE, "*** . . : : You may hear alarms and sirens screaming outside the bank in Mulholland: : . .  ***");
            new string[18];
            format(string, sizeof(string), "Robbing the bank");
            GameTextForPlayer(playerid, string, 299995, 5);
            //GameTextForPlayer(playerid, string, 6000, 5); //for testing
         }
    } else {
        SendClientMessage(playerid, COLOR_WHITE, "You can't rob the bank right now!");
    }
    return 1;
}

CMD:buyitems(playerid, params[])
{
    if(IsPlayerInRangeOfPoint(playerid, 7, 2561.2803,1403.9896,7699.5845))
    ShowPlayerDialog(playerid, DIALOGITEMS, DIALOG_STYLE_LIST, "Items menu - New items soon!","Bank robbery timer reset (150k)","Buy","Cancel");
}
 //Test CMDS
/*CMD:bank(playerid, params[])
{
    SetPlayerPos(playerid, 2144.2012,1640.6323,993.5761);
    SetPlayerInterior(playerid, 1);
}

CMD:vip(playerid, params[])
{
    SetPlayerPos(playerid, 2561.2803,1403.9896,7699.5845);
    GivePlayerMoney(playerid, 200000);
    TogglePlayerControllable(playerid, 0);
}

CMD:unfreeze(playerid, params[])
{
    TogglePlayerControllable(playerid, 1);
}

CMD:setmoney(playerid, params[])
{
    GivePlayerMoney(playerid, 0);
    return 1;
}*/


public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    if(IsPlayerInRangeOfPoint(playerid, 3, 2144.2012,1640.6323,993.5761))
    {
        if(issuerid !=INVALID_PLAYER_ID && weaponid == 20 || 21 || 22 || 23 || 24 || 25 || 26 || 27 || 28 || 29 || 30 || 31 || 32 || 33 || 34)
        {
            robpossible = 1;
        }
    }
    return 1;
}

public OnPlayerUpdate(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 3, 2144.2012,1640.6323,993.5761))
    {
        if(GetPlayerHealth(playerid) <20) return SendClientMessage(playerid, COLOR_WHITE, "You have less than 20hp, bank robbery cancelled!"); //I am receiving the warning on this line
        TogglePlayerControllable(playerid, 1);
        KillTimer(robtimer); //This line returns an error, I need it to cancel the robtimer so if the player is shot at and has less than 20hp he doesn't receive the money
    }
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == DIALOGITEMS)
    {
        if(response)
        {
            switch(listitem)
            {
                case 0:
            {
                ShowPlayerDialog(playerid, DIALOGITEMS2, DIALOG_STYLE_MSGBOX, "Are you sure you want to buy this item?","Buying this item will reset the bank timer so you're\nable to rob the bank again without waiting 30 minutes.\nRemember: There is no point in buying this timer if the bank has\nnot been robbed in the past 30 minutes.","Buy item","Cancel");
            }
       
            }
        }
    }

    if(dialogid == DIALOGITEMS2)
    {
        if(response)
        {
            if(GetPlayerMoney(playerid) <150000) return SendClientMessage(playerid, COLOR_WHITE, "You do not have enough money to purchase this item!");
            SendClientMessage(playerid, COLOR_WHITE, "You have purchased a bank robbery timer reset!");
            SendClientMessage(playerid, COLOR_WHITE, "The bank timer has been reset!");
            GivePlayerMoney(playerid, -150000);
            robpossible = 1;
        }
    }
    return 1;
}

//Functions
public robtimer(playerid)
{
    new string2[128];
    new cash = random(200000);
    GivePlayerMoney(playerid, cash);
    TogglePlayerControllable(playerid, 1);

    format(string2, sizeof(string2), "You have successfully robbed $%d from the bank!", cash);
    SendClientMessage(playerid, COLOR_WHITE, string2);
    new string3[18];
    format(string3, sizeof(string3), "Sucessful!");
    GameTextForPlayer(playerid, string3, 2000, 5);
}

public waittimer()
{
    robpossible = 1;
}
The errors and warning is under OnPlayerUpdate. I commented the lines

Any help would be greatly appreciated! Thank you!
Reply
#2

You have "robtimer" set as a public function. KillTimer expects a timer ID. You need to make a separate variable (should be global) for the timer itself. For example, in your robbank command:

pawn Код:
//at the top of the script
new banktimer;

CMD:robbank(playerid, params[]) {
//all your other stuff
banktimer = SetTimer("robtimer", 300000, false);
}

public OnPlayerUpdate(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 3, 2144.2012,1640.6323,993.5761))
    {
        if(GetPlayerHealth(playerid) <20) return SendClientMessage(playerid, COLOR_WHITE, "You have less than 20hp, bank robbery cancelled!"); //I am receiving the warning on this line
        TogglePlayerControllable(playerid, 1);
        KillTimer(banktimer);
    }
    return 1;
}
Reply
#3

Thanks shit loads man!
Reply
#4

For some reason, I've added the filterscript and now when I type a command the server restarts. Do you know what's going on?
Reply
#5

Well, pffff, how can I tell you, first of all you must use SetTimerEx, because you want the timer to work for each player at different times, of course.
It's not an universal timer(so you can use SetTimer, wich most likely will cause the timer to work at the same time for all players, I've had this problem a long time ago). Therefor I will rewrite the code for you, but use the same names, so you understand what's all about:

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_PURPLE 0xC2A2DAAA
#define DIALOGITEMS 1
#define DIALOGITEMS2 2

//Function forwarding
/*
Firstly we have to forward the functions that we are going
to use later in our sript.
*/


forward RobTimer(playerid);
forward ResetTimer();
new Timer1[MAX_PLAYERS];
//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, 2144.2012,1640.6323,993.5761))
        {
            RobPossible = 0;
            SetTimer("WaitTimer", 5500000, false);
            Timer1[playerid]=SetTimerEx("RobTimer", 300000, false, "i", playerid);
            SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid)+4);
            TogglePlayerControllable(playerid, 0);
            SendClientMessage(playerid, COLOR_WHITE, "You are now robbing the bank, the police have been notified!");
            SendClientMessage(playerid, COLOR_WHITE, "You must stay in the bank for 5 minutes in order to rob it!");
            SendClientMessageToAll(COLOR_PURPLE, "*** . . : : You may hear alarms and sirens screaming outside the bank in Mulholland: : . .  ***");
            new string[18];
            format(string, sizeof(string), "Robbing the bank");
            GameTextForPlayer(playerid, string, 299995, 5);
         }
    } else {
        SendClientMessage(playerid, COLOR_WHITE, "You can't rob the bank right now!");
    }
    return 1;
}

CMD:buyitems(playerid, params[])
{
    if(IsPlayerInRangeOfPoint(playerid, 7, 2561.2803,1403.9896,7699.5845))
    ShowPlayerDialog(playerid, DIALOGITEMS, DIALOG_STYLE_LIST, "Items menu - New items soon!","Bank robbery timer reset (150k)","Buy","Cancel");
}
 //Test CMDS
/*CMD:bank(playerid, params[])
{
    SetPlayerPos(playerid, 2144.2012,1640.6323,993.5761);
    SetPlayerInterior(playerid, 1);
}

CMD:vip(playerid, params[])
{
    SetPlayerPos(playerid, 2561.2803,1403.9896,7699.5845);
    GivePlayerMoney(playerid, 200000);
    TogglePlayerControllable(playerid, 0);
}

CMD:unfreeze(playerid, params[])
{
    TogglePlayerControllable(playerid, 1);
}

CMD:setmoney(playerid, params[])
{
    GivePlayerMoney(playerid, 0);
    return 1;
}*/


public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    if(IsPlayerInRangeOfPoint(playerid, 3, 2144.2012,1640.6323,993.5761))
    {
        if(issuerid !=INVALID_PLAYER_ID && weaponid == 20 || 21 || 22 || 23 || 24 || 25 || 26 || 27 || 28 || 29 || 30 || 31 || 32 || 33 || 34)
        {
            RobPossible = 1;
        }
    }
    return 1;
}

public OnPlayerUpdate(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 3, 2144.2012,1640.6323,993.5761))
    {
        new Float:pHealth;
        GetPlayerHealth(playerid,pHealth);
        if(pHealth < 20.0) return SendClientMessage(playerid, COLOR_WHITE, "You have less than 20hp, bank robbery cancelled!");
        TogglePlayerControllable(playerid, 1);
        KillTimer(Timer1[playerid]);
    }
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == DIALOGITEMS)
    {
        if(response)
        {
            switch(listitem)
            {
                case 0:
            {
                ShowPlayerDialog(playerid, DIALOGITEMS2, DIALOG_STYLE_MSGBOX, "Are you sure you want to buy this item?","Buying this item will reset the bank timer so you're\nable to rob the bank again without waiting 30 minutes.\nRemember: There is no point in buying this timer if the bank has\nnot been robbed in the past 30 minutes.","Buy item","Cancel");
            }
       
            }
        }
    }

    if(dialogid == DIALOGITEMS2)
    {
        if(response)
        {
            if(GetPlayerMoney(playerid) <150000) return SendClientMessage(playerid, COLOR_WHITE, "You do not have enough money to purchase this item!");
            SendClientMessage(playerid, COLOR_WHITE, "You have purchased a bank robbery timer reset!");
            SendClientMessage(playerid, COLOR_WHITE, "The bank timer has been reset!");
            GivePlayerMoney(playerid, -150000);
            robpossible = 1;
        }
    }
    return 1;
}

//Functions
public RobTimer(playerid)
{
    new string2[128];
    new cash = random(200000);
    GivePlayerMoney(playerid, cash);
    TogglePlayerControllable(playerid, 1);
    format(string2, sizeof(string2), "You have successfully robbed $%d from the bank!", cash);
    SendClientMessage(playerid, COLOR_WHITE, string2);
    new string3[18];
    format(string3, sizeof(string3), "Sucessful!");
    GameTextForPlayer(playerid, string3, 2000, 5);
}

public WaitTimer()
{
    RobPossible = 1;
}
Now, replace the filterscript with that, and everything should be fine, I hope.
Reply
#6

SetTimer causes lag, why you don't use better gettime instead? You just need to create a variable for saving the time, when the player has used.

pawn Код:
new g_RobTimer[MAX_PLAYERS]
pawn Код:
g_RobTimer[playerid] = gettime(); // Use this, when the /rob command worked successfully for the player.
Then add this top of your cmd, where if(RobPossible == 1) is.

pawn Код:
if( (gettime() - g_RobTimer[playerid]) > 300 )
{
    // Rob command
}
else
{
    SendClientMessage(playerid, COLOR_WHITE, "You can't rob the bank right now!");
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)