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

OnTriggerEnter / Events driven scripts ?


Philoupe
 Share

Recommended Posts

Hi,

 

I'm planing to create some additional missions for GTA V, but I didn't found anything about envents like entering a zone, so I wonder if that was possible with the ScriptHook SDK.

 

My goal is to start the mission when you enter a specific zone and not being forced to check you position every frame.

 

Did anyone found something about it ?

Thanks in advance.

Link to comment
Share on other sites

jedijosh920

Ha, came from Unity? I'm learning and making games with it too. Anyways, try checking the distance between coordinates, should do what you want.

Link to comment
Share on other sites

I came from lot of thing but yeah, I made some game with Unity

 

I know that I can check distance, but it's not very powerful and it's à little dirty.

 

The fact is, I want to start a mission by entering a marker, and to do that I would need to check position every time if I can't use events.

 

Thanks in advance.

Link to comment
Share on other sites

InfamousSabre

You have to check position every frame (or every other frame, if you want). It isn't dirty. What do you think Unity does underneath those events? Checks position.

Edited by InfamousSabre
Link to comment
Share on other sites

Isn't it too heavy to get position at each frames ?

 

Unity check position but I though he get the position only once by object, group object by locations approximations and compare distance only when the 2 objects are in the same ( or surrounding ) areas.

 

It isn't very dirty to get position for one script but if there is multiple scripts using players position to calculate distance, it isn't very optimized.

 

Thanks.

Link to comment
Share on other sites

jedijosh920

Nah it's fine just use position distance, and I noticed the function from Unity http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerEnter.html because I was messing with it earlier.

 

EDIT: Now that I think of it, you can probably use one of the many collision functions as well or ray cast.

Edited by jedijosh920
Link to comment
Share on other sites

InfamousSabre

Getting position isnt heavy at all. Its just reading 3 floats from memory. If youre really concerned, just do it every other frame or something. If youre concerned about checking distance being a heavy calculation, just skip the sqrt operations and check for your distance, squared.

Link to comment
Share on other sites

I ran this in a loop Vector3 coords = ENTITY::GET_ENTITY_COORDS(playerPed, true); 500000 times. It took 63 ms.

 

GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(100, 100, 100, 1000, 1500, 2500, 1); // 5 million times, 547 ms
SYSTEM::VDIST(100, 100, 100, 1000, 1500, 2500); // 5 million times, 550 ms
My computer is 8 years old.
Edited by R3QQ
Link to comment
Share on other sites

It's wierd that GET_DISTANCE_BETWEEN_COORDS is faster than VDIST when the first one should do the sqrt function, and the vdist don't.

And 550ms can appears small but I just remember that you game should do all (Not only yours) calculations in 16ms to be at 60FPS. ;)

EDIT : And if I had events, i could avoid all of this :
PLAYER::PLAYER_ID();

PLAYER::GET_PLAYER_PED(player);

ENTITY::GET_ENTITY_COORDS(playerPed, true);

SYSTEM::VDIST(playerPos.x, playerPos.y, playerPos.z, 1000, 1500, 2500);

 

(because, when the user is not near the target, I don't need him.)

Thanks.

Edited by Philoupe
Link to comment
Share on other sites

InfamousSabre

It's wierd that GET_DISTANCE_BETWEEN_COORDS is faster than VDIST when the first one should do the sqrt function, and the vdist don't.

And 550ms can appears small but I just remember that you game should do all (Not only yours) calculations in 16ms to be at 60FPS. ;)

 

EDIT : And if I had events, i could avoid all of this :

PLAYER::PLAYER_ID();

PLAYER::GET_PLAYER_PED(player);

ENTITY::GET_ENTITY_COORDS(playerPed, true);

SYSTEM::VDIST(playerPos.x, playerPos.y, playerPos.z, 1000, 1500, 2500);

 

(because, when the user is not near the target, I don't need him.)

 

Thanks.

You dont need natives to check distance. Just check it yourself.

 

Again. Even with events you wouldn't be avoiding anything. I don't know how much more plainly I can say this. The operations would happen behind-the-scenes in order for the event to ever fire.

Edited by InfamousSabre
Link to comment
Share on other sites

You cold avoid most of the calls.
Instad of calling :

PLAYER::PLAYER_ID();

PLAYER::GET_PLAYER_PED(player);

ENTITY::GET_ENTITY_COORDS(playerPed, true);
for each scripts you would only call them once.

And you could define zones and only check distance by zones if your script subbscribed on events by zones.

As
VDIST seems to be the distance calculation without the sqrt function, I don't think I can do something faster.

Thanks

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.