Colata Posted July 11, 2015 Share Posted July 11, 2015 Im trying to make a vehicle spawn, but before spawning a vehicle i want to remove one that might be already spawned (which should be under 10 units away) var Buzzard = new MenuButton("Buzzard"); Buzzard.Activated += (sender, args) => { Vehicle NearbyVeh = Function.Call<Vehicle>(Hash.GET_PED_NEARBY_VEHICLES, player, 10f); NearbyVeh.Delete(); World.CreateVehicle(VehicleHash.Buzzard, MazeBankHeli); }; helicopterMenuItems.Add(Buzzard); When i try a button press in the menu to spawn a vehicle, it crashes the game. I'm trying to fetch a vehicle (GET_PED_NEARBY_VEHICLES) from a remote location (where the is almost no vehicles) so my only thought on why it's crashing the game is because it cant find any vehicle to return. Link to comment Share on other sites More sharing options...
leftas Posted July 11, 2015 Share Posted July 11, 2015 (edited) Before you using native figure I out what paramaters it takes, and c# script hook had already wrapped this native, it's in world class. And it returns array of vehicles, to return one you can use either get vehicle in sphere to get or get closest vehicle. And check if it exists. All the best, Paul. Edited July 11, 2015 by leftas Link to comment Share on other sites More sharing options...
InfamousSabre Posted July 11, 2015 Share Posted July 11, 2015 (edited) Well, first of all, that function does not return a Vehicle.Second: you must make sure it exists before trying to act upon it. This function actually requires a struct, where the first value is the maximum number of elements to return. Here is a sample of how I was able to get it to work correctly, without yet knowing the struct format.//Setup the arrayconst int numElements = 10;const int arrSize = numElements * 2 + 2;Any veh[arrSize];//0 index is the size of the arrayveh[0] = numElements;int count = PED::GET_PED_NEARBY_VEHICLES(PLAYER::PLAYER_PED_ID(), veh);if (veh != NULL){//Simple loop to go through resultsfor (int i = 0; i < count; i++){int offsettedID = i * 2 + 2;//Make sure it existsif (veh[offsettedID] != NULL && ENTITY::DOES_ENTITY_EXIST(veh[offsettedID])){//Do something}}} Also, you should know that that function is not able to see certain vehicles. I don't really remember which ones right now, but if missing a vehicle or two (or all, depending on circumstances) is an issue, just keep this in mind.If you're just wanting to remove vehicles that your script has spawned: simply keep a list of them. Edited July 11, 2015 by InfamousSabre leftas 1 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