Sign in to follow this  
MrDoge124

Help with custom backpack for custom character.

Recommended Posts

MrDoge124    3

I'm trying to make a backpack for my custom character but I got this error.

 [string "../mods/Green's backpack/modmain.lua"]:25: attempt to index local 'player' (a nil value)
LUA ERROR stack traceback:
        ../mods/Green's backpack/modmain.lua(25,1)
        =(tail call) ?
        =[C] in function 'xpcall'
        scripts/mods.lua(131,1)
        scripts/mods.lua(709,1) in function 'SimPostInit'
        scripts/gamelogic.lua(688,1) in function 'DoInitGame'
        scripts/gamelogic.lua(789,1) in function 'cb'
        scripts/saveindex.lua(285,1)
        =[C] in function 'GetPersistentString'
        scripts/saveindex.lua(267,1) in function 'GetSaveDataFile'
        scripts/saveindex.lua(293,1) in function 'GetSaveData'

Anyone know whats going wrong?

modmain.lua

Share this post


Link to post
Share on other sites
Cunning fox    569

You can try this:

function SimInit(player)
if player ~= nil then
	print("spawning item")
	local prefab = SpawnPrefab("green_backpack")
	player.components.inventory:GiveItem(prefab)
	end
end

But I don't know will it work or not.

  • Like 1

Share this post


Link to post
Share on other sites
MrDoge124    3

I tried the code and figured out that I had to put it in modmain.lua and it got to the character select screen which is great!

But i got a new error when playing as the character that the back pack is meant for.

[string "scripts/components/inventory.lua"]:634: attempt to index local 'inst' (a nil value)
LUA ERROR stack traceback:
    scripts/components/inventory.lua:634 in (method) GiveItem (Lua) <633-766>
    scripts/prefabs/player_common.lua:1892 in (method) OnNewSpawn (Lua) <1888-1900>
    scripts/networking.lua:250 in () ? (Lua) <238-256>
    =[C]:-1 in (method) SendSpawnRequestToServer (C) <-1--1>
    scripts/mainfunctions.lua:1272 in (local) cb (Lua) <1270-1273>
    scripts/frontend.lua:531 in (method) DoFadingUpdate (Lua) <495-535>
    scripts/frontend.lua:583 in (method) Update (Lua) <543-695>
    scripts/update.lua:92 in () ? (Lua) <33-129>

I think it's something to do with the backpack trying to be in the inventory but it normally goes straight on the torso slot.

I not really sure. 

Share this post


Link to post
Share on other sites

player = GLOBAL.ThePlayer

Right now your code uses player, but player on it's own doesn't exist. Just put in the code above before you call your SimInit function and it should work.

Share this post


Link to post
Share on other sites
Amalleus    13

Could you also drop us your green_backpack.lua? GiveItem doesn't see the item which you gives to it as argument. probably SpawnPrefab doesn't summon your green_backpack

Edited by Amalleus

Share this post


Link to post
Share on other sites
Amalleus    13
8 hours ago, RedHairedHero said:

player = GLOBAL.ThePlayer

Right now your code uses player, but player on it's own doesn't exist. Just put in the code above before you call your SimInit function and it should work.

This will refer to host. And AddSimPostInit initializes on current player itself

Share this post


Link to post
Share on other sites
MrDoge124    3

I put player "= GLOBAL.ThePlayer" in the scripts...

[string "../mods/Green's backpack/scripts/prefabs/gr..."]:112: variable 'GLOBAL' is not declared
LUA ERROR stack traceback:
        =[C] in function 'error'
        scripts/strict.lua(23,1)
        ../mods/Green's backpack/scripts/prefabs/green_backpack.lua(112,1) in function 'fn'
        scripts/mainfunctions.lua(93,1)
        =(tail call) ?

It didn't work. I'm not sure whats going on with this one...

Share this post


Link to post
Share on other sites

player = GLOBAL.ThePlayer should be in the modmain, not in the green_backpack.lua. Let me know if you get any other errors. If you want to provide the entire folder I can test it on my own and try to fix it if needed.

Edited by RedHairedHero

Share this post


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