Se8870

fixveh.pwn

Dec 6th, 2020
198
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <a_samp>
  2. #include <sscanf2>
  3.  
  4. // YSI 5.x
  5. #include <YSI_Data\y_iterate>
  6.  
  7. #define sec * 1000
  8.  
  9. forward WaktuServer(playerid);
  10. forward OnFinishedRepair(playerid, vehicleid);
  11.  
  12. enum E_PARAM_TYPE {
  13.     PARAM_ENGINE,
  14.     PARAM_LIGHTS,
  15.     PARAM_ALARM,
  16.     PARAM_DOORS,
  17.     PARAM_BONNET,
  18.     PARAM_BOOT,
  19.     PARAM_OBJECTIVE
  20. };
  21.  
  22. ToggleVehicleParams(vehicleid, E_PARAM_TYPE:type, toggle) {
  23.     new
  24.         engine, lights, alarm,
  25.         doors, bonnet, boot, objective
  26.     ;
  27.  
  28.     GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
  29.  
  30.     switch (type) {
  31.         case PARAM_ENGINE:      engine = toggle;
  32.         case PARAM_LIGHTS:      lights = toggle;
  33.         case PARAM_ALARM:       alarm = toggle;
  34.         case PARAM_DOORS:       doors = toggle;
  35.         case PARAM_BONNET:      bonnet = toggle;
  36.         case PARAM_BOOT:        boot = toggle;
  37.         case PARAM_OBJECTIVE:   objective = toggle;
  38.     }
  39.  
  40.     SetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
  41.     return 1;
  42. }
  43.  
  44. IsPlayerNearVehicle(playerid, Float:range = 1.5) {
  45.     foreach (new i : StreamedVehicle[playerid]) {
  46.         new
  47.             Float:vehX, Float:vehY, Float:vehZ;
  48.  
  49.         GetVehiclePos(vehicleid, vehX, vehY, vehZ);
  50.  
  51.         if (IsPlayerInRangeOfPoint(playerid, range, vehX, vehY, vehZ))
  52.             return i;
  53.     }
  54.     return INVALID_VEHICLE_ID;
  55. }
  56.  
  57. public WaktuServer(playerid)
  58. {
  59.     if (IsPlayerInAnyVehicle(playerid)) {
  60.         new
  61.             Float:health,
  62.             vehicleid = GetPlayerVehicleID(playerid);
  63.  
  64.         GetVehicleHealth(vehicleid, health);
  65.  
  66.         if (health <= 350.0) {
  67.             if (GetPlayerState(playerid) == PLAYER_STATE_DRIVER) {
  68.                 ToggleVehicleParams(vehicleid, PARAM_ENGINE, false);
  69.                 GameTextForPlayer(playerid,
  70.                     /* Title */
  71.                     "Mesin mobil rusak parah\n\
  72.                     Hubungi mechanic segera!",
  73.                     /* Additional Parameters */
  74.                     200, 5
  75.                 );
  76.             }
  77.         }
  78.     }
  79.     return 1;
  80. }
  81.  
  82. public OnFinishedRepair(playerid, vehicleid) {
  83.     if (!IsValidVehicle(vehicleid))
  84.         return 0;
  85.  
  86.     SetVehicleHealth(vehicleid, 100.0);
  87.     return 1;
  88. }
  89.  
  90. public OnFilterScriptInit()
  91. {
  92.     SetTimer("WaktuServer", 1000, true);
  93.     return 1;
  94. }
  95.  
  96.  
  97. CMD:vhealth(playerid, params[])
  98. {
  99.     new
  100.         vehicleid, Float:vHealth;
  101.  
  102.     if (sscanf(params, "if", vehicleid, vHealth))
  103.             return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /vhealth <vehid (gunakan /dl)> <health value>");
  104.  
  105.     if (!IsValidVehicle(vehicleid))
  106.         return SendClientMessage(playerid, COLOR_WHITE, "ERROR: invalid vehicle id");
  107.  
  108.     SetVehicleHealth(vehicleid, vHealth);
  109.     SendClientMessage(playerid, -1, "Kesehatan mesin di rubah");
  110.     return 1;
  111. }
  112.  
  113. CMD:repair(playerid, params[]) {
  114.     new
  115.         vehicleid;
  116.  
  117.     if ((vehicleid = IsPlayerNearVehicle(playerid)) == INVALID_VEHICLE_ID)
  118.         return SendClientMessage(playerid, COLOR_WHITE, "Anda tidak dekat mobil apapun");
  119.  
  120.     PlayerPlaySound(playerid, 1100, 0.0, 0.0, 0.0);
  121.     ToggleVehicleParams(vehicleid, PARAM_BONNET, true);
  122.     //cmd_makan(playerid);
  123.  
  124.     SetTimerEx(#OnFinishedRepair, 60 sec, false, "ii", playerid, vehicleid);
  125.     return 1;
  126. }
  127.  
RAW Paste Data