CMD:use(playerid, params[])
{
new string[128];
if(sscanf(params, "s[8]", params))
{
SendClientMessage(playerid, COLOR_WHITE, "[Usage]: /use [type]");
SendClientMessage(playerid, COLOR_GREY, "TYPES: Cigar | cocaine");
return 1;
}
if(IsPlayerCuffed(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You can't do this right now.");
if(!strcmp(params, "cigar", true))
{
if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You can't do this right now.");
if(!PlayerInfo[playerid][pCigar]) return SendClientMessage(playerid, COLOR_GREY, "You don't have any cigarettes on you.");
new Float:H;
SetPlayerSpecialAction(playerid, SPECIAL_ACTION_SMOKE_CIGGY);
SetPlayerHealth(playerid, H+5);
GetPlayerHealth(playerid, H);
if(H > 100) SetPlayerHealth(playerid, 100);
PlayerInfo[playerid][pCigar] --;
format(string, sizeof(string), "* %s takes out a cigarette and lights it up.", RPN(playerid));
SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
SetTimerEx("Regenation",10000,false,"dd",playerid,1);
}
forward Regernation(playerid,times);
public Regernation(playerid,times)
{
if(times)
{
new Float:Health;
GetPlayerHealth(playerid, Health);
if(Health > 100) SetPlayerHealth(playerid, 98.0);
else SetPlayerHealth(playerid, Health - 2.0);
SetTimerEx("Regenation",2000,false,"dd",playerid,1);
}
return 1;
}
SetPlayerHealth(playerid, H+5);
GetPlayerHealth(playerid, H);
Make a timer that repeats every minute and check if they have used the command. If they have then do:
new Float: HP GetPlayerHealth(playerid, HP); SetPlayerHealth(playerid, HP-1); ... To take one HP away... |
If you are using something like SmokeCommand[playerid] = 1 it would be...
CMD ![]() { if(SmokeCommand[playerid] == 0) return SendClientMessage(playerid, -1, "You're not even smoking..."); SmokeCommand[playerid] = 0; SendClientMessage(playerid, -1, "You have stopped smoking."); return 1; } Then stop the timer. |
SetTimerEx("Timer",60000,1,"i",playerid);
forward Timer(playerid); // Tell the server that "Timer" is a public function
public Timer(playerid)
{
new Float:hp; // Create a float value where we will store the players HP
GetPlayerHealth(playerid,hp); // Get players health and store it inside "hp"
SetPlayerHealth(playerid,hp-1); // Set Players health to their current health (hp) minus 1
}