Player can't spawn external prop "ydr file" when player is far from original prop

Hi

I want to spawn a prop using a command, that prop is an external 3d object and is suposed to be dynamic and not static in the map, mean that player can spawn it where he want.

The way i do that is first the 3d model is added to the game as a resource in “stream” with files “ymf, ymap, ytyp, ydr” and it’s spawned in the game but hiden inside a buildind or garage so player can’t see it “purpose is that player spawn in it in his position”.

And it’s working so player in fact spawn it BUT the problem is that it only work when i am in specific range of this original spawned prop, seem’s like gta unload it when i am away from the model range.

This is my C# code to load and keep seeking for object to be loaded

uint spawnModel = (uint)GetHashKey(“myModel”);
var model = new Model((int)spawnModel);
model.Request();

while (!model.IsLoaded)
{
Miscellaneous.SendMessage(“Error”, “model myModel is not loaded”, 255, 0, 0);
await Delay(1000);
}

So first is it the right way to load external object to spawn it dynamically in the game and second how to make it permanent and avalaible everywhere in the map.

I already post an issue in the link bellow but maybe i wasn’t clear:

Thank you for your response.

Hi! No need to create another topic.

Anyway, I am not quite sure whether I fully understand the problem. You are having issues spawning the prop in an interior, correct? Now - try using this native to create the prop:

Setting isNetwork and netMissionEntity to true should resolve your issue with the prop disappearing.

Hope that helps.

Hi
i tryed this option but same problem
the problem is that the prop is not loaded to be created as entity, and it does only when i am in this f***g range.

while (!model.IsLoaded)
{
Miscellaneous.SendMessage(“Error”, “model1 is not loaded”, 255, 0, 0);
await Delay(1000);
}

the loop goes infinite untill i aproach the original model.

Could you provide the whole snippet? I don’t think spawning the object is the problem. Also, are you running the script on OneSync Infinity server?

not onesync no infinity, i dev in localhost for fun.

I use C#

uint spawnModel = (uint)GetHashKey(“model1”);
var model = new Model((int)spawnModel);
model.Request();

while (!model.IsLoaded)
{
Miscellaneous.SendMessage(“Warning”, “model1 is not loaded yet”, 255, 0, 0);
await Delay(1000);
}

Miscellaneous.SendMessage(“Information”, “model1 is loaded”, 0, 255, 0);

As i already said, if my spoon is far away the position of my addon object that is spawned in a hidden place in the map, then the loop go infinite, but as soon as i approach it the loop set free and then i can go where i want and i can invoc my object since it’s already loaded.

One way is to teleport player to the position of the add-on object and wait untill object is loaded and teleport him again in the original spoon but it’s ugly way.

I still can’t see where you spawn the object in the code. Anyway - spawning an object needs to be done as follows:

It may be possible (and is very likely), that you won’t be able to create an object outside of your render distance. In that case you’d have to check if the client got close enough for the object to be spawned. Please note that the model can be loaded without creating it’s instance in-game, and thus it shouldn’t cause problems which you are having. Try using natives I’ve provided in the links.

what i wrote is a code behind an action that trigger this code, it could be a command or when pressing a key and actually i use a key but it does’nt matter cause code remain the same.

and this is the problem, object is not loaded untill you get close to it IF it’s an external “not built in with gta”, otherwize it works.

i just use natives as you said but same, it does not work.

uint spawnModel = (uint)GetHashKey(“model1”);

RequestModel(spawnModel);
while(!HasModelLoaded(spawnModel))
{
Miscellaneous.SendMessage(“Error”, “model 1 is not loaded”, 255, 0, 0);
await Delay(1000);
}

Maybe i use the wrong way, i use object as a map model, i mean i create a resource as a map with __resource.lua is :
resource_manifest_version ‘44febabe-d386-4d18-afbe-5e627f4af937’

this_is_a_map ‘yes’

and in the stream folder i put the files
_manifest.ymf, ymap “where is spawned in game using codewalker”, ytyp, ydr (3d model)

maybe is there another way to import object to gta as object not map!!! but it’s the only way to add add-on to gta as far as i know -_-

Use a DLC_ITYP_REQUEST in your fxmanifest.lua to ensure the .#typ file is always loaded, and not only when near a map.

For example:

data_file 'DLC_ITYP_REQUEST' 'dummy/myfile.ytyp'

(if your .ytyp is called myfile.ytyp. The game will ignore the dummy/ part.)

it worked like a charme :slight_smile:

Thank you and GIMIcz for the support and time you gave to me i appreciate a lote.