[New to modding] Player/Ped obj ID property not defined, how to obtain it?
Hello Community !
I'm completely new to GTAV modding but I have some experience in programming. By following this tutorial playlist (videos are from more than a year ago)
I got running a super simple mod which spawns dogs by pressing a key. I got stuck when trying to obtain the ID property of a Ped object, like follows:
Ped player = Game.Player.Character;
int pID = player.ID // VS error about no definition for ID
Ped pedObj = GTA.World.CreatePed(pedModelName, spawnLocation);
int pID = PedObj.ID; // Same error.
A screenshot of tutorial here: https://1drv.ms/i/s!Anc-GpEvfA8Qg6ts--4y24t5ECFCNA (ID is found) and my code (where undefined) https://1drv.ms/i/s!Anc-GpEvfA8Qg6tqohwUbaX-AIwDaQ
By browsing on ScriptHookVdotNet (I have latest version as January 2017) I can check that ID has not been defined so maybe it is obtained differently now, my only guess right now in order to make the code run is:
which also returns Int but of course the meaning is different. So my questions are:
- Is it safe to assume this ID simply as a unique identifier of created objects? (if so then I assign them one myself)
- Is it safe to assume the meaning of GetHashCode() is a unique identifier for each object within the library?
- How do I obtain the ID number?
@pc_user86 As far as I know, GetHashCode gets the hash for the model used, so two Peds could have the same hashcode if they are using the same model, even if they looked different because of clothing/accessory variations.
I have never come across any ID property for the player, so the only thing I know will be unique, is the instance of the Ped itself. If you wanted to assign ID numbers, then you would have to build a class to store Ped information and then make that Ped persistent.
I suspect the IDs are not used because for the majority of the time, Peds are not persistent. They spawn, walk around and then vanish, so an ID wouldn't have much practical use in that short lifespan.
ID was replaced with Handle.
@aimless Ah, thank you. That'll teach me to make speculative assumptions.
@pc_user86 Sorry for the misleading information, I've only been modding for around 6 months and very little with Peds... I have so much to learn yet it's untrue.
@LeeC2202 I would would not have known about what an ID is. If i never saw that tutorial.
@aimless Do you know if the Handles are recycled after a period of time or are they always guaranteed to be unique?
If they are unique, I can use them in my dirty cars mod and the OP gets a perfect solution to their problem as well. I call that a win-win for you.
Thank you guys @aimless and @LeeC2202 for your reply. This was very useful!.
Please allow me add 2 quick questions:
- How do I print text on the screen? (and update the actual string, for example displaying a ever-changing number on the middle-right of the screen?)
- Is there any document with guidelines, syntax usage, code examples, things like this that we could always use for quick-referencing and consultation?
Thanks again guys!
@LeeC2202 I believe they are unique.
@pc_user86 You can use UI.ShowSubtitle(Game.Player.Character.Position.ToString(), 100);
in a loop or on tick to display your players position. It shows at center bottom of screen. You can do it at a different position but you need ether use NativeUI or use function calls. I have some links that ill post later to some code examples.
@aimless this worked perfect is just what I need, thank you man.
Lots of examples in these two.
Setting ped relationships and groups
Setting Ped components.
Simple helpful functions.
Display Help Text
Driving style guid
Task sequnce using natives
NativeUI Menu Library
lots of list and usefull info.
Vehicle modle table