Sziasztok!
Azt fogom bemutatni, hogy hogyan tudunk speedometert készíteni.
A kód nem az enyém az Angol sampforumról hoztam át.
Készítette: pmk1
Beillesztem a kódot:
[pawn]/*-------------------------------------------------------
Basic Speed\'o\'Meter & Health\'o\'Meter Script By Pmk1
-------------------------------------------------------*/
#define FILTERSCRIPT
//-------------------------------------------------------
#include <a_samp>
//-------------------------------------------------------
new Text:SPEEDOS[MAX_PLAYERS];
new Text:HEALTH[MAX_PLAYERS];
//-------------------------------------------------------
forward Speedometer(playerid);
//-------------------------------------------------------
public OnFilterScriptInit()
{
SetTimer(\"Speedometer\", 100, true); //change 100 to what pleases you,but i\'d say it\'s better to keep it like that.
return 1;
}
//-------------------------------------------------------
public OnPlayerConnect(playerid)
{
SPEEDOS[playerid] = TextDrawCreate(10.0,200.0,\" \");
TextDrawShowForPlayer(playerid,SPEEDOS[playerid]);
HEALTH[playerid] = TextDrawCreate(10.0,180.0,\" \");
TextDrawShowForPlayer(playerid,HEALTH[playerid]);
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;
vehicleid = GetPlayerVehicleID(playerid);
new Float:vehicle_health,final_vehicle_health,health_string[256];
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))*250.666667; // 250.666667 = kmph // 199,4166672= mph
final_speed_int = floatround(final_speed,floatround_round);
format(speed_string,256,\"Speed: %i\",final_speed_int);
TextDrawSetString(SPEEDOS[playerid], speed_string);
GetVehicleHealth(vehicleid,vehicle_health);
final_vehicle_health = floatround(floatround(vehicle_health - 250)/ 7.5); //This will make the health show at 100 when the vehicle is not damaged and at 0 when it is in fire.
format(health_string,256,\"Health %i\", final_vehicle_health);
TextDrawSetString(HEALTH[playerid], health_string);
}
else
{
TextDrawSetString(SPEEDOS[playerid], \" \");
TextDrawSetString(HEALTH[playerid], \" \");
}
return 1;
}
[/pawn]