Vehicle System - 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: Vehicle System (
/showthread.php?tid=338714)
Vehicle System -
DexX39 - 30.04.2012
Hello all,
I would like to change my existing vehicle system.
I would like to calculate and store the number of miles traveled by the vehicle. As in real life so they can say: At 20 000 km, it is necessary to change the oil ... etc..
I did this calcul :
Код:
new Float:Dist;
Dist = floatsqroot(floatpower(floatabs(floatsub(PosX[i],x)),2)+floatpower(floatabs(floatsub(PosY[i],y)),2)+floatpower(floatabs(floatsub(PosZ[i],z)),2));
distVehicle[i] = floatround(Dist,floatround_round);
CarInfo[vehicleid][cMetre] = distVehicle[i];
if(CarInfo[vehicleid][cMetre] == 1000)
{
CarInfo[vehicleid][cKm] += 1;
}
I wonder if I'm on track or not.
Thank you for your help and sorry for my bad English..
Re: Vehicle System -
Yuryfury - 01.05.2012
Looks good. A few things I would add:
- make sure you reset cMetre after you add 1 to cKm
- make sure the player is in a vehicle
- use a timer to get distance every second or so
EDIT: Something like this, probably has errors, but it is just to give you an idea
pawn Код:
#include <a_samp>
new distancetimer[MAX_PLAYERS];
forward DistanceDriven(playerid);
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
if(ispassenger==0)
{
distancetimer[playerid] = SetTimerEx("DistanceDriven,1000,1,"i",playerid);
}
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
KillTimer(distancetimer[playerid]);
return 1;
}
public DistanceDriven(playerid)
{
//save the X,Y,Z coordinates to an array (GetVehiclePos(vehicleid,CarInfo[vehicleid][X],CarInfo[vehicleid][Y],CarInfo[vehicleid][Z)]
//get the distance between the new X,Y,Z and the saved ones
return 1;
}