Jump to content

Custom Professions


RegularX

Recommended Posts

Trying to add custom professions, poked around the Trait and ProfessionFactory code and I can get them to show up in the character builder, but even code this simple:

function DoProfessions()local joe = ProfessionFactory.addProfession("joe", "Joe", "Prof_ParkRanger");endEvents.OnGameBoot.Add(DoProfessions);

Keeps the game from actually loading.  You get the "This is How You Died" screen, but the game never loads and there is no "Click to Skip" option.

 

Is there a step missing here?

Link to comment
Share on other sites

:( No go:

function XDoProfessions()local joe = ProfessionFactory.addProfession("joe", "Joe", "Prof_ParkRanger");endEvents.OnGameBoot.Add(XDoProfessions);

Has the same effect, good point though.  My original code nested this all in an XProfessions object.  So more like:

XProfessions = {}XProfessions.DoTraits = function()...endXProfessions.XDoProfessions = function()...endEvents.OnGameBoot.Add(XProfessions.DoTraits);Events.OnGameBoot.Add(XProfessions.DoProfessions);

Custom traits, however, seem to work just fine with the XProfessions.DoTraits setup.

Link to comment
Share on other sites

Bizarre log message too:

 

8/21/13 11:42:50.321 AM [0x0-0x1d11d10].com.projectzomboid: java.lang.NullPointerException8/21/13 11:42:50.321 AM [0x0-0x1d11d10].com.projectzomboid:  at zombie.iso.IsoChunkMap.renderBloodForChunks(IsoChunkMap.java:668)8/21/13 11:42:50.321 AM [0x0-0x1d11d10].com.projectzomboid:  at zombie.iso.IsoCell.RenderTiles(IsoCell.java:808)8/21/13 11:42:50.321 AM [0x0-0x1d11d10].com.projectzomboid:  at zombie.iso.IsoCell.render(IsoCell.java:4442)8/21/13 11:42:50.321 AM [0x0-0x1d11d10].com.projectzomboid:  at zombie.iso.IsoWorld.render(IsoWorld.java:1471)8/21/13 11:42:50.321 AM [0x0-0x1d11d10].com.projectzomboid:  at zombie.GameWindow.save(GameWindow.java:1409)8/21/13 11:42:50.321 AM [0x0-0x1d11d10].com.projectzomboid:  at zombie.GameWindow.save(GameWindow.java:1359)8/21/13 11:42:50.321 AM [0x0-0x1d11d10].com.projectzomboid:  at zombie.GameWindow.run(GameWindow.java:1027)8/21/13 11:42:50.321 AM [0x0-0x1d11d10].com.projectzomboid:  at zombie.GameWindow.maina(GameWindow.java:856)8/21/13 11:42:50.321 AM [0x0-0x1d11d10].com.projectzomboid:  at zombie.gameStates.MainScreenState.main(MainScreenState.java:95)
Link to comment
Share on other sites

Is there a place where "joe" is used as a texture?  I thought that was what the ParkRanger param was for.  Might it have something to do with starting clothes or inventory?  I'll poke around the PlayerSpawn code if I get a chance.

Link to comment
Share on other sites

Is there a place where "joe" is used as a texture?  I thought that was what the ParkRanger param was for.  Might it have something to do with starting clothes or inventory?  I'll poke around the PlayerSpawn code if I get a chance.

 

It was just a wild guess because, if you add traits then the first string also designates the texture to use:

TraitFactory.addTrait("vc_lightSleeper", "Light Sleeper", -1, Sleeping_Text.lightSleeper_descr, false);

I don't want to send you down the wrong route, but it was the first thing that came to mind ;)

Link to comment
Share on other sites

No, I think you may have sent me down the nearly exactly right route.  My guess is that it can't create a spawn point:

BaseGameCharacterDetails.DoSpawnPoint = function()BaseGameCharacterDetails.spawnPoint = {        unemployed = {...

Looks like it expects an exact list.  I have no time to test it for a few hours, but I wonder if:

local joe = ProfessionFactory.addProfession("unemployed", "Joe", "Prof_ParkRanger");

Might fix it - but that depends on how ProfessionFactory is storing things.  It might "fix" it, but also overwrite/break the unemployed Profession.

 

 

Link to comment
Share on other sites

I'm at home right now and I wanted to look into custom professions anyway, so I'm gonna give it a go.

 


 

UPDATE 1:

So I tested it with:

function LockpickingProfessions.addProfession()    local burglar = ProfessionFactory.addProfession("unemployed", "Burglar", "Prof_ParkRanger");end

It worked, but the unemployed profession got replaced (which was more or less expected I guess).

 


 

Update 2:

 

After I included my own spawn points into the BaseGameCharacterDetails.spawnPoint table it worked ;)

burglar = {        { worldX = 11, worldY = 9, posX = 62, posY = 47 }, -- Medium house2        { worldX = 11, worldY = 8, posX = 116, posY = 232 }, -- little house2        { worldX = 11, worldY = 8, posX = 3, posY = 173 }, -- little house2        { worldX = 11, worldY = 8, posX = 118, posY = 229 }, -- little house2        { worldX = 11, worldY = 6, posX = 142, posY = 72 },        { worldX = 11, worldY = 6, posX = 150, posY = 190 },        { worldX = 11, worldY = 6, posX = 72, posY = 189 },        { worldX = 11, worldY = 7, posX = 176, posY = 185 },        { worldX = 11, worldY = 7, posX = 50, posY = 246 },        { worldX = 11, worldY = 7, posX = 54, posY = 294 },        { worldX = 11, worldY = 8, posX = 108, posY = 94 },        { worldX = 11, worldY = 8, posX = 84, posY = 259 },        { worldX = 11, worldY = 8, posX = 123, posY = 196 },    },

... the only problem is, that the burglar only wears white clothes at the moment xD The colours are apparently set in the CharacterCreationProfession.lua file.

Link to comment
Share on other sites

Yeah - that's the culprit.  In MainCreationMethods.lua, BaseGameCharacterDetails.DoSpawnPoint is generating spawn points based on that first param.  And since it is enclosed within that function, I don't think there is a hook because any modification to BaseGameCharacterDetails.spawnPoint might be too late (but I could very well be wrong on that).  But at the moment I don't see a way around except for manually updating that method.  Which since it's a stock lua file in the game, when I told that to a panda - the panda got kinda sad...

 

I can move forward with just Traits for now I think (although since I'm working with wildly overpowered concepts, you might get a Fireman who is also a occultist hitman)  - but should this go into the Lua Request pile?  Even DoSpawnPoint had a fallback if it didn't recognize the profession.

 

Oh and shifting it to unemployed doesn't fix it because it looks like the ProfessionsFactory is (properly) a first come, first serve kind of shop.

Link to comment
Share on other sites

Yeah - that's the culprit.  In MainCreationMethods.lua, BaseGameCharacterDetails.DoSpawnPoint is generating spawn points based on that first param.  And since it is enclosed within that function, I don't think there is a hook because any modification to BaseGameCharacterDetails.spawnPoint might be too late (but I could very well be wrong on that).  But at the moment I don't see a way around except for manually updating that method.  Which since it's a stock lua file in the game, when I told that to a panda - the panda got kinda sad...

 

Well you could overwrite the whole function after / while game boot (I did the same thing with the ISWorldContext stuff for my sleeping overhaul mod) - so that people can remove your mod without screwing up their vanilla files. Of course that still breaks compatibility with other "Profession-Mods" but well I don't see any other way to do it.

 

Hm ... I also don't think that this is something for the lua requests because it would be more of a complete overhaul of the current character creation :o

 

I didn't look further at the code, but maybe you could add hooks yourself so others could use that as a base for their mods?

Link to comment
Share on other sites

Yeah I hadn't realized it looped in things like apparel at first.  I'll look into a hook, but will probably be problematic - it's expecting a full object instead of a Lua table, so unless there some dark corner of Lua where you can translate strings into variable names, overriding the object in full may be the only option for now.  I'll look into a way of forcing a default, but same basic problem applies there.

 

Maybe some structure, clearly defined README on install/uninstall of professions per mod or something.  I'll make a plea for having the unemployed definition at least be a default for when no known profession is found on the Java side, though - a decent hotfix for now.

Link to comment
Share on other sites

OK I think I got it:

 

  • add require "NPCs/MainCreationMethods" to your professions lua
  • Append the spawnPoint:
XProfessions.DoSpawnPoint = function()	print("Xmod:: Updating Spawn Points");	BaseGameCharacterDetails.spawnPoint.smartEmployee = {
  • And then add the hook: Events.OnGameBoot.Add(XProfessions.DoSpawnPoint);

 

And I think that will add to the current definition without having to completely overwrite anything.  Both my custom profession and an old profession proceeded to get into the game.

Link to comment
Share on other sites

OK I think I got it:

 

  • add require "NPCs/MainCreationMethods" to your professions lua
  • Append the spawnPoint:
XProfessions.DoSpawnPoint = function()	print("Xmod:: Updating Spawn Points");	BaseGameCharacterDetails.spawnPoint.smartEmployee = {
  • And then add the hook: Events.OnGameBoot.Add(XProfessions.DoSpawnPoint);

 

And I think that will add to the current definition without having to completely overwrite anything.  Both my custom profession and an old profession proceeded to get into the game.

 

Strange ... i tried to do the same thing with table.insert but that didn't work :???: Guess there is still a lot to learn about lua :D

 

Thanks for the solution!

Link to comment
Share on other sites

No problem! Yeah, my guess is that somewhere is a sneaky translation between the string in addProfession (which I guess is probably stored to a table somewhere?) to a variable name on spawnPoint, so it avoids using a table in this particular completely.  Of course, this is dependent on the mod lua's being called after the base ones - and I don't really know how that order is determined.  If that's problematic, though, it would theoretically be resolvable by 9.17's mod structure.

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...