Japer Posted March 13, 2014 Share Posted March 13, 2014 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 loadingI 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 hasprofessionHelp 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 More sharing options...
RoboMat Posted March 13, 2014 Share Posted March 13, 2014 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 More sharing options...
Japer Posted March 13, 2014 Author Share Posted March 13, 2014 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 itemsAlso 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 More sharing options...
RoboMat Posted March 13, 2014 Share Posted March 13, 2014 Does getPlayer() return IsoPlayer? If it returns nil it might be deprecated ... try it with getSpecificPlayer(0). Link to comment Share on other sites More sharing options...
Japer Posted March 13, 2014 Author Share Posted March 13, 2014 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 More sharing options...
RoboMat Posted March 13, 2014 Share Posted March 13, 2014 But the game starts when you comment out the Events.OnGameStart.Add(giveItems); line? Even if you select the profession? You are not trying this on multiplayer, right? Link to comment Share on other sites More sharing options...
Japer Posted March 13, 2014 Author Share Posted March 13, 2014 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 More sharing options...
RoboMat Posted March 13, 2014 Share Posted March 13, 2014 Try this instead: local function giveItems(_player, _sq) local p = _player; if p:HasTrait("stars") then p:getInventory():AddItems("Base.Bullets9mm", 1); endendEvents.OnNewGame.Add(giveItems); Link to comment Share on other sites More sharing options...
Japer Posted March 13, 2014 Author Share Posted March 13, 2014 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 More sharing options...
Japer Posted March 14, 2014 Author Share Posted March 14, 2014 It appears that the profession will load, but only in west point, otherwise the game just hangs. Will tweak the spawn points (even though they did work earlier) and test these methods tomorrow. Link to comment Share on other sites More sharing options...
Japer Posted March 14, 2014 Author Share Posted March 14, 2014 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now