Jump to content

Profession Framework Mod


Fenris_Wolf

Recommended Posts

This mod is designed to simply the process of adding new professions, or editing the default ones. As well as simplifying the addition/modification of a profession's skills, traits and known recipes, it also allows for the creation of custom profession starting kits: both items in inventory and on the ground in front of them, and running a custom OnNewGame event for each profession. The 'special effect traits' (ones that don't edit skill levels) such as brave, lucky, outdoorsman, etc can be properly used by new professions without bugs and extra coding on the modder's part.

 

Please note this mod adds no new professions or changes itself, it is simply a framework for use by other modders.

 

Example of a upgraded Park Ranger, starting with the outdoorsman trait, ORGM's Lee Enfield No4 (with scope and sling attached), spare ammo, a hiking bag, and a tent and campfire kit on the ground at their feet:

Spoiler

ProfessionFramework.addProfession('parkranger', {
    cost = -4, 
    xp = {
        [Perks.Trapping] = 2,
        [Perks.PlantScavenging] = 2,
        [Perks.Woodwork] = 2,
    },
    traits = {"Outdoorsman2"},
    -- note these recipes are already given to the park ranger, they are only here as a example
    recipes = {"Make Stick Trap", "Make Snare Trap", "Make Wooden Cage Trap", "Make Trap Box", "Make Cage Trap"},
    inventory = {
        ["ORGM.LENo4"] = 1,
        ["ORGM.LENo4Mag"] = 2,
        ["ORGM.Ammo_762x51mm_FMJ_Box"] = 3,
        ["Base.NormalHikingBag"] = 1,
    },
    square = {
        ["camping.CampingTentKit"] = 1,
        ["camping.CampfireKit"] = 1,
    },
    OnNewGame = function(player, square, profession)
        local item = player:getInventory():FindAndReturn("ORGM.LENo4")
        item:attachWeaponPart(InventoryItemFactory.CreateItem("ORGM.2xScope"))
        item:attachWeaponPart(InventoryItemFactory.CreateItem("ORGM.Rifsling"))
    end,
})

 

 

Example of a new profession: The Military Sniper, starting with Inconspicuous, Graceful and Brave, ORGM's SR-25 (with scope and sling) and spare ammo:

Spoiler

ProfessionFramework.addProfession('sniper', {
    name = "Military Sniper",
    icon = "profession_veteran2",
    cost = -10,
    xp = {
        [Perks.Aiming] = 5,
        [Perks.Reloading] = 2,
        [Perks.Sneak] = 2,
        [Perks.Lightfoot] = 1,
    },
    traits = {"Inconspicuous2", "Graceful2", "Brave2"},
    inventory = {
        ["ORGM.SR25"] = 1,
        ["ORGM.SR25Mag"] = 2,
        ["ORGM.Ammo_762x51mm_FMJ_Box"] = 3,
    },
    OnNewGame = function(player, square, profession)
        local item = player:getInventory():FindAndReturn("ORGM.SR25")
        item:attachWeaponPart(InventoryItemFactory.CreateItem("ORGM.8xScope"))
        item:attachWeaponPart(InventoryItemFactory.CreateItem("ORGM.Rifsling"))
    end,
})

 

 

Example of a updated Chef, starting with a set of GOOD kitchen knives:

Spoiler

ProfessionFramework.addProfession('chef', {
    inventory = {
        ["Base.KitchenKnife"] = 6,
    },
    OnNewGame = function(player, square, profession)
        local knives = player:getInventory():FindAll("Base.KitchenKnife")
        for i=1,knives:size() do
            local knife = knives:get(i-1)
            knife:setName("Fancy Kitchen Knife")
            knife:setConditionLowerChance(10)
        end
    end,
})

 

 

List of all 'special effect traits' that can now be added to professions:

Spoiler

Note the profession versions are replaced by the real traits OnNewGame, to ensure the effects function properly.

 

profession version name (real trait name)

Brave2 (Brave)

Cowardly2 (Cowardly)

Clumsy2 (Clumsy)

Graceful2 (Graceful)

ShortSighted2 (ShortSighted)

EagleEyed2 (EagleEyed)

HardOfHearing2 (HardOfHearing)

Deaf2 (Deaf)

KeenHearing2 (KeenHearing)

HeartyAppitite2 (HeartyAppitite)

LightEater2 (LightEater)

ThickSkinned2 (ThickSkinned)

Thinskinned2  (Thinskinned)

Resilient2 (Resilient)

ProneToIllness2 (ProneToIllness)

Lucky2 (Lucky)

Unlucky2 (Unlucky)

Dextrous2 (Dextrous)

AllThumbs2 (AllThumbs)

FastHealer2 (FastHealer)

SlowHealer2 (SlowHealer)

FastLearner2 (FastLearner)

SlowLearner2 (SlowLearner)

FastReader2 (FastReader)

SlowReader2 (SlowReader)

Illiterate2 (Illiterate)

NeedsLessSleep2 (NeedsLessSleep)

NeedsMoreSleep2 (NeedsMoreSleep)

Inconspicuous2 (Inconspicuous)

Conspicuous2 (Conspicuous)

Organized2 (Organized)

Disorganized2 (Disorganized)

LowThirst2 (LowThirst)

HighThirst2 (HighThirst)

WeakStomach2 (WeakStomach)

IronGut2 (IronGut)

Outdoorsman2 (Outdoorsman)

AdrenalineJunkie2 (AdrenalineJunkie)

NightVision2 (NightVision)

Hypercondriac2 (Hypercondriac)

Agoraphobic2 (Agoraphobic)

Claustophobic2 (Claustophobic)

Hemophobic2 (Hemophobic)

Insomniac2 (Insomniac)

Pacifist2 (Pacifist)

Smoker2 (Smoker)

Asthmatic2 (Asthmatic)

 

 

For best use and compatibility with other profession mods that may use this framework, it is advised you don't actually include this mods lua files in your mod. Instead make it a requirement, and just call the ProfessionFramework.addProfession( ) function from your own mod.

 

Downloads:

Current Version (1.00-stable): https://downloads.tekagis.ca/ProjectZomboidMods/ProfessionFramework.zip

Steam workshop (1.00-stable): http://steamcommunity.com/sharedfiles/filedetails/?id=1343686691

 

Github Development Version:  https://github.com/FWolfe/ProfessionsFramework

 

Edited by Fenris_Wolf
Link to comment
Share on other sites

It should at some point if someone is willing to upload and maintain it there when updates come out (since I'm not a steam user).  Not being on steam really limits the usefulness of such a framework.

That being said, its still in a semi-testing phase, and I'd like to refine it more first, including adding error/sanity checking features and such.

Link to comment
Share on other sites

No hurry, but yes, its use would be rather limited if its not on Steam.

My ultimate hope: more of such frameworks would find its way into the base game, would make modding so much easier. And thats not just the profession-system, pretty much all of it could use a proper framework for interacting.

Link to comment
Share on other sites

Agreed. Some of the current implementations in the base game are rather clunky. When it's a bit more refined, would you be interested in handling the steam upload? Given the nature of most of your current framework style mods, I can't really think of anyone better suited. ;)

Link to comment
Share on other sites

  • 2 weeks later...
5 hours ago, Ʀocky said:

After the activation of this mod, the profession of the unemployed disappears.

uh it shouldn't...this mod doesn't actually change anything.  All the base professions are setup using a single function in the base game's lua files, so if one disappeared, then they all would.

If your using it with some other mods that edit professions then I can't predict the results.

Link to comment
Share on other sites

Just now, Ʀocky said:

possible to hide some professions with the help of your mod?

In the media/lua/shared/2ProfessionFramework.lua file, at line 5, there's a RemoveDefaultProfessions = false.

You can set that to 'true' and it should stop all the default professions from being registered (or simply add a line of code somewhere in your own mod ProfessionFramework.RemoveDefaultProfessions = true)

BUT, i should mention this is entirely untested at this point. This mod is still very much a work in progress.

 

Link to comment
Share on other sites

2ProfessionFramework.lua

 

Line 329: code refers to this.recipies instead of this.recipes

 

I also added a description to mine that changes line 337 to:

BaseGameCharacterDetails.SetProfessionDescription(this)

if details.description and details.description ~= "" then
	this:setDescription(details.description .. " <LINE>" .. this:getDescription())
end

This way if you set description you end up with profession tooltip like:

This is a description for this profession.
+2 Skill One
+1 Skill Two
Trait 1

 

Edited by JackMods
Link to comment
Share on other sites

3 minutes ago, JackMods said:

Line 329: code refers to this.recipies instead of this.recipes

Thanks for the heads up on that. A oversight when i was correcting earlier typos. I'll push the change to github

 

for the handling of this:setDecription()...this is unnecessary. Its called automatically by BaseGameCharacterDetails.SetProfessionDescription (right at the end of the function), and handles not just a text description, but also all the perk bonuses shown.

Link to comment
Share on other sites

2 hours ago, Fenris_Wolf said:

Thanks for the heads up on that. A oversight when i was correcting earlier typos. I'll push the change to github

 

for the handling of this:setDecription()...this is unnecessary. Its called automatically by BaseGameCharacterDetails.SetProfessionDescription (right at the end of the function), and handles not just a text description, but also all the perk bonuses shown.

 

Mine is appending an additional description definable in the addProfession call. For instance,

 

ProfessionFramework.addProfession('sniper', {
    name = "Military Sniper",
    description="A grizzled military sniper.",
    icon = "profession_veteran2",
    cost = -10,
    xp = {
        [Perks.Aiming] = 5,
        [Perks.Reloading] = 2,
        [Perks.Sneak] = 2,
        [Perks.Lightfoot] = 1,
    },
*** SNIP ***
})

would generate a tooltip of:

A grizzled military Sniper.
+5 Aiming
+2 Reloading
... etc.

 

 

Link to comment
Share on other sites

48 minutes ago, JackMods said:

Mine is appending an additional description definable in the addProfession call.

Ya, I was tempted to add it there, but the description can be added by adding a translation in the translation files such as 'UI_profdesc_sniper', which I figured would be the better way to go. It produces the same result, and allows for mods to use multiple languages, though it does lack the convenience of having everything defined in a single spot.

Link to comment
Share on other sites

4 minutes ago, Fenris_Wolf said:

Ya, I was tempted to add it there, but the description can be added by adding a translation in the translation files such as 'UI_profdesc_sniper', which I figured would be the better way to go. It produces the same result, and allows for mods to use multiple languages, though it does lack the convenience of having everything defined in a single spot.

 

Ah I see, in practice I was actually using my own token:

 

description = getText("UI_Profession_Researcher_Description")

but I was unaware there was already a specific translation token that the base game was looking for.  Thanks for the heads up.

Link to comment
Share on other sites

Updated github with some cool changes:

Added custom trait registration features similar to how professions are handled, including adjusting xp values, triggering of specific OnNewGame and OnGameStart events, and adding items to the players starting kit (both inventory and on floor)

 

Example of adding a trait that causes the player to suffer nightmares:

ProfessionFramework.addTrait('Nightmares', {
    name = "Nightmares",
    description = "Character occasionally suffers nightmares, waking from sleep in a panic",
    exclude = {"Desensitized"},
    cost = -6,
    requiresSleepEnabled = true,
    inventory = {
        ["Base.PillsBeta"] = 1,
        ["Base.PillsSleepingTablets"] = 1,
    },
    OnGameStart = function(trait)
        Events.EveryTenMinutes.Add(function()
            local p = getSpecificPlayer(0)
            if p:isAsleep() and ZombRand(100) < 2 then
                p:forceAwake()
                p:getStats():setPanic(90)
            end
        end)
    end
})

 

Note: for the name and description fields, these can be basic strings or the name of a translation entry, more fields exist then what are shown in this example (see the documention comments in shared/2ProfessionFramework.lua for the ProfessionFramework.addTrait function)

 

Other minor changes include some built in logging functions, renaming of client/ProfessionItems.lua to client/ProfessionFrameworkClient.lua,

and moving of all profession 'special' traits (ie: brave2, lucky2) to a separate file using the new trait registration functions.

 

Link to comment
Share on other sites

1 hour ago, Fenris_Wolf said:

Updated github.

fixed WeakStomach2 missing icon

added Herbalist2 trait

added option for traits to add free recipes

added option for traits to add other traits OnNewGame instead of just swapping

 

Thanks for all the updates to this and ORGM! We appreciate your hard work. :)

Link to comment
Share on other sites

5 minutes ago, JackMods said:

Thanks for all the updates to this and ORGM! We appreciate your hard work.

lol your welcome. I should probably move this out of alpha phase and into a proper beta release candidate as it seems to be fairly efficient so far. We've been using it on our server with custom professions and traits, just looking for more ideas to add to the framework, and still need to add a check in to see if 3rd party mods attempt to overwrite BaseGameCharacterDetails.DoProfessions and BaseGameCharacterDetails.DoTraits. Not a problem on initial character creation, but would be if you die on a server and start a new character.

 

Link to comment
Share on other sites

  • 2 weeks later...
On 3/8/2018 at 2:45 AM, JackMods said:

Very cool! I think you might be missing the trait herbalist2 though.

So I've been poking through the java files today looking for other traits I missed that have hardcoded effects (seems there's quite a few), but apparently herbalist isn't one of them. Its only bonus is giving the free recipe Herbalist, which does have a effect.

At any rate I'll update this soon with the missing traits once I'm done my search.

Link to comment
Share on other sites

v1.00-stable is up.

 

* added profession traits Handy2, Jogger2

 

* fixed so profession names try to find a translation entry

 

Added a direct download link to the initial post.

 

@Dr_Cox1911 This is probably more then ready for workshop upload whenever you find the time. When you do I'll add the link the initial post ;)

 

Side note: The trait "BaseballPlayer" exists in the lua, but hardcoded in the java the non-existent trait "PlaysBaseball" lowers your swing time with bats...my search through the code was very enlightening on the actual effects of some traits  :lol:

Link to comment
Share on other sites

On 21.3.2018 at 1:34 AM, Fenris_Wolf said:

@Dr_Cox1911 This is probably more then ready for workshop upload whenever you find the time. When you do I'll add the link the initial post ;)

Any wishes/suggestions/pics for the workshop preview picture?

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