y_timers don't stop
#1

Well, I've searched and searched and found no solution yet, so I decided to post here.
My problem is basically I can't stop a timer. It gives me no errors and no warnings, it simply doesn't stop. It's used for 2 things and in 2 different situations, 1st it's used when a player enters the vehicle as driver and the other is started when a mechanic is fixing it, they don't start at same time never. The problem is that it doesn't stop, when he exits or when he stops fixing and when I enter another car it just do both (well it's just for updating textdraws for velocity and kilometers and other shits, so when I exit it and enter another vehicle the textdraws updates overlap. I've added a debug line to the timer to be sure if it would stop and found out it wouldn't...)

So can please someone tell me if I'm doing something wrong or what I can do to fix this?

The code is too damn long so I won't post it all here, but the main things are there:

pawn Код:
new Timer:VU[MAX_VEHICLES];

timer VehiclesU[500](vid, playerid)
{
    if(!PlayInfo[playerid][Fixing])
    {
        new Float:sx, Float:sy, Float:sz, Float:speed1, Float:speed2, speedo[40], kms[100], TW[100], oil[100], fuel[100], engine, lights, alarm, doors, bonnet, boot, objective;
        GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective);
        //engine
        if(VehInfo[vid][StartEng] >= 1)
        {
            if(VehInfo[vid][StartEng] < 4)
                VehInfo[vid][StartEng]++;
            else
            {
                SendClientMessage(playerid, X11_GREEN_4, "[INFO]: Engine Started.");
                VehInfo[vid][StartEng] = 0;
                SetVehicleParamsEx(vid, 1, lights, alarm, doors, bonnet, boot, objective);
            }
        }
....
    }
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        VU[GetPlayerVehicleID(playerid)] = repeat VehiclesU(GetPlayerVehicleID(playerid), playerid);
        PlayInfo[playerid][InCar] = GetPlayerVehicleID(playerid);
        PlayerTextDrawShow(playerid, SpeedoBack[playerid]);
        PlayerTextDrawShow(playerid, Speedometer[playerid]);
        PlayerTextDrawShow(playerid, TurnLeft[playerid]);
        PlayerTextDrawShow(playerid, HeadLights[playerid]);
        PlayerTextDrawShow(playerid, TurnRight[playerid]);
        PlayerTextDrawShow(playerid, Kilometrage[playerid]);
        PlayerTextDrawShow(playerid, FuelLevel[playerid]);
        PlayerTextDrawShow(playerid, OilLevel[playerid]);
        PlayerTextDrawShow(playerid, FuelWarn1[playerid]);
        PlayerTextDrawShow(playerid, FuelWarn2[playerid]);
        PlayerTextDrawShow(playerid, OilWarn1[playerid]);
        PlayerTextDrawShow(playerid, OilWarn2[playerid]);
        /*if(VehType(playerid) != 3 && VehType(playerid) != 4)
        {*/

        PlayerTextDrawShow(playerid, TireWarn1[playerid]);
        PlayerTextDrawShow(playerid, TireWarn2[playerid]);
        PlayerTextDrawShow(playerid, TireWear[playerid]);
        //}
    }
    if(oldstate == PLAYER_STATE_DRIVER)
    {
        stop VU[PlayInfo[playerid][InCar]];
        PlayInfo[playerid][InCar] = 0;
        PlayerTextDrawHide(playerid, SpeedoBack[playerid]);
        PlayerTextDrawHide(playerid, Speedometer[playerid]);
        PlayerTextDrawHide(playerid, TurnLeft[playerid]);
        PlayerTextDrawHide(playerid, HeadLights[playerid]);
        PlayerTextDrawHide(playerid, TurnRight[playerid]);
        PlayerTextDrawHide(playerid, Kilometrage[playerid]);
        PlayerTextDrawHide(playerid, FuelLevel[playerid]);
        PlayerTextDrawHide(playerid, OilLevel[playerid]);
        PlayerTextDrawHide(playerid, TireWear[playerid]);
        PlayerTextDrawHide(playerid, FuelWarn1[playerid]);
        PlayerTextDrawHide(playerid, FuelWarn2[playerid]);
        PlayerTextDrawHide(playerid, OilWarn1[playerid]);
        PlayerTextDrawHide(playerid, OilWarn2[playerid]);
        PlayerTextDrawHide(playerid, TireWarn1[playerid]);
        PlayerTextDrawHide(playerid, TireWarn2[playerid]);
    }
    return 1;
}
Reply
#2

Quote:
Originally Posted by ******
Посмотреть сообщение
pawn Код:
main()
{
    repeat DelayedFunction(42);
    new
        Timer:x = repeat DelayedFunction(42);
    stop x;
}
The "repeat" example above gave one more little command: "stop". This, quite simply, stops a running timer.
Will this work ?
Reply
#3

Quote:
Originally Posted by Wizzy951
Посмотреть сообщение
Will this work ?
Uh, nope... It continues sending the message from the "DelayedFunction" without stopping :/
Reply
#4

I found it, you used repeat (Continues) instead of defer (Once)

pawn Код:
VU[GetPlayerVehicleID(playerid)] = defer VehiclesU(GetPlayerVehicleID(playerid), playerid);
Reply
#5

Quote:
Originally Posted by pds2k12
Посмотреть сообщение
I found it, you used repeat (Continues) instead of defer (Once)

pawn Код:
VU[GetPlayerVehicleID(playerid)] = defer VehiclesU(GetPlayerVehicleID(playerid), playerid);
No that's not the problem. Defer just makes the function of the timer do only once after 500 ms. What I want is it to run what's inside it every 500 ms and then stop when the guy exits the car. So it has to be repeat, from what ****** said on the topic about the timers. I've just tried defer and did what I said above.

Thanks though.
Reply
#6

I've read ****** 's tutorial and I think that, this should work: stop VehiclesU[playerid];
EDIT: does it still repeat ?
Reply
#7

Quote:
Originally Posted by Wizzy951
Посмотреть сообщение
I've read ****** 's tutorial and I think that, this should work: stop VehiclesU[playerid];
EDIT: does it still repeat ?
Well that would never work I think. Though I tried stop VehiclesU(PlayInfo[playerid][InCar], playerid); and still it continues without stopping.
Reply
#8

Well, uh, can someone help me or not? :/

If you need more of the code just ask I'll post it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)