Jump to content
MrSledgeGaming

Change module item attributes programmatically

Recommended Posts

Im looking into setting all pages of all skill books (regardless of mod) to X pages. I'm still pretty new to modding but I'm an experienced programmer, and saw there was something similar on the steam workshop called "read faster" (Not sure if I'm allowed to post the link). Unfortunately, the mod author didnt do the changes in the pages programmatically, so if u have other book mods, it wont change them and I was wondering if it was possible.

 

My thoughts are: get all items from itemType "Skill Book" -> Set page # (can be just hard coded in the code or maybe mod options?)

 

Would it be possible to update existing books or would they need to be spawned in?

 

I would be developing this for a multiplayer server of the latest build

Edited by MrSledgeGaming

Share this post


Link to post
Share on other sites

A good place to look is the existing game code that searches and changes the 'Literature' objects.  Look at the file ISLiteratureUI.lua in the "media/lua/client/ISUI' folder of the game files.  Here is a snip of a  function that manipulates the same data you want to change.

-- Code copied from ISLiteratureUI:setLists() function
function myEditSkillBooks()
	local skillBooks = {}
	local allItems = getScriptManager():getAllItems()
	for i=1,allItems:size() do
		local item = allItems:get(i-1)
		if item:getType() == Type.Literature then
			if SkillBook[item:getSkillTrained()] then
        		-- This is a skillbook item store in structure for later
				table.insert(skillBooks, item)
        		-- Can edit item here if you wish
        		-- item:DoParam("Weight = 0.5");
			end
		end
	end
end

-- Example of a SkillBook item
--[[
    item BookTailoring1
    {
        DisplayCategory = SkillBook,
        NumberOfPages	=	220,
        Weight	=	0.8,
        Type	=	Literature,
        DisplayName	=	Tailoring for Beginners,
        Icon	=	Book11,
        SkillTrained = Tailoring,
        LvlSkillTrained = 1,
        NumLevelsTrained = 2,
        StaticModel = Book,
        WorldStaticModel = BookYellow_Ground,
	}
--]]

You would then need to have this function added to some  game events to change all the data. 

Events.OnSpawnRegionsLoaded.Add(myEditSkillBooks)
Events.OnLoad.Add(myEditSkillBooks)

**Note:  This function would edit/override all skill book data, possibly even new ones adds by other mods depending on load order.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...