Jump to content

Rename weapon mod/lua script


Wayfarer

Recommended Posts

Hello.  I'm a little surprised this isn't floating around on here somewhere....  I've seen bits about adding context menus, but not something for weapon renaming specifically.  I figured, since we can rename bags and evolved recipe dishes, it's pretty much already in there and just needs a bit adding for weapons.  And here it is :)

 

This will enable renaming weapons in inventory context menu, just like bags. Go forth and give that hammer you've been swinging around in the Exclusion Zone for 2 months a special name ;)

 

I expect renamed items should continue to work fine for recipes, as the display name is what's being changed, not the underlying ID.

 

Bit of a disclaimer:
- I've not personally tested in multiplayer, either hosted or joined, but it's been commented that it works, however.
- I've not personally tested with renaming weapons from mods, but that's also been commented to work. I expected it would, it operates against hand weapon items after all.


Credit / References:
- Indie Stone, of course. Basically, I've adapted relevant bits of the base ISInventoryPaneContextMenu.lua.
- I referred a bit to RoboMat's Creating Inventory Context Menus tutorial and MisterInSayne's Giving custom options to items when you right click them thread.

 

 

  • Download the mod file .7z archive from here; or
  • Copy paste the below, or attachment, into a mod media/lua/client folder; or
  • It's on Steam Workshop as well.

 

 

----------------------------------------------------------------------------------------------------------

ISInventoryRenameWeapon = {};

require "ISInventoryPaneContextMenu"
ISInventoryRenameWeapon.createMenu = function(player, context, items)
	local canBeRenamedWeapon = nil;

	for i, v in ipairs(items) do
		local item = v;
		
		if not instanceof(v, "InventoryItem") then
			item = v.items[1];
		end
		
		if instanceof(item, "HandWeapon") then
			isHandWeapon = item;
			canBeRenamedWeapon = item;
		end
	end

	if canBeRenamedWeapon then
		context:addOption(getText("Rename weapon"), canBeRenamedWeapon, ISInventoryRenameWeapon.onRenameWeapon, player);
	end
end

ISInventoryRenameWeapon.onRenameWeapon = function(weapon, player)
    local modal = ISTextBox:new(0, 0, 280, 180, getText("Change item name"), weapon:getName(), nil, ISInventoryRenameWeapon.onRenameWeaponClick, player, getSpecificPlayer(player), weapon);
    modal:initialise();
    modal:addToUIManager();
end

function ISInventoryRenameWeapon:onRenameWeaponClick(button, player, item)
    if button.internal == "OK" then
        if button.parent.entry:getText() and button.parent.entry:getText() ~= "" then
            item:setName(button.parent.entry:getText());
            local pdata = getPlayerData(player:getPlayerNum());
            pdata.playerInventory:refreshBackpacks();
            pdata.lootInventory:refreshBackpacks();
        end
    end
end

Events.OnPreFillInventoryObjectContextMenu.Add(ISInventoryRenameWeapon.createMenu);

 

 

ISInventoryRenameWeapon.lua

Edited by Wayfarer
Link to comment
Share on other sites

  • 1 month later...
On 1/17/2017 at 0:39 AM, TheLeonBM said:

Great! I love it, been wanting something like this for a while. A couple of questions: Does it work with the latest build? Will it be available on the Steam Workshop?

 

Cheers :)

 

Yep it's working on the latest, IWBUMS too.  Unless/until the existing renaming method gets changed I don't expect anything to go wrong.  I've probably just jinxed it, however...

I've just added to the Steam Workshop, updated with link.  Otherwise just search "Rename Weapon Mod".

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