My small drug system gets timer error :/
#1

Hey, Im a newb with timers, just look at this, how to kill the regernation timer after you have full health?

/takedrugs cmd:
Код:
if (strcmp("/takedrugs",cmdtext,true)==0)
{
  if(pInfo[playerid][HasDrugs] == 0)
  {
    SendClientMessage(playerid, 0xFF0000AA, "Error: You don't have any drugs to take!");
  }
  else
  {
    SetTimer("Regernation",5000,true);
    SendClientMessage(playerid, 0xFFFF00AA, "You took the drugs! You will regernate health every 10 seconds!");
    pInfo[playerid][HasDrugs] = 0;
    SetPlayerDrunkLevel(playerid, 1000);
  }
  return 1;
}
Regernation function:

Код:
forward Regernation(playerid);
public Regernation(playerid)
{
  new Float:Health;
  GetPlayerHealth(playerid, Health);

  SetPlayerHealth(playerid, Health + 10.0);
  
  if(Health >= 100)
  {
    pInfo[playerid][OnDrugs] = 0;
    SetPlayerDrunkLevel(playerid, 0);
    SendClientMessage(playerid, 0xFFFF00AA, "You are now not on drugs anymore!");
    KillTimer("Regernation");
  }
  return 1;
}
Reply
#2

u need to add a timer to check the heal

and a constant if(weedreg[playerid] == 1) by exempl

public CheckHealth(playerid)
{
new Float:health;
GetPlayerHealth(playerid,health);

if(health ==100)
{
if(weedreg[playerid] == 1)
{
SendClientMessage(playerid,COLOR_RED,"You are revive");
KillTimer("Regernation");
}
Reply
#3

and add weedreg[playerid] == 1 in yr timer regernation
Reply
#4

Like this?

Take drugs command:
Код:
if (strcmp("/takedrugs",cmdtext,true)==0)
{
  if(pInfo[playerid][HasDrugs] == 0)
  {
    SendClientMessage(playerid, 0xFF0000AA, "Error: You don't have any drugs to take!");
  }
  else
  {
    SetTimer("Regernation",5000,true);
    pInfo[playerid][Reg] = 1;
    pInfo[playerid][HasDrugs] = 0;
    SendClientMessage(playerid, 0xFFFF00AA, "You took the drugs! You will regernate health every 10 seconds!");
    SetPlayerDrunkLevel(playerid, 1000);
  }
  return 1;
}
Regernation function:
Код:
forward Regernation(playerid);
public Regernation(playerid)
{
  new Float:Health;
  GetPlayerHealth(playerid, Health);

  SetPlayerHealth(playerid, Health + 10.0);
  
  if(pInfo[playerid][Reg] == 1)
  {
    SetTimer("HealthCheck", 100, true);
  }
  return 1;
}
HealthCheck function:
Код:
forward HealthCheck(playerid);
public HealthCheck(playerid)
{
  new Float:Health;
  GetPlayerHealth(playerid, Health);
  
  if(Health >= 100 && pInfo[playerid][Reg] == 1)
  {
    pInfo[playerid][OnDrugs] = 0;
    pInfo[playerid][Reg] = 0;
    SetPlayerDrunkLevel(playerid, 0);
    SendClientMessage(playerid, 0xFFFF00AA, "You are now not on drugs anymore!");
  }
  return 1;
}
Reply
#5

no try
Код:
under gamemodeinit 
	SetTimerEx("CheckHealth",100,1,"d",playerid);


if (strcmp("/takedrugs",cmdtext,true)==0)
{
if(pInfo[playerid][HasDrugs] == 0)
{
SendClientMessage(playerid, 0xFF0000AA, "Error: You don't have any drugs to take!");
}
else
{
SetTimer("Regernation",5000,true);
SendClientMessage(playerid, 0xFFFF00AA, "You took the drugs! You will regernate health every 10 seconds!");
pInfo[playerid][HasDrugs] = 0;
SetPlayerDrunkLevel(playerid, 1000);
}
return 1;
}

forward Regernation(playerid);
public Regernation(playerid)
{
new Float:Health;
GetPlayerHealth(playerid, Health);

SetPlayerHealth(playerid, Health + 10.0);
weedreg[playerid] = 1;

return 1;
}
forward CheckHealth(playerid);
public CheckHealth(playerid)
{
public CheckHealth(playerid)
{
new Float:health;
GetPlayerHealth(playerid,health);

if(health ==100)
{
if(weedreg[playerid] == 1)
{
pInfo[playerid][OnDrugs] = 0;
SetPlayerDrunkLevel(playerid, 0);
SendClientMessage(playerid, 0xFFFF00AA, "You are now not on drugs anymore!");
KillTimer("Regernation");
weedreg[playerid] = 0;
}
return 1;
}
Reply
#6

but maybe yr will work too
mine work because i use it lol and its tested

but use pInfo[playerid][Reg]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)