Jump to content

Recommended Posts

I tried this but it doesn't work

 

local function DropMore(inst)
  inst.components.lootdropper:SpawnLootPrefab("goldnugget") --test
end
 
AddPrefabPostInit("koalefant_summer",DropMore)
AddPrefabPostInit("koalefant_winter",DropMore)
 
What's the correct way of doing this?
 
Thanks.

Oh ok. It works but it gives 2 gold.

I added prefab post init twice one for summer and one for winter.

I spawned and killed a winter but got 2 gold instead of 1.

(next kill = 2 gold, next kill after that = 2 gold so it's good)

 

AddPrefabPostInit("koalefant_summer",function(inst)
table.insert(inst.components.lootdropper.loot, "goldnugget")
end)
 
AddPrefabPostInit("koalefant_winter",function(inst)
table.insert(inst.components.lootdropper.loot, "goldnugget")
end)
 
Hm...
  • Developer

@SenL

 

I suspect there was two koalefants in your level when you tested this (or at least two had been spawned)? All koalefants_summer share the same loot table, so if you spawn two koalefants the loot table is modified twice. You'd have to keep track of whether you already modified it so you won't do it again for the next spawned koalefant (and the next and the next and.....by the time you get to your 10th koalefant it'd be dropping 10 gold)

Hm, client gets a crash on 1st day of winter but not immediately.

Crash on lootdropper being nil.

 

Code:

AddPrefabPostInit("koalefant_winter",function(inst)

  inst.components.lootdropper:AddChanceLoot("mycustomitem", 1)

end

 

I do have "Koalefant family" mod which adds baby koalefant.

Should I change to:

 

if not inst.components.lootdropper then

  inst.components.lootdropper:AddChanceLoot("mycustomitem", 1)

end

 

or is it safe to change it to:

 

if not inst.components.lootdropper then

  inst:AddComponents("lootdropper")

end

inst.components.lootdropper:AddChanceLoot("mycustomitem", 1)

 

?

Thanks.

Crap... does this apply to anything else or just AddPrefabPostInit in modmain?

 

I recommend you read the stickied topics at the top of this subforum. You'll learn a lot of the answers you're seeking. To answer your question, code which only needs to be ran on the server that code should be applied so it doesn't run on the client.

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