Sup? Help me out! - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Sup? Help me out! (
/showthread.php?tid=647595)
Sup? Help me out! -
BluePlayBG - 07.01.2018
Код:
CMD:takejob(playerid, params[])
{
static
id = -1;
if ((id = Job_Nearest(playerid)) != -1)
{
if (PlayerData[playerid][pJob] == JobData[id][jobType])
return SendErrorMessage(playerid, "You have this job already.");
PlayerData[playerid][pJob] = JobData[id][jobType];
return SendServerMessage(playerid, "You are now a %s - type \"/jobcmds\" for job commands.", Job_GetName(JobData[id][jobType]));
}
SendErrorMessage(playerid, "You are not in range of any job pickup.");
return 1;
}
How to make it usable every hour?
Re: Sup? Help me out! -
RowdyrideR - 07.01.2018
So a player needs an hour cool down between taking two different jobs?
Re: Sup? Help me out! -
BluePlayBG - 07.01.2018
Yep.
Re: Sup? Help me out! -
RowdyrideR - 07.01.2018
Use something like new bool:CoolDown[MAX_PLAYERS];
When someone uses the command set it to true and run a timer for the player and when that hour is done (timer) set the player’s CoolDown to false.
And dont forget to add in the command “if(CoolDown[playerid] == false)” let the command work, or else tell him to wait an hour.
Let me know if you need the exact code.
Re: Sup? Help me out! -
BluePlayBG - 07.01.2018
Can you send me the exact code please? Really appreciate it.
Re: Sup? Help me out! -
shourya - 07.01.2018
try this
PHP код:
new CoolDown[MAX_PLAYERS],
CoolDownTimer[MAX_PLAYERS];
CMD:takejob(playerid, params[])
{
static
id = -1;
if(CoolDown[playerid])
return SendClientMessage(playerid, color, "your message here because 1hr is not done");
if ((id = Job_Nearest(playerid)) != -1)
{
if (PlayerData[playerid][pJob] == JobData[id][jobType])
return SendErrorMessage(playerid, "You have this job already.");
PlayerData[playerid][pJob] = JobData[id][jobType];
CoolDown[playerid] = 60;
CoolDownTimer[playerid] = SetTimerEx("CheckCoolDown",60000,true,"i",playerid);
return SendServerMessage(playerid, "You are now a %s - type \"/jobcmds\" for job commands.", Job_GetName(JobData[id][jobType]));
}
SendErrorMessage(playerid, "You are not in range of any job pickup.");
return 1;
}
forward CheckCoolDown(playerid);
public CheckCoolDown(playerid)
{
if(CoolDown[playerid] != 0)
{
CoolDown[playerid]--;
}
else
{
KillTimer(CoolDownTimer[playerid]);
CoolDown[playerid] = 0;
}
}
Re: Sup? Help me out! -
RowdyrideR - 07.01.2018
On top of your script:
Код:
new bool:CoolDown[MAX_PLAYERS];
The command:
Код:
CMD:takejob(playerid, params[])
{
if(CoolDown[playerid] == true) return SendClientMessage(playerid,RED, " You have to wait an hour between jobs");
static
id = -1;
if ((id = Job_Nearest(playerid)) != -1)
{
if (PlayerData[playerid][pJob] == JobData[id][jobType])
return SendErrorMessage(playerid, "You have this job already.");
PlayerData[playerid][pJob] = JobData[id][jobType];
SetTimerEx("JobCoolDown",60*60000,false,"i",playerid);
CoolDown[playerid]=true;
return SendServerMessage(playerid, "You are now a %s - type \"/jobcmds\" for job commands.", Job_GetName(JobData[id][jobType]));
}
SendErrorMessage(playerid, "You are not in range of any job pickup.");
return 1;
}
anywhere in your script:
Код:
forward JobCoolDown(playerid);
public JobCoolDown(playerid)
{
CoolDown[playerid]=false;
}
I still believe there's some errors with the cmd itself, But you didnt complain so yea.
Re: Sup? Help me out! -
BluePlayBG - 07.01.2018
Thanks so much guys. +rep !