Speedo
#1

So, I dun goofed some how...

I was mucking around with a speedo code I was working on (Snippet below that isn't working) and whenever I enter the vehicle, the name is shown as None, and the Speed as 0 KPH, however, I cannot figure out why, some help would be appreciated, cheers.

Code:
Код:
public Speedometer(playerid) {
	sv[3] = GetVehicleVelocity(GetPlayerVehicleID(playerid),sv[0],sv[1],sv[2]);
	sv[3] = (floatsqroot(((sv[0]*sv[0])+(sv[1]*sv[1])+(sv[2]*sv[2]))* 181.5));
	sv[3] = floatround(sv[3],floatround_round);
	format(fquery,sizeof(fquery),"Vehicle: %s~n~Speed: %i KPH",GetVehicleNameFromModel(GetVehicleModel(GetPlayerVehicleID(playerid))),sv[3]);
	PlayerTextDrawSetString(playerid,Speedo[playerid],fquery);
	return 1; }
Oh, and to clarify, the GetVehicleNameFromModel is fine in other areas, but, just in case:

Код:
new const VehicleNames[][] =
{
	"Landstalker", "Bravura", "Buffalo", "Linerunner", "Perenniel", "Sentinel", "Dumper", "Firetruck", "Trashmaster",
	"Stretch", "Manana", "Infernus", "Voodoo", "Pony", "Mule", "Cheetah", "Ambulance", "Leviathan", "Moonbeam", "Esperanto",
	"Taxi", "Washington", "Bobcat", "Mr. Whoopee", "BF Injection", "Hunter", "Premier", "Enforcer", "Securicar", "Banshee",
	"Predator", "Bus", "Rhino", "Barracks", "Hotknife", "Article Trailer", "Previon", "Coach", "Cabbie", "Stallion", "Rumpo",
	"RC Bandit", "Romero", "Packer", "Monster", "Admiral", "Squallo", "Seasparrow", "Pizzaboy", "Tram", "Article Trailer 2",
	"Turismo", "Speeder", "Reefer", "Tropic", "Flatbed", "Yankee", "Caddy", "Solair", "Berkley's RC Van", "Skimmer", "PCJ-600",
	"Faggio", "Freeway", "RC Baron", "RC Raider", "Glendale", "Oceanic", "Sanchez", "Sparrow", "Patriot", "Quad", "Coastguard",
	"Dinghy", "Hermes", "Sabre", "Rustler", "ZR-350", "Walton", "Regina", "Comet", "BMX", "Burrito", "Camper", "Marquis",
	"Baggage", "Dozer", "Maverick", "SAN News Maverick", "Rancher", "FBI Rancher", "Virgo", "Greenwood", "Jetmax",
	"Hotring Racer", "Sandking", "Blista Compact", "Police Maverick", "Boxville", "Benson", "Mesa", "RC Goblin",
	"Hotring Racer 2", "Hotring Racer 3", "Bloodring Banger", "Rancher 2", "Super GT", "Elegant", "Journey", "Bike",
	"Mountain Bike", "Beagle", "Cropduster", "Stuntplane", "Tanker", "Roadtrain", "Nebula", "Majestic", "Buccaneer", "Shamal",
	"Hydra", "FCR-900", "NRG-500", "HPV1000", "Cement Truck", "Towtruck", "Fortune", "Cadrona", "FBI Truck", "Willard",
	"Forklift", "Tractor", "Combine Harvester", "Feltzer", "Remington", "Slamvan", "Blade", "Freight", "Brownstreak", "Vortex",
	"Vincent", "Bullet", "Clover", "Sadler", "Firetruck LA", "Hustler", "Intruder",	"Primo", "Cargobob", "Tampa", "Sunrise",
	"Merit", "Utility Van",	"Nevada", "Yosemite", "Windsor", "Monster A", "Monster B", "Uranus", "Jester", "Sultan", "Stratum",
	"Elegy", "Raindance", "RC Tiger", "Flash", "Tahoma", "Savanna", "Bandito", "Freight Flat Trailer", "Streak Trailer", "Kart",
	"Mower", "Dune", "Sweeper", "Broadway", "Tornado", "AT400", "DFT-30", "Huntley", "Stafford", "BF-400", "Newsvan", "Tug",
	"Petrol Trailer", "Emperor", "Wayfarer", "Euros", "Hotdog", "Club", "Freight Box Trailer", "Article Trailer 3",
	"Andromada", "Dodo", "RC Cam", "Launch", "Police Car (LSPD)", "Police Car (SFPD)", "Police Car (LVPD)", "Police Ranger",
	"Picador", "S.W.A.T.", "Alpha", "Phoenix", "Glendale Shit", "Sadler Shit", "Baggage Trailer A", "Baggage Trailer B",
	"Tug Stairs Trailer", "Boxville 2", "Farm Trailer", "Utility Trailer"
};
stock GetVehicleNameFromModel(modelid)
{
	format(cname,sizeof(cname),"%s",VehicleNames[GetVehicleModel(modelid) - 400]);
	return cname;
}
Reply
#2

OP show your sv array definition please.

Edit: For starters, few code improvements:
pawn Код:
public Speedometer(playerid) {
    GetVehicleVelocity(GetPlayerVehicleID(playerid),sv[0],sv[1],sv[2]); //This function doesn't return a value
    sv[3] = floatround((floatsqroot(((sv[0]*sv[0])+(sv[1]*sv[1])+(sv[2]*sv[2]))* 181.5), floatround_round); // If sv[3] is an integer, your previous code will mess up stuff.
    format(fquery,sizeof(fquery),"Vehicle: %s~n~Speed: %i KPH", GetVehicleNameFromModel(GetPlayerVehicleID(playerid)),sv[3]); //Model will be fetched from inside that function
    PlayerTextDrawSetString(playerid,Speedo[playerid],fquery);
    return 1;
}

//and
stock GetVehicleNameFromModel(modelid)
{
    return VehicleNames[GetVehicleModel(modelid) - 400];
}
Reply
#3

This is the array definition:

Код:
new Float:sv[4];
Also, cheers, I'll update the code with that now....
Reply
#4

Ok, so you need to store a float inside sv[3], then round it only for format function:
pawn Код:
public Speedometer(playerid) {
    GetVehicleVelocity(GetPlayerVehicleID(playerid), sv[0], sv[1], sv[2]);
    sv[3] = floatsqroot(((sv[0]*sv[0])+(sv[1]*sv[1])+(sv[2]*sv[2]))* 181.5);

    format(fquery, sizeof(fquery), "Vehicle: %s~n~Speed: %i KPH", GetVehicleNameFromModel(GetPlayerVehicleID(playerid)), floatround(sv[3], floatround_round));
    PlayerTextDrawSetString(playerid, Speedo[playerid], fquery);
   
    return 1;
}
Reply
#5

This now works pretty well, the one issue it has is I tried it in an Infernus, when I used the speedo, instead of like 10/100 KPH, it shows 1KPH, and so on, I don't know what the issue (I don't dabble into Speedometers much)
Reply
#6

Oh, it seems one of us misplaced a parentheseseseses (no idea how this is spelled in singular form).

pawn Код:
public Speedometer(playerid) {
    GetVehicleVelocity(GetPlayerVehicleID(playerid), sv[0], sv[1], sv[2]);
    sv[3] = floatsqroot(sv[0]*sv[0]+sv[1]*sv[1]+sv[2]*sv[2]) * 181.5;

    format(fquery, sizeof(fquery), "Vehicle: %s~n~Speed: %i KPH", GetVehicleNameFromModel(GetPlayerVehicleID(playerid)), floatround(sv[3], floatround_round));
    PlayerTextDrawSetString(playerid, Speedo[playerid], fquery);
   
    return 1;
}
Reply
#7

Just had to change that up a bit, adding the parentheses between the squared and add calculations, now it works fine, thanks!
Reply
#8

Well, operators precendence makes multiplication done before addition.
Reply
#9

Well, it IS working, but now The plan I had is I'd make the fuel drop proportional to the speed of the car, naturally, this hasn't worked out well, as I moved the function above into it's own function for getting speed, so now it's producing some odd numbers....

Whenever the timer clicks to lower fuel, I have it set to print the formula I'm using to calculate the fuel drop, which is below, and then print the resulting fuel, except the number it's returning is really odd, the latest one was this:

1070836887

And when it subtracted that from the vehicle's fuel (in litres) no matter how many L of fuel the vehicle had (the Roadtrain has 200, the Infernus has 50L, both were affected in the exact same way.) The fuel drops to 0 right away, but when I look at the output, I get this:

B>b>

So, a little confused here, here's the relevant code snips:

pawn Код:
public FuelTimer() {
    foreach(Player,i) {
        if(IsFueling[i]) continue;
        new veh = GetPlayerVehicleID(i);
        if(GetPlayerVehicleSeat(i) == 0) {
            printf("%d",(GetVehSpeed(veh) * 3 / 100));
            Fuel[veh] -= (GetVehSpeed(veh) * 3 / 100);//This and the one above and below are the calculation lines
            print(Fuel[veh]);
            if(Fuel[veh] < 1 || !IsAPushBike(veh)) {
                Fuel[veh] = 0;
                new engine,lights,alarm,doors,bonnet,boot,objective;
                GetVehicleParamsEx(veh,engine,lights,alarm,doors,bonnet,boot,objective);
                SetVehicleParamsEx(veh,0,0,alarm,doors,bonnet,boot,objective); }}
        CallLocalFunction("Speedometer","i",i); }
    return 1; }
And:

pawn Код:
Float:GetVehSpeed(vehID) {
    new Float:speed[3],Float:sSpeed;
    GetVehicleVelocity(vehID, speed[0], speed[1], speed[2]);
    sSpeed = floatsqroot((speed[0]*speed[0])+(speed[1]*speed[1])+(speed[2]*speed[2]))* 181.5;
    return sSpeed; }
Reply
#10

Is "Fuel[ ]" a floating point number?
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)