Speedometer -
carz0159 - 19.06.2012
Hello,
This is really urgent. I need a speedometer filterscript for my server, nothing more, i dont know any car commands or a dynamic car system, i have all that, alls i need is a speedometer. Just a line on the bottom of the screen to display how fast youre going in a car. Thats it. I dont need to know the vehicle health or status, just the speed. If anyone can help me out with that. Thanks
Re: Speedometer -
Jonny5 - 19.06.2012
ill alter mine give me a min,
its just the speed in MPH,
using PlayerText:
Re: Speedometer -
carz0159 - 19.06.2012
Thanks
Re: Speedometer -
Jonny5 - 19.06.2012
here ya go
just save as JSpeedo.inc
and add to your mode and your done.
it includes the ALS Hooks so you dont have to add any code to your mode.
I have also made the mph/kmph an option
just read the top comments in the code.
also adjust the time update time for you own personal needs.
regards,
pawn Код:
/*
JSpeedo.inc
By: Jonny5 2012
Version: 0.1
Use at your own risk!
*/
//#define JSPEEDO_KMPH //uncomment to use KMPH , default is MPH
#define JSPEEDO_TIMER_UPDATE 800 //time in MS that the timer updates.
new PlayerText:ptdSpeedo[MAX_PLAYERS];
new bool:pSpeedo_Shown[MAX_PLAYERS];
stock GetVehicleSpeed( vehicleid, bool:kmph=false )
{
new Float:x, Float:y, Float:z;GetVehicleVelocity( vehicleid, x, y, z );
if(kmph) return floatround( floatsqroot( x*x + y*y + z*z ) * 180 ); // RETURN kmph
return floatround( floatsqroot( x*x + y*y + z*z ) * 180 / 1.609344 ); //RETURN mph
}
forward SpeedoUpdate();
public SpeedoUpdate()
{
new vehicleid;
new str[12];
new playerid;
for(playerid = 0;playerid<MAX_PLAYERS;playerid++) //if you use for each then replace this line.
{
vehicleid = GetPlayerVehicleID(playerid);
if((vehicleid > 0) && (GetPlayerState(playerid) == PLAYER_STATE_DRIVER))
{
#if !defined JSPEEDO_KMPH
format(str, 12, "%i", GetVehicleSpeed(vehicleid));
#else
format(str, 12, "%i", GetVehicleSpeed(vehicleid,true));
#endif
PlayerTextDrawSetString(playerid,ptdSpeedo[playerid],str);
if (!pSpeedo_Shown[playerid])
{
PlayerTextDrawShow(playerid,ptdSpeedo[playerid]);
pSpeedo_Shown[playerid]=true;
}
}
else
{
if (pSpeedo_Shown[playerid])
{
PlayerTextDrawSetString(playerid,ptdSpeedo[playerid]," ");
PlayerTextDrawHide(playerid,ptdSpeedo[playerid]);
pSpeedo_Shown[playerid] = false;
}
}
}
return 1;
}
//For more info on ALS Hooking check
//https://sampforum.blast.hk/showthread.php?tid=85907
static gSpeedo_HasCB[2];
//--------------OnGameModeInit Hook-------------------
public OnGameModeInit()
{
SetTimer("SpeedoUpdate",true,JSPEEDO_TIMER_UPDATE);
gSpeedo_HasCB[0] = funcidx("Speedo_OnPlayerConnect") != -1;
gSpeedo_HasCB[1] = funcidx("Speedo_OnPlayerDisconnect") != -1;
if (funcidx("Speedo_OnGameModeInit") != -1) CallLocalFunction("Speedo_OnGameModeInit", "");
return 1;
}
#if defined _ALS_OnGameModeInit
#undef OnGameModeInit
#else
#define _ALS_OnGameModeInit
#endif
#define OnGameModeInit Speedo_OnGameModeInit
forward Speedo_OnGameModeInit();
//--------------OnPlayerConnect Hook-------------------
public OnPlayerConnect(playerid)
{
ptdSpeedo[playerid] =
CreatePlayerTextDraw (playerid, 630.000000, 370.000000, " ");
PlayerTextDrawAlignment (playerid, ptdSpeedo[playerid], 3);
PlayerTextDrawBackgroundColor (playerid, ptdSpeedo[playerid], 255);
PlayerTextDrawFont (playerid, ptdSpeedo[playerid], 3);
PlayerTextDrawLetterSize (playerid, ptdSpeedo[playerid], 0.800000, 4.000000);
PlayerTextDrawColor (playerid, ptdSpeedo[playerid], 16711935);
PlayerTextDrawSetOutline (playerid, ptdSpeedo[playerid], 1);
PlayerTextDrawSetProportional (playerid, ptdSpeedo[playerid], 1);
if (gSpeedo_HasCB[0]) CallLocalFunction("Speedo_OnPlayerConnect", "i", playerid);
return 1;
}
#if defined _ALS_OnPlayerConnect
#undef OnPlayerConnect
#else
#define _ALS_OnPlayerConnect
#endif
#define OnPlayerConnect Speedo_OnPlayerConnect
forward Speedo_OnPlayerConnect(playerid);
//--------------OnPlayerDisconnect Hook-------------------
public OnPlayerDisconnect(playerid, reason)
{
PlayerTextDrawDestroy(playerid, ptdSpeedo[playerid]);
if (gSpeedo_HasCB[1]) CallLocalFunction("Speedo_OnPlayerDisconnect", "ii", playerid, reason);
return 1;
}
#if defined _ALS_OnPlayerDisconnect
#undef OnPlayerDisconnect
#else
#define _ALS_OnPlayerDisconnect
#endif
#define OnPlayerDisconnect Speedo_OnPlayerDisconnect
forward Speedo_OnPlayerDisconnect(playerid, reason);
Re: Speedometer -
carz0159 - 19.06.2012
Ok
Let's hope that this one works. Thanks for your time.
Re: Speedometer -
Jonny5 - 19.06.2012
it works i just tested it in a blank mode.
if you know how to make textdraws then you'll be able to alter the way it looks.
if you have any problems with it just post back here.
Re: Speedometer -
carz0159 - 19.06.2012
Alright thanks, it's late here so I'll test it tomorrow but I'll post the results in about 14 hours. Thanks.
Re: Speedometer -
carz0159 - 19.06.2012
Ok, so I put it into my GM, and i got a few errors,
C:\Users\Benny\Desktop\s.rpbackup6.18.12\gamemodes \exec-rp2.pwn(96362) : error 025: function heading differs from prototype
C:\Users\Benny\Desktop\s.rpbackup6.18.12\gamemodes \exec-rp2.pwn(96363) : error 021: symbol already defined: "GetVehicleSpeed"
C:\Users\Benny\Desktop\s.rpbackup6.18.12\gamemodes \exec-rp2.pwn(96381) : warning 202: number of arguments does not match definition
C:\Users\Benny\Desktop\s.rpbackup6.18.12\gamemodes \exec-rp2.pwn(96411) : error 021: symbol already defined: "Audio_OnGameModeInit"
C:\Users\Benny\Desktop\s.rpbackup6.18.12\gamemodes \exec-rp2.pwn(96430) : error 021: symbol already defined: "Audio_OnPlayerConnect"
C:\Users\Benny\Desktop\s.rpbackup6.18.12\gamemodes \exec-rp2.pwn(96454) : error 021: symbol already defined: "Audio_OnPlayerDisconnect"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
5 Errors.
Can you help me out with these?
Re: Speedometer -
Jonny5 - 19.06.2012
sure,
the only ones related to the speedo are the first 2
post the code lines for each error and im sure we can sort it.
also post your GetVehicleSpeed function,
not the one i given you. We should be able to adapt the speedo to work with your GetVehicleSpeed function.
Re: Speedometer -
tyler12 - 19.06.2012
http://pastebin.com/f10add09f
/speedo to enable/disable