Jump to content
Okamikurainya

Failure to work twice

Recommended Posts

As an experiment on my way to something more in depth, I tried:

local function addItems()	
	local player = getSpecificPlayer(0);    -- Java: get player one	
    local inv = player:getInventory();      -- Java: access player inv	
    
    -- Java: add the actual items to the inventory	
    inv:AddItem("Base.Axe");	
    inv:AddItem("Base.RippedSheets");	
    inv:AddItem("camping.TentPeg");
end

Events.OnCreatePlayer.Add(addItems);


It worked exactly as I expected... But after I reloaded the game (without changing anything) it is now throwing up:

 

SEVERE: Error found in LUA file: C:/Users/(snip)/Zomboid/mods/OccupationalItemsOnSpawn/media/lua/client/AddItems.lua
java.lang.ArrayIndexOutOfBoundsException: 65022


It worked fine the first time, it's literally just a copy paste of Robomat's tutorial. What could have caused it to stop working if I didn't change anything?
(All other mods are disabled, so totally vanilla minus this)

Any help is appreciated on my way to figuring this stuff out! :)

Share this post


Link to post
Share on other sites
local function addItems(id)	
    local player = getSpecificPlayer(id);    -- Java: get player which is just created	
    local inv = player:getInventory();      -- Java: access player inv	
    
    -- Java: add the actual items to the inventory	
    inv:AddItem("Base.Axe");	
    inv:AddItem("Base.RippedSheets");	
    inv:AddItem("camping.TentPeg");
end

Events.OnCreatePlayer.Add(addItems);

OR

local function addItems(id, player)	
    if not player then return end -- just for sure
    local inv = player:getInventory();      -- Java: access player inv	
    
    -- Java: add the actual items to the inventory	
    inv:AddItem("Base.Axe");	
    inv:AddItem("Base.RippedSheets");	
    inv:AddItem("camping.TentPeg");
end

Events.OnCreatePlayer.Add(addItems);

 

Edited by Maris

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

×
×
  • Create New...