Quantcast

Jump to content

» «
Photo

C# Teleport to Coords On Button Press Templete

4 replies to this topic
ShadowCoderKing
  • ShadowCoderKing

    GTA V Modder

  • Members
  • Joined: 14 Aug 2008
  • None

#1

Posted 09 May 2017 - 09:52 AM Edited by SpiderMight, 10 May 2017 - 03:09 PM.

 C# Teleports to Coords On Button Press Templete

 

for anyone that wants to learn

using GTA;
using GTA.Math;
using GTA.Native;
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;

public class teleportTest : Script
{
    Vector3 teleportToPos = new Vector3(55.89523f, -1890.027f, 21.62341f);  // sets teleport position coords 
    public teleportTest()
    {

        Tick += OnTick;
        KeyDown += OnKeyDown;
        KeyUp += OnKeyUp;

    }

    private void OnTick(object sender, EventArgs e)
    {

    }

    void OnKeyDown(object sender, KeyEventArgs e)
    {

    }

    void OnKeyUp(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.U)   // if key pressed U then it will fade the screen and teleport to grove street and fade back in
        {
            Game.FadeScreenOut(100);
            Script.Wait(500);
            Game.Player.Character.Position = teleportToPos;
            Script.Wait(1000);
            Game.FadeScreenIn(100);

        }
    }
}
  • MrGTAmodsgerman likes this

Nacorpio
  • Nacorpio

    Proficient in C# and Java

  • Members
  • Joined: 05 May 2013
  • Sweden

#2

Posted 10 May 2017 - 01:08 PM

Why have you set the script interval to 10?

  • jedijosh920 likes this

ShadowCoderKing
  • ShadowCoderKing

    GTA V Modder

  • Members
  • Joined: 14 Aug 2008
  • None

#3

Posted 10 May 2017 - 01:28 PM

thanks for pointing that out, fixed it


SteamSilence
  • SteamSilence

    What am I doing

  • New Members
  • Joined: 09 May 2017
  • Brazil

#4

Posted 27 May 2017 - 10:51 PM

If you want to "automatically" add Xbox Controller support, you can call the native "IS_CONTROL_PRESSED", like:

bool isControlPressed()
    {
        bool buttonPress = (Game.IsControlPressed(2, GTA.Control.Cover)); //"Q" or "RB" == GTA.Control.Cover
        return buttonPress;
    }

That way, if the player is pressing "Q" (or whatever is being used to take cover) on keyboard or "RB" on the controller, you'll get the key press.


jedijosh920
  • jedijosh920

    ⭐⭐⭐⭐⭐

  • Members
  • Joined: 01 Mar 2012
  • United-States

#5

Posted 29 May 2017 - 02:12 AM

If you want to "automatically" add Xbox Controller support, you can call the native "IS_CONTROL_PRESSED", like:

bool isControlPressed()
    {
        bool buttonPress = (Game.IsControlPressed(2, GTA.Control.Cover)); //"Q" or "RB" == GTA.Control.Cover
        return buttonPress;
    }

That way, if the player is pressing "Q" (or whatever is being used to take cover) on keyboard or "RB" on the controller, you'll get the key press.

 

 

Suggestion:

bool isControlPressed()
{
    return (Game.IsControlPressed(2, GTA.Control.Cover)); //"Q" or "RB" == GTA.Control.Cover
}

Cleaner/less code :)

  • SteamSilence likes this




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users