Advertisement
Guest User

Untitled

a guest
Mar 12th, 2011
5,071
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.00 KB | None | 0 0
  1. #include <a_samp>
  2. new Text:td_fuel[MAX_PLAYERS];
  3. new Text:td_vhealth[MAX_PLAYERS];
  4. new Text:td_vspeed[MAX_PLAYERS];
  5. new Text:td_box[MAX_PLAYERS];
  6.  
  7. forward timer_update();
  8. forward timer_refuel(playerid);
  9. new isrefuelling[MAX_PLAYERS] = 0;
  10. new fuel[MAX_VEHICLES];
  11. new Float:max_vhealth[MAX_VEHICLES];
  12.  
  13. public OnFilterScriptInit()
  14. {
  15.     for(new i=0;i<MAX_VEHICLES;i++) {
  16.         GetVehicleHealth(i,max_vhealth[i]); //getting max health
  17.         fuel[i] = 250 + random(150);  //setting fuel for vehicles
  18.     }
  19.  
  20.     for(new i=0;i<MAX_PLAYERS;i++) { //setting up all textdraws
  21.         td_fuel[i] = TextDrawCreate(476,355,"Fuel:");
  22.         td_vhealth[i] = TextDrawCreate(478,376,"Health:");
  23.         td_vspeed[i] = TextDrawCreate(478,397,"Speed:");
  24.         td_box[i] = TextDrawCreate(478.000000,328.000000,"Vehicle Stats: ~n~~n~~n~~n~");
  25.         TextDrawUseBox(td_box[i],1);
  26.         TextDrawBoxColor(td_box[i],0x00000066);
  27.         TextDrawTextSize(td_box[i],626.000000,21.000000);
  28.         TextDrawAlignment(td_fuel[i],0);
  29.         TextDrawAlignment(td_vhealth[i],0);
  30.         TextDrawAlignment(td_vspeed[i],0);
  31.         TextDrawAlignment(td_box[i],0);
  32.         TextDrawBackgroundColor(td_fuel[i],0x000000ff);
  33.         TextDrawBackgroundColor(td_vhealth[i],0x000000ff);
  34.         TextDrawBackgroundColor(td_vspeed[i],0x000000ff);
  35.         TextDrawBackgroundColor(td_box[i],0x000000cc);
  36.         TextDrawFont(td_fuel[i],1);
  37.         TextDrawLetterSize(td_fuel[i],0.699999,2.699999);
  38.         TextDrawFont(td_vhealth[i],1);
  39.         TextDrawLetterSize(td_vhealth[i],0.699999,2.699999);
  40.         TextDrawFont(td_vspeed[i],1);
  41.         TextDrawLetterSize(td_vspeed[i],0.699999,2.699999);
  42.         TextDrawFont(td_box[i],0);
  43.         TextDrawLetterSize(td_box[i],0.699999,2.899999);
  44.         TextDrawColor(td_fuel[i],0xffffffff);
  45.         TextDrawColor(td_vhealth[i],0xffffffff);
  46.         TextDrawColor(td_vspeed[i],0xffffffff);
  47.         TextDrawColor(td_box[i],0xffffffff);
  48.         TextDrawSetOutline(td_fuel[i],1);
  49.         TextDrawSetOutline(td_vhealth[i],1);
  50.         TextDrawSetOutline(td_vspeed[i],1);
  51.         TextDrawSetOutline(td_box[i],1);
  52.         TextDrawSetProportional(td_fuel[i],1);
  53.         TextDrawSetProportional(td_vhealth[i],1);
  54.         TextDrawSetProportional(td_vspeed[i],1);
  55.         TextDrawSetProportional(td_box[i],1);
  56.         TextDrawSetShadow(td_fuel[i],1);
  57.         TextDrawSetShadow(td_vhealth[i],1);
  58.         TextDrawSetShadow(td_vspeed[i],1);
  59.         TextDrawSetShadow(td_box[i],10);
  60.     }
  61.     SetTimer("timer_update",1000,true);
  62.     return 1;
  63. }
  64.  
  65. public OnFilterScriptExit()
  66. {
  67.     for(new i=0;i<MAX_PLAYERS;i++) {
  68.         TextDrawDestroy(td_fuel[i]);
  69.         TextDrawDestroy(td_vhealth[i]);
  70.         TextDrawDestroy(td_vspeed[i]);
  71.         TextDrawDestroy(td_box[i]);
  72.     }
  73.     return 1;
  74. }
  75.  
  76. public OnPlayerStateChange(playerid, newstate, oldstate)
  77. {
  78.     if (newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
  79.     {
  80.  
  81.         TextDrawSetString(td_fuel[playerid],"Fuel:");
  82.         TextDrawSetString(td_vhealth[playerid],"Health:");
  83.         TextDrawSetString(td_vspeed[playerid],"Speed:");
  84.  
  85.         TextDrawShowForPlayer(playerid,td_fuel[playerid]);
  86.         TextDrawShowForPlayer(playerid,td_vspeed[playerid]);
  87.         TextDrawShowForPlayer(playerid,td_vhealth[playerid]);
  88.         TextDrawShowForPlayer(playerid,td_box[playerid]);
  89.     } else {
  90.         TextDrawHideForPlayer(playerid,td_fuel[playerid]);
  91.         TextDrawHideForPlayer(playerid,td_vspeed[playerid]);
  92.         TextDrawHideForPlayer(playerid,td_vhealth[playerid]);
  93.         TextDrawHideForPlayer(playerid,td_box[playerid]);
  94.     }
  95.     return 1;
  96. }
  97.  
  98.  
  99. public OnPlayerCommandText(playerid,cmdtext[]) {
  100.  
  101.     if (!strcmp("/refuel",cmdtext,true,7)) {
  102.         if (!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,0xFFC800FF,"You are not in an vehicle!"); //if a player isnt in a vehicle, it stops here
  103.         if (isrefuelling[playerid]) return SendClientMessage(playerid,0xFFC800FF,"You are already refuelling!"); //if a player is already refuelling, it stops here
  104.         if (GetPlayerMoney(playerid) - 80 <0) return SendClientMessage(playerid,0xFFC800FF,"You dont have enough money!"); //if a player doesnt have $80 anymore, it stops here
  105.         GivePlayerMoney(playerid,-80); //Sets the player's cash -$80
  106.         SetCameraBehindPlayer(playerid); //Sets the camera behind the player (looks better because the player will be frozen for a few secs)
  107.         TogglePlayerControllable(playerid,0); //freezes the player so he cant drive and refuel at the same time
  108.         isrefuelling[playerid] = 1; //setting isrefuelling to 1 so the player cant spam /refuel
  109.         TextDrawSetString(td_fuel[playerid],"Refuelling..."); //changing textdraw to /refuel
  110.         SetTimerEx("timer_refuel",4500,false,"i",playerid); //setting refueltimer
  111.         return 1;
  112.     }
  113.  
  114.     return 0;
  115. }
  116.  
  117. public timer_update()
  118. {
  119.     for(new i=0;i<MAX_PLAYERS;i++) {
  120.         if (isrefuelling[i]) continue;
  121.         new vid = GetPlayerVehicleID(i);
  122.         if (GetPlayerVehicleSeat(i) == 0) {
  123.             fuel[vid] = fuel[vid] - 2;
  124.             if (fuel[vid]<1)
  125.             {
  126.                 fuel[vid] = 0;
  127.                 RemovePlayerFromVehicle(i);
  128.                 GameTextForPlayer(i,"~r~You are out of ~w~fuel~r~!",5000,4);
  129.             }
  130.         }
  131.         new string[128];format(string,sizeof string,"Fuel:    %i",fuel[vid] /4);
  132.         TextDrawSetString(td_fuel[i],string);
  133.  
  134.         new Float:speed_x,Float:speed_y,Float:speed_z,Float:temp_speed,final_speed,Float:health;
  135.  
  136.         GetVehicleVelocity(vid,speed_x,speed_y,speed_z);
  137.         temp_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*136.666667;
  138.         final_speed = floatround(temp_speed,floatround_round);
  139.         format(string,sizeof string,"Speed:  %i",final_speed);
  140.         TextDrawSetString(td_vspeed[i],string);
  141.  
  142.         GetVehicleHealth(vid,health);
  143.         if (max_vhealth[vid] == 0)//if its an random spawned vehicle
  144.         {
  145.             fuel[vid] = 400;
  146.             GetVehicleHealth(vid,max_vhealth[vid]);
  147.         }
  148.         health = (((health - max_vhealth[vid]) /max_vhealth[vid]) *100)+ 100;
  149.         format(string,sizeof string,"Health: %i",floatround(health,floatround_round));
  150.         TextDrawSetString(td_vhealth[i],string);
  151.     }
  152.     return 1;
  153. }
  154.  
  155. public timer_refuel(playerid)
  156. {
  157.     new vid = GetPlayerVehicleID(playerid);
  158.     fuel[vid] = fuel[vid] = 400;
  159.     isrefuelling[playerid] = 0;
  160.     TextDrawSetString(td_fuel[playerid],"Fuel:100");
  161.     TogglePlayerControllable(playerid,1);
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement