Quantcast

Jump to content

» «
Photo

[C#] Car disappear from itself

10 replies to this topic
nordi
  • nordi

    Crackhead

  • Members
  • Joined: 17 Mar 2014
  • France

#1

Posted 06 May 2014 - 03:15 PM Edited by nordi, 16 August 2014 - 05:37 PM.

Hey

 

I spawn a car, about 200 meters away from the player, when "1" is pressed, but:

  • the car spawn, with emergency lights on (and the siren is turned on)
  • then the car disappear right after that !
  • I do not get any error.

 

I don't see where is the error, and sometimes, when I press "1" multiple time (4 or 5 times), the model spawn, and drive to my position.

 

 

Thanks.


LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#2

Posted 06 May 2014 - 03:36 PM

try making the vehicle required for mission after u spawn


julionib
  • julionib

    Coder

  • Feroci Racing
  • Joined: 13 Sep 2012
  • Brazil

#3

Posted 06 May 2014 - 03:58 PM Edited by julionib, 06 May 2014 - 03:58 PM.

and remember to set NoLongerNeeded when it is not required anymore, this will avoid "Frozen entities" bug


nordi
  • nordi

    Crackhead

  • Members
  • Joined: 17 Mar 2014
  • France

#4

Posted 07 May 2014 - 12:40 PM Edited by nordi, 07 May 2014 - 12:40 PM.

try making the vehicle required for mission after u spawn

 

Not working either, the car still spawn then disappear 2 seconds later ...  or after pressing multiple times the numpad key "1", it eventually works.

I think it's more because of a computer spec issue (which is weird, because I have a pretty good computer): because I actually spawn 2 models when "1" is pressed (but the code is the same, a copy & paste, with only different variables).

 

and remember to set NoLongerNeeded when it is not required anymore, this will avoid "Frozen entities" bug

Alright, will do, thanks for the tip.


julionib
  • julionib

    Coder

  • Feroci Racing
  • Joined: 13 Sep 2012
  • Brazil

#5

Posted 07 May 2014 - 03:36 PM

maybe other mod is deleting the vehicle or setting it to nolongerNeeded, try to remove other .asi or Scripts and test your mod alone, also try to create the car close to you and on screen to see if isnt the NoLongerNeeded that is deleting it


nordi
  • nordi

    Crackhead

  • Members
  • Joined: 17 Mar 2014
  • France

#6

Posted 07 May 2014 - 04:58 PM Edited by nordi, 16 August 2014 - 05:37 PM.

maybe other mod is deleting the vehicle or setting it to nolongerNeeded, try to remove other .asi or Scripts and test your mod alone, also try to create the car close to you and on screen to see if isnt the NoLongerNeeded that is deleting it

 

The problem seems to be the distance I spawn the model, at:


LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#7

Posted 07 May 2014 - 05:29 PM Edited by LordOfTheBongs, 07 May 2014 - 05:40 PM.

 

maybe other mod is deleting the vehicle or setting it to nolongerNeeded, try to remove other .asi or Scripts and test your mod alone, also try to create the car close to you and on screen to see if isnt the NoLongerNeeded that is deleting it

 

The problem seems to be the distance I spawn the model, at:

  • It works when I set the distance at: 15f: engine_1alarm = World.CreateVehicle(new Model(Settings.GetValueString("ENGINE", "MODELS", "firetruk")), World.GetNextPositionOnStreet(Player.Character.Position.Around(15.0f)));
  • It do not work when I set the distance at 150f: engine_1alarm = World.CreateVehicle(new Model(Settings.GetValueString("ENGINE", "MODELS", "firetruk")), World.GetNextPositionOnStreet(Player.Character.Position.Around(150.0f)));

 

doesnt make sense, ive spawned vehicles on the other side of the map no problem...

 

first spawn... then the very next line u mark it required for mission... also if u want to wait for some GTA object to exist before u access it then dont access it before the wait...

 

bad

engine_1alarm = World.CreateVehicle(new Model(Settings.GetValueString("ENGINE", "MODELS", "firetruk")), World.GetNextPositionOnStreet(Player.Character.Position.Around(150.0f)));

//these will crash if fire truck isnt created
engine_1alarm.PlaceOnNextStreetProperly();
engine_1alarm.SirenActive = true;

// Wait until the model creates.
while (!engine_1alarm.Exists())
{
    Wait(300);
}

good

//declared at top of script
string fireTruckModel;
//in constructor
fireTruckModel = Settings.GetValueString("ENGINE", "MODELS", "firetruk");

engine_1alarm = World.CreateVehicle(new Model(fireTruckModel), World.GetNextPositionOnStreet(Player.Character.Position.Around(150.0f)));

// Wait until the model creates.
while (!Game.Exists(engine_1alarm))
{
    Wait(0);//300 is not necessary
}

engine_1alarm.isRequiredForMission = true;
engine_1alarm.PlaceOnNextStreetProperly();
engine_1alarm.SirenActive = true;

also it is less work for your script to just save all ini settings on load to values u declare in your script... dont load your ini settings everytime u have to spawn... you can but you make more work for your PC than necessary

 

also using Game.Exists or Script.Exists will check the GTA object for a null value before checking existence... u will get a null exception if for some reason creating the object fails and the create method returns null. In programming you need to avoid accessing objects that are null.


nordi
  • nordi

    Crackhead

  • Members
  • Joined: 17 Mar 2014
  • France

#8

Posted 07 May 2014 - 06:22 PM Edited by nordi, 07 May 2014 - 07:37 PM.

 

 

maybe other mod is deleting the vehicle or setting it to nolongerNeeded, try to remove other .asi or Scripts and test your mod alone, also try to create the car close to you and on screen to see if isnt the NoLongerNeeded that is deleting it

 

The problem seems to be the distance I spawn the model, at:

  • It works when I set the distance at: 15f: engine_1alarm = World.CreateVehicle(new Model(Settings.GetValueString("ENGINE", "MODELS", "firetruk")), World.GetNextPositionOnStreet(Player.Character.Position.Around(15.0f)));
  • It do not work when I set the distance at 150f: engine_1alarm = World.CreateVehicle(new Model(Settings.GetValueString("ENGINE", "MODELS", "firetruk")), World.GetNextPositionOnStreet(Player.Character.Position.Around(150.0f)));

 

doesnt make sense, ive spawned vehicles on the other side of the map no problem...

 

first spawn... then the very next line u mark it required for mission... also if u want to wait for some GTA object to exist before u access it then dont access it before the wait...

 

bad

engine_1alarm = World.CreateVehicle(new Model(Settings.GetValueString("ENGINE", "MODELS", "firetruk")), World.GetNextPositionOnStreet(Player.Character.Position.Around(150.0f)));

//these will crash if fire truck isnt created
engine_1alarm.PlaceOnNextStreetProperly();
engine_1alarm.SirenActive = true;

// Wait until the model creates.
while (!engine_1alarm.Exists())
{
    Wait(300);
}

good

//declared at top of script
string fireTruckModel;
//in constructor
fireTruckModel = Settings.GetValueString("ENGINE", "MODELS", "firetruk");

engine_1alarm = World.CreateVehicle(new Model(fireTruckModel), World.GetNextPositionOnStreet(Player.Character.Position.Around(150.0f)));

// Wait until the model creates.
while (!Game.Exists(engine_1alarm))
{
    Wait(0);//300 is not necessary
}

engine_1alarm.isRequiredForMission = true;
engine_1alarm.PlaceOnNextStreetProperly();
engine_1alarm.SirenActive = true;

also it is less work for your script to just save all ini settings on load to values u declare in your script... dont load your ini settings everytime u have to spawn... you can but you make more work for your PC than necessary

 

also using Game.Exists or Script.Exists will check the GTA object for a null value before checking existence... u will get a null exception if for some reason creating the object fails and the create method returns null. In programming you need to avoid accessing objects that are null.

 

 

 

Still not working, but I don't understand why ! In another function, i also spawn a car, very far from the player, and there is no problem ! (the only difference is that I don't spawn peds and assign them a task).


LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#9

Posted 07 May 2014 - 06:35 PM Edited by LordOfTheBongs, 07 May 2014 - 06:36 PM.

try making all firemen peds u spawn in the vehicle required for mission too... my only guess is the game wants to delete the peds and since they are in a car the game maybe deletes the car too

  • nordi likes this

julionib
  • julionib

    Coder

  • Feroci Racing
  • Joined: 13 Sep 2012
  • Brazil

#10

Posted 07 May 2014 - 07:03 PM

yep, something is wrong in your gta/scripts running, is not normal a entity be deleted after his creation, game seems to automatically set as required for mission when we create entities.

what i do here is create the objects behind camera (-20 * camera direction + to ground) and then i position it where i need, i started making this because sometimes distant created peds are created invisible and nothing can set them visible again ^^

  • nordi likes this

nordi
  • nordi

    Crackhead

  • Members
  • Joined: 17 Mar 2014
  • France

#11

Posted 07 May 2014 - 07:39 PM

try making all firemen peds u spawn in the vehicle required for mission too... my only guess is the game wants to delete the peds and since they are in a car the game maybe deletes the car too

 

It works, thanks !

 

yep, something is wrong in your gta/scripts running, is not normal a entity be deleted after his creation, game seems to automatically set as required for mission when we create entities.

what i do here is create the objects behind camera (-20 * camera direction + to ground) and then i position it where i need, i started making this because sometimes distant created peds are created invisible and nothing can set them visible again ^^

 

"game seems to automatically set as required for mission when we create entities": That's what I thought, but obviously it didn't this time...

Thanks for the tips ;)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users