why this timer keeps repeating itselfs?
#1

hey guys,
i have this timer that when a player does /deal when he is in a infernus then there gets a random deal started..
and that works fine but now i have that when a player exits the vehicle he has 20 seconds to enter his car again before he loses his job...
but when i exit it and enter it again the timer isnt stopping... but it should stop...
and when i exit the infernus again the timer starts again from 20 to 0...
and then when the timer has reached 0 he should just say 1 time: you lost your job; and he loses 2k...
but he is repeating that msg and i keep losing money...
i just want that when i exit the vehicle that the timer starts and thwne it reached 0 that i just lose 1 time 2k and it says the msg once...

can anyone tell me whats wrong in this code?:

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(GetVehicleModel(GetPlayerVehicleID(playerid)) == infernus)
    {
        if( DealEnable[ playerid ] == 1 )
        {
            KillTimer(StopDealt[playerid]);
        }
    }
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(GetVehicleModel(GetPlayerVehicleID(playerid)) == infernus)
    {
        if( DealEnable[ playerid ] == 1 )
        {
        StopDealCount[playerid] = 20; //how many seconds it should take (15 or 20)
        StopDealt[playerid] = SetTimerEx("StopDeal", 1000, 1, "d", playerid); //1 second timer
        SendClientMessage(playerid, COLOR_RED, "Go back in your car!, else you will lose your Job!!");
        StopAudioStreamForPlayer(playerid);
        }
    }
    StopAudioStreamForPlayer(playerid);
    return 1;
}
public StopDeal(playerid)
{
    if(StopDealCount[playerid] == 0)
    {
        SetPlayerWantedLevel(playerid, 0);
        DealEnable[ playerid ] = 0;
        KillTimer(StopDealt[playerid]);
        GivePlayerMoney(playerid, -2000);
        SendClientMessage(playerid, COLOR_BLUE, "you Lost your Job!");
        SendClientMessage(playerid, COLOR_BLUE, "you Lost your Job!");
        SendClientMessage(playerid, COLOR_BLUE, "you Lost your Job!");
        SendClientMessage(playerid, COLOR_ORANGE, "you lost $2000 because you quited your Job");
    }
    else
    {
        StopDealCount[playerid] --;
        new string[128];
        format(string, sizeof(string), "~g~Time left: ~r~%i", StopDealCount[playerid]);
        GameTextForPlayer(playerid, string,4000,3);
    }
    return 1;
}
my /deal cmd and stopdeal cmd(stopdeal cmd works fine:
pawn Код:
CMD:deal(playerid, params[])
{
    new pick = random(sizeof(Jobs));
    if(GetVehicleModel(GetPlayerVehicleID(playerid)) == infernus)
    {
        DealEnable[ playerid ] = 1;
        SetPlayerCheckpoint(playerid, Jobs[pick][xPos], Jobs[pick][yPos], Jobs[pick][zPos], 7.0);
        new string[128], pName[MAX_PLAYER_NAME];
        GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
        format(string, sizeof(string), "{FF0000}Player %s is now Hauling %s",pName, Jobs[pick][Name]);
        SendClientMessageToAll(playerid, string); // the first parameter is the color not the playerid, but that doesnt matter if you set a color in the text with "{}"
        new string1[128];
        format(string1, sizeof(string1), "Now go to the {FF0000}%s {00FF00}Deal Meeting",Jobs[pick][Name]);
        SendClientMessage(playerid, COLOR_GREEN, string1);
        SetPlayerWantedLevel(playerid, 3);
        new string2[128];
        format(string2, sizeof(string2), "Watch out for the Cops!!, your Hauling {FF0000}%s", Jobs[pick][Name]);
        SendClientMessage(playerid, COLOR_GREEN, string2);
        return 1;
    }
    SendClientMessage(playerid, COLOR_RED, "you can only use /deal when you are in a infernus");
    return 1;
}
CMD:stopdeal(playerid, params[])
{
    SetPlayerWantedLevel(playerid, 0);
    DealEnable[ playerid ] = 0;
    SendClientMessage(playerid, COLOR_RED, "you quited your Job!");
    SendClientMessage(playerid, COLOR_ORANGE, "you lost $2000 because you quited your Job");
    GivePlayerMoney(playerid, -2000);
    return 1;
}
and my NEW:
pawn Код:
new DealEnable[ MAX_PLAYERS ];
new StopDealCount[MAX_PLAYERS];
new StopDealt[MAX_PLAYERS]; //the timer for each player
pawn Код:
enum Deals
{
    Name[50],
    Float:xPos,
    Float:yPos,
    Float:zPos
}
new RandomMoney[] =
{
    5000,
    3900,
    8900,
    7600,
    6758,
    4589,
    3000,
    4000,
    1999,
    1500,
    4500,
    3400,
    5600
};
stock const Jobs[][Deals] =
{
    { "Drugs", 253.5252,2915.4497,3.6876  },
    { "Weapons", -1436.7029,15.5975,6.0000 },
    { "Whores", 2310.8088,1787.8976,10.8203 },
    { "Cars", 1789.8225,-1695.8379,13.4898 },
    { "Trucks", 2867.6177,2576.0308,10.8203},
    { "Weed", -1110.8634,-1621.4261,76.3672 },
    { "Tropical Wood", -1967.7827,-2435.0137,30.6250 },
    { "Boats", -2432.1255,2294.9141,4.9844 }
};
pawn Код:
forward Deal(playerid);
forward StopDeal(playerid);
AND PLS DO NOT USE THIS AS YOUR OWN(except if you send me a PM and say you gonna use it with my credits)

pls help with this

greets niels
Reply
#2

You should use OnPlayerStateChange.
Reply
#3

but will that fix the problem?

EDIT: yeah it works XD lol never thought that would fix it but yeah it fixed the problem so THNX man REP+ XD

EDIT2: lol someway i can't give u another rep... XD anyway THNX
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)