SA-MP Forums Archive
I need help with speedometer script! - 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: I need help with speedometer script! (/showthread.php?tid=407264)



I need help with speedometer script! - pasha97 - 13.01.2013

I dont know why, but my speedometer is show only for one player, who first sits in the vehicle. Others do not see it, or sometimes they see, but it shows only one speed. Here is a code(public speedometer is a function called by a timer to update player speed in speedometer):

pawn Код:
public speedometer()
{
   
    for(new i; i<MAX_PLAYERS; i++)
    {
    if(IsPlayerConnected(i) && !IsPlayerNPC(i))
    {
                 new vehiclestate[MAX_PLAYERS];
                vehiclestate[i] = GetPlayerState(i);
                if(vehiclestate[i] == PLAYER_STATE_DRIVER)
                {
                new vehicleid[MAX_PLAYERS],Float:speed_x[MAX_PLAYERS],Float:speed_y[MAX_PLAYERS],Float:speed_z[MAX_PLAYERS],Float:final_speed[MAX_PLAYERS],speed_string[256],final_speed_int[MAX_PLAYERS];
                vehicleid[i] = GetPlayerVehicleID(i);
                GetVehicleVelocity(vehicleid[i],speed_x[i],speed_y[i],speed_z[i]);
                final_speed[i] = floatsqroot(((speed_x[i]*speed_x[i])+(speed_y[i]*speed_y[i]))+(speed_z[i]*speed_z[i]))*136.666667;
                final_speed_int[i] = floatround(final_speed[i],floatround_round);
                format(speed_string,256,"Speed: %i",final_speed_int[i]);
                PlayerTextDrawSetString(i,speedom2[i], speed_string);
                PlayerTextDrawSetString(i,speedom3[i], "km/h");
               
                 }
                else
                {
                PlayerTextDrawSetString(i,speedom2[i], " ");
                PlayerTextDrawSetString(i,speedom3[i], " ");
                PlayerTextDrawSetString(i,speedom4[i], " ");
                }
    }
    }
    return 1;
}



Re: I need help with speedometer script! - gDarius - 13.01.2013

Edit that part of your script to this

pawn Код:
PlayerTextDrawSetString(i,speedom2[playerid], speed_string);
                PlayerTextDrawSetString(i,speedom3[playerid], "km/h");
               
                 }
                else
                {
                PlayerTextDrawSetString(i,speedom2[playerid], " ");
                PlayerTextDrawSetString(i,speedom3[playerid], " ");
                PlayerTextDrawSetString(i,speedom4[playerid], " ");
                }



Re: I need help with speedometer script! - pasha97 - 13.01.2013

Quote:
Originally Posted by gDarius
Посмотреть сообщение
Edit that part of your script to this

pawn Код:
PlayerTextDrawSetString(i,speedom2[playerid], speed_string);
                PlayerTextDrawSetString(i,speedom3[playerid], "km/h");
               
                 }
                else
                {
                PlayerTextDrawSetString(i,speedom2[playerid], " ");
                PlayerTextDrawSetString(i,speedom3[playerid], " ");
                PlayerTextDrawSetString(i,speedom4[playerid], " ");
                }
lol, why playerid? it is not a player timer. I used for(new i; i<MAX_PLAYERS; i++). SO there must be [i], i guess


Re: I need help with speedometer script! - gDarius - 13.01.2013

....
Try what i said.


Re: I need help with speedometer script! - pasha97 - 13.01.2013

Quote:
Originally Posted by gDarius
Посмотреть сообщение
....
Try what i said.
you don't understand.it won't work, because variable playerid is not defined in the public function heading. this is silly