SpeedoMeter Bug
#1

Hello Guys,
I Have Problem With My Speedometer Script

It Show The Train NPC Stats In The Speedometer And If The NPC Not Connected And Some One Entered Vehicle And I Am Not In Vehicle It Will Show His Vehicle Stats In Speedometer

Here Is The Code:
pawn Код:
public OnGameModeInit()
{
    SetTimer("Speedometer", 100, true);
    VStats = TextDrawCreate(450,340," ");
    VName = TextDrawCreate(450,360," ");
    SPEEDOS = TextDrawCreate(450,380.0," ");
    HEALTH = TextDrawCreate(450,400.0," ");
    Doors = TextDrawCreate(450,420.0," ");
    TextDrawColor(VStats,GREEN);
    TextDrawColor(VName,GREEN);
    TextDrawColor(SPEEDOS,GREEN);
    TextDrawColor(HEALTH,GREEN);
    TextDrawColor(Doors,GREEN);
    TextDrawFont(VStats, 1);
    TextDrawFont(VName, 1);
    TextDrawFont(SPEEDOS, 1);
    TextDrawFont(HEALTH, 1);
    TextDrawFont(Doors, 1);
    TextDrawSetOutline(VStats, 1);
    TextDrawSetOutline(VName, 1);
    TextDrawSetOutline(SPEEDOS, 1);
    TextDrawSetOutline(HEALTH, 1);
    TextDrawSetOutline(Doors, 1);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    TextDrawShowForPlayer(playerid,VStats);
    TextDrawShowForPlayer(playerid,VName);
    TextDrawShowForPlayer(playerid,SPEEDOS);
    TextDrawShowForPlayer(playerid,HEALTH);
    TextDrawShowForPlayer(playerid,Doors);
    return 1;
}

public Speedometer(playerid)
{
    new vehicleid,Float:speed_x,Float:speed_y,Float:speed_z,Float:final_speed,speed_string[256],final_speed_int;
    new Float:vehicle_health,final_vehicle_health,health_string[256],namesstring[200];
    vehicleid = GetPlayerVehicleID(playerid);
    if (IsPlayerInAnyVehicle(playerid)) {
            if(PInfo[playerid][lock] == 1) TextDrawSetString(Doors, "Doors: Locked");
            if(PInfo[playerid][lock] == 0) TextDrawSetString(Doors, "Doors: UnLocked");
            GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
            final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*250.666667;
            final_speed_int = floatround(final_speed,floatround_round);
            format(speed_string,256,"Speed: %i",final_speed_int);
            TextDrawSetString(SPEEDOS, speed_string);
            GetVehicleHealth(vehicleid,vehicle_health);
            final_vehicle_health = floatround(floatround(vehicle_health - 250)/ 7.5);
            format(health_string,256,"Health: %i", final_vehicle_health);
            TextDrawSetString(HEALTH, health_string);
            format(namesstring, sizeof namesstring,"Name: %s",VNames[GetVehicleModel(GetPlayerVehicleID(playerid))-400]);
            TextDrawSetString(VName,namesstring);
            TextDrawSetString(VStats, "Vehicle Stats:");
        }
        else {
        TextDrawSetString(VStats, " ");
        TextDrawSetString(SPEEDOS, " ");
        TextDrawSetString(HEALTH, " ");
        TextDrawSetString(VName, " ");
        TextDrawSetString(Doors," ");
    }
    return 1;
}
Thanks
Reply
#2

You'll have to use SetTimerEx becuse the function Speedomeeter wants to have a variable into it, do it like this:
Код:
SetTimerEx("Speedometer", 100, true, "i", playerid);
I'm not sure if this will work, because you have one textdraw for all the players, you will need to have one textdraw for every player, otherwise you'll just be able to measure one players speed.
And if you don't want it to show if the player is not in a car you'll have to do it like a timer that gets the players state and if he's in a car you show him the textdraw of that car.

Hope it helped, ask if you need any more help
Reply
#3

If I Added This It Will Say undefined Symbol Playerid Because Gamemodeinit Doesn't Have The (playerid)
Reply
#4

Hide the textdraws if you're outside vehicle, and disable that functions for the NPC?
Reply
#5

ok, then this is how you have to do it so it should work correct.

You'll have to edit the Speedometer function, you'll have to loop throught all your players, get their state and if they are in a car (as driver) you show them the textdraws, You'll also have to do different textdraws for each vehicle ingame.
Reply
#6

I Made That When I Enter The Vehicle It Show The NPC Vehicle Stats In The SpeedoMeter And If The NPC Not Connected And Some One Entered Vehicle And I Am Not In Vehicle It Will Show His Vehicle Stats In Speedometer And When I Exit It Hide The SpeedoMeter
pawn Код:
if(newstate == PLAYER_STATE_DRIVER) {
        TextDrawShowForPlayer(playerid,VStats);
        TextDrawShowForPlayer(playerid,VName);
        TextDrawShowForPlayer(playerid,SPEEDOS);
        TextDrawShowForPlayer(playerid,HEALTH);
        TextDrawShowForPlayer(playerid,Doors);
    }
    if(newstate == PLAYER_STATE_ONFOOT) {
        TextDrawHideForPlayer(playerid,VStats);
        TextDrawHideForPlayer(playerid,VName);
        TextDrawHideForPlayer(playerid,SPEEDOS);
        TextDrawHideForPlayer(playerid,HEALTH);
        TextDrawHideForPlayer(playerid,Doors);
  }
Reply
#7

Yeah, but you'll have to have one textdraw for every vehicle, like:

pawn Код:
VStats[MAX_VEHICLES];
VName[MAX_VEHICLES];
SPEEDOS[MAX_VEHICLES];
HEALTH[MAX_VEHICLES];
Doors[MAX_VEHICLES];

and then you'll have to update all the vehicles variables, like:
for(new i = 0; i<MAX_VEHICLES; i++){
new vehhp = GetVehicleHealth(i);
//set the text to vehhp here
}
//and on player enter veh/playerstatechange
        vehid = GetVehicleID(playerid);
        TextDrawShowForPlayer(playerid,VStats[vehid]);
        TextDrawShowForPlayer(playerid,VName[vehid]);
        TextDrawShowForPlayer(playerid,SPEEDOS[vehid]);
        TextDrawShowForPlayer(playerid,HEALTH[vehid]);
        TextDrawShowForPlayer(playerid,Doors[vehid]);
Hope you understand how to do it, don't know what more i can explain.
Reply
#8

You mean To Add [i] In The Speedometer And Change The Playerid To i
Like This
pawn Код:
TextDrawColor(VStats[i],GREEN);
GetPlayerVehicleID(i);
Reply
#9

Quote:
Originally Posted by misho1
Посмотреть сообщение
You mean To Change The (playerid) to (i) ?
nah, that is what you are going to have on the PlayerStateChange part, to check when a player enter a vehicle.
Reply
#10

I Don't How To Make It Doesn't Work
If Any one Know Reply And I Will Send To Him Team Viewer ID And Pass On The PM
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)