Jump to content

Recommended Posts

I have been trying for about 3 days to figure out how to give my custom character a % based sanity regain on killing an enemy based on their max health, like Wigfrid has. I have checked the wathgrithr.lua and cannot seem to get her coding to work with my lua. Also have tried varients of what i want such as a static gain on kill or on hit from other posts in the forum but I don't understand the required syntax that is crashing my game. 

 

Was wondering if anyone could give me a hand with this issue?

 

I am currently using this code I pulled off a post from Blueberrys 

 

-- where inst is the player instance
inst:ListenForEvent("killed", function(inst, data)
    inst.components.health:DoDelta(10)
    inst.components.sanity:DoDelta(10)
    -- inst.components.hunger:DoDelta(10)
end)
 
Here is a link to my error log

@Maeltor Your log:

...rve/data/../mods/wiegraf/scripts/prefabs/wiegraf.lua:42: variable 'inst' is not declared

Notice that in my code, I wrote "where inst is the player's instance". That's your problem, inst doesn't refer to anything in your code. Please provide your code so we can explain where it should go.

Not OP, but I'm stuck on the same thing. I've only ever coded in Java before and I wasn't too great at that, so I'm pretty much clueless! Here's my code so far.

local MakePlayerCharacter = require "prefabs/player_common"local assets = {        Asset( "ANIM", "anim/player_basic.zip" ),        Asset( "ANIM", "anim/player_idles_shiver.zip" ),        Asset( "ANIM", "anim/player_actions.zip" ),        Asset( "ANIM", "anim/player_actions_axe.zip" ),        Asset( "ANIM", "anim/player_actions_pickaxe.zip" ),        Asset( "ANIM", "anim/player_actions_shovel.zip" ),        Asset( "ANIM", "anim/player_actions_blowdart.zip" ),        Asset( "ANIM", "anim/player_actions_eat.zip" ),        Asset( "ANIM", "anim/player_actions_item.zip" ),        Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ),        Asset( "ANIM", "anim/player_actions_bugnet.zip" ),        Asset( "ANIM", "anim/player_actions_fishing.zip" ),        Asset( "ANIM", "anim/player_actions_boomerang.zip" ),        Asset( "ANIM", "anim/player_bush_hat.zip" ),        Asset( "ANIM", "anim/player_attacks.zip" ),        Asset( "ANIM", "anim/player_idles.zip" ),        Asset( "ANIM", "anim/player_rebirth.zip" ),        Asset( "ANIM", "anim/player_jump.zip" ),        Asset( "ANIM", "anim/player_amulet_resurrect.zip" ),        Asset( "ANIM", "anim/player_teleport.zip" ),        Asset( "ANIM", "anim/wilson_fx.zip" ),        Asset( "ANIM", "anim/player_one_man_band.zip" ),        Asset( "ANIM", "anim/shadow_hands.zip" ),        Asset( "SOUND", "sound/sfx.fsb" ),        Asset( "SOUND", "sound/wilson.fsb" ),        Asset( "ANIM", "anim/beard.zip" ),        Asset( "ANIM", "anim/athena.zip" ),}local prefabs = {}local start_inv = {	-- Custom starting items}local fn = function(inst)		-- choose which sounds this character will play	inst.soundsname = "willow"	-- Minimap icon	inst.MiniMapEntity:SetIcon( "athena.tex" )		-- Stats		inst.components.health:SetMaxHealth(150)	inst.components.hunger:SetMax(150)	inst.components.sanity:SetMax(170)		-- Damage multiplier (optional)    inst.components.combat.damagemultiplier = 1.2		-- Hunger rate (optional)	inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE		-- Movement speed (optional)	inst.components.locomotor.walkspeed = 4	inst.components.locomotor.runspeed = 6	endreturn MakePlayerCharacter("athena", prefabs, assets, fn, start_inv)

Any help is appreciated and thanks for putting up with us noobs :)

I took this code from wathgrithr.lua.

inst:ListenForEvent("entity_death", function(wrld, data) 	if data.cause == inst.prefab then		local delta = 10 -- amount		inst.components.health:DoDelta(delta)		inst.components.sanity:DoDelta(delta)		inst.components.hunger:DoDelta(delta)	endend, GetWorld())

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