Mileage?
#1

Simplified:

Basically foreach x || y traveled it puts a tick into a var and divides that by lets say 100, then adds that to the current mileage. Any thoughts would help

Just need a point in the right direction.

Thanks


Complex:
I am looking to create a mileage system that puts ticks of integers into a variable based on a X or Y moved divided by a given int. So if we define a float range of lets say 1000, it returns 1 mile on the odometer. foreach is not my strong point Any help is appreciated.

I found this system:
PHP код:

new Float:Milleage[MAX_VEHICLES];
new 
Float:ST[4], vehicleid;
vehicleid GetPlayerVehicleID(playerid);
    
GetVehicleVelocity(vehicleid,ST[0],ST[1],ST[2]);
    
ST[3] = floatsqroot(floatpower(floatabs(ST[0]), 2.0) + floatpower(floatabs(ST[1]), 2.0) + floatpower(floatabs(ST[2]), 2.0)) * 179.28625;
    
Milleage[vehicleid] += ST[3]/2000;
Credits to ball 
But have no idea a good way to call this. A timer perhaps?

EDIT: Scratch that code, its for a speedometer.
Reply
#2

bump.
Reply
#3

Well, it's pure math actually. You set a timer to get the speed of the car. If you go 60 miles per hour, you go 1 mile per minute.

That basically means if you divide the Km/h with 60, you get per minute. There's 3600 second in an hour, so that means if you divide it by 3600, you get 0,0167 miles per second.

If you want it to be saved in a float, it would be something like this

pawn Код:
new Float:MileageTimer[MAX_PLAYERS];

enum cInfo
{
    Float:cMileage
}
new CarInfo[MAX_VEHICLES][cInfo];


public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(!ispassenger)
    {
        MileageTimer[playerid] = SetTimerEx("GetPlayerSpeed", 1000, true, "ii", playerid, vehicleid); // Sets a timer for every second
    }
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    KillTimer(MileageTimer[playerid]);
    return 1;
}

stock GetPlayerSpeed(playerid, vehicleid)
{
    new Float:speed_x,Float:speed_y,Float:speed_z,Float:final_speed,final_speed_int;
    if(vehicleid != 0)
    {
        GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
        final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*136;
        final_speed_int = floatround(final_speed,floatround_round);
        CarInfo[vehicleid][cMileage] += final_speed_int / 3600; // Saves the mileage every second
    }
    return final_speed_int;
}
This function will both set the mileage of the car, and return the speed, if you wish to use it in a speedometer.
Reply
#4

So then I can add that to the existing mileage eachtime the timer is killed and save it via mysql?

Would that work?


I converted the enums to work with my script and make a test command.

But the mileage does not increase.
Thoughts?
CMD:miles(playerid,params[]){
new vehicleid = GetPlayerVehicleID(playerid);
printf("MileageDebug: %i", V[vehicleid][miles]);
format(stringsize, sizeof(stringsize), "Mileage is %i", V[vehicleid][miles]);
SendClientMessage(playerid,COLOR_YELLOW,stringsize );
return 1;
}
Reply
#5

Edited the post I made. The mileage might have to be floats! Because of the decimals!
Reply
#6

Line(343) : warning 213: tag mismatch

343> KillTimer(MileageTimer[playerid]);


I think its because you listed the timer as a float >> new Float:MileageTimer[MAX_PLAYERS]
Reply
#7

Yes, sorry about that. That one is not supposed to be a float.
Reply
#8

Tried it out, still no dice. I sent you a PM here. I do appreciate all this help.

I even modified the / 3600 to 25 to see if it was actually returning anything, and still nothing.

I just can't figure out why the enum isn't updating with any data, no matter how long or far I drive.

I would love for it to floatround and return and int so the milage is easy in sql.

I just can't seem to figure out why it isn't working either lol.

perhaps if we parse it through 2 enums

1 current mileage(total)
and 1 new mileage and have it add new + current = current return current
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)