Please help improve my gate script
-
So I'm not a coder. GTA 5 is the first time I've tried any form of scripting for a game. I have accomplished a few things including the following script, which at the moment, is a proof of concept that allows gates and doors to be held open indefinitely. This should let you get your vehicle through the gate before the damn thing closes in your shiny paintwork.
See the example video here. @chonkie I think this is what you kinda want, yes?
https://mega.nz/file/ig0CCQ7L#nHLfCN9w6sWEHX9cFRWi1Goo4D9AZzPWAjr6cSuLm_cAnd here is the script. At the moment only the gates in the video are defined, that is prop_facgate_03_l and prop_facgate_03_r. @Jitnaught Thanks for offering to take a look, mate.
Imports GTA Imports System Imports System.Windows.Forms Public Class Dogamizer_Lock_In_Position Inherits Script Private Gate1 As Integer = 437009729 Private Gate2 As Integer = 450182863 Private Gate1Closest As Single Private Gate2Closest As Single Private Gate1Exist As Boolean Private Gate2Exist As Boolean Private PosX As Single Private PosY As Single Private PosZ As Single Private LockInPos As Boolean Private Sub General_Tick(ByVal Sender As Object, ByVal e As EventArgs) Handles MyBase.Tick Lock_In_Position() End Sub Private Sub Lock_In_Position() PosX = Game.Player.Character.Position.X PosY = Game.Player.Character.Position.Y PosZ = Game.Player.Character.Position.Z Gate1Closest = Native.Function.Call(Of Single)(Native.Hash.GET_CLOSEST_OBJECT_OF_TYPE, PosX, PosY, PosZ, 2.0, Gate1, false, 0, 0) Gate2Closest = Native.Function.Call(Of Single)(Native.Hash.GET_CLOSEST_OBJECT_OF_TYPE, PosX, PosY, PosZ, 2.0, Gate2, false, 0, 0) Gate1Exist = Native.Function.Call(Of Boolean)(Native.Hash.DOES_OBJECT_OF_TYPE_EXIST_AT_COORDS, PosX, PosY, PosZ, 2.0, Gate1, 0) Gate2Exist = Native.Function.Call(Of Boolean)(Native.Hash.DOES_OBJECT_OF_TYPE_EXIST_AT_COORDS, PosX, PosY, PosZ, 2.0, Gate2, 0) If Gate1Exist = True Then If LockInPos = True Then Native.Function.Call(Native.Hash.FREEZE_ENTITY_POSITION, Gate1Closest, true) If LockInPos = False Then Native.Function.Call(Native.Hash.FREEZE_ENTITY_POSITION, Gate1Closest, false) End If If Gate2Exist = True Then If LockInPos = True Then Native.Function.Call(Native.Hash.FREEZE_ENTITY_POSITION, Gate2Closest, true) If LockInPos = False Then Native.Function.Call(Native.Hash.FREEZE_ENTITY_POSITION, Gate2Closest, false) End If End Sub Private Sub OnKeyDown(ByVal Sender As Object, ByVal e As KeyEventArgs) Handles MyBase.KeyDown If (Gate1Exist = True Or Gate2Exist = True) And Game.IsKeyPressed(Keys.L) Then If LockInPos = False Then GTA.UI.Notify("LOCKED IN PLACE") LockInPos = True Exit Sub End If If LockInPos = True Then GTA.UI.Notify("UNLOCKED") LockInPos = False Exit Sub End If End If End Sub End Class
I haven't learned how to read lists from ini files yet so this script would become bloated if I continued as is. I'm definitely sure there are easier ways to do the same, but I'm still learning this whole coding thing.
-
@Dogamizer Yes, it is exactly what I would need.
-
@chonkie So if I know the object name or hash, I can add it to the script. At this point, it will be listed as gate1, gate2, gate3, etc. until I learn how or someone shows me how to read external lists. I'll spend the next few days adding the gates and doors I find and then I'll post the updated script here.
The locked in place true / false thing also needs work.
The script doesn't need to be compiled. Just copy the contents to a text file and name it with the .vb extention and put it in the scripts folder.
-
Made some improvements. Now there's an INI for changing the key, the radius, and whether to lock gates by default. It also reads a txt file of all of the models you want to lock. Oh and this version uses SHVDN v3 instead of v2.
I coded it in C#, since that is what I'm used to. But I also used a program to convert it to VB, since you used that.
Let me know if you have any questions.
C# version (copy to
GateLock.cs
in scripts folder)
VB version (automatically converted, untested) (copy toGateLock.vb
in scripts folder)INI settings (copy to
GateLock.ini
in scripts folder)
Gate models (copy toGates.txt
in scripts folder)
-
I use this for unlocking doors in the world or doors i spawn.
public class Gate
{
private readonly bool DEBUG = false;
public Prop Prop;
public bool Locked { get; private set; } = true;
public Gate(Prop prop)
{
this.Prop = prop;
}
public void Unlock()
{
Locked = false;
Function.Call(Hash._DOOR_CONTROL, this.Prop.Model.Hash, this.Prop.Position.X, this.Prop.Position.Y, this.Prop.Position.Z, false, 0f, 50f, 0f);
//if (this.DEBUG) { UI.Notify(this.Prop.Model.Hash + " Door unlocked " + this.Prop.Position); }
}
public void Lock()
{
Locked = true;
Function.Call(Hash._DOOR_CONTROL, this.Prop.Model.Hash, this.Prop.Position.X, this.Prop.Position.Y, this.Prop.Position.Z, true, 0f, 50f, 0f);
//if (this.DEBUG) { UI.Notify(this.Prop.Model.Hash + " Door locked " + this.Prop.Position); }
}
}Might be of some use to you. This does not hold them open, instead locks/unlocks a door so the player can/cant push it open.
-
@Jitnaught Nice. Thanks, mate. I'll dissect your script to learn how you did the gates list and ini stuff. Never tried C# coding before but then again, I only started with the VB stuff just recently. Never too late to learn something new.
Should this be released? How do you want to go about it? It's now essentially your script so you have rights over it.
One last thing. I wish there were more openly helpful people like you willing to part with knowledge instead of hoarding it. The community seems to be splitting into those who want to help and those who want to lock and sell. I think we could accomplish a lot more if we shared, like a community. I will never condone blatant theft of someone else's property, but locking everything away prevents people from learning how things are done.
Thanks again.
-
If you want to release it, feel free to do so. If you release my version just credit me for improving the mod. I don't want to release it.
I agree with the sharing of information. There are many things I'm sure are documented by somebody, but they don't want to share for whatever reason. One example I know of is the RagePluginHook devs.