Page 1 of 1

Unlocking Items Automatically

Posted: Mon Jul 29, 2019 9:55 pm
by JohnWordsworth
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?

Re: Unlocking Items Automatically

Posted: Thu Aug 15, 2019 11:35 am
by petri
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?

Re: Unlocking Items Automatically

Posted: Thu Aug 15, 2019 12:25 pm
by petri
I added the functions mentioned above. Check out the new version in Steam.

Re: Unlocking Items Automatically

Posted: Fri Aug 16, 2019 1:52 pm
by JohnWordsworth
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 :).

Re: Unlocking Items Automatically

Posted: Thu Aug 22, 2019 9:55 pm
by JohnWordsworth
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?

Re: Unlocking Items Automatically

Posted: Fri Aug 23, 2019 3:52 am
by petri
Sorry, I renamed a couple of functions:
get_registry, set_registry, get_merchant_inventory.

They should be documented in the scripting reference now.

Re: Unlocking Items Automatically

Posted: Fri Aug 23, 2019 6:53 am
by JohnWordsworth
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

Re: Unlocking Items Automatically

Posted: Fri Aug 23, 2019 7:19 am
by petri
Cool! :)

Re: Unlocking Items Automatically

Posted: Fri Aug 23, 2019 7:43 am
by JohnWordsworth
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!