Originally Posted by CaptainMactavish
Simple and clear script, but I found some bugs.
I will explain...
Look at this:
pawn Код:
SetTimer("Speed", 1000, true);
You started a timer in OnFilterScriptInit, but that function has a parameter:
pawn Код:
forward Speed(playerid); public Speed(playerid) { //....
There's no id passed, just an empty variable which is equal to 0, therefore it only works with player ID 0.
The solution is simple, I'm gonna correct your script by myself:
pawn Код:
#include <a_samp>
new PlayerText:SpeedoVehicle[MAX_PLAYERS], PlayerText:SpeedoVelocity[MAX_PLAYERS];
stock const Vehicles[][] ={ "Landstalker","Bravura","Buffalo","Linerunner","Pereniel","Sentinel","Dumper","Firetruck","Trashmaster", "Stretch","Manana","Infernus","Voodoo","Pony","Mule","Cheetah","Ambulance","Leviathan","Moonbeam","Esperanto", "Taxi","Washington","Bobcat","Mr Whoopee","BF Injection","Hunter","Premier","Enforcer","Securicar","Banshee", "Predator","Bus","Rhino","Barracks","Hotknife","Trailer","Previon","Coach","Cabbie","Stallion","Rumpo", "RC Bandit","Romero","Packer","Monster","Admiral","Squalo","Seasparrow","Pizzaboy","Tram","Trailer", "Turismo","Speeder","Reefer","Tropic","Flatbed","Yankee","Caddy","Solair","Berkley's RC Van","Skimmer", "PCJ-600","Faggio","Freeway","RC Baron","RC Raider","Glendale","Oceanic","Sanchez","Sparrow","Patriot", "Quad","Coastguard","Dinghy","Hermes","Sabre","Rustler","ZR3 50","Walton","Regina","Comet","BMX", "Burrito","Camper","Marquis","Baggage","Dozer","Maverick","News Chopper","Rancher","FBI Rancher","Virgo", "Greenwood","Jetmax","Hotring","Sandking","Blista Compact","Police Maverick","Boxville","Benson","Mesa", "RC Goblin","Hotring Racer A","Hotring Racer B","Bloodring Banger","Rancher","Super GT","Elegant", "Journey","Bike","Mountain Bike","Beagle","Cropdust","Stunt","Tanker","RoadTrain","Nebula","Majestic", "Buccaneer","Shamal","Hydra","FCR-900","NRG-500","HPV1000","Cement Truck","Tow Truck","Fortune","Cadrona", "FBI Truck","Willard","Forklift","Tractor","Combine","Feltzer","Remington","Slamvan","Blade","Freight", "Streak","Vortex","Vincent","Bullet","Clover","Sadler","Firetruck","Hustler","Intruder","Primo","Cargobob", "Tampa","Sunrise","Merit","Utility","Nevada","Yosemite","Windsor","Monster A","Monster B","Uranus", "Jester","Sultan","Stratum","Elegy","Raindance","RC Tiger","Flash","Tahoma","Savanna","Bandito","Freight", "Trailer","Kart","Mower","Duneride","Sweeper","Broadway","Tornado","AT-400","DFT-30","Huntley","Stafford", "BF-400","Newsvan","Tug","Trailer A","Emperor","Wayfarer","Euros","Hotdog","Club","Trailer B","Trailer C", "Andromada","Dodo","RC Cam","Launch","Police Car (LSPD)","Police Car (SFPD)","Police Car (LVPD)","Police Ranger", "Picador","S.W.A.T. Van","Alpha","Phoenix","Glendale","Sadler","Luggage Trailer A","Luggage Trailer B", "Stair Trailer","Boxville","Farm Plow","Utility Trailer" };
public OnFilterScriptInit() { print("Speedo-Meter By Littlehelper AKA iKing"); SetTimer("Speed", 1000, true); return 1; }
public OnPlayerConnect(playerid) { SpeedoVehicle[playerid] = CreatePlayerTextDraw(playerid, 39.000000, 134.000000, "Vehicle: Loading"); PlayerTextDrawBackgroundColor(playerid, SpeedoVehicle[playerid], 255); PlayerTextDrawFont(playerid, SpeedoVehicle[playerid], 1); PlayerTextDrawLetterSize(playerid, SpeedoVehicle[playerid], 0.500000, 1.000000); PlayerTextDrawColor(playerid, SpeedoVehicle[playerid], 16711935); PlayerTextDrawSetOutline(playerid, SpeedoVehicle[playerid], 1); PlayerTextDrawSetProportional(playerid, SpeedoVehicle[playerid], 1); PlayerTextDrawUseBox(playerid, SpeedoVehicle[playerid], 1); PlayerTextDrawBoxColor(playerid, SpeedoVehicle[playerid], 255); PlayerTextDrawTextSize(playerid, SpeedoVehicle[playerid], 187.000000, 549.000000);
SpeedoVelocity[playerid] = CreatePlayerTextDraw(playerid, 39.000000, 149.000000, "Velocity: Loading"); PlayerTextDrawBackgroundColor(playerid, SpeedoVelocity[playerid], 255); PlayerTextDrawFont(playerid, SpeedoVelocity[playerid], 1); PlayerTextDrawLetterSize(playerid, SpeedoVelocity[playerid], 0.500000, 1.000000); PlayerTextDrawColor(playerid, SpeedoVelocity[playerid], 16711935); PlayerTextDrawSetOutline(playerid, SpeedoVelocity[playerid], 1); PlayerTextDrawSetProportional(playerid, SpeedoVelocity[playerid], 1); PlayerTextDrawUseBox(playerid, SpeedoVelocity[playerid], 1); PlayerTextDrawBoxColor(playerid, SpeedoVelocity[playerid], -1); PlayerTextDrawTextSize(playerid, SpeedoVelocity[playerid], 187.000000, 272.000000); return 1; }
public OnPlayerDisconnect(playerid, reason) { PlayerTextDrawHide(playerid, SpeedoVehicle[playerid]); PlayerTextDrawDestroy(playerid, SpeedoVehicle[playerid]); PlayerTextDrawHide(playerid, SpeedoVelocity[playerid]); PlayerTextDrawDestroy(playerid, SpeedoVelocity[playerid]); return 1; }
public OnPlayerStateChange(playerid, newstate, oldstate) { if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER) { PlayerTextDrawShow(playerid, SpeedoVehicle[playerid]); PlayerTextDrawShow(playerid, SpeedoVelocity[playerid]); } else if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER) { PlayerTextDrawHide(playerid, SpeedoVehicle[playerid]); PlayerTextDrawHide(playerid, SpeedoVelocity[playerid]); } return 1; } forward Speed(); public Speed() { static MySpeed[48], MyCar[48], playerstate; #if defined _FOREACH_LOCAL_VERSION foreach(Player, playerid){ #else for(new playerid;playerid<MAX_PLAYERS;playerid++) if(IsPlayerConnected(playerid)){ #endif playerstate = GetPlayerState(playerid); if(playerstate == PLAYER_STATE_DRIVER || playerstate == PLAYER_STATE_PASSENGER){ format(MySpeed,sizeof(MySpeed),"Velocity: %d Km/h",GetSpeed(playerid)); format(MyCar,sizeof(MyCar),"Vehicle: %s",Vehicles[GetVehicleModel(GetPlayerVehicleID(playerid))-400]); PlayerTextDrawSetString(playerid, SpeedoVelocity[playerid], MySpeed); PlayerTextDrawSetString(playerid, SpeedoVehicle[playerid], MyCar); } } return 1; } // Credits To SlashPT For GetsSpeed Stock. stock GetSpeed ( playerid , mode = 1 ) { static Float:Velocity [3]; GetVehicleVelocity ( GetPlayerVehicleID ( playerid ) , Velocity [ 0 ] , Velocity [ 1 ] , Velocity [ 2 ] ) ; return IsPlayerInAnyVehicle ( playerid ) ? floatround ( ( ( floatsqroot ( ( ( Velocity [ 0 ] * Velocity [ 0 ] ) + ( Velocity [ 1 ] * Velocity [ 1 ] ) + ( Velocity [ 2 ] * Velocity [ 2 ] ) ) ) * ( !mode ? 105.0 : 170.0 ) ) ) * 1 ) : 0; }
This compiles perfectly. It has some bugs and it wouldn't work with more than one player because you didn't use a array textdraw o player textdraws from 0.3e, so I passed these textdraws to player textdraws, that they will work for all players. It has compatibility with foreach too.
It's obvious that you need 0.3e includes, I can make a version for previous SA-MP versions too.
|