Advertisement
Guest User

Walk on Water Source Code

a guest
Aug 29th, 2019
1,159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.62 KB | None | 0 0
  1. using GTA;
  2. using GTA.Math;
  3. using GTA.Native;
  4. using System;
  5. using System.Windows.Forms;
  6.  
  7. public class WalkOnWater : Script
  8. {
  9.     private bool toggle = false;
  10.     private Ped p = Game.Player.Character;
  11.     private ScriptSettings config;
  12.     private float height;
  13.     private Prop platform2;
  14.     private Keys toggleKey;
  15.     private Vector3 position;
  16.  
  17.     public WalkOnWater()
  18.     {
  19.         this.Tick += new EventHandler(this.OnTick);
  20.         this.KeyDown += new KeyEventHandler(this.OnKeyDown);
  21.         this.KeyUp += new KeyEventHandler(this.OnKeyUp);
  22.         config = ScriptSettings.Load("scripts\\Walk On Water.ini");
  23.         toggleKey = config.GetValue("Options", "toggleKey", Keys.L);      
  24.         this.Interval = 10;
  25.     }
  26.  
  27.     float GetWaterHeight(Vector3 pos) //function for getting the water height
  28.     {
  29.         OutputArgument outputArgument = new OutputArgument();
  30.         Function.Call<bool>(Hash._0xF6829842C06AE524, (InputArgument)pos.X, (InputArgument)pos.Y, (InputArgument)pos.Z, (InputArgument)outputArgument); //gets the water height
  31.         return outputArgument.GetResult<float>(); //returns the water height as a float value
  32.     }
  33.  
  34.     private void OnTick(object sender, EventArgs e)
  35.     {
  36.         if (toggle == true && p.IsOnFoot && platform2.Exists()) //checks if the toggle is true, the player is on foot, and is the prop exists
  37.         {
  38.             Prop prop = platform2;
  39.             prop.FreezePosition = true;
  40.             position = new Vector3(this.p.Position.X, this.p.Position.Y, this.p.Position.Z); //Gets the player's position
  41.             float waterHeight = GetWaterHeight(position); //gets the water height (Z coordinate of the top of the water)
  42.             Function.Call(Hash._0x06843DA7060A026B, (InputArgument)prop, (InputArgument)position.X, (InputArgument)position.Y, (InputArgument)waterHeight, (InputArgument)1, (InputArgument)0, (InputArgument)0, (InputArgument)1); //Changes the position of the prop underneath the player
  43.             prop.Rotation = new Vector3(90f, 0.0f, 0.0f); //adjusts the rotation of the prop underneath the player
  44.             prop.IsVisible = false; //Makes the prop invisible
  45.             prop.IsInvincible = true; //Makes the prop unbreakbale
  46.         }
  47.         if (toggle == true)
  48.         {
  49.             if (!p.IsAlive || !p.IsOnFoot || !p.Exists()) //toggles the "toggle" boolean and deletes the prop if the player does not exist, is not on foot, or is not alive.
  50.             {
  51.                 toggle = false;
  52.                 platform2.Delete(); //deletes the prop underneath the player
  53.             }
  54.         }          
  55.     }
  56.  
  57.     private void OnKeyDown(object sender, KeyEventArgs e)
  58.     {
  59.     }
  60.  
  61.     private void OnKeyUp(object sender, KeyEventArgs e)
  62.     {
  63.         if (e.KeyCode == toggleKey && toggle == true && platform2.Exists()) //checks if the "toggle" boolean has been toggled and that the platform exists.
  64.         {
  65.             toggle = false;
  66.             platform2.Delete(); //deletes the prop underneath the player
  67.             return; //ensures the next if statement does not go through
  68.         }
  69.         if (e.KeyCode == toggleKey && toggle == false && p.IsOnFoot && p.IsInWater) //checks in the player is on foot, is in water, and that the "toggle" boolean is false
  70.         {
  71.             toggle = true;
  72.             platform2 = World.CreateProp((Model)"prop_huge_display_02", this.p.Position, false, false); //creates the prop that makes the player walk on water
  73.             this.p.Position = new Vector3(p.Position.X, p.Position.Y, + GetWaterHeight(p.Position)); //teleports the player just above the water
  74.             return;
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement