Equip command with timer -
Jimbo01 - 02.03.2011
I have some gang equip commands like this
Код:
if(strcmp(cmdtext, "/gang1equip", true) == 0)
{
if(gTeam[playerid] == 8)
{
if(IsPlayerInRangeOfPoint(playerid,2.0, 948.4193,-2159.3289,14.5618))
{
ResetPlayerWeapons(playerid);
GivePlayerWeapon(playerid, 24, 50); // deagle
GivePlayerWeapon(playerid, 30, 500); // ak47
GameTextForPlayer(playerid,"~r~!", 5000, 1);
}
else
{
SendClientMessage(playerid, COLOR_GREY," !");
}
}
else
{
SendClientMessage(playerid, COLOR_RED,"* !");
}
return 1;
}
if(strcmp(cmdtext, "/gang2equip", true) == 0)
{
if(gTeam[playerid] == 8)
{
if(IsPlayerInRangeOfPoint(playerid,2.0, 948.4193,-2159.3289,14.5618))
{
ResetPlayerWeapons(playerid);
GivePlayerWeapon(playerid, 24, 50); // deagle
GivePlayerWeapon(playerid, 30, 500); // ak47
GameTextForPlayer(playerid,"~r~!", 5000, 1);
}
else
{
SendClientMessage(playerid, COLOR_GREY," !");
}
}
else
{
SendClientMessage(playerid, COLOR_RED,"* !");
}
return 1;
}
How can i make it with timers that i can use it only every 10mins + if he/she use it before he/she should get a msg that he must to wait
Re: Equip command with timer -
Sasino97 - 02.03.2011
You should use
GetTickCount()
pawn Код:
new EquipTickCount[MAX_PLAYERS];
At the start of the command:
pawn Код:
EquipTickCount[playerid] = GetTickCount();
if(GetTickCount()-EquipTickCount[playerid] < 600000/*I think it's 10 minutes*/) return /*ERROR MESSAGE*/;
It's something like this.
Re: Equip command with timer -
Jimbo01 - 02.03.2011
tried some ways... didnt works.. can anyone show me it please
Re: Equip command with timer -
Jimbo01 - 02.03.2011
made somethins like this but still dont works
Код:
if(strcmp(cmdtext, "/gang1equip", true) == 0)
{
if(gTeam[playerid] == 8)
{
if(IsPlayerInRangeOfPoint(playerid,2.0, 948.4193,-2159.3289,14.5618))
{
new iLastHealed[MAX_PLAYERS];
new iCount = GetTickCount();
if((iCount - iLastHealed[playerid]) > 50000)
{
//ResetPlayerWeapons(playerid);
GivePlayerWeapon(playerid, 24, 50); // deagle
GivePlayerWeapon(playerid, 30, 500); // ak47
iLastHealed[playerid] = iCount;
GameTextForPlayer(playerid,"~r~!", 5000, 1);
}
}
else
{
SendClientMessage(playerid, COLOR_GREY," !");
}
}
else
{
SendClientMessage(playerid, COLOR_RED,"* !");
}
return 1;
}
Re: Equip command with timer -
JaTochNietDan - 02.03.2011
You want "iLastHealed" to be a global variable, as we need the data stored there to be persistant per server instance. Otherwise as soon as the statement is in, is finished executing, all of the values and information stored in that variable will be destroyed. How do you make it global? Take it out of the command and put it at the top of your script to keep things neat and tidey:
pawn Код:
new iLastHealed[MAX_PLAYERS];
When you've put it as a global variable, the stored tickcount of the last successful heal will be there.
Re: Equip command with timer -
Sasino97 - 02.03.2011
Also iCount should be a per-player variable, because if it's general all players have to wait for the timer....
Re: Equip command with timer -
JaTochNietDan - 02.03.2011
Quote:
Originally Posted by [GF]Sasino97
Also iCount should be a per-player variable, because if it's general all players have to wait for the timer....
|
It can be both global and "per-player"? Just make it an array so you can reference to the unique cells by the ID of the player, not sure what being global or locally scoped has to do with it!
Edit: Thought you were talking about a different variable in this code, nevermind that. Although iCount shouldn't be per player anyway.
Re: Equip command with timer -
Sasino97 - 02.03.2011
Quote:
Originally Posted by JaTochNietDan
It can be both global and "per-player"? Just make it an array so you can reference to the unique cells by the ID of the player, not sure what being global or locally scoped has to do with it!
|
I mean:
Sorry for my bad english xD
EDIT: AAAAAAH I TAUGHT THAT ICOUNT WAS THE VARIABLE TO GET THE TICKCOUNT OF THE PLAYER...
Re: Equip command with timer -
JaTochNietDan - 02.03.2011
Quote:
Originally Posted by [GF]Sasino97
I mean:
Sorry for my bad english xD
|
iCount doesn't need to be global or per-player, it's only a temporary variable to store the tickcount for that bit of code.
Edit: Misunderstanding
Re: Equip command with timer -
Jimbo01 - 02.03.2011
Thank all!
It works..