Timer / Command issue
#1

I've been sitting around trying to work on and really make a good drug system. I've only gotten around to crack so far, but it has all been going along nicely until now. My issue is that I have a system where if the player uses 6 grams of crack - they will overdose and need to get medical attention. I haven't fully implemented the EMS group, so the command I made to kill the timer and heal the player is healcrackoverdose. Well, the thing is that it's not working. I've tried timer ID 0, 1, and 2. It should be 0 as this was the first timer I've created in my entire script. Can someone tell me my issue?

Here is a good portion of all of the code I've made:

PHP код:
CMD:usecrack(playeridparams[])
{
    if(
UseDrugsTimer[playerid]) return SendClientMessage(playerid,COLOR_GREY,"You must wait 5 seconds!");
       if(
PlayerCrackStoned[playerid] >= 5)
    {
        
SendClientMessage(playeridCOLOR_RED"You have used too much crack; therefore you have overdosed!");
        
SendClientMessage(playeridCOLOR_RED"You must seek medical attention or you will die!");
        
SetTimerEx("Crackdeath"10000true"i"playerid);
    }
    if(
PlayerCrackStoned[playerid] >= 2)
    {
        
GameTextForPlayer(playerid"~w~You are~n~~p~Stoned"40001);
        
SetPlayerDrunkLevel(playerid15000);
        
SetPlayerWeather(playerid2009);
    }
    if(
PlayerDrugInfo[playerid][pCrack] >= 1)
    {
        new 
Float:armor;
        
GetPlayerArmour(playeridarmor);
        if(
armor 80) { SetPlayerArmour(playerid100.0); }
        else { 
SetPlayerArmour(playeridarmor 10.0); }
        
PlayerCrackStoned[playerid] += 1;
        
SendClientMessage(playeridCOLOR_BLUE"You have used a gram of crack!");
        
UseDrugsTimer[playerid] = 1PlayerDrugInfo[playerid][pCrack] -= 1;
        
SetTimerEx("UseDrugs",5*1000,0,"i",playerid);
        return 
1;
    }
    else
    {
        
SendClientMessage(playeridCOLOR_RED"You don't have any crack left!");
    }
    return 
1;
}
forward UseDrugs(playerid);
forward Crackdeath(playerid);
public 
UseDrugs(playerid)
{
    if(!
IsPlayerConnected(playerid)) return 0;
    if(
UseDrugsTimer[playerid])
    {
        
UseDrugsTimer[playerid] = 0;
    }
    return 
1;
}
public 
Crackdeath(playerid)
{
    new 
Float:hp;
    
GetPlayerHealth(playerid,hp);
    
SetPlayerHealth(playerid,hp-5);
}
CMD:healcrackoverdose(playeridparams[])
{
    
SetPlayerHealth(playerid100);
    
KillTimer();
    return 
1;

And then here is the rest:

PHP код:
new PlayerCrackStoned[MAX_PLAYERS];
new 
UseDrugsTimer[MAX_PLAYERS]; 
PHP код:
PlayerCrackStoned[playerid] = 0;
UseDrugsTimer[playerid] = 0
And then that right there I put under OnPlayerConnect.
Reply
#2

Does anyone know what's wrong with my code?
Reply
#3

Try this.
pawn Код:
new CrackDeathTimer[MAX_PLAYERS];
CMD:usecrack(playerid, params[])
{
    if(UseDrugsTimer[playerid]) return SendClientMessage(playerid,COLOR_GREY,"You must wait 5 seconds!");
       if(PlayerCrackStoned[playerid] >= 5)
    {
        SendClientMessage(playerid, COLOR_RED, "You have used too much crack; therefore you have overdosed!");
        SendClientMessage(playerid, COLOR_RED, "You must seek medical attention or you will die!");
        CrackDeathTimer[playerid] = SetTimerEx("Crackdeath", 10000, true, "i", playerid);
    }
    if(PlayerCrackStoned[playerid] >= 2)
    {
        GameTextForPlayer(playerid, "~w~You are~n~~p~Stoned", 4000, 1);
        SetPlayerDrunkLevel(playerid, 15000);
        SetPlayerWeather(playerid, 2009);
    }
    if(PlayerDrugInfo[playerid][pCrack] >= 1)
    {
        new Float:armor;
        GetPlayerArmour(playerid, armor);
        if(armor > 80) { SetPlayerArmour(playerid, 100.0); }
        else { SetPlayerArmour(playerid, armor + 10.0); }
        PlayerCrackStoned[playerid] += 1;
        SendClientMessage(playerid, COLOR_BLUE, "You have used a gram of crack!");
        UseDrugsTimer[playerid] = 1; PlayerDrugInfo[playerid][pCrack] -= 1;
        SetTimerEx("UseDrugs",5*1000,0,"i",playerid);
        return 1;
    }
    else
    {
        SendClientMessage(playerid, COLOR_RED, "You don't have any crack left!");
    }
    return 1;
}
forward UseDrugs(playerid);
forward Crackdeath(playerid);

public UseDrugs(playerid)
{
    if(!IsPlayerConnected(playerid)) return 0;
    if(UseDrugsTimer[playerid])
    {
        UseDrugsTimer[playerid] = 0;
    }
    return 1;
}

public Crackdeath(playerid)
{
    new Float:hp;
    GetPlayerHealth(playerid,hp);
    SetPlayerHealth(playerid,hp-5);
}

CMD:healcrackoverdose(playerid, params[])
{
    SetPlayerHealth(playerid, 100);
    KillTimer(CrackDeathTimer[playerid]);
    return 1;
}
Reply
#4

Quote:
Originally Posted by EiresJason
Посмотреть сообщение
Try this.
pawn Код:
new CrackDeathTimer[MAX_PLAYERS];
CMD:usecrack(playerid, params[])
{
    if(UseDrugsTimer[playerid]) return SendClientMessage(playerid,COLOR_GREY,"You must wait 5 seconds!");
       if(PlayerCrackStoned[playerid] >= 5)
    {
        SendClientMessage(playerid, COLOR_RED, "You have used too much crack; therefore you have overdosed!");
        SendClientMessage(playerid, COLOR_RED, "You must seek medical attention or you will die!");
        CrackDeathTimer[playerid] = SetTimerEx("Crackdeath", 10000, true, "i", playerid);
    }
    if(PlayerCrackStoned[playerid] >= 2)
    {
        GameTextForPlayer(playerid, "~w~You are~n~~p~Stoned", 4000, 1);
        SetPlayerDrunkLevel(playerid, 15000);
        SetPlayerWeather(playerid, 2009);
    }
    if(PlayerDrugInfo[playerid][pCrack] >= 1)
    {
        new Float:armor;
        GetPlayerArmour(playerid, armor);
        if(armor > 80) { SetPlayerArmour(playerid, 100.0); }
        else { SetPlayerArmour(playerid, armor + 10.0); }
        PlayerCrackStoned[playerid] += 1;
        SendClientMessage(playerid, COLOR_BLUE, "You have used a gram of crack!");
        UseDrugsTimer[playerid] = 1; PlayerDrugInfo[playerid][pCrack] -= 1;
        SetTimerEx("UseDrugs",5*1000,0,"i",playerid);
        return 1;
    }
    else
    {
        SendClientMessage(playerid, COLOR_RED, "You don't have any crack left!");
    }
    return 1;
}
forward UseDrugs(playerid);
forward Crackdeath(playerid);

public UseDrugs(playerid)
{
    if(!IsPlayerConnected(playerid)) return 0;
    if(UseDrugsTimer[playerid])
    {
        UseDrugsTimer[playerid] = 0;
    }
    return 1;
}

public Crackdeath(playerid)
{
    new Float:hp;
    GetPlayerHealth(playerid,hp);
    SetPlayerHealth(playerid,hp-5);
}

CMD:healcrackoverdose(playerid, params[])
{
    SetPlayerHealth(playerid, 100);
    KillTimer(CrackDeathTimer[playerid]);
    return 1;
}
Yeah, this worked. Thanks man!
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)