Quantcast

Jump to content

» «
Photo

[Q] Make Vehicle Persistent

3 replies to this topic
JebediahKerman
  • JebediahKerman

    Player Hater

  • Members
  • Joined: 14 Jan 2014

#1

Posted 03 February 2014 - 03:01 PM

I want to spawn a Vehicle at a fixed position, so it might be out of the default render distance, and I want to keep that Vehicle.

If I set isRequiredForMission to true It still doesn't work correctly. Sometimes everything goes fine and sometimes when I try working with the Vehicle I am getting the Message that the object isn't set. I tried stacking isRequiredForMission and the native SET_VEHICLE_ALWAYS_RENDER but It still doesn't do the job right.

 


LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#2

Posted 03 February 2014 - 03:10 PM

you are doing it right, u simply need to create and then after say it is required for mission... once is enough... my only guess is u have a conflicting script like maybe a traffic loader or gta has reached the vehicle limit for the world and the spawn failed. Not sure the issue but you could test with out other scripts installed to be sure it isnt a conflict with another script


JebediahKerman
  • JebediahKerman

    Player Hater

  • Members
  • Joined: 14 Jan 2014

#3

Posted 03 February 2014 - 03:39 PM Edited by JebediahKerman, 03 February 2014 - 03:41 PM.

you are doing it right, u simply need to create and then after say it is required for mission... once is enough... my only guess is u have a conflicting script like maybe a traffic loader or gta has reached the vehicle limit for the world and the spawn failed. Not sure the issue but you could test with out other scripts installed to be sure it isnt a conflict with another script

Strange, I even tried spawning the Vehicle under the player so It gets loaded, then setting it to be a required Vehicle and then teleporting It back to where It is supposed to be.

 

Now I have no clue at all what this is. I post my code:

Vehicle vehicle = GTA.World.CreateVehicle(Model.FromString(v.Name), player.Character.Position);
Game.Console.Print("1");
vehicle.isRequiredForMission = true;
Game.Console.Print("2");

After my little debugging, it turns out, that the error occures after "1" and before "2" so the one line above created Vehicle at the player.

 

I have no Traffic Loader installed so It must be your second point because of the randomness of the success. Any Ideas what I could do, this isn't normal so I must have done something wrong.


LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#4

Posted 03 February 2014 - 09:42 PM Edited by LordOfTheBongs, 03 February 2014 - 09:46 PM.

Maybe you can try to delete some vehicles in the world before u spawn...

int deleteCount = 0;
foreach (Vehicle veh in World.GetAllVehicles())
{
    if (!Game.Exists(veh)) continue; //prevents null exceptions
    if (veh.isOnScreen) continue; //dont delete if on screen
    if (veh.isRequiredForMission) continue; //just in case u have some vehicles u marked required (you can remove if u know u dont)
    if (veh.Position.DistanceTo(Game.LocalPlayer.Character.Position) < 50f) continue; //dont delete cars too close or people may notice, maybe edit the range
 
    veh.Delete();
    deleteCount++;
}

Game.Console.Print(deleteCount.ToString() + " vehicles deleted");
 
//Now your code...
Vehicle vehicle = GTA.World.CreateVehicle(Model.FromString(v.Name), player.Character.Position);
Game.Console.Print("1");
vehicle.isRequiredForMission = true;
Game.Console.Print("2");

maybe try that





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users