Jump to content

mod lootdorp is not working


Recommended Posts

[00:01:57]: error calling PrefabPostInit: rocky in mod workshop-1480192127 (The Gorge Extension): 
[string "../mods/workshop-1480192127/modmain.lua"]:148: attempt to index field 'lootdropper' (a nil value)
LUA ERROR stack traceback:
        ../mods/workshop-1480192127/modmain.lua(148,1) in function 'Rockycrabmeat'
        ../mods/workshop-1480192127/modmain.lua(152,1)
        =(tail call) ?
        =[C] in function 'xpcall'
        scripts/mods.lua(158,1) in function 'mod'
        scripts/mainfunctions.lua(267,1)    
[00:01:57]: Disabling workshop-1480192127 (The Gorge Extension) because it had an error.    
[00:01:57]: [string "../mods/workshop-1480192127/modmain.lua"]:148: attempt to index field 'lootdropper' (a nil value)
LUA ERROR stack traceback:
        ../mods/workshop-1480192127/modmain.lua(148,1) in function 'Rockycrabmeat'
        ../mods/workshop-1480192127/modmain.lua(152,1)
        =(tail call) ?
        =[C] in function 'xpcall'
        scripts/mods.lua(158,1) in function 'mod'
        scripts/mainfunctions.lua(267,1)
[00:01:57]: [string "../mods/workshop-1480192127/modmain.lua"]:148: attempt to index field 'lootdropper' (a nil value)
LUA ERROR stack traceback:
        ../mods/workshop-1480192127/modmain.lua(148,1) in function 'Rockycrabmeat'
        ../mods/workshop-1480192127/modmain.lua(152,1)
        =(tail call) ?
        =[C] in function 'xpcall'
        scripts/mods.lua(158,1) in function 'mod'
        scripts/mainfunctions.lua(267,1)

 

how can fix?

exv.zip

Link to comment
Share on other sites

Well, your code looks right, and the "rocky" prefab does have a lootdropper component. But it only has a lootdropper component on the server, and not on the clients. I'm guessing your server has caves on it, which means you are a client on the server, and so you get this error.

Look at the prefabs you're changing. If whatever components you're changing/accessing are added after this part of their initialization function, fn():

    if not TheWorld.ismastersim then
        return inst
    end

...then you also need to do this check, or something similar, before making the changes.

In this particular instance, where you're only changing things which need to be on the server, I'd just do this:

if not GLOBAL.TheWorld.ismastersim then
    AddPrefabPostInit("lightninggoat",MilkGoat)
    AddPrefabPostInit("rocky",AddRockCrabmeatLoot)
    AddPrefabPostInit("beefalo",AddBeefaloGutLoot)
end

Alternatively, if your AddPrefabPostInit's at some point contain both client and server code, you can change them to look like this.

local function MilkGoat(inst)
    -- Do client stuff
    if not GLOBAL.TheWorld.ismastersim then
        return inst
    end
    -- Do server stuff
	inst:AddComponent("beard")
	inst.components.beard.prize = "goatmilk"
	inst.components.beard.bits = 3
	inst.components.beard.daysgrowth = 3 + 1 
end

 

Edited by Ultroman
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...