rendered paste body//------------------------------------------------------------------------------
//
//
// Created by zeruel_angel translated by GTAIV
// Swapped to MpH from KpH by No$
// Added speed limited by Antironix
//
//------------------------------------------------------------------------------
#include <a_samp>
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_RED 0xAA3333AA
#define COLOR_BLUE 0xAA33AA33
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_WHITE 0xFFFFFFAA
#define MAX_VECTOR 700
new Text:Velocimetro[MAX_PLAYERS];
new objectcreated;
new flits[MAX_PLAYERS];
new maxobject;
enum SavePlayerPosEnum
{
Float:LastX,
Float:LastY,
Float:LastZ
}
new distance1[MAX_PLAYERS];
new SavePlayerPos[MAX_PLAYERS][SavePlayerPosEnum];
forward flits1(playerid);
forward Speedometer();
forward Float:GetDistanceToPoint(playerid,Float:x2,Float:y2,Float:z2);
//-----------------------------------------------------------------------------------------------------
public Speedometer()
{
for (new player=0;player<MAX_PLAYERS;player++)
{
if ((IsPlayerConnected(player))&&(IsPlayerInAnyVehicle(player)))
{
actualizarVelocimetro(player);
}
}
}
//-----------------------------------------------------------------------------------------------------
actualizarVelocimetro(playerid)
{
new tmp[255];
new Float:x,Float:y,Float:z;
new Float:distance;
GetPlayerPos(playerid, x, y, z);
distance = floatsqroot(floatpower(floatabs(floatsub(x,SavePlayerPos[playerid][LastX])),2)+floatpower(floatabs(floatsub(y,SavePlayerPos[playerid][LastY])),2)+floatpower(floatabs(floatsub(z,SavePlayerPos[playerid][LastZ])),2));
SavePlayerPos[playerid][LastX] = x;
SavePlayerPos[playerid][LastY] = y;
SavePlayerPos[playerid][LastZ] = z;
distance1[playerid] = floatround(distance*5.3);
format(tmp, sizeof(tmp), "MpH:%d",floatround(distance* 5.3));
TextDrawDestroy(Velocimetro[playerid]);
Velocimetro[playerid] = TextDrawCreate(250.0, 400.0,tmp);
TextDrawFont(Velocimetro[playerid],3);
TextDrawColor(Velocimetro[playerid], 0x33CCFFAA);
TextDrawLetterSize(Velocimetro[playerid], 1, 1.33);
TextDrawTextSize(Velocimetro[playerid], 50.0, 35.0);
TextDrawSetOutline(Velocimetro[playerid],1);
TextDrawShowForPlayer(playerid,Velocimetro[playerid]);
maxobject=2;
AddFlitsPaal(playerid, 1278, 2077.5579,1013.2529,10.8203, 20, 50);
AddFlitsPaal(playerid, 1278, 2078.9189,1235.0403,10.3865, 20, 40);
}
//-----------------------------------------------------------------------------------------------------
public OnFilterScriptInit()
{
print("\n Speedo Filter Script + Speeding control v1.0 loaded\n**********************\n by Antironix \n");
SetTimer("Speedometer",500,1);
}
//-----------------------------------------------------------------------------------------------------
public OnFilterScriptExit()
{
print("\n Speedo Filter Script + Speeding control v1.0 unloaded\n**********************\n by Antironix \n");
return 1;
}
//------------------------------------------------------------------------------------------------------
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if (newstate==PLAYER_STATE_ONFOOT)
{
TextDrawHideForPlayer(playerid,Velocimetro[playerid]);
new Float:x,Float:y,Float:z;
GetPlayerPos(playerid, x, y, z);
SavePlayerPos[playerid][LastX] = x;
SavePlayerPos[playerid][LastY] = y;
SavePlayerPos[playerid][LastZ] = z;
}
return 1;
}
//-----------------------------------------------------------------------------------------------------
public OnPlayerExitedMenu(playerid)
{
//seguro que hace falta
TogglePlayerControllable(playerid,true);
return 1;
}
//-----------------------------------------------------------------------------------------------------
public Float:GetDistanceToPoint(playerid,Float:x2,Float:y2,Float:z2)
{
if (IsPlayerConnected(playerid))
{
new Float:x1,Float:y1,Float:z1;
GetPlayerPos(playerid,x1,y1,z1);
return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}
return -1.0;
}
//-----------------------------------------------------------------------------------------------------
IsPlayerInCircle(playerid,Float:x,Float:y,radius)
{
if(GetPlayerDistanceToPoint(playerid,Float:x,Float:y) < radius)
{
return 1;
}
return 0;
}
GetPlayerDistanceToPoint(playerid,Float:x,Float:y)
{
new Float:x1,Float:y1,Float:z1; GetPlayerPos(playerid,x1,y1,z1);
new Float:tmpdis = floatsqroot(floatpower(floatabs(floatsub(x,x1)),2)+
floatpower(floatabs(floatsub(y,y1)),2));
return floatround(tmpdis);
}
stock AddFlitsPaal(playerid, modelid, Float:xx, Float:yy, Float:zz, radius, speed)
{
new fine[MAX_PLAYERS];
new str[256];
if(objectcreated==maxobject)
{
CreateObject(modelid, xx, yy, zz, 0.0, 0.0, 10);
objectcreated++;
}
if((distance1[playerid])>speed && flits[playerid]==0)
{
if(IsPlayerInCircle(playerid, xx, yy, radius))
{
flits[playerid]=1;
SetTimer("flits1", 1000*10, 0);
fine[playerid]=((distance1[playerid]*17/10)-speed);
GivePlayerMoney(playerid, -fine[playerid]);
format(str,sizeof(str), "You were driving faster than %d(%d) MpH and got fined for $%d",speed, distance1 ,fine);
SendClientMessage(playerid, COLOR_YELLOW, str);
}
}
}
public flits1(playerid)
{
flits[playerid]=0;
}