Adding a time limit on /equip
#1

I just wanted to add a 1 minute wait between the time someone can use /equip in a HQ, here is my cmd

pawn Код:
if(strcmp(cmd, "/equip", true) == 0)
{
new playhq = PlayerInfo[playerid][pGang]-1;
if (PlayerToPoint(50, playerid,HQInfo[playhq][hqExitx], HQInfo[playhq][hqExity], HQInfo[playhq][hqExitz]))
{
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string), "* %s gets equipped", sendername);
ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
if ((HQInfo[playhq][hqGun1])||(HQInfo[playhq][hqGun2])||(HQInfo[playhq][hqGun3])||(HQInfo[playhq][hqGun4]) > 1)
{
GivePlayerWeapon(playerid,HQInfo[playhq][hqGun1],HQInfo[playhq][hqAmo1]);
GivePlayerWeapon(playerid,HQInfo[playhq][hqGun2],HQInfo[playhq][hqAmo2]);
GivePlayerWeapon(playerid,HQInfo[playhq][hqGun3],HQInfo[playhq][hqAmo3]);
GivePlayerWeapon(playerid,HQInfo[playhq][hqGun4],HQInfo[playhq][hqAmo4]);
GivePlayerWeapon(playerid,HQInfo[playhq][hqGun5],HQInfo[playhq][hqAmo5]);
}
if (HQInfo[playhq][hqHel] == 1)
{
SetPlayerHealth(playerid,100.0);
SendClientMessage(playerid, TEAM_GREEN_COLOR,"You have been healed to 100 health");
}
if (HQInfo[playhq][hqArm] == 1)
{
SetPlayerArmour(playerid,100.0);
SendClientMessage(playerid, TEAM_GREEN_COLOR,"You put on body armour");
}
format(string, sizeof(string), "You picked up some weapon's");
SendClientMessage(playerid, TEAM_GREEN_COLOR,string);
printf("%s", string);
return 1;
}
else
{
SendClientMessage(playerid, COLOR_GRAD2, "You are not in a gang HQ");
return 1;
}
}
If someone could kindly tell me how i can do this, that would be greatly appreciated
Reply
#2

use


https://sampwiki.blast.hk/wiki/SetTimer
Reply
#3

I tried adding this into my script but it doesn't seem to fit in appropriately. I am still learning how to script and try and learn as much as i can by trail and error but i cant seem to get this one right. So i was wondering if you or anyone could work out what i need to do in order for this to run with my script. Thanks again.
Reply
#4

Really easy one

set a variable

Код:
new wait;
within /equip do this at the top:

Код:
wait = 1;
then set a timer

Код:
SetTimer("mytimer", 60000, 0);
thats a 60 second timer

function

Код:
forward mytimer();
public mytimer(){
return wait=0;
}
then all you need is an if within your function

Код:
if(wait == 1){
cant do this
}
else{
your script
}
Reply
#5

Thanks for that, but i had a bit of trouble adding it into my cmd as seen below. I added the "new wait;" part but as of everything else was unsure where it all fits in, if you wouldn't mind putting it into this for me that would be awesome and much appreciated.

pawn Код:
if(strcmp(cmd, "/equip", true) == 0)
{
new playhq = PlayerInfo[playerid][pGang]-1;
if (PlayerToPoint(50, playerid,HQInfo[playhq][hqExitx], HQInfo[playhq][hqExity], HQInfo[playhq][hqExitz]))
{
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string), "* %s gets equipped", sendername);
ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
if ((HQInfo[playhq][hqGun1])||(HQInfo[playhq][hqGun2])||(HQInfo[playhq][hqGun3])||(HQInfo[playhq][hqGun4]) > 1)
{
GivePlayerWeapon(playerid,HQInfo[playhq][hqGun1],HQInfo[playhq][hqAmo1]);
GivePlayerWeapon(playerid,HQInfo[playhq][hqGun2],HQInfo[playhq][hqAmo2]);
GivePlayerWeapon(playerid,HQInfo[playhq][hqGun3],HQInfo[playhq][hqAmo3]);
GivePlayerWeapon(playerid,HQInfo[playhq][hqGun4],HQInfo[playhq][hqAmo4]);
GivePlayerWeapon(playerid,HQInfo[playhq][hqGun5],HQInfo[playhq][hqAmo5]);
}
if (HQInfo[playhq][hqHel] == 1)
{
SetPlayerHealth(playerid,100.0);
SendClientMessage(playerid, TEAM_GREEN_COLOR,"You have been healed to 100 health");
}
if (HQInfo[playhq][hqArm] == 1)
{
SetPlayerArmour(playerid,100.0);
SendClientMessage(playerid, TEAM_GREEN_COLOR,"You put on body armour");
}
format(string, sizeof(string), "You picked up some weapon's");
SendClientMessage(playerid, TEAM_GREEN_COLOR,string);
printf("%s", string);
return 1;
}
else
{
SendClientMessage(playerid, COLOR_GRAD2, "You are not in a gang HQ");
return 1;
}
}
Reply
#6

If someone could just quickly edit the pawn code for me, and add in the specific things i would greatly appreciate it.
Reply
#7

pawn Код:
if(strcmp(cmd, "/equip", true) == 0)
{

SetTimer("mytimer", 60000, 0);
if(wait[playerid] == 1){
//CANT DO THIS CODE HERE
}
else{
wait[playerid] = 1;
new playhq = PlayerInfo[playerid][pGang]-1;
if (PlayerToPoint(50, playerid,HQInfo[playhq][hqExitx], HQInfo[playhq][hqExity], HQInfo[playhq][hqExitz]))
{
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string), "* %s gets equipped", sendername);
ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
if ((HQInfo[playhq][hqGun1])||(HQInfo[playhq][hqGun2])||(HQInfo[playhq][hqGun3])||(HQInfo[playhq][hqGun4]) > 1)
{
GivePlayerWeapon(playerid,HQInfo[playhq][hqGun1],HQInfo[playhq][hqAmo1]);
GivePlayerWeapon(playerid,HQInfo[playhq][hqGun2],HQInfo[playhq][hqAmo2]);
GivePlayerWeapon(playerid,HQInfo[playhq][hqGun3],HQInfo[playhq][hqAmo3]);
GivePlayerWeapon(playerid,HQInfo[playhq][hqGun4],HQInfo[playhq][hqAmo4]);
GivePlayerWeapon(playerid,HQInfo[playhq][hqGun5],HQInfo[playhq][hqAmo5]);
}
if (HQInfo[playhq][hqHel] == 1)
{
SetPlayerHealth(playerid,100.0);
SendClientMessage(playerid, TEAM_GREEN_COLOR,"You have been healed to 100 health");
}
if (HQInfo[playhq][hqArm] == 1)
{
SetPlayerArmour(playerid,100.0);
SendClientMessage(playerid, TEAM_GREEN_COLOR,"You put on body armour");
}
format(string, sizeof(string), "You picked up some weapon's");
SendClientMessage(playerid, TEAM_GREEN_COLOR,string);
printf("%s", string);
return 1;
}
else
{
SendClientMessage(playerid, COLOR_GRAD2, "You are not in a gang HQ");
}
return 1;
}
}
create the function as shown in previous post outside all other functions

same with this line

Код:
new wait[MAX_PLAYERS];
Код:
forward mytimer(playerid);
public mytimer(playerid){
return wait[playerid]=0;
}
Reply
#8

Ok seems to work fine now, i tried adding in a cmd like "SendClientMessage(playerid, COLOR_RED, "You can only /equip once a minute" but doesn't do anything. Thanks for your help.
Reply
#9

you want that line here:

Код:
if(wait[playerid] == 1){
//CANT DO THIS CODE HERE (HERE)
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)