Put to a command a wait time before using again.
#1

Hi, im a newbie in scripting and i try to make a gamemode and i need help with a command: I will put a waiting time to the comand before using again... Please help me, here are the code:


PHP Code:
#include            <a_samp>
#include            <streamer>
#include            <sscanf2>
#include            <zcmd>
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_RED 0xAA3333AA
#define MAX_RANDOM_GIFTS 3
public OnFilterScriptInit()
{
    print(
"\n--------------------------------------");
    print(
"Gift system by Sllime is loaded.");
    print(
"--------------------------------------\n");
    return 
1;
}
stock RandomGift(playerid)
{
    new 
randomgift random(MAX_RANDOM_GIFTS) + 1;
    switch (
randomgift)
    {
        case 
1:
        {
            
GivePlayerMoney(playerid50000);
            
SendClientMessage(playeridCOLOR_YELLOW"You have won 50000$ enjoy!.");
        }
        case 
2:
        {
            
GivePlayerMoney(playerid10000);
            
SendClientMessage(playeridCOLOR_YELLOW"You have won 10000$ enjoy!.");
        }
        case 
3:
        {
            
SetPlayerArmour(playerid100);
            
SendClientMessage(playeridCOLOR_YELLOW"You have a vest enjoy!.");
        }
    }
    return 
1;
}
new 
Float:giftPos[4];
new 
giftboxobject;
new 
giftboxcreated 0;
new 
Text3D:giftbox3DText;
CMD:giftbox(playeridparams[])
{
    if(!
IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1"You are not an admin!");
    if (
isnull(params))
     {
         
SendClientMessage(playerid, -1"/giftbox [Option]");
        
SendClientMessage(playeridCOLOR_YELLOW"[OPTIONS]: place, destroy");
        return 
1;
    }
    static
        
Float:X,
        
Float:Y,
        
Float:Z,
        
Float:A;
    
GetPlayerPos(playeridXYZ);
    
GetPlayerFacingAngle(playeridA);
    if (!
strcmp(params"place"true))
    {
        if (
IsPlayerInAnyVehicle(playerid))
            return 
SendClientMessage(playeridCOLOR_RED"You must be outside vehicle first.");
        if(
giftboxcreated == 1) return SendClientMessage(playeridCOLOR_RED"Giftbox is already placed.");
            
giftPos[0] = X;
            
giftPos[1] = Y;
            
giftPos[2] = Z;
            
giftboxcreated 1;
            
giftboxobject CreateDynamicObject(19054XY0.40.00.0A);
            
giftbox3DText CreateDynamic3DTextLabel("/getgift\nTo get your gift.",0x10F441AA,XYZ+0.25,8.0);
            
SendClientMessage(playerid, -1"You have placed a giftbox");
            return 
1;
    }
    
    if (!
strcmp(params"destroy"true))
    {
     if(
giftboxcreated == 0) return SendClientMessage(playeridCOLOR_RED"Giftbox is not placed yet.");
            
DestroyDynamicObject(giftboxobject);
            
DestroyDynamic3DTextLabel(giftbox3DText);
            
giftboxcreated 0;
            
SendClientMessage(playerid, -1"You have destoryed the giftbox");
            return 
1;
    }
    return 
1;
}
CMD:getgift(playerid)
{
    if(!
IsPlayerConnected(playerid))
        return 
SendClientMessage(playerid, -1"You must be logged in to do this.");
    
GetObjectPos(giftboxobjectgiftPos[0], giftPos[1], giftPos[2]);
    
    if(
IsPlayerInRangeOfPoint(playerid5.0giftPos[0], giftPos[1], giftPos[2]) && giftboxcreated == 1)
    {
    
RandomGift(playerid);
    }
    return 
1;

Please put to the /getgift comand a wait time.... i can edit after these.... Thanks.
Reply
#2

I give you 3 methods :

PHP Code:
/*
    FIRST METHOD :
*/
new
    
timer_Waiting[MAX_PLAYERS];
    
CMD:wait(playeridparams[])
{
    if(
timer_Waiting[playerid] > 0)
        return 
SendClientMessage(playerid, -1"You can't use this command now.");
        
    
// Script of your commands
    
timer_Waiting[playerid] = 5// Wait 5 seconds after retype this command.
    
SetTimerEx("WaitingCommands"1000false"i"playerid); // Dйsincrement the variable all seconds of 1 value.
}
forward WaitingCommands(playerid);
public 
WaitingCommands(playerid)
{
    
timer_Waiting[playerid]--;
    return 
1;

PHP Code:
/*
    SECOND METHOD :
*/
new
    
bool:blockedCmds[MAX_PLAYERS];
CMD:wait(playeridparams[])
{
    if(
blockedCmds[playerid] == true)
        return 
SendClientMessage(playerid, -1"You can't use this command now.");
    
// Script of your commands
    
blockedCmds[playerid] = true// Turn the boolean variable to "true".
    
SetTimerEx("WaitingCommands"5000false"i"playerid); // In 5 seconds, we turn the boolean variable to "false"
}
forward WaitingCommands(playerid);
public 
WaitingCommands(playerid)
{
    
timer_Waiting[playerid] = false;
    return 
1;

PHP Code:
/*
    THIRTY METHOD :
*/
new
    
timer_Waiting[MAX_PLAYERS];
CMD:wait(playeridparams[])
{
    if(
timer_Waiting[playerid] < gettime()+5000)
        return 
SendClientMessage(playerid, -1"You can't use this command now.");
    
// Script of your commands
    
timer_Waiting[playerid] = gettime(); // Save the actual time and check if "5s" was ecouled

Reply
#3

Quote:
Originally Posted by YouServ
View Post
I give you 3 methods :

PHP Code:
/*
    FIRST METHOD :
*/
new
    
timer_Waiting[MAX_PLAYERS];
    
CMD:wait(playeridparams[])
{
    if(
timer_Waiting[playerid] > 0)
        return 
SendClientMessage(playerid, -1"You can't use this command now.");
        
    
// Script of your commands
    
timer_Waiting[playerid] = 5// Wait 5 seconds after retype this command.
    
SetTimerEx("WaitingCommands"1000false"i"playerid); // Dйsincrement the variable all seconds of 1 value.
}
forward WaitingCommands(playerid);
public 
WaitingCommands(playerid)
{
    
timer_Waiting[playerid]--;
    return 
1;

PHP Code:
/*
    SECOND METHOD :
*/
new
    
bool:blockedCmds[MAX_PLAYERS];
CMD:wait(playeridparams[])
{
    if(
blockedCmds[playerid] == true)
        return 
SendClientMessage(playerid, -1"You can't use this command now.");
    
// Script of your commands
    
blockedCmds[playerid] = true// Turn the boolean variable to "true".
    
SetTimerEx("WaitingCommands"5000false"i"playerid); // In 5 seconds, we turn the boolean variable to "false"
}
forward WaitingCommands(playerid);
public 
WaitingCommands(playerid)
{
    
timer_Waiting[playerid] = false;
    return 
1;

PHP Code:
/*
    THIRTY METHOD :
*/
new
    
timer_Waiting[MAX_PLAYERS];
CMD:wait(playeridparams[])
{
    if(
timer_Waiting[playerid] < gettime()+5000)
        return 
SendClientMessage(playerid, -1"You can't use this command now.");
    
// Script of your commands
    
timer_Waiting[playerid] = gettime(); // Save the actual time and check if "5s" was ecouled

So its good?: Do not forget'm new in scripting!
PHP Code:
 #include            <a_samp> 
#include            <streamer> 
#include            <sscanf2> 
#include            <zcmd> 
#define COLOR_YELLOW 0xFFFF00AA 
#define COLOR_RED 0xAA3333AA 
#define MAX_RANDOM_GIFTS 3 
public OnFilterScriptInit() 

    print(
"\n--------------------------------------"); 
    print(
"Gift system by Sllime is loaded."); 
    print(
"--------------------------------------\n"); 
    return 
1

stock RandomGift(playerid

    new 
randomgift random(MAX_RANDOM_GIFTS) + 1
    switch (
randomgift
    { 
        case 
1
        { 
            
GivePlayerMoney(playerid50000); 
            
SendClientMessage(playeridCOLOR_YELLOW"You have won 50000$ enjoy!."); 
        } 
        case 
2
        { 
            
GivePlayerMoney(playerid10000); 
            
SendClientMessage(playeridCOLOR_YELLOW"You have won 10000$ enjoy!."); 
        } 
        case 
3
        { 
            
SetPlayerArmour(playerid100); 
            
SendClientMessage(playeridCOLOR_YELLOW"You have a vest enjoy!."); 
        } 
    } 
    return 
1

new 
Float:giftPos[4]; 
new 
giftboxobject
new 
giftboxcreated 0
new 
Text3D:giftbox3DText
CMD:giftbox(playeridparams[]) 

    if(!
IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1"You are not an admin!"); 
    if (
isnull(params)) 
     { 
         
SendClientMessage(playerid, -1"/giftbox [Option]"); 
        
SendClientMessage(playeridCOLOR_YELLOW"[OPTIONS]: place, destroy"); 
        return 
1
    } 
    static 
        
Float:X
        
Float:Y
        
Float:Z
        
Float:A
    
GetPlayerPos(playeridXYZ); 
    
GetPlayerFacingAngle(playeridA); 
    if (!
strcmp(params"place"true)) 
    { 
        if (
IsPlayerInAnyVehicle(playerid)) 
            return 
SendClientMessage(playeridCOLOR_RED"You must be outside vehicle first."); 
        if(
giftboxcreated == 1) return SendClientMessage(playeridCOLOR_RED"Giftbox is already placed."); 
            
giftPos[0] = X
            
giftPos[1] = Y
            
giftPos[2] = Z
            
giftboxcreated 1
            
giftboxobject CreateDynamicObject(19054XY0.40.00.0A); 
            
giftbox3DText CreateDynamic3DTextLabel("/getgift\nTo get your gift.",0x10F441AA,XYZ+0.25,8.0); 
            
SendClientMessage(playerid, -1"You have placed a giftbox"); 
            return 
1
    } 
     
    if (!
strcmp(params"destroy"true)) 
    { 
     if(
giftboxcreated == 0) return SendClientMessage(playeridCOLOR_RED"Giftbox is not placed yet."); 
            
DestroyDynamicObject(giftboxobject); 
            
DestroyDynamic3DTextLabel(giftbox3DText); 
            
giftboxcreated 0
            
SendClientMessage(playerid, -1"You have destoryed the giftbox"); 
            return 
1
    } 
    return 
1

CMD:getgift(playerid

        if(
timer_Waiting[playerid] > 0
            return 
SendClientMessage(playerid, -1"You can't use this command now."); 
        
// Script of your commands 
        
timer_Waiting[playerid] = 5// Wait 5 seconds after retype this command. 
         
SetTimerEx("WaitingCommands"1000false"i"playerid); // Dйsincrement the variable all seconds of 1 value. 
        //My content... 
        
if(!IsPlayerConnected(playerid)) 
        return 
SendClientMessage(playerid, -1"You must be logged in to do this."); 
        
GetObjectPos(giftboxobjectgiftPos[0], giftPos[1], giftPos[2]); 
        if(
IsPlayerInRangeOfPoint(playerid5.0giftPos[0], giftPos[1], giftPos[2]) && giftboxcreated == 1
        { 
        
RandomGift(playerid); 
        } 

forward WaitingCommands(playerid); 
public 
WaitingCommands(playerid

        
timer_Waiting[playerid]--; 
        return 
1

Reply
#4

You could actually not use timers and just do:
PHP Code:
if(gettime() < timer_Waiting[playerid])
// and then
timer_Waiting[playerid] = gettime() + seconds// Replace seconds with whatever. 
Reply
#5

Yeah your version is good. The player need to wait 5 seconds to re-type the commands /getgift.
Reply
#6

Quote:
Originally Posted by YouServ
View Post
Yeah your version is good. The player need to wait 5 seconds to re-type the commands /getgift.
Ok i maked the system to work, but this error occurs:
PHP Code:
getgift.TPM(133) : warning 209: function "cmd_getgift" should return a value 
It's compiling and go until the end, it makes the .amx file, it is important to fix the error?
Thanks for helping me.
Reply
#7

Before the end of the curley brace place return 1; that'll fix your error.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)