Jump to content

Getting the name of the item participating in the craft.


Nebula

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
Link to comment
Share on other sites

  • 2 months later...

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