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

[C++] Gravity gun deleting objects instead of picking them up


Flying Scotsman
 Share

Recommended Posts

Flying Scotsman

I originally had some form of gravity gun code (courtesy of Mafin's excellent Menya Baes) ages back, but it didn't work for me so I shelved it.

 

I went back to it recently and it turns out it was using the wrong kind of 'is aiming at entity' native (it originally used one for melee lock on style targeting and not weapon ones) so I fixed that but now it just deletes objects/entities/peds/vehicles instead of picking them up and I'm not sure why.

 

This is the code I'm using (originally created by Mafins):

/* Gravity Gun related globals */bool grav_target_locked = false;Entity grav_entity = 0;DWORD graf_partfx = 0;/* Begin Gravity Gun related functions*/Vector3 GetCoordsFromCam(float distance){	Vector3 Rot = CAM::GET_GAMEPLAY_CAM_ROT(2);	static Vector3 Coord = CAM::GET_GAMEPLAY_CAM_COORD();	Rot.y = distance * cos(Rot.x);	Coord.x = Coord.x + Rot.y * sin(Rot.z * -1.0f);	Coord.y = Coord.y + Rot.y * cos(Rot.z * -1.0f);	Coord.z = Coord.z + distance * sin(Rot.x);	return Coord;}void VectorToFloat(Vector3 unk, float *Out){	Out[0] = unk.x;	Out[1] = unk.y;	Out[2] = unk.z;}void RequestControlEntity(Entity entity) //needed so we can pick up props/Peds. This is needed in SP, even though it's a NETWORK native{	int tick = 0;	while (!NETWORK::NETWORK_HAS_CONTROL_OF_ENTITY(entity) && tick <= 12)	{		NETWORK::NETWORK_REQUEST_CONTROL_OF_ENTITY(entity);		tick++;	}}/* End Gravity Gun related functions*///Gravity Gun	if (bPlayerExists && featureGravityGun)	{		Ped tempPed;		Hash tempWeap;		if (!grav_target_locked) PLAYER::GET_PLAYER_TARGET_ENTITY(PLAYER::PLAYER_ID(), &grav_entity);		tempPed = PLAYER::PLAYER_ID(); WEAPON::GET_CURRENT_PED_WEAPON(PLAYER::PLAYER_PED_ID(), &tempWeap, 1);		if ((PLAYER::IS_PLAYER_FREE_AIMING(tempPed) || PLAYER::IS_PLAYER_TARGETTING_ANYTHING(tempPed)) && ENTITY::DOES_ENTITY_EXIST(grav_entity) && tempWeap == GAMEPLAY::GET_HASH_KEY("weapon_stungun"))		{			if (!grav_target_locked)			{				PLAYER::GET_PLAYER_TARGET_ENTITY(PLAYER::PLAYER_ID(), &grav_entity); grav_target_locked = true;			}			float Coord[3]; VectorToFloat(GetCoordsFromCam(5.5f), Coord);			/*This isn't mandatory, but makes it look nice			if (!GRAPHICS::DOES_PARTICLE_FX_LOOPED_EXIST(grav_partfx))			{			STREAMING::REQUEST_PTFX_ASSET();			if (STREAMING::HAS_PTFX_ASSET_LOADED())			{			grav_partfx = GRAPHICS::START_PARTICLE_FX_LOOPED_AT_COORD((char*)"scr_drug_traffic_flare_L", Coord[0], Coord[1], Coord[2], 0.0f, 0.0f, 0.0f, 0.5f, 0, 0, 0, 0);			GRAPHICS::SET_PARTICLE_FX_LOOPED_COLOUR(grav_partfx, 1.0f, 0.84f, 0.0f, 0);			}			}*/			RequestControlEntity(grav_entity); //so we can pick up the ped/prop/vehicle			ENTITY::SET_ENTITY_COORDS_NO_OFFSET(grav_entity, Coord[0], Coord[1], Coord[2], 0, 0, 0);			if (ENTITY::IS_ENTITY_A_VEHICLE(grav_entity))			{				ENTITY::SET_ENTITY_HEADING(grav_entity, ENTITY::GET_ENTITY_HEADING(PLAYER::PLAYER_PED_ID()) + 90.0f);			}			if (PED::IS_PED_SHOOTING(PLAYER::PLAYER_PED_ID()))			{				//AUDIO::PLAY_SOUND_FROM_ENTITY(-1, (char*)"Foot_Swish", grav_entity, (char*)"docks_heist_finale_2a_sounds", 0, 0);				ENTITY::SET_ENTITY_HEADING(grav_entity, ENTITY::GET_ENTITY_HEADING(PLAYER::PLAYER_PED_ID()));				ENTITY::APPLY_FORCE_TO_ENTITY(grav_entity, 1, 0.0f, 350.0f, 2.0f, 2.0f, 0.0f, 0.0f, 0, 1, 1, 1, 0, 1);				grav_target_locked = false;			}		}		/*else if (GRAPHICS::DOES_PARTICLE_FX_LOOPED_EXIST(grav_partfx))		{		GRAPHICS::STOP_PARTICLE_FX_LOOPED(grav_partfx, 0);		GRAPHICS::REMOVE_PARTICLE_FX(grav_partfx, 0);		STREAMING::REMOVE_PTFX_ASSET();		}*/		if (!PLAYER::IS_PLAYER_FREE_AIMING_AT_ENTITY(tempPed, grav_entity) || !PLAYER::IS_PLAYER_TARGETTING_ENTITY(tempPed, grav_entity))		{			grav_target_locked = false;		}		featureGravityGunUpdated = false;		set_status_text("Gravity gun: ~r~called");	}}

Now, when you use it in-game and aim the stun-gun at any entity - it just deletes it (or teleports it to the top of the sky for some reason (I've seen cars collide in the air but it mainly seems to delete them completely).

 

I seem to be looping it correctly as when the option is called, the status text appears on screen until I turn it off so I don't think that's the issue.

 

Any help would be greatly appreciated!

Edited by Zemanez
Link to comment
Share on other sites

Flying Scotsman

Mark them as mission entities.

 

Thanks for the reply.

 

I've set any entities as mission ones to prevent them despawning but it turns out, holding right click just sets the coords as negatives, and increments them (holding it for ~30 seconds made the X coord -6546.13 for example) and I have no idea why...

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.