26.06.2013, 07:10
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:
Now, replace the filterscript with that, and everything should be fine, I hope.
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;
}