Unlocking Items Automatically

Talk about creating mods for Druidstone here.

Moderator: Sir Tawmis

Post Reply
User avatar
JohnWordsworth
Posts: 35
Joined: Fri Apr 12, 2019 5:59 am

Unlocking Items Automatically

Post by JohnWordsworth » Mon Jul 29, 2019 9:55 pm

Sorry, I might just be missing something in the documentation - but I am at the stage where I am adding some new weapons to the game but I was hoping to have the weapons/cards available "for free" without providing them as loot.

I am just testing with an accessory to start with to get my own cards into the game. Does anyone have any tips on any flags I can pass to def_accessory and/or something I can add to the load map hook to get the cards available without having to unlock them in the game?

User avatar
petri
Posts: 117
Joined: Thu Apr 11, 2019 10:07 am

Re: Unlocking Items Automatically

Post by petri » Thu Aug 15, 2019 11:35 am

Sorry for the looong delay! We've been on a long break after the intensive crunch we had in spring and we've just got back to finish the modding support.

The answer to your question depends where/when you want to add the cards. E.g. do you want to add them to the merchant stock after a mission, or add to the shared party inventory at the start of the campaign? Adding cards at the start of the campaign would be problematic because new mods can be added in the middle of a campaign, so the "start campaign" event would not be triggered...

I'm thinking something like the following would be a good addition to the modding API.

Code: Select all

if not get_registry_key("$mod.new_merchant_items_added") then
    local inv = get_merchant_stock()
    add_inventory(inv, "$mod.johns_mighty_axe")
    set_registry_key("$mod.new_merchant_items_added", true)
end
The functions set_registry() / get_registry() could be used to store any arbitrary key-value pairs in a global dictionary. The contents of the dictionary would be stored in savegames and could be a primitive way for mods to communicate with each other.

Would this work for you?

User avatar
petri
Posts: 117
Joined: Thu Apr 11, 2019 10:07 am

Re: Unlocking Items Automatically

Post by petri » Thu Aug 15, 2019 12:25 pm

I added the functions mentioned above. Check out the new version in Steam.

User avatar
JohnWordsworth
Posts: 35
Joined: Fri Apr 12, 2019 5:59 am

Re: Unlocking Items Automatically

Post by JohnWordsworth » Fri Aug 16, 2019 1:52 pm

Hope you had a great vacation!

Many thanks for the response (and the handy feature to support it) - I'm busy for the next few days but I am already looking forward to adding a few more items to the game and having my first small little mod ready :).

User avatar
JohnWordsworth
Posts: 35
Joined: Fri Apr 12, 2019 5:59 am

Re: Unlocking Items Automatically

Post by JohnWordsworth » Thu Aug 22, 2019 9:55 pm

I might be being completely stupid, but I tried the above code in my mod and it doesn't seem to recognise the new functions that you mention. I have the following in my mod_main.lua file but it doesn't seem to recognise any of the new functions (get_registry_key or get_merchant_stock)...

Code: Select all

-- make alterations to the world map
register_global_hook("on_enter_world_map", function(map)
	local site = spawn("map_herb_plant", map, 0, 0, 0)
	register_named_obj(map, site, "$mod.my_site")
	set_world_pos3(site, 108.169685, 0.000000, -126.138138)	-- TODO: you should probably relocate the mod to somewhere else to avoid overlapping with other mods
	set_world_rot_euler(site, 0.000000, 0.563791, 0.000000)
	set_obj_scale3(site, 1.0, 1.0, 1.0)

	if not get_registry_key("$mod.new_merchant_items_added") then
	    local inv = get_merchant_stock()
	    add_inventory(inv, "$mod.johns_mighty_axe")
	    set_registry_key("$mod.new_merchant_items_added", true)
	end

end)
Am I doing something stupid?

User avatar
petri
Posts: 117
Joined: Thu Apr 11, 2019 10:07 am

Re: Unlocking Items Automatically

Post by petri » Fri Aug 23, 2019 3:52 am

Sorry, I renamed a couple of functions:
get_registry, set_registry, get_merchant_inventory.

They should be documented in the scripting reference now.

User avatar
JohnWordsworth
Posts: 35
Joined: Fri Apr 12, 2019 5:59 am

Re: Unlocking Items Automatically

Post by JohnWordsworth » Fri Aug 23, 2019 6:53 am

Ahhh - that's great, many thanks! Sorry for not checking - when I looked before the launch they weren't in the reference.

I will try again this weekend and see if I can get my "Oriental Weapons Pack" ported from Grimrock to Druidstone :).

// JW

User avatar
petri
Posts: 117
Joined: Thu Apr 11, 2019 10:07 am

Re: Unlocking Items Automatically

Post by petri » Fri Aug 23, 2019 7:19 am

Cool! :)

User avatar
JohnWordsworth
Posts: 35
Joined: Fri Apr 12, 2019 5:59 am

Re: Unlocking Items Automatically

Post by JohnWordsworth » Fri Aug 23, 2019 7:43 am

That works a treat - I can see the card in Steelface's inventory - many thanks! I should have everything I need now to get my first 3D item into the game. Thanks again for your help!

Post Reply