Jump to content

Help with custom backpack for custom character.


Recommended Posts

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

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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

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

×
  • Create New...