WillowHiggsbury Posted December 12, 2014 Share Posted December 12, 2014 So, I've got a character fleshed out pretty well, but there is one thing I can't figure out. How do I make a players' stats (hunger, health, sanity) increase when said character kills a creature. In addition, is it possible to set a different stat increase for different creatures? Link to comment Share on other sites More sharing options...
Silentdarkness1 Posted December 12, 2014 Share Posted December 12, 2014 Likely. You'd have to establish a function that activates whenever a creature dies. Of course, first having it check to make sure that it died because of the player, and then it checks to see what the dead entity's name is, and then increase the health, hunger or sanity appropriately according to what gets returned. Link to comment Share on other sites More sharing options...
OatmealEFN Posted December 12, 2014 Share Posted December 12, 2014 and then wait for people to farm rabbits. Link to comment Share on other sites More sharing options...
Developer PeterA Posted December 12, 2014 Developer Share Posted December 12, 2014 You'll probably want to do something similar to this.--in your component's constructorself.inst:ListenForEvent("entity_death", function(world, data) self:OnEntityDied(data) end, TheWorld)function YourComponent:OnEntityDied(data) if ( data.inst:HasTag("monster") or data.inst:HasTag("killer") or data.inst:HasTag("animal") ) and data.afflicter:HasTag("player") then if data.afflicter == self.inst then self.inst.components.health:DoDelta( 5 ) end endend Link to comment Share on other sites More sharing options...
Ridder Geel Posted December 12, 2014 Share Posted December 12, 2014 (edited) This is easy, I did this myself today:local ZARKI_MIN_HUNGER = 150local ZARKI_MAX_HUNGER = 150local ZARKI_MIN_SANITY = 150local ZARKI_MAX_SANITY = 150local ZARKI_MIN_HEALTH = 125local ZARKI_MAX_HEALTH = 200local ZARKI_EXPERIENCE_GAIN_PERCENT = 0.10local ZARKI_MAX_EXPERIENCE = 75local function applyexperience(inst) inst.level = math.min(inst.level, ZARKI_MAX_EXPERIENCE) local hunger_percent = inst.components.hunger:GetPercent() local health_percent = inst.components.health:GetPercent() local sanity_percent = inst.components.sanity:GetPercent()-- inst.components.hunger.max = math.ceil(ZARKI_MIN_HUNGER + inst.level * (ZARKI_MAX_HUNGER - ZARKI_MIN_HUNGER) / ZARKI_MAX_EXPERIENCE) inst.components.health:SetMaxHealth(math.ceil(ZARKI_MIN_HEALTH + inst.level * (ZARKI_MAX_HEALTH - ZARKI_MIN_HEALTH) / ZARKI_MAX_EXPERIENCE))-- inst.components.sanity.max = math.ceil(ZARKI_MIN_SANITY + inst.level * (ZARKI_MAX_SANITY - ZARKI_MIN_SANITY) / ZARKI_MAX_EXPERIENCE) inst.components.hunger:SetPercent(hunger_percent) inst.components.health:SetPercent(health_percent) inst.components.sanity:SetPercent(sanity_percent)endlocal function onkill(inst, data) if data.cause == inst.prefab and not data.inst:HasTag("prey") and not data.inst:HasTag("veggie") and not data.inst:HasTag("structure") then local delta = (data.inst.components.combat.defaultdamage) * 0.25 inst.components.sanity:DoDelta(delta) local expdelta = (data.inst.components.combat.defaultdamage) * ZARKI_EXPERIENCE_GAIN_PERCENT inst.level = inst.level + expdelta applyexperience(inst) endendIts similar to the code of the robot guy Just look at his code, and see what is done there.The exp gained depends on the attacking creature's attack damage. Edited December 12, 2014 by Ridder Geel Link to comment Share on other sites More sharing options...
WillowHiggsbury Posted December 12, 2014 Author Share Posted December 12, 2014 @OatmealEFN No, that's why each creature has it's own "upgrade value" rabbits would be pretty low on the value. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now