Equip command with timer
#1

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
Reply
#2

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.
Reply
#3

tried some ways... didnt works.. can anyone show me it please
Reply
#4

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;
	}
Reply
#5

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.
Reply
#6

Also iCount should be a per-player variable, because if it's general all players have to wait for the timer....
Reply
#7

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.
Reply
#8

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:

pawn Код:
new iCount[MAX_PLAYERS];
Sorry for my bad english xD

EDIT: AAAAAAH I TAUGHT THAT ICOUNT WAS THE VARIABLE TO GET THE TICKCOUNT OF THE PLAYER...
Reply
#9

Quote:
Originally Posted by [GF]Sasino97
Посмотреть сообщение
I mean:

pawn Код:
new iCount[MAX_PLAYERS];
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
Reply
#10

Thank all!

It works..
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)