Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Support

    3. Suggestions

Happy Holidays from the GTANet team!

[C#] Most efficient way to remove hard-locked fences


CliffHanger
 Share

Recommended Posts

CliffHanger

I have major annoyances with hard-locked fences, for instance the gates around the dock area.

They won't open when you're driving in front of them or trying to smash them, and there's many of them in the game.

 

I was thinking yeah I could probably find them individually, get their hash and call the script to move them away or removed them, but is there a more efficient way to approach this problem?

 

Thanks!

Link to comment
Share on other sites

Yes there is, there's a few things you need to know first.

  • The model name of the gates: Use somehting like menyoo, or Developer Helper to get the model name/hash of the gates. We're gonna need them later.
  • The exact coordinates of the gate. Again this is another things that matters, you can use the same tools as explained above to get these values.

Here's an example script that should serve as a template.

Keep in mind, that it's entirely possible to just pass the players coordinates to the function, and achieve the same result (since this function just get's the closest door of type).

int hash = Function.Call<int>(Hash.GET_HASH_KEY, "my_gate_prop_model_name");Vector3 coords = /*The coordinates of the door/gate. You can also use the players position if you don't want to get the coordinates for every prop.*/;// 0f: fully closed// 1f: opening// -1f: fully openedfloat startingStateOfDoor = 0f;bool doorIsLocked = false; // Set's the door to unlocked.Function.Call(Hash.SET_STATE_OF_CLOSEST_DOOR_OF_TYPE, hash, coords.X, coords.Y, coords.Z, doorIsLocked, startingStateOfDoor, false);

There are a few natives you should check out (at the time I'm writing this, NativeDB's database has been cleared again so you'll have to wait for the information to come back):

  • void _DOOR_CONTROL(Hash doorHash, float x, float y, float z, BOOL locked, float p5, float p6, float p7) // 9B12F9A24FABEDB0 4E0A260B
  • void GET_STATE_OF_CLOSEST_DOOR_OF_TYPE(Hash type, float x, float y, float z, BOOL *locked, float *heading) // EDC1A5B84AEF33FF 4B44A83D
  • void SET_STATE_OF_CLOSEST_DOOR_OF_TYPE(Hash type, float x, float y, float z, BOOL locked, floatheading, BOOL p6) // F82D8F1926A02C3D 38C951A4
You mentioned:
get their hash and call the script to move them away or removed them, but is there a more efficient way to approach this problem?

In game-design or programming in general, there's no way to tell an object to do something, without a reference to that object. So even if it was a native function you'd still need some kind of pointer to the object in memory. Edited by sollaholla
  • Like 1
Link to comment
Share on other sites

Also this might help you:

public enum DoorState{    Closed,    Opened}public static class PropExt{	public static void SetStateOfDoor(this Prop prop, bool locked, DoorState heading)	{		Function.Call(Hash.SET_STATE_OF_CLOSEST_DOOR_OF_TYPE, prop.Model.Hash, prop.Position.X, prop.Position.Y, prop.Position.Z, locked, (int)heading, 1);	}	public static bool GetDoorLockState(this Prop prop)	{		var locked = false;		var heading = 0;		unsafe		{			Function.Call(Hash.GET_STATE_OF_CLOSEST_DOOR_OF_TYPE, prop.Model.Hash, prop.Position.X, prop.Position.Y, prop.Position.Z, &locked, &heading);		}		return locked;	}}

It's just an easier way of doing it, without ugly code.

Example:

if (myGate.GetDoorLockState()) // The gate is locked{    myGate.SetStateOfDoor(false, DoorState.Clsoed); // Unlock it, and default it to closed.}

My theory is, that you could just do World.GetNearbyProps(); and loop through them, then use this example code in a loop. This is untested, and I don't know if it will f*ck up objects that aren't actually doors.

 

 

EDIT: I completely forgot about BOOL _DOES_DOOR_EXIST(Hash doorHash) // C153C43EA202C8C1 5AFCD8A1
So you can just check if the object is a door, and bam you have yourself a solution.

Edited by sollaholla
  • Like 1
Link to comment
Share on other sites

CliffHanger

Very good feedback!

 

I'm currently testing this very low-stress script and so far it doesn't seem to be causing problems. It's applying SET_STATE_OF_CLOSEST_DOOR_OF_TYPE to every objects within a 20 radius every 2 seconds.

        getDoorsDelay -= FramerateDividedBy60;        if (getDoorsDelay <= 0)        {            getDoorsDelay = 120f;            Prop[] GetProps = World.GetNearbyProps(Game.Player.Character.Position, 20f);            for (int i = 0; i < GetProps.Length; i++)            {                Function.Call(Hash.SET_STATE_OF_CLOSEST_DOOR_OF_TYPE, GetProps[i].Model.Hash, GetProps[i].Position.X, GetProps[i].Position.Y, GetProps[i].Position.Z, false, 0, 1);            }        }

I'll have to test this thoroughly to make sure it's not f*cking up with very specific objects that aren't doors, as you already specified. But so far the doors are unlocking!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.