Flying Scotsman Posted March 21, 2016 Share Posted March 21, 2016 (edited) 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 March 21, 2016 by Zemanez Link to comment Share on other sites More sharing options...
jedijosh920 Posted March 22, 2016 Share Posted March 22, 2016 Mark them as mission entities. Link to comment Share on other sites More sharing options...
Flying Scotsman Posted March 22, 2016 Author Share Posted March 22, 2016 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now