Jump to content

Recommended Posts

So this is my first time modding and I'm trying to make a mod that changes the loot chance that a mob will drop. So it's easy for people to farm pigskin, silk, electric milk, etc. 

 

Anyway, I'm having trouble. How do you distinguish a normal pig, guardpig, and werepig in the code? They're all under the same prefab (pigman) so I don't know how to separate them. 

 

If I try to modify the drop rates, only the normal pig is affected. The werepig still retains its original drop rate. Is there a way to separate them? Sorry, I'm really new to programming. 

 

 

Here's my code so far. 

function spiderpostinit(inst)	inst.components.lootdropper:SetLoot(nil)	inst.components.lootdropper:AddRandomLoot("monstermeat", .8)	inst.components.lootdropper:AddRandomLoot("silk", 1)	inst.components.lootdropper:AddRandomLoot("spidergland", 1)	inst.components.lootdropper.numrandomloot = 2 --This changes the amount of items it will drop.endfunction spider_warriorpostinit(inst)	inst.components.lootdropper:SetLoot(nil)	inst.components.lootdropper:AddRandomLoot("monstermeat", .8)	inst.components.lootdropper:AddRandomLoot("silk", 1)	inst.components.lootdropper:AddRandomLoot("spidergland", 1)	inst.components.lootdropper.numrandomloot = 3endfunction pigmanpostinit(inst)	inst.components.lootdropper:SetLoot(nil)	inst.components.lootdropper:AddRandomLoot("meat", 1)	inst.components.lootdropper:AddRandomLoot("pigskin", 1)	inst.components.lootdropper.numrandomloot = 4end--Add PrefabPostInitAddPrefabPostInit("pigman", pigmanpostinit)AddPrefabPostInit("spider_warrior", spider_warriorpostinit)AddPrefabPostInit("spider", spiderpostinit)
Link to comment
https://forums.kleientertainment.com/forums/topic/48561-need-help-modding/
Share on other sites

  • Developer

The guardpig is it's own prefab "pigguard", and the werepig gets changed after the postinit when transition to and from it's were state. You'll want to take a look at this code
 

inst.components.werebeast:SetOnNormalFn(SetNormalPig) --this gets run when transitioning back to a normal pigand inst.components.werebeast:SetOnWereFn(SetWerePig) --this gets run when transitioning to a werepig

In your postinit function you probably want to override what it set to werebeast:SetOnNormalFn and werebeast:SetOnWereFn so that the lootdropper component always gets the values you want.

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