Speedo freaks.
#3

There are a lot of logic errors in your script. The main problem is that you are setting that timer every time someone in your server enters a vehicle. So if two people enter a vehicle then that timer is checking for everyone in the server twice a second. And under OnPlayerStateChange, there is no need to see if their newstate equals 2 and not 3 because if it equals 2 it's obviously not 3. I think I fixed the timer and the OnPlayerStateChange problems and removed some unnecessary things. You just need to add SpeedTimer into the enum for PlayerData.

pawn Код:
forward UpSpeed(playerid,vehicleid);
public UpSpeed(playerid,vehicleid)
{
    new Float:pX,Float:pY,Float:pZ;
    GetVehiclePos(vehicleid,Float:pX,Float:pY,Float:pZ);
    VehicleSpeed[vehicleid] = floatsqroot(floatpower(floatabs(floatsub(pX,PlayerData[playerid][OSX])),2)+floatpower(floatabs(floatsub(pY,PlayerData[playerid][OSY])),2)+floatpower(floatabs(floatsub(pZ,PlayerData[playerid][OSZ])),2));
    VehicleSpeed[vehicleid] = floatround(VehicleSpeed[vehicleid] * 5000 / 1000);

    PlayerData[playerid][OSX]=floatround(pX);
    PlayerData[playerid][OSY]=floatround(pY);
    PlayerData[playerid][OSZ]=floatround(pZ);
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == 2)
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        VehicleSpeed[vehicleid]=0;
        PlayerData[playerid][SpeedTimer] = SetTimerEx("UpSpeed",1000,1,"ii",playerid,vehicleid);
        return 1;
    }
    if(newstate == 1)
    {
        if(PlayerData[playerid][SpeedTimer] != -1)
        {
            KillTimer(PlayerData[playerid][SpeedTimer]);
            return 1;
        }
    }
    return 1;
}
Try that.
Reply


Messages In This Thread
Speedo freaks. - by RaFsTar - 13.09.2009, 15:17
Re: Speedo freaks. - by RaFsTar - 13.09.2009, 15:46
Re: Speedo freaks. - by Backwardsman97 - 13.09.2009, 16:08

Forum Jump:


Users browsing this thread: 1 Guest(s)