Jump to content
Sign in to follow this  
Nebula

Getting the name of the item participating in the craft.

Recommended Posts

I need to get the item name display.
How to do it right? It gives me an error:
Callframe at: PerformMakeItem
Object tried to call nil in recipe_ recipe name

I have this code:


 

    item WorkItem1
    {
        Type				=			Normal,
        DisplayName			=		    WorkItem1,
        Icon				=			WorkItem1,
        Weight				=			0.1,
    }



recipe WorkItemExample
    {
        WоrkItem1,WorkItem2,WorkItem3,WorkItem4,WorkItem5
        destroy WorkItemqqq,
        Result:WorkItemResult,
        Time:30.0,
        NeedToBeLearn:false,
        OnCreate:recipe_WorkExampleCreat,

   }

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

function recipe_WorkExampleCreat(items, result, player)
    WorkItemName = getPlayer():getInventory():getModData():getDisplayName(getText("IGUI_WorkItem1"));
end

IGUI_WorkItem is recorded in the IGUI_EN table

You need to iterate over the names from the first list in the recipe.
And save in the variable WorkItemName the name of the IGUI of the object that was used when crafting ...

 

You need to get the name that I indicated in IGUI_EN

 

Edited by Nebula

Share this post


Link to post
Share on other sites
Posted (edited)

You must iterate through the list of items that are participating in the craft from the "items" ArrayList<InventoryItem>.

 

 

This for loop will iterate through each single item that is participating in the craft.

 

The if statements will make sure to only give the correct DisplayName that you need for the "WorkItemName" varaible.

I do not know which name you need so you'll have to play with this until you get a desired outcome.

function recipe_WorkExampleCreat(items, result, player)
    for i=0, items:size()-1 do
        local item = items:get(i)
        local itemDisplayName = item:getDisplayName()
        local itemName = item:getName()
    
    	-- Is "IGUI_WorkItem1" the "itemDisplayName" for the "item" at items:get(i)?
        if itemDisplayName == getText("IGUI_WorkItem1") then
            WorkItemName = itemDisplayName   -- Store item display name into WorkItemName
        end
        
    	-- Is "IGUI_WorkItem1" the "itemName" for the "item" at items:get(i)?
    	if itemName == getText("IGUI_WorkItem1") then
            WorkItemName = itemName   -- Store item name into WorkItemName
        end
    
    end
end

 

If you need the result item's displayname, then you must use "result:getDisplayName()"

function recipe_WorkExampleCreat(items, result, player)
    WorkItemName = result:getDisplayName()
end

 

 

This is the InventoryItem class with all the methods I used:

 

https://projectzomboid.com/modding/zombie/inventory/InventoryItem.html

https://projectzomboid.com/modding/zombie/inventory/InventoryItem.html#getDisplayName--

 

image.png.f22c16fd705977753fd96a72c8f66fcf.png

 

https://projectzomboid.com/modding/zombie/inventory/InventoryItem.html#getName--

image.png.f154c8502bdd141635a09b314e00f016.png

Edited by ATPHHe

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...
Sign in to follow this  

×
×
  • Create New...