Advertisement
TheManatee

SteamSilence's Teleport Utility 1.0 - Source Code

Jan 17th, 2017
1,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.76 KB | None | 0 0
  1.  
  2. /*This is the STCE's Teleport Utility Initial release source code
  3.                         By SteamSIlenceChannel                 */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Windows.Forms;
  7. using GTA;
  8. using GTA.Native;
  9. using NativeUI;
  10. using GTA.Math;
  11.  
  12. public class MainClass : Script
  13. {
  14.     private MenuPool menuPool_;
  15.     UIMenu mainMenu;
  16.     UIMenuItem showButtonsItem;
  17.    
  18.     UIMenu playerMenu;
  19.     UIMenu teleportMenu;
  20.  
  21.     private Player player = Game.Player;
  22.     private Ped playerPed = Game.Player.Character;
  23.  
  24.     List<dynamic> teleportLocations = new List<dynamic>();
  25.     float currentLocationX;
  26.     float currentLocationY;
  27.     float currentLocationZ;
  28.  
  29.     public MainClass()
  30.     {
  31.  
  32.         setup();
  33.        
  34.         Tick += onTick;
  35.         KeyDown += onKeyDown;
  36.     }
  37.     void setup()
  38.     {
  39.         menuPool_ = new MenuPool();
  40.         mainMenu = new UIMenu("", "Quick teleport with Button combinations");
  41.         mainMenu.SetBannerType("scripts\\texture\\customBanner.png");
  42.        
  43.         menuPool_.Add(mainMenu);
  44.        
  45.         playerMenu = menuPool_.AddSubMenu(mainMenu, "Player");
  46.         teleportMenu = menuPool_.AddSubMenu(mainMenu, "Teleport Options");
  47.        
  48.  
  49.         setupPlayerFunction();
  50.        
  51.     }
  52.  
  53.     void setupPlayerFunction()
  54.     {
  55.         godMode();
  56.         NeverWantedLevel();
  57.         teleportSetup();
  58.     }
  59.  
  60.    
  61.     void godMode()
  62.     {
  63.         UIMenuCheckboxItem chkGodMode = new UIMenuCheckboxItem("God Mode", false);
  64.         playerMenu.SetBannerType("scripts\\texture\\customBanner.png");
  65.         playerMenu.AddItem(chkGodMode);
  66.         player.Character.IsInvincible = false;
  67.         player.IsInvincible = false;
  68.         playerMenu.OnItemSelect += (sender, item, index) =>
  69.         {
  70.             if(item == chkGodMode)
  71.             {
  72.                 chkGodMode.Checked = !chkGodMode.Checked;
  73.             }
  74.         };
  75.  
  76.         playerMenu.OnCheckboxChange += (sender, item, index) =>
  77.         {
  78.             if(item == chkGodMode)
  79.             {
  80.                 if (chkGodMode.Checked)
  81.                 {
  82.                     player.IsInvincible = true;
  83.                     player.Character.IsInvincible = true;
  84.                    
  85.                 }else
  86.                 {
  87.                     player.IsInvincible = false;
  88.                     player.Character.IsInvincible = false;
  89.                 }
  90.             }
  91.         };
  92.     }
  93.     bool NeverWantedLevelChecker;
  94.     void NeverWantedLevel()
  95.     {
  96.         UIMenuCheckboxItem chkNeverWanted = new UIMenuCheckboxItem("Never Wanted", false);
  97.         playerMenu.AddItem(chkNeverWanted);
  98.        
  99.         playerMenu.OnItemSelect += (sender, item, index) =>
  100.         {
  101.             if(item == chkNeverWanted)
  102.             {
  103.                 chkNeverWanted.Checked = !chkNeverWanted.Checked;
  104.             }
  105.            
  106.         };
  107.         playerMenu.OnCheckboxChange += (sender, item, index) =>
  108.         {
  109.             if (item == chkNeverWanted)
  110.             {
  111.                 if (chkNeverWanted.Checked)
  112.                 {
  113.                    NeverWantedLevelChecker = true;
  114.                 }
  115.                 else
  116.                 {
  117.                     NeverWantedLevelChecker = false;
  118.                 }
  119.                 //the function to set never wanted is in OnTick event
  120.             }
  121.         };
  122.     }
  123.    
  124.     public static bool GetButtonDown()
  125.     {
  126.         bool isCombinationPressed;
  127.         if ((Function.Call<bool>(Hash.IS_CONTROL_PRESSED/*6342219533232326959L*/, new InputArgument[] { 2, 74 }) ) &&
  128.             (Function.Call<bool>(Hash.IS_CONTROL_PRESSED/*6342219533232326959L*/, new InputArgument[] { 2, 44 })))//19 down) 44rb, 15left
  129.         {
  130.             isCombinationPressed = true;
  131.         }
  132.         else
  133.         {
  134.             isCombinationPressed = false;
  135.         }
  136.  
  137.         return isCombinationPressed;
  138.     }
  139.     bool isTeleportCombinationPressed()
  140.     {
  141.         bool isCombinationPressed;
  142.         if ((Function.Call<bool>(Hash.IS_CONTROL_PRESSED/*6342219533232326959L*/, new InputArgument[] { 2, 18 })) &&
  143.             (Function.Call<bool>(Hash.IS_CONTROL_PRESSED/*6342219533232326959L*/, new InputArgument[] { 2, 22 })&&
  144.             (Function.Call<bool>(Hash.IS_CONTROL_PRESSED/*6342219533232326959L*/, new InputArgument[] { 2, 37 }))))//19 pra baixo)
  145.         {
  146.             isCombinationPressed = true;
  147.         }
  148.         else
  149.         {
  150.             isCombinationPressed = false;
  151.         }
  152.  
  153.         return isCombinationPressed;
  154.     }
  155.     bool isTeleportCombination2Pressed()
  156.     {
  157.         bool isCombinationPressed;
  158.         if ((Function.Call<bool>(Hash.IS_CONTROL_PRESSED/*6342219533232326959L*/, new InputArgument[] { 2, 18 })) &&
  159.             (Function.Call<bool>(Hash.IS_CONTROL_PRESSED/*6342219533232326959L*/, new InputArgument[] { 2, 45 }) &&
  160.             (Function.Call<bool>(Hash.IS_CONTROL_PRESSED/*6342219533232326959L*/, new InputArgument[] { 2, 37 }))))//19 pra baixo)
  161.         {
  162.             isCombinationPressed = true;
  163.         }
  164.         else
  165.         {
  166.             isCombinationPressed = false;
  167.         }
  168.  
  169.         return isCombinationPressed;
  170.     }
  171.    
  172.  
  173.     private void onTick(object sender, EventArgs e)
  174.     {
  175.         //controller test
  176.         if (GetButtonDown())
  177.         {
  178.             mainMenu.Visible = !mainMenu.Visible;
  179.         }
  180.         //controller test
  181.         if (isTeleportCombinationPressed())
  182.         {
  183.             teleportToWaypoint();
  184.         }
  185.         if (isTeleportCombination2Pressed())
  186.         {
  187.             teleportToChilliad();
  188.             // Game.Player.Character.Position = new Vector3(markerPosition.X, groundHeight, player.Character.Position.Z);
  189.             //Game.Player.Character.Position = markerPosition + (Vector3.WorldDown * 200.5f);
  190.             // Game.Player.Character.Position = new Vector3(451.2820f,5572.9897f, 796.6793f);
  191.             // Game.Player.Character.Position.Normalize();
  192.         }
  193.         if (shouldTeleportWhenDie)
  194.         {
  195.             currentLocationX = player.Character.Position.X;
  196.             currentLocationY = player.Character.Position.Y;
  197.             currentLocationZ = player.Character.Position.Z;
  198.             if (player.Character.IsDead)
  199.             {
  200.                 Wait(20000);
  201.                 player.Character.Position = new Vector3(currentLocationX, currentLocationY, currentLocationZ);
  202.             }
  203.         }
  204.  
  205.         if (menuPool_ != null)
  206.         {
  207.             menuPool_.ProcessMenus();
  208.         }
  209.         if(NeverWantedLevelChecker == true)
  210.         {
  211.             player.WantedLevel = 0;
  212.         }
  213.     }
  214.     private void onKeyDown(object sender, KeyEventArgs e)
  215.     {
  216.         if (e.KeyCode == Keys.F3 && !menuPool_.IsAnyMenuOpen())
  217.         {
  218.             mainMenu.Visible = !mainMenu.Visible;
  219.         }
  220.         if(e.Alt & e.KeyCode == Keys.W)
  221.         {
  222.             teleportToWaypoint();
  223.         }
  224.         if (e.Alt & e.KeyCode == Keys.U)
  225.         {
  226.             teleportToChilliad();
  227.         }
  228.     }
  229.     bool shouldTeleportWhenDie;
  230.     private void teleportSetup()
  231.     {
  232.         teleportLocations.Add("Waypoint");
  233.         teleportLocations.Add("Mount Chilliad");
  234.         UIMenuCheckboxItem chkTeleportWhenDie = new UIMenuCheckboxItem("Teleport to last location when you die", false);
  235.         teleportMenu.SetBannerType("scripts\\texture\\customBanner.png");
  236.         teleportMenu.AddItem(chkTeleportWhenDie);
  237.         UIMenuListItem listOfTeleports = new UIMenuListItem("Teleport location: ", teleportLocations, 0);
  238.         teleportMenu.AddItem(listOfTeleports);
  239.  
  240.         showButtonsItem = new UIMenuItem("Show Buttons");
  241.         teleportMenu.AddItem(showButtonsItem);
  242.         teleportMenu.OnItemSelect += (sender, item, index) =>
  243.         {
  244.             if (item == showButtonsItem)
  245.             {
  246.                 showButtonSet();
  247.             }
  248.         };
  249.  
  250.         teleportMenu.OnItemSelect += (sender, item, index) =>
  251.         {
  252.             if(item == chkTeleportWhenDie)
  253.             {
  254.                 chkTeleportWhenDie.Checked = !chkTeleportWhenDie.Checked;
  255.             }
  256.         };
  257.  
  258.         teleportMenu.OnCheckboxChange += (sender, item, index) =>
  259.         {
  260.             if (item == chkTeleportWhenDie)
  261.             {
  262.                 if (chkTeleportWhenDie.Checked)
  263.                 {
  264.                     shouldTeleportWhenDie = true;
  265.                 }else
  266.                 {
  267.                     shouldTeleportWhenDie = false;
  268.                 }
  269.             }
  270.         };
  271.  
  272.        
  273.         UIMenuItem btnTeleportNow = new UIMenuItem("Teleport To chosen location Now");
  274.         teleportMenu.AddItem(btnTeleportNow);
  275.         teleportMenu.OnItemSelect += (sender, item, index) =>
  276.         {
  277.             if(item == btnTeleportNow)
  278.             {
  279.                 teleportNow(listOfTeleports);
  280.             }
  281.         };
  282.        
  283.     }
  284.     void teleportNow(UIMenuListItem list)
  285.     {
  286.         var markerPosition = World.GetWaypointPosition();
  287.         var groundHeight = World.GetGroundHeight(markerPosition);
  288.  
  289.         if (list.Index == 0)
  290.         {
  291.             teleportToWaypoint();
  292.         }
  293.         if (list.Index == 1)
  294.         {
  295.             teleportToChilliad();
  296.         }
  297.     }
  298.  
  299.     void teleportToWaypoint()
  300.     {
  301.         var markerPosition = World.GetWaypointPosition();
  302.         var groundHeight = World.GetGroundHeight(markerPosition);
  303.  
  304.         if (!player.Character.IsInVehicle())
  305.         {
  306.             player.Character.Position = markerPosition + (Vector3.WorldDown * 200.5f);
  307.         }else
  308.         {
  309.             Vehicle v = player.Character.CurrentVehicle;
  310.             v.Position = markerPosition + (Vector3.WorldDown * 200.5f);
  311.         }
  312.        
  313.  
  314.         Wait(2000);
  315.        
  316.     }
  317.     void teleportToChilliad()
  318.     {
  319.         if (!player.Character.IsInVehicle())
  320.         {
  321.             player.Character.Position = new Vector3(451.2820f, 5572.9897f, 796.6793f);
  322.         }
  323.         else
  324.         {
  325.             Vehicle v = player.Character.CurrentVehicle;
  326.             v.Position = new Vector3(451.2820f, 5572.9897f, 796.6793f);
  327.         }
  328.        
  329.  
  330.         Wait(2000);
  331.     }
  332.     void showButtonSet()
  333.     {
  334.         UI.Notify("If you're using a xbox controller: \n"+
  335.             "\"LB\" + \"X\" + \"A\" => Teleport to Waypoint \n"+
  336.             "\"LB\" + \"B\" + \"A\" => Teleport to Mount Chilliad \n");
  337.         UI.Notify("If you're a Keyboard player: \n" +
  338.             "\"Alt\" + \"W\" => Teleport to Waypoint \n" +
  339.             "\"Alt\" + \"U\" => Teleport to Mount Chilliad \n");
  340.     }
  341.  
  342. }
  343. // Game.Player.Character.Position = new Vector3(markerPosition.X, groundHeight, player.Character.Position.Z);
  344. //Game.Player.Character.Position = markerPosition + (Vector3.WorldDown * 200.5f);
  345. // Game.Player.Character.Position = new Vector3(451.2820f,5572.9897f, 796.6793f);
  346. // Game.Player.Character.Position.Normalize();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement