Timer on my command?
#1

Hello guys.

I would REALLY REALLY REALLY appriciate (fail) if one of you could help me with this. I just got a /search
Command for my Zombie Server, but now i want a TIMER on it. This means that a player can only use this command
each 5 minutes. Could one of you edit it with that?

COMMAND: search(playerid,params[])
{
#pragma unused params
new rand;
rand = (5);
switch(random(rand) )
{
case 0: SetPlayerHealth(playerid,100);
case 1: SetPlayerArmour(playerid,100);
case 2: GivePlayerWeapon(playerid,24,500);
case 3: GivePlayerWeapon(playerid,30,500);
case 4: GivePlayerMoney(playerid,500);
case 5: GivePlayerMoney(playerid,1000);
}
return 1;
}

Please help me
Reply
#2

pawn Код:
new DisSearchT[MAX_PLAYERS]; // I made it as a per-player global var because multiple players can use your command, right?
new CanNotUseSearch[MAX_PLAYERS]; // This will be used to check whether a player is able to use /search or not
// 0 = can
// 1 = can not
// Now in your command
COMMAND: search(playerid,params[])
{
    #pragma unused params
    if(CanNotUseSearch[playerid] == 1)
        return SendClientMessage(playerid, -1, "You can use this command once every 5 minutes!"), 1;
    new rand;
    rand = (5);
    switch(random(rand) )
    {
        case 0: SetPlayerHealth(playerid,100);
        case 1: SetPlayerArmour(playerid,100);
        case 2: GivePlayerWeapon(playerid,24,500);
        case 3: GivePlayerWeapon(playerid,30,500);
        case 4: GivePlayerMoney(playerid,500);
        case 5: GivePlayerMoney(playerid,1000);
    }
    CanNotUseSearch[playerid] = 1; // set it to 1 = player can not use the /search command
    DisSearchT[playerid]= SetTimerEx("ResetSearchStatus", 300000, false, "d", playerid); // this will call the forwarded public ResetSearchStatus which resets the player status
    return 1;
}

forward ResetSearchStatus(playerid);
public ResetSearchStatus(playerid)
{
    CanNotUseSearch[playerid] = 0; // here he's able to use /search again.
    SendClientMessage(playerid, -1, "Now you can use the command /search again.");
    return 1;
}
Sorry for the bad explaination I did it in a hurry because I gotta go.
Reply
#3

Thank you so much!

Now, for the people that are bored, i have another question (I know im asking much XD)

I want it as when people get a random item, like a weapon, it sends a ClientMessage to the player saying ''You've found a weapon!''. I need it on all of them. I tried editing the cases, but i dont get a sh*t of it.
Please add the texts to the following:

Код:
new DisSearchT[MAX_PLAYERS]; // I made it as a per-player global var because multiple players can use your command, right?
new CanNotUseSearch[MAX_PLAYERS]; // This will be used to check whether a player is able to use /search or not
// 0 = can
// 1 = can not
// Now in your command
COMMAND: search(playerid,params[])
{
    #pragma unused params
    if(CanNotUseSearch[playerid] == 1)
        return SendClientMessage(playerid, -1, "You can use this command once every 5 minutes!"), 1;
    new rand;
    rand = (5);
    switch(random(rand) )
    {
        case 0: SetPlayerHealth(playerid,100);
        case 1: SetPlayerArmour(playerid,100);
        case 2: GivePlayerWeapon(playerid,24,500);
        case 3: GivePlayerWeapon(playerid,30,500);
        case 4: GivePlayerMoney(playerid,500);
        case 5: GivePlayerMoney(playerid,1000);
    }
    CanNotUseSearch[playerid] = 1; // set it to 1 = player can not use the /search command
    DisSearchT[playerid]= SetTimerEx("ResetSearchStatus", 300000, false, "d", playerid); // this will call the forwarded public ResetSearchStatus which resets the player status
    return 1;
}

forward ResetSearchStatus(playerid);
public ResetSearchStatus(playerid)
{
    CanNotUseSearch[playerid] = 0; // here he's able to use /search again.
    SendClientMessage(playerid, -1, "Now you can use the command /search again.");
    return 1;
}
Greetz, CrazyManiac. (Btw if ur already gettin sick of me, this is my last question. Lmao.)
Reply
#4

HellSphinX, there is no need of a timer when you can do it with such an easy method.. It saves memory you know? timers make your server lag if they are more then enough..

So the following code is what I made for you mate and I think it's more efficient then the timer:-

pawn Код:
new sz_bSearchRestrict[ MAX_PLAYERS ]; // at top

#define SEARCH_TIME (300000) // 5 minutes put it at top

CMD:search( playerid, params[ ] )
{
    new szString[ 80 ];
    format( szString, sizeof( szString ), "Wait for %i seconds before using it again!", ( sz_bSearchRestrict[ playerid ] - GetTickCount( ) )/1000 );
    if(sz_bSearchRestrict[ playerid ] > GetTickCount( ) ) return SendClientMessage( playerid, -1, szString );
   
    new rand;
    rand = random( 5 );
    switch( rand )
    {
        case 0: SetPlayerHealth( playerid, 100 ), SendClientMessage( playerid, -1, "You got full health" );
        case 1: SetPlayerArmour( playerid, 100 ), SendClientMessage( playerid, -1, "You got full armour" );
        case 2: GivePlayerWeapon( playerid, 24, 500 ), SendClientMessage( playerid, -1, "You got weapon id 24" );
        case 3: GivePlayerWeapon( playerid, 30, 500 ), SendClientMessage( playerid, -1, "You got weapon id 30" );
        case 4: GivePlayerMoney( playerid, 500 ), SendClientMessage( playerid, -1, "You got cash $500" );
        case 5: GivePlayerMoney( playerid, 1000 ), SendClientMessage( playerid, -1, "You got cash $1000" );
    }
   
    sz_bSearchRestrict[ playerid ] = GetTickCount( ) + SEARCH_TIME;
    return 1;
}
And next to that we don't need "#pragma unused params" because ZCMD does NOT return any warning/error when we don't use the params!!

Hope this helps.

Regards,
FalconX
Reply
#5

Thank you SO SO SO SO SOOOOOOOOO much! =DDDD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)