Cooldown Timer for Garage CMD
#1

Hi, I'm trying to script a garage and i want to create a cooldown timer for the command. If anyone could please help, I'd appreciate it. Note: I am fairly new to scripting and only use scripting for mapping.

Here is the garage code:
Код:
CMD:garage(playerid, params[])
{
new Float: x, Float: y, Float: z;
GetDynamicObjectPos(H148Gate, x, y, z);
if(IsPlayerInRangeOfPoint(playerid, 30, x, y, z))
{
if(H148GarageWait == 1)
{
SetTimerEx("H148GarageWait", 2500, false, "i", playerid);
{
switch(H148GarageOpen)
{
case 0:
{
H148GarageOpen = 1;
new string[128];
format(string, sizeof(string), "* %s uses their remote to open the garage.", GetName(playerid));
NearByMessage(playerid, 0x9A2EFEFF, string);
MoveDynamicObject(H148Garage, 1656.53455, 2575.88188, 12.24580, 0.5, 0.00000, -90.00000, 90.00000);
MoveDynamicObject(H148GarageCol1, 1657.35132, 2576.01870, 12.25530, 0.5, 0.00000, -90.00000, 90.00000);
MoveDynamicObject(H148GarageCol2, 1655.71033, 2576.01870, 12.25530, 0.5, 0.00000, -90.00000, 90.00000);
H148GarageSound1(playerid);
}
case 1:
{
H148GarageOpen = 0;
new string[128];
format(string, sizeof(string), "* %s uses their remote to close the garage.", GetName(playerid));
NearByMessage(playerid, 0x9A2EFEFF, string);
MoveDynamicObject(H148Garage, 1656.53455, 2576.24587, 11.12580, 0.5, 0.00000, 0.00000, 90.00000);
MoveDynamicObject(H148GarageCol1, 1657.35132, 2576.29858, 11.61530, 0.5, 0.00000, 0.00000, 90.00000);
MoveDynamicObject(H148GarageCol2, 1655.71033, 2576.29858, 11.61530, 0.5, 0.00000, 0.00000, 90.00000);
H148GarageSound1(playerid);
}
}
}
}
}
return 1;
}

forward H148GarageSound1(playerid);
public H148GarageSound1(playerid)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInRangeOfPoint(i, 30, 1656.4711, 2576.2517, 10.8535))
{
PlayerPlaySound(i, 1153, 1656.4711, 2576.2517, 10.8535);
SetTimerEx("H148GarageSound2", 2000, false, "i", playerid);
}
}
}

forward H148GarageSound2(playerid);
public H148GarageSound2(playerid)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInRangeOfPoint(i, 30, 1656.4711, 2576.2517, 10.8535))
{
PlayerPlaySound(i, 1154, 1656.4711, 2576.2517, 10.8535);
}
}
}
Reply
#2

pawn Код:
//At your global variables
new HasPlayerUserGarageCommand[MAX_PLAYERS];

//Under OnPlayerConnect
HasPlayerUserGarageCommand[MAX_PLAYERS] = 0;

//When the played uses the command
if(HasPlayerUserGarageCommand[playerid] == 0)
{
    HasPlayerUserGarageCommand[playerid] = 1;
    SetTimerEx("GarageCommandCooldown", YourTimerInMilliseconds, false, "i", playerid);
    //Garage stuff here
}
else return SendClientMessage(playerid, PutYourOwnColourHere, "Put your message here");

//Somewhere in your script
forward GarageCommandCooldown(playerid);
public GarageCommandCooldown(playerid)
{
    HasPlayerUserGarageCommand[playerid] = 0;
    return 1;
}
Just edit "YourTimerInMilliseconds", "PutYourOwnColourHere" and "Put your message here" to your own stuff..
Reply
#3

Quote:
Originally Posted by [NWA]Hannes
Посмотреть сообщение
pawn Код:
//At your global variables
new HasPlayerUserGarageCommand[MAX_PLAYERS];

//Under OnPlayerConnect
HasPlayerUserGarageCommand[MAX_PLAYERS] = 0;

//When the played uses the command
if(HasPlayerUserGarageCommand[playerid] == 0)
{
    HasPlayerUserGarageCommand[playerid] = 1;
    SetTimerEx("GarageCommandCooldown", YourTimerInMilliseconds, false, "i", playerid);
    //Garage stuff here
}
else return SendClientMessage(playerid, PutYourOwnColourHere, "Put your message here");

//Somewhere in your script
forward GarageCommandCooldown(playerid);
public GarageCommandCooldown(playerid)
{
    HasPlayerUserGarageCommand[playerid] = 0;
    return 1;
}
Just edit "YourTimerInMilliseconds", "PutYourOwnColourHere" and "Put your message here" to your own stuff..
I don't understand what's the HasPlayerUserGarageCommand is for.
Reply
#4

Quote:
Originally Posted by Robert515
Посмотреть сообщение
I don't understand what's the HasPlayerUserGarageCommand is for.
It's just a name for the variable, set it to 1 when the player uses the command to indicate that the player has used the command through the variable, thus the player will not be able to use the command again until you've set the variable to 0 which I've made an example of in my timer.
Reply
#5

So I did as you said and got this.
Код:
House.pwn(722) : error 032: array index out of bounds (variable "H148GarageCool")
House.pwn(1020) : error 001: expected token: ";", but found "forward"
House.pwn(1138) : warning 215: expression has no effect
House.pwn(1138) : error 001: expected token: ";", but found ")"
House.pwn(1138) : error 029: invalid expression, assumed zero
House.pwn(1167) : error 029: invalid expression, assumed zero
House.pwn(1167) : warning 215: expression has no effect
House.pwn(1167) : error 001: expected token: ";", but found "return"
House.pwn(1173) : error 021: symbol already defined: "H148GarageCool"
House.pwn(1174) : error 021: symbol already defined: "H148GarageCool"
House.pwn(1177) : error 010: invalid function or declaration
Reply
#6

Show me these lines of code
Reply
#7

ok so i managed to shorten it down a bit.
Код:
House.pwn(722) : error 032: array index out of bounds (variable "HasPlayerUserGarageCommand")
House.pwn(1145) : error 002: only a single statement (or expression) can follow each "case"
House.pwn(1145) : error 017: undefined symbol "string"
House.pwn(1145) : warning 215: expression has no effect
House.pwn(1145) : error 001: expected token: ";", but found "]"
House.pwn(1145) : fatal error 107: too many error messages on one line
Line 722, this is under OnPlayerConnect:
Код:
HasPlayerUserGarageCommand[MAX_PLAYERS] = 0;
Line 1145:
Код:
new string[128];
This is the code:
Код:
CMD:garage(playerid, params[])
{
new Float: x, Float: y, Float: z;
GetDynamicObjectPos(H148Gate, x, y, z);
if(IsPlayerInRangeOfPoint(playerid, 30, x, y, z))
{
if(HasPlayerUserGarageCommand[playerid] == 0)
{
HasPlayerUserGarageCommand[playerid] = 1;
SetTimerEx("GarageCommandCooldown", 2500, false, "i", playerid);
{
switch(H148GarageOpen)
{
case 0:
H148GarageOpen = 1;
new string[128];
format(string, sizeof(string), "* %s uses their remote to open the garage.", GetName(playerid));
NearByMessage(playerid, 0x9A2EFEFF, string);
MoveDynamicObject(H148Garage, 1656.53455, 2575.88188, 12.24580, 0.5, 0.00000, -90.00000, 90.00000);
MoveDynamicObject(H148GarageCol1, 1657.35132, 2576.01870, 12.25530, 0.5, 0.00000, -90.00000, 90.00000);
MoveDynamicObject(H148GarageCol2, 1655.71033, 2576.01870, 12.25530, 0.5, 0.00000, -90.00000, 90.00000);
H148GarageSound1(playerid);
}
case 1:
{
H148GarageOpen = 0;
new string[128];
format(string, sizeof(string), "* %s uses their remote to close the garage.", GetName(playerid));
NearByMessage(playerid, 0x9A2EFEFF, string);
MoveDynamicObject(H148Garage, 1656.53455, 2576.24587, 11.12580, 0.5, 0.00000, 0.00000, 90.00000);
MoveDynamicObject(H148GarageCol1, 1657.35132, 2576.29858, 11.61530, 0.5, 0.00000, 0.00000, 90.00000);
MoveDynamicObject(H148GarageCol2, 1655.71033, 2576.29858, 11.61530, 0.5, 0.00000, 0.00000, 90.00000);
H148GarageSound1(playerid);
}
}
}
}
else return SendClientMessage(playerid, -1, "The garage is already moving. Wait to open/close it again.");
}
return 1;
}

forward GarageCommandCooldown(playerid);
public GarageCommandCooldown(playerid)
{
    HasPlayerUserGarageCommand[playerid] = 0;
    return 1;
}
Reply
#8

pawn Код:
//Under OnPlayerConnect
HasPlayerUserGarageCommand[playerid] = 0;
Reply
#9

Quote:
Originally Posted by IceBilizard
Посмотреть сообщение
pawn Код:
//Under OnPlayerConnect
HasPlayerUserGarageCommand[playerid] = 0;
i still get that line 1145 errors
Reply
#10

post your 1145 line
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)