Using custom object with CreateObject()

Hi, sorry it takes time but I have no ideas what the problem might be. A similar post where I couldn’t find help.

Getting started will start like someone on this topic

This is inside my resource folder
1

This is inside my stream folder
2

This is the .ytyp file
3

This is my resource file
4

This is the code I’m using to spawn the object
5

The strange problem is that the object appears on the map easily via the ymap file
6

But when I try to load it with a script, the script gets stuck in a loop possibly because it cannot load it
8
7

As you can see with the print command, the hash gets from the model but cannot load it

1 Like

Are you loading the YTYP in the fxmanifest?

Run this to see if it even exists IsModelInCdimage, which will help debug some answers.

Hi, what do you mean include ytyp in fxmanifest how can i do it i can’t see solutions on internet

and the IsModelInCdimage returns false

First things first; THANK YOU, THANK YOU, THANK YOU!
You actually included all of the information required to help you. Ladies and gentlemen, we found someone with brains! hahaha. But seriously, thank you for actually structuring your support topic so well.

Anyway, please add the following to the __resource.lua file that you shared. The one that has “this_is_a_map” inside it.

files {
    'stream/carrot.ytyp'
}

data_file 'DLC_ITYP_REQUEST' 'stream/carrot.ytyp'

That should fix your issue.


But please allow me to help you further. Here is some advice;
Stop using __resource.lua files and start using fxmanifest.lua files. They do the same thing, but have a different structure and the latter is the new way of doing things. So if you are creating new stuff, which you are, you shouldn’t be using outdated and deprecated ways of doing stuff. More information can be found here → Resource manifest - Cfx.re Docs

But basically, you can convert it easily. Change the name of the file from “__resource” to “fxmanifest” and replace the contents with the following;

fx_version 'cerulean'
games { 'gta5' }

this_is_a_map 'yes'

files {
	'stream/carrot.ytyp'
}

data_file 'DLC_ITYP_REQUEST' 'stream/carrot.ytyp'

Also, with the script that you use to spawn, GetHashKey is a function that should be avoided when possible. It is used by everyone, everywhere. But it shouldn’t be. Instead of placing model names inside the GetHashKey function, simply encase them with backticks ( ` ), for a process known as Jenkins hashing. At run time, this will be read by the computer as the hask key, not the name. So in your example, you had the following;

local hash = GetHashKey("carrot")

This can become;

local hash = `carrot`

Because `carrot` (with those backticks), is the same as GetHashKey(“carrot”). Now your scripts will be faster!

4 Likes

Thanks for the precise answer and a few tips helped!