Advertisement
Eddlm

Seatbelt + Better Damage From Crashes

Aug 7th, 2016
1,198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.44 KB | None | 0 0
  1. using GTA;
  2. using GTA.Native;
  3. using System;
  4. using System.IO;
  5. using System.Windows.Forms;
  6.  
  7.  
  8.  
  9. public class BetterPlayerDamageFromAccidents : Script
  10. {
  11.     string ScriptName = "Better Player Damage From Accidents";
  12.     string ScriptVer = "1.0";
  13.     int GameTimeRef = Game.GameTime;
  14.     int DisableControlsTime = Game.GameTime;
  15.     bool ControlsDisabled = false;
  16.     float OldSpeed = 0;
  17.     int SeatbeltScore = 0;
  18.     int NeededSeabeltScore = 100;
  19.     public BetterPlayerDamageFromAccidents()
  20.     {
  21.         Function.Call(Hash._STOP_ALL_SCREEN_EFFECTS);
  22.         Tick += OnTick;
  23.         if (CanWeUse(Game.Player.Character.CurrentVehicle))
  24.         {
  25.             OldSpeed = Game.Player.Character.CurrentVehicle.Speed;
  26.         }
  27.         else
  28.         {
  29.             OldSpeed = Game.Player.Character.Velocity.Length();
  30.         }
  31.     }
  32.  
  33.     void OnTick(object sender, EventArgs e)
  34.     {
  35.         if (CanWeUse(Game.Player.Character.CurrentVehicle))
  36.         {
  37.             Vehicle veh = Game.Player.Character.CurrentVehicle;
  38.             if (Game.Player.Character.CanFlyThroughWindscreen && !veh.Model.IsBike && !veh.Model.IsBicycle)
  39.             {
  40.                 if (veh.IsStopped && SeatbeltScore < NeededSeabeltScore) SeatbeltScore++;
  41.                 if (SeatbeltScore == NeededSeabeltScore)
  42.                 {
  43.                     Game.Player.Character.CanFlyThroughWindscreen = false;
  44.                     DisplayHelpTextThisFrame("~g~Seatbelt on.");
  45.                 }
  46.             }
  47.         }
  48.         else
  49.         {
  50.             if (SeatbeltScore != 0) SeatbeltScore = 0;
  51.             if (!Game.Player.Character.CanFlyThroughWindscreen) Game.Player.Character.CanFlyThroughWindscreen=true;
  52.         }
  53.  
  54.  
  55.         if (ControlsDisabled)
  56.         {
  57.             Game.DisableAllControlsThisFrame(2);
  58.         }
  59.  
  60.         if (Game.GameTime > DisableControlsTime)
  61.         {
  62.             ControlsDisabled = false;
  63.             Function.Call(Hash._TRANSITION_FROM_BLURRED, 500f);
  64.         }
  65.         if (Game.GameTime > GameTimeRef + 100)
  66.         {
  67.             if (CanWeUse(Game.Player.Character.CurrentVehicle))
  68.             {
  69.                 Vehicle veh = Game.Player.Character.CurrentVehicle;
  70.                 float SpeedDifference = Math.Abs(Game.Player.Character.CurrentVehicle.Speed - OldSpeed);
  71.                 int Treshold = 3;
  72.                 if (veh.Model.IsBike || veh.Model.IsBicycle) Treshold = 5;
  73.                 if (Math.Abs(SpeedDifference) > Treshold)
  74.                 {
  75.                     if (Game.Player.Character.GetConfigFlag(32))
  76.                     {
  77.                         Function.Call(Hash._START_SCREEN_EFFECT, "SwitchShortTrevorIn", 500, false);
  78.                         int damage = (int)SpeedDifference;
  79.                         if (veh.IsUpsideDown)
  80.                         {
  81.                             damage = damage * 2;
  82.                             Game.Player.Character.ApplyDamage((int)Math.Abs(damage));
  83.                         }
  84.                         else
  85.                         {
  86.                             Game.Player.Character.ApplyDamage((int)Math.Abs(damage));
  87.                         }
  88.  
  89.                         if (damage > 10 && !Game.Player.Character.IsWearingHelmet)
  90.                         {
  91.                             ControlsDisabled = true;
  92.                             DisableControlsTime = Game.GameTime + ((damage * 1000) / 10);
  93.                             Function.Call(Hash._TRANSITION_TO_BLURRED, 1);
  94.                         }
  95.                     }
  96.                 }
  97.                 OldSpeed = Game.Player.Character.CurrentVehicle.Speed;
  98.             }
  99.             else if (OldSpeed > 0) OldSpeed = 0;
  100.             GameTimeRef = Game.GameTime;
  101.         }
  102.     }
  103.  
  104.  
  105.  
  106.     /// TOOLS ///
  107.     void WarnPlayer(string script_name, string title, string message)
  108.     {
  109.         Function.Call(Hash._SET_NOTIFICATION_TEXT_ENTRY, "STRING");
  110.         Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, message);
  111.         Function.Call(Hash._SET_NOTIFICATION_MESSAGE, "CHAR_SOCIAL_CLUB", "CHAR_SOCIAL_CLUB", true, 0, title, "~b~" + script_name);
  112.     }
  113.  
  114.     bool CanWeUse(Entity entity)
  115.     {
  116.         return entity != null && entity.Exists();
  117.     }
  118.  
  119.     void DisplayHelpTextThisFrame(string text)
  120.     {
  121.         Function.Call(Hash._SET_TEXT_COMPONENT_FORMAT, "STRING");
  122.         Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, text);
  123.         Function.Call(Hash._DISPLAY_HELP_TEXT_FROM_STRING_LABEL, 0, false, true, -1);
  124.     }
  125.  
  126.  
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement