Jump to content

[Solved] Profession Spawn with 'X' Item


Japer

Recommended Posts

I need help to get a certain profession to start a game with a certain item. Much like the policeman in the early builds who started off with a pistol.

I have a seen a mod that references a trait, 'if trait then add inventory x'

My game just loads up and freezes after the initial loading so I can't find code errors as the cmd just shows the game loading

I have tried many different things but i'm a complete noob at coding, here is what i've got so far;

ResidentEvilProfessions = {}function ResidentProfessions.giveItems()	if getPlayer():HasTrait("Stars") == true then		getPlayer():getInventory():AddItem("Base.Bullets9mm");	endendEvents.OnGameStart.Add(ResidentEvilProfessions.giveItems);

The trait 'stars' does nothing what-so-ever. I just created it for a if reference. So ideally if anyone knows of code that can skip that part would be handy, i.e. if getplayer hasprofession

Help would be much appreciated thanks.

(*note this is in it's own .lua file, I have tried it in it the professions.lua and many many other variations)

Link to comment
Share on other sites

Can you also post the code where you create the profession? Is the game hanging before you get into the main menu, or when you try to get into the actual game? Not sure if this is still the case, but a few versions ago trait names had to be lowercase (note, that I mean the internal name not the external one that is shown in the game).

 

Btw. you don't need to create the global table ResidentEvilProfessions. You can simply write a local function, e.g.:

 

local function giveItems() -- do awesome stuffendEvents.OnGameStart.Add(giveItems);
Link to comment
Share on other sites

The game hangs as I try to get into the actual game. I can pick the profession (and the trait shows up)
Just gave that a try and to no avail. 

local function giveItems()	if getPlayer():HasTrait("stars") = true then		getPlayer():getInventory():AddItem("Base.Bullets9mm");	endendEvents.OnGameStart.Add(giveItems);

The items have to be specific to profession, as each profession will have different items


Also the code for the actual profession works, and it is identical to your tutorial (thanks for that). It has custom icon, colors, spawn point and base traits.

Link to comment
Share on other sites

Tried it with both getplayer() and getSpecificPlayer(0)


getSpecificPlayer(0) works if I want to start the game and spawn items (for testing purposes) but I want it to spawn for a specific profession (for playing purposes)

Link to comment
Share on other sites

If I put this into the .lua with professions it does not work, so I have it in it's own .lua Without it there the profession works fine.

 

local function giveItems()	if getSpecificPlayer(0):HasTrait("stars") = true then		getSpecificPlayer(0):getInventory():AddItem("Base.Bullets9mm");	endendEvents.OnGameStart.Add(giveItems);

It's running on stable build 23 (where I've written the rest of my mods)

Link to comment
Share on other sites

Steam was down and couldn't get testing. Reverted back to basics and decided to build from there onwards. Now the game hangs when it tries to load a new game whenever I add a custom trait. 

It shows up in the profession selection menu, but just hangs on load. (Other professions work) and the trait is copied directly from your tutorial. (Oddly enough it worked earlier with custom traits, now it doesn't)

Link to comment
Share on other sites

This was the only code to work, thanks a tonne RoboMat, your a great help! 

 

local function giveItems(_player, _sq)    local p = _player;    if p:HasTrait("stars") then        p:getInventory():AddItems("Base.Bullets9mm", 1);    end    if p:HasTrait("uss") then        p:getInventory():AddItems("Base.Bullets9mm", 1);    end    if p:HasTrait("ubcs") then        p:getInventory():AddItems("Base.Bullets9mm", 1);    endendEvents.OnNewGame.Add(giveItems);

For anyone else wondering, they all have to be within the same local function, in a separate .lua file. stars/uss/ubcs are the traits you reference and you can just add items to suit your needs.

*This should be in the help section (my bad) can someone move this there and mark this as solved*

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...