Advertisement
ErikSon_

Tachosystem [S2] by ErikSon

Aug 3rd, 2014
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 11.48 KB | None | 0 0
  1. /*                              Tachosystem [S2] by ErikSon                             */
  2.  
  3. #include <a_samp>
  4. #include <progress>
  5.  
  6. /*      Settings        */
  7. #undef MAX_PLAYERS
  8. #define MAX_PLAYERS     5   //Server-Slotanzahl
  9. /*      Settings        */
  10.  
  11. #define formatEx(%0,%1,%2)          format(%0,sizeof(%0),%1,%2)
  12.  
  13. enum T_EC{
  14.     Text:Name,
  15.     Text:Zustand,
  16.     Text:StatusMotor,
  17.     Text:StatusLicht,
  18.     Text:Speed,
  19.     Text:Box,
  20.     Bar:ZustandBar,
  21.     _switch
  22. }
  23. new Tacho[MAX_PLAYERS][T_EC];
  24.  
  25. new VehName[][] ={
  26.         "Landstalker", "Bravura", "Buffalo", "Linerunner", "Perrenial", "Sentinel",
  27.         "Dumper", "Firetruck", "Trashmaster", "Stretch", "Manana", "Infernus",
  28.         "Voodoo", "Pony", "Mule", "Cheetah", "Ambulance", "Leviathan", "Moonbeam",
  29.         "Esperanto", "Taxi", "Washington", "Bobcat", "Whoopee", "BF Injection",
  30.         "Hunter", "Premier", "Enforcer", "Securicar", "Banshee", "Predator", "Bus",
  31.         "Rhino", "Barracks", "Hotknife", "Trailer", "Previon", "Coach", "Cabbie",
  32.         "Stallion", "Rumpo", "RC Bandit", "Romero", "Packer", "Monster", "Admiral",
  33.         "Squalo", "Seasparrow", "Pizzaboy", "Tram", "Trailer", "Turismo", "Speeder",
  34.         "Reefer", "Tropic", "Flatbed", "Yankee", "Caddy", "Solair", "Berkley's RC Van",
  35.         "Skimmer", "PCJ-600", "Faggio", "Freeway", "RC Baron", "RC Raider", "Glendale",
  36.         "Oceanic","Sanchez", "Sparrow", "Patriot", "Quad", "Coastguard", "Dinghy",
  37.         "Hermes", "Sabre", "Rustler", "ZR-350", "Walton", "Regina", "Comet", "BMX",
  38.         "Burrito", "Camper", "Marquis", "Baggage", "Dozer", "Maverick", "News Chopper",
  39.         "Rancher", "FBI Rancher", "Virgo", "Greenwood", "Jetmax", "Hotring", "Sandking",
  40.         "Blista Compact", "Police Maverick", "Boxvillde", "Benson", "Mesa", "RC Goblin",
  41.         "Hotring Racer A", "Hotring Racer B", "Bloodring Banger", "Rancher", "Super GT",
  42.         "Elegant", "Journey", "Bike", "Mountain Bike", "Beagle", "Cropduster", "Stunt",
  43.         "Tanker", "Roadtrain", "Nebula", "Majestic", "Buccaneer", "Shamal", "Hydra",
  44.         "FCR-900", "NRG-500", "HPV1000", "Cement Truck", "Tow Truck", "Fortune",
  45.         "Cadrona", "FBI Truck", "Willard", "Forklift", "Tractor", "Combine", "Feltzer",
  46.         "Remington", "Slamvan", "Blade", "Freight", "Streak", "Vortex", "Vincent",
  47.         "Bullet", "Clover", "Sadler", "Firetruck", "Hustler", "Intruder", "Primo",
  48.         "Cargobob", "Tampa", "Sunrise", "Merit", "Utility", "Nevada", "Yosemite",
  49.         "Windsor", "Monster", "Monster", "Uranus", "Jester", "Sultan", "Stratum",
  50.         "Elegy", "Raindance", "RC Tiger", "Flash", "Tahoma", "Savanna", "Bandito",
  51.         "Freight Flat", "Streak Carriage", "Kart", "Mower", "Dune", "Sweeper",
  52.         "Broadway", "Tornado", "AT-400", "DFT-30", "Huntley", "Stafford", "BF-400",
  53.         "News Van", "Tug", "Trailer", "Emperor", "Wayfarer", "Euros", "Hotdog", "Club",
  54.         "Freight Box", "Trailer", "Andromada", "Dodo", "RC Cam", "Launch", "Police Car",
  55.         "Police Car", "Police Car", "Police Ranger", "Picador", "S.W.A.T", "Alpha",
  56.         "Phoenix", "2. Gebrauchtwagen", "1. Gebrauchtwagen", "Luggage", "Luggage", "Stairs", "Boxville",
  57.         "Tiller", "Utility Trailer"
  58. };
  59.  
  60.  
  61. public OnFilterScriptInit(){
  62.     print("\n--------------------------------------");
  63.     print(" Tachosystem [S2] by ErikSon");
  64.     print("--------------------------------------\n");
  65.     for(new i = 0; i<MAX_PLAYERS; i++){
  66.         Tacho[i][Box] = TextDrawCreate(542.000000, 304.000000, "~n~");
  67.         TextDrawBackgroundColor(Tacho[i][Box], 255);
  68.         TextDrawFont(Tacho[i][Box], 1);
  69.         TextDrawLetterSize(Tacho[i][Box], 0.500000, 9.700002);
  70.         TextDrawColor(Tacho[i][Box], 0x00000088);
  71.         TextDrawSetOutline(Tacho[i][Box], 0);
  72.         TextDrawSetProportional(Tacho[i][Box], 1);
  73.         TextDrawSetShadow(Tacho[i][Box], 1);
  74.         TextDrawUseBox(Tacho[i][Box], 1);
  75.         TextDrawBoxColor(Tacho[i][Box], 0x00000088);
  76.         TextDrawTextSize(Tacho[i][Box], 634.000000, 30.000000);
  77.         TextDrawSetSelectable(Tacho[i][Box], 0);
  78.        
  79.         Tacho[i][Name] = TextDrawCreate(565.000000, 312.000000, "-");
  80.         TextDrawBackgroundColor(Tacho[i][Name], 255);
  81.         TextDrawFont(Tacho[i][Name], 3);
  82.         TextDrawLetterSize(Tacho[i][Name], 0.300000, 1.000000);
  83.         TextDrawColor(Tacho[i][Name], -1);
  84.         TextDrawSetOutline(Tacho[i][Name], 0);
  85.         TextDrawSetProportional(Tacho[i][Name], 1);
  86.         TextDrawSetShadow(Tacho[i][Name], 1);
  87.         TextDrawSetSelectable(Tacho[i][Name], 0);
  88.  
  89.         Tacho[i][Speed] = TextDrawCreate(547.000000, 330.000000, "- KM/H");
  90.         TextDrawBackgroundColor(Tacho[i][Speed], 255);
  91.         TextDrawFont(Tacho[i][Speed], 3);
  92.         TextDrawLetterSize(Tacho[i][Speed], 0.299999, 1.000000);
  93.         TextDrawColor(Tacho[i][Speed], -1);
  94.         TextDrawSetOutline(Tacho[i][Speed], 0);
  95.         TextDrawSetProportional(Tacho[i][Speed], 1);
  96.         TextDrawSetShadow(Tacho[i][Speed], 1);
  97.         TextDrawSetSelectable(Tacho[i][Speed], 0);
  98.        
  99.         Tacho[i][ZustandBar] = CreateProgressBar(543.00, 352.00, 89.80, 13.19, 1684301055, 100.0);
  100.         SetProgressBarColor(Tacho[i][ZustandBar],0x646464FF);
  101.         Tacho[i][Zustand] = TextDrawCreate(546.000000, 354.000000, "Zustand: -%%");
  102.         TextDrawBackgroundColor(Tacho[i][Zustand], 255);
  103.         TextDrawFont(Tacho[i][Zustand], 1);
  104.         TextDrawLetterSize(Tacho[i][Zustand], 0.320000, 0.899999);
  105.         TextDrawColor(Tacho[i][Zustand], -1);
  106.         TextDrawSetOutline(Tacho[i][Zustand], 0);
  107.         TextDrawSetProportional(Tacho[i][Zustand], 1);
  108.         TextDrawSetShadow(Tacho[i][Zustand], 0);
  109.         TextDrawSetSelectable(Tacho[i][Zustand], 0);
  110.  
  111.         Tacho[i][StatusMotor] = TextDrawCreate(543.000000, 376.000000, "Motor: '-'");
  112.         TextDrawBackgroundColor(Tacho[i][StatusMotor], 255);
  113.         TextDrawFont(Tacho[i][StatusMotor], 1);
  114.         TextDrawLetterSize(Tacho[i][StatusMotor], 0.220000, 0.999999);
  115.         TextDrawColor(Tacho[i][StatusMotor], -1);
  116.         TextDrawSetOutline(Tacho[i][StatusMotor], 0);
  117.         TextDrawSetProportional(Tacho[i][StatusMotor], 1);
  118.         TextDrawSetShadow(Tacho[i][StatusMotor], 1);
  119.         TextDrawSetSelectable(Tacho[i][StatusMotor], 0);
  120.  
  121.         Tacho[i][StatusLicht] = TextDrawCreate(591.000000, 376.000000, "Licht: '-'");
  122.         TextDrawBackgroundColor(Tacho[i][StatusLicht], 255);
  123.         TextDrawFont(Tacho[i][StatusLicht], 1);
  124.         TextDrawLetterSize(Tacho[i][StatusLicht], 0.230000, 0.899999);
  125.         TextDrawColor(Tacho[i][StatusLicht], -1);
  126.         TextDrawSetOutline(Tacho[i][StatusLicht], 0);
  127.         TextDrawSetProportional(Tacho[i][StatusLicht], 1);
  128.         TextDrawSetShadow(Tacho[i][StatusLicht], 1);
  129.         TextDrawSetSelectable(Tacho[i][StatusLicht], 0);
  130.     }
  131.     return SetTimer("TachoUpdate",444,true);
  132. }
  133.  
  134. public OnFilterScriptExit(){
  135.     for(new i = 0; i<MAX_PLAYERS; i++){
  136.         TextDrawHideForPlayer(i,Tacho[i][Box]);
  137.         TextDrawHideForPlayer(i,Tacho[i][Name]);
  138.         TextDrawHideForPlayer(i,Tacho[i][Zustand]);
  139.         TextDrawHideForPlayer(i,Tacho[i][Speed]);
  140.         TextDrawHideForPlayer(i,Tacho[i][StatusMotor]);
  141.         TextDrawHideForPlayer(i,Tacho[i][StatusLicht]);
  142.         HideProgressBarForPlayer(i,Tacho[i][ZustandBar]);
  143.            
  144.         TextDrawDestroy(Tacho[i][Box]);
  145.         TextDrawDestroy(Tacho[i][Name]);
  146.         TextDrawDestroy(Tacho[i][Zustand]);
  147.         TextDrawDestroy(Tacho[i][Speed]);
  148.         TextDrawDestroy(Tacho[i][StatusMotor]);
  149.         TextDrawDestroy(Tacho[i][StatusLicht]);
  150.         DestroyProgressBar(Tacho[i][ZustandBar]);
  151.     }
  152.     return 1;
  153. }
  154.  
  155. public OnPlayerConnect(playerid){
  156.     return 1;
  157. }
  158.  
  159. public OnPlayerDisconnect(playerid, reason){
  160.     if(IsPlayerInAnyVehicle(playerid)){
  161.         TextDrawHideForPlayer(playerid, Tacho[playerid][Box]);
  162.         TextDrawHideForPlayer(playerid, Tacho[playerid][Name]);
  163.         TextDrawHideForPlayer(playerid, Tacho[playerid][Zustand]);
  164.         TextDrawHideForPlayer(playerid, Tacho[playerid][Speed]);
  165.         TextDrawHideForPlayer(playerid, Tacho[playerid][StatusMotor]);
  166.         TextDrawHideForPlayer(playerid,Tacho[playerid][StatusLicht]);
  167.         HideProgressBarForPlayer(playerid,Tacho[playerid][ZustandBar]);
  168.     }
  169.     return 1;
  170. }
  171.  
  172. public OnPlayerStateChange(playerid, newstate, oldstate){
  173.     if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER){
  174.         TextDrawShowForPlayer(playerid, Tacho[playerid][Box]);
  175.         TextDrawShowForPlayer(playerid, Tacho[playerid][Name]);
  176.         TextDrawShowForPlayer(playerid, Tacho[playerid][Zustand]);
  177.         TextDrawShowForPlayer(playerid, Tacho[playerid][Speed]);
  178.         TextDrawShowForPlayer(playerid, Tacho[playerid][StatusMotor]);
  179.         TextDrawShowForPlayer(playerid,Tacho[playerid][StatusLicht]);
  180.         ShowProgressBarForPlayer(playerid,Tacho[playerid][ZustandBar]);
  181.     }
  182.     if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER){
  183.         TextDrawHideForPlayer(playerid, Tacho[playerid][Box]);
  184.         TextDrawHideForPlayer(playerid, Tacho[playerid][Name]);
  185.         TextDrawHideForPlayer(playerid, Tacho[playerid][Zustand]);
  186.         TextDrawHideForPlayer(playerid, Tacho[playerid][Speed]);
  187.         TextDrawHideForPlayer(playerid, Tacho[playerid][StatusMotor]);
  188.         TextDrawHideForPlayer(playerid,Tacho[playerid][StatusLicht]);
  189.         HideProgressBarForPlayer(playerid,Tacho[playerid][ZustandBar]);
  190.     }
  191.     return 1;
  192. }
  193.  
  194. forward TachoUpdate();
  195. public TachoUpdate(){
  196.     for(new i = 0; i<MAX_PLAYERS; i++){
  197.         if(!IsPlayerConnected(i))continue;
  198.         if(!IsPlayerInAnyVehicle(i))continue;
  199.        
  200.         new veh = GetPlayerVehicleID(i),str[64],Float:hp,speed = GetVehicleSpeed(veh);
  201.         if(speed < 100)formatEx(str,"Speed: ~g~%d~g~ KM/H", speed);
  202.         else if(speed > 100 && speed < 160)formatEx(str,"Speed: ~y~%d~y~ KM/H",speed);
  203.         else if(speed > 160)formatEx(str,"Speed: ~r~%d~r~ KM/H",speed);
  204.         TextDrawSetString(Tacho[i][Speed],str);
  205.         GetVehicleHealth(veh, hp); hp = floatround(hp / 10);
  206.         if(hp > 70)formatEx(str,"Zustand: ~g~%.0f %%", hp),Tacho[i][_switch] = 0;
  207.         else if(hp > 35 && hp < 70)formatEx(str,"Zustand: ~y~%.0f %%", hp),Tacho[i][_switch] = 0;
  208.         else if(hp < 35){
  209.             formatEx(str,"Zustand: ~r~%.0f %%", hp);
  210.             switch(Tacho[i][_switch]){
  211.                 case 0:Tacho[i][_switch] = 1,TextDrawHideForPlayer(i,Tacho[i][Zustand]);
  212.                 case 1:Tacho[i][_switch] = 0,TextDrawShowForPlayer(i,Tacho[i][Zustand]);
  213.             }
  214.         }
  215.         TextDrawSetString(Tacho[i][Zustand],str);
  216.         formatEx(str,"~r~%s", VehName[GetVehicleModel(veh)-400]), TextDrawSetString(Tacho[i][Name],str);
  217.         new motor,lichter,objektiv,boot,bonnet,doors,alarm;
  218.         GetVehicleParamsEx(veh,motor,lichter,alarm,doors,bonnet,boot,objektiv);
  219.         if(IsNoTachoVeh(veh)){
  220.             TextDrawSetString(Tacho[i][StatusMotor],"Motor: '-"),
  221.             TextDrawSetString(Tacho[i][StatusLicht],"Licht: '-");
  222.         }
  223.         else{
  224.             formatEx(str,"Motor: '%s'",(!motor) ? ("~r~Aus~w~") : ("~g~An~w~")), TextDrawSetString(Tacho[i][StatusMotor],str);
  225.             formatEx(str,"Licht: '%s'",(!lichter) ? ("~r~Aus~w~") : ("~g~An~w~")),TextDrawSetString(Tacho[i][StatusLicht],str);
  226.         }
  227.         SetProgressBarValue(Tacho[i][ZustandBar],hp);
  228.         UpdateProgressBar(Tacho[i][ZustandBar],i);
  229.     }
  230.     return 1;
  231. }
  232.  
  233. stock GetVehicleSpeed(vehicleid){
  234.     new Float:xPos[3];
  235.     GetVehicleVelocity(vehicleid, xPos[0], xPos[1], xPos[2]);
  236.     return floatround(floatsqroot(xPos[0] * xPos[0] + xPos[1] * xPos[1] + xPos[2] * xPos[2]) * 100 * 1.61);
  237. }
  238.  
  239. stock IsNoTachoVeh(vehicleid)
  240. {
  241.     if(vehicleid == INVALID_VEHICLE_ID)return 0;
  242.     if(GetVehicleModel(vehicleid)==441||GetVehicleModel(vehicleid)==449||GetVehicleModel(vehicleid)==450||GetVehicleModel(vehicleid)==464||GetVehicleModel(vehicleid)==465||
  243.     GetVehicleModel(vehicleid)==481||GetVehicleModel(vehicleid)==501||GetVehicleModel(vehicleid)==509||GetVehicleModel(vehicleid)==510||GetVehicleModel(vehicleid)==537||
  244.     GetVehicleModel(vehicleid)==538||GetVehicleModel(vehicleid)==564||GetVehicleModel(vehicleid)==569||GetVehicleModel(vehicleid)==570||GetVehicleModel(vehicleid)==584||
  245.     GetVehicleModel(vehicleid)==590||GetVehicleModel(vehicleid)==591||GetVehicleModel(vehicleid)==594||GetVehicleModel(vehicleid)==606||GetVehicleModel(vehicleid)==607||
  246.     GetVehicleModel(vehicleid)==608||GetVehicleModel(vehicleid)==610||GetVehicleModel(vehicleid)==611)return 1;
  247.     return 0;
  248. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement