SA-MP Forums Archive
Speedometer/GPS/Wristwatch bug - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Speedometer/GPS/Wristwatch bug (/showthread.php?tid=491344)



Speedometer/GPS/Wristwatch bug - Lunixx - 30.01.2014

Problem is that If I type /gps it shows correctly at upper side of minimap
If I type wristwatch it doesn't show anywhere at all
And speedometer sometimes appears at GPS like this:

Speedometer:
pawn Код:
#include <a_samp>

new Float:svx[MAX_PLAYERS];
new Float:svy[MAX_PLAYERS];
new Float:svz[MAX_PLAYERS];
new Float:s1[MAX_PLAYERS];
new s2[MAX_PLAYERS];
new s3[MAX_PLAYERS][256];
new Text:sdisplay[MAX_PLAYERS];
new Text:sbox[MAX_PLAYERS];
new Text:stitle[MAX_PLAYERS];
new stimer[MAX_PLAYERS];

forward speedometer(playerid);

public OnFilterScriptInit() {
    print("\nSimple speedometer filterscript - loaded.\n");
    return 1;
}

public OnFilterScriptExit() {
    return 1;
}

public OnPlayerConnect(playerid) {
    sbox[playerid] = TextDrawCreate(602.888916, 379.313323, "usebox");
    TextDrawLetterSize(sbox[playerid], 0.000000, 4.218642);
    TextDrawTextSize(sbox[playerid], 540.666687, 0.000000);
    TextDrawAlignment(sbox[playerid], 1);
    TextDrawColor(sbox[playerid], 0);
    TextDrawUseBox(sbox[playerid], true);
    TextDrawBoxColor(sbox[playerid], 102);
    TextDrawSetShadow(sbox[playerid], 0);
    TextDrawSetOutline(sbox[playerid], 0);
    TextDrawFont(sbox[playerid], 0);
    stitle[playerid] = TextDrawCreate(551.556030, 381.297943, "speed");
    TextDrawLetterSize(stitle[playerid], 0.299777, 1.455644);
    TextDrawAlignment(stitle[playerid], 1);
    TextDrawColor(stitle[playerid], -16776961);
    TextDrawSetShadow(stitle[playerid], 0);
    TextDrawSetOutline(stitle[playerid], 1);
    TextDrawBackgroundColor(stitle[playerid], 51);
    TextDrawFont(stitle[playerid], 2);
    TextDrawSetProportional(stitle[playerid], 1);
    sdisplay[playerid] = TextDrawCreate(558.222290, 396.728881, " ");
    TextDrawLetterSize(sdisplay[playerid], 0.192221, 1.535288);
    TextDrawAlignment(sdisplay[playerid], 1);
    TextDrawColor(sdisplay[playerid], -1);
    TextDrawSetShadow(sdisplay[playerid], 0);
    TextDrawSetOutline(sdisplay[playerid], 1);
    TextDrawBackgroundColor(sdisplay[playerid], 51);
    TextDrawFont(sdisplay[playerid], 1);
    TextDrawSetProportional(sdisplay[playerid], 1);
    TextDrawShowForPlayer(playerid, sdisplay[playerid]);
    return 1;
}

public speedometer(playerid) {
    GetVehicleVelocity(GetPlayerVehicleID(playerid), svx[playerid], svy[playerid], svz[playerid]);
    s1[playerid] = floatsqroot(((svx[playerid]*svx[playerid])+(svy[playerid]*svy[playerid]))+(svz[playerid]*svz[playerid]))*100;
    s2[playerid] = floatround(s1[playerid],floatround_round);
    format(s3[playerid],256,"%i MPH", s2[playerid]);
    TextDrawSetString(sdisplay[playerid], s3[playerid]);
    return 1;
}

public OnPlayerUpdate(playerid)
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        TextDrawShowForPlayer(playerid, sbox[playerid]);
        TextDrawShowForPlayer(playerid, stitle[playerid]);
    }
    else
    {
        TextDrawHideForPlayer(playerid, sbox[playerid]);
        TextDrawHideForPlayer(playerid, stitle[playerid]);
        return 1;
    }
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate) {
    KillTimer(stimer[playerid]);
    TextDrawSetString(sdisplay[playerid], " ");
    if(newstate == 2) stimer[playerid] = SetTimerEx("speedometer", 255, true, "i", playerid);
    else if(newstate == 3) stimer[playerid] = SetTimerEx("speedometer", 250, true, "i", playerid);
    return 1;
}
Wristwatch:
pawn Код:
CMD:wristwatch(playerid, params[])
{
    if(PlayerInfo[playerid][pWristwatch] > 0)
    {
        new string[128];
        if(GetPVarInt(playerid, "wristwatchonoff") == 0)
        {
            SetPVarInt(playerid, "wristwatchonoff", 1);
            new hour,minuite,second;
            gettime(hour,minuite,second);
            FixHour(hour);
            hour = shifthour;
            if(minuite < 10)
            {
                format(string, sizeof(string), "%d:0%d", hour, minuite);
            }
            else
            {
                format(string, sizeof(string), "%d:%d", hour, minuite);
            }
            TextDrawShowForPlayer(playerid, WristWatch);
            format(string, sizeof(string), "* %s turns on their wristwatch.", GetPlayerNameEx(playerid));
            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
        }
        else
        {
            KillTimer(GetPVarInt(playerid, "wristwatchtimer"));
            TextDrawHideForPlayer(playerid, WristWatch);
            DeletePVar(playerid, "wristwatchonoff");
            format(string, sizeof(string), "* %s turns off their wristwatch.", GetPlayerNameEx(playerid));
            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
        }
    }
    else
    {
        SendClientMessageEx(playerid, COLOR_GRAD1, "You don't have a wristwatch!");
    }
    return 1;
}
GPS:
pawn Код:
CMD:gps(playerid, params[])
{
    if(PlayerInfo[playerid][pGPS] > 0)
    {
        new string[128];
        if(GetPVarInt(playerid, "gpsonoff") == 0)
        {
            format(string, sizeof(string), "* %s turns on their GPS.", GetPlayerNameEx(playerid));
            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            SetPVarInt(playerid, "gpsonoff", 1);
            GPS[playerid] = TextDrawCreate(85.000000, 322.000000, "Loading..");
            textdrawscount++;
            TextDrawAlignment(GPS[playerid], 2);
            TextDrawBackgroundColor(GPS[playerid], 255);
            TextDrawFont(GPS[playerid], 0);
            TextDrawLetterSize(GPS[playerid], 0.809998, 1.500000);
            TextDrawColor(GPS[playerid], -1);
            TextDrawSetOutline(GPS[playerid], 1);
            TextDrawSetProportional(GPS[playerid], 1);
            TextDrawShowForPlayer(playerid, GPS[playerid]);
        }
        else
        {
            format(string, sizeof(string), "* %s turns off their GPS.", GetPlayerNameEx(playerid));
            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            KillTimer(GetPVarInt(playerid, "gpstimer"));
            DeletePVar(playerid, "gpsonoff");
            TextDrawDestroy(GPS[playerid]);
            textdrawscount--;
        }
    }

    else
    {
        SendClientMessageEx(playerid, COLOR_GRAD1, "You don't have a GPS!");
    }
    return 1;
}



Re: Speedometer/GPS/Wristwatch bug - Sawalha - 30.01.2014

Wrong, You should create the speed meter when a player enters the vehicle, but showing it when checking if he's driver or passenger if you want, At OnPlayerStateChange:
pawn Код:
if(newstate == PLAYER_STATE_DRIVE || PLAYER_STATE_PASSENGER)
{
             TextDrawShowForPlayer(playerid, sidisplay[playerid]);
}
else
{
             TextDrawHideForPlayer(playerid, sidisplay[playerid]);
}
return 1;
and OnPlayerExitVehicle, Hide it


Re: Speedometer/GPS/Wristwatch bug - CuervO - 30.01.2014

There could be many things wrong with the code.

Where's the wristwatch definition? When is it created in the mode? Did it work previously without the speedo?

As mentioned above it's more efficent if you show/hide the textdraw at OnPlayerStateChange instead of OnPlayerUpdate. But that wont fix the actual issue.


Re: Speedometer/GPS/Wristwatch bug - Lunixx - 30.01.2014

That's why im trying to find a scripter for my server. Wanna fix them quickly and buy host next week.