Jump to content

Recommended Posts

I am creating a sword to go along with my custom character, got most effects working. Basically its a darkness sword that gains power from the wielder's life force and slowly turn them insane. (Thanks tehMugWump for OPCane and theDanaAddams for Dark Link's Dark Sword)

 

Details;

---------

 

Pro's -- add speed, chop trees, lit things on fire, Night vision(glows faint red in the dark), hits like a spear

 

Con's -- Sanity drain, Hunger drain (need help on this)

 

Manage to add cons of sanity drain, but working to add hunger drain as well. I check armor_slurper and slurper's prefabs but not able to get them to work. I'm new to Lua so i might add them wrongly. if i remove the hunger codes it works fine. Some help checking my codes would be appeciated :-)

 

Edit;

I should have put [Help] instead of [Request] for the Thread Title... silly me

 

 

 

This is the codes;

local assets={	Asset("ANIM", "anim/darksword.zip"),   	Asset("ANIM", "anim/swap_darksword.zip"),	    Asset("ATLAS", "images/inventoryimages/darksword.xml")}local function onfinished(inst)    inst:Remove()endlocal function onequip(inst, owner)     owner.AnimState:OverrideSymbol("swap_object", "swap_darksword", "swap_nightmaresword")    owner.AnimState:Show("ARM_carry")     owner.AnimState:Hide("ARM_normal") 		inst.task = inst:DoPeriodicTask(2, function() swordhunger(inst, owner) end)		    local light = inst.entity:AddLight()    light:SetFalloff(0.7)    light:SetIntensity(.3)    light:SetRadius(2)    light:SetColour(235/255,12/255,12/255)    light:Enable(true)    inst.AnimState:SetBloomEffectHandle( "shaders/anim.ksh" )endlocal function onunequip(inst, owner)     owner.AnimState:Hide("ARM_carry")     owner.AnimState:Show("ARM_normal") endlocal function swordhunger(inst, owner)    if (owner.components.hunger and owner.components.hunger.current > 0 )then        owner.components.hunger:DoDelta(-3)                endend	local function fn(Sim, target, inst) --MOD	local inst = CreateEntity()	local trans = inst.entity:AddTransform()	local anim = inst.entity:AddAnimState()    inst.entity:AddSoundEmitter()            MakeInventoryPhysics(inst)      	anim:SetBank("nightmaresword")	 	anim:SetBuild("darksword")	 	anim:PlayAnimation("idle")	--------------------------------------    local light = inst.entity:AddLight()    light:SetFalloff(0.7)    light:SetIntensity(.5)    light:SetRadius(.5)    light:SetColour(235/255,12/255,12/255)    light:Enable(true)    inst.AnimState:SetBloomEffectHandle( "shaders/anim.ksh" )    ---------------------------------    inst:AddComponent("weapon")    inst.components.weapon:SetDamage(TUNING.SPEAR_DAMAGE)        inst:AddComponent("inspectable")        inst:AddComponent("inventoryitem")        inst:AddComponent("equippable")    inst:AddComponent("lighter")       inst:AddComponent("dapperness")    inst.components.dapperness.dapperness = -0.2    inst.components.equippable:SetOnEquip( onequip )    inst.components.equippable:SetOnUnequip( onunequip )    inst.components.equippable.walkspeedmult = TUNING.CANE_SPEED_MULT    inst.components.inventoryitem.atlasname = "images/inventoryimages/darksword.xml"      inst:AddTag("sharp")    inst:AddComponent("tool") -- doesn't work with "Target"	--inst:AddComponent("key") -- works with "Target"	inst:AddComponent("workable")	inst.components.tool:SetAction(ACTIONS.CHOP, 2)-----------    return instend-------------------------return Prefab( "common/inventory/darksword", fn, assets)
Edited by Zaran

Put this in your modmain.lua

function newhungerdelta(inst)    local oldDoDelta = inst.DoDelta    inst.DoDelta = function (self, delta, overtime, ignore_invincible)        local ourmodtohungerrate = 1        for k,v in pairs (self.inst.components.inventory.equipslots) do            if v.itemchangeshungerrateby then                ourmodtohungerrate = ourmodtohungerrate + v.itemchangeshungerrateby            end                end        delta = delta * ourmodtohungerrate        oldDoDelta(self, delta, overtime, ignore_invincible)    endendAddComponentPostInit("hunger", newhungerdelta)

then add to your prefab function

inst.itemchangeshungerrateby = 1

A value of 1 would increase the hunger rate by 100% while the item is equipped. You can use different values on different items you have equipped at the same time, and they will stack additively (1+1 = 2 = 200% increase in hunger rate). If you set negative numbers the game will treat them the same way: -0.2 and you'll be getting 80% of normal hungerrate. If you go below -1.0 in total you'll gain hunger while the items are equipped.

Edited by Heavenfall

Sorry, you'll get some crashes. Put this in modmain.lua instead

function newhungerdelta(inst)    local oldDoDelta = inst.DoDelta    inst.DoDelta = function (self, delta, overtime, ignore_invincible)        local ourmodtohungerrate = 1        if self.inst.components.inventory then        for k,v in pairs (self.inst.components.inventory.equipslots) do            if v.itemchangeshungerrateby then                ourmodtohungerrate = ourmodtohungerrate + v.itemchangeshungerrateby            end                end        end        delta = delta * ourmodtohungerrate        oldDoDelta(self, delta, overtime, ignore_invincible)    endendAddComponentPostInit("hunger", newhungerdelta)
Edited by Heavenfall

Tested and it works great! :-)

 

My sword is now complete, just need more test drive to make it balance my character

 

The code that you post is a little advance for me, still much to learn

 

This issue is SOLVED

 

Now... finding new stuff to tinker with!

 

:wickerbottomthanks: 

 

Edit;

 

Ok i'll try the new codes pronto,

I'll inform if i have any crashes,

works great so far :)

Edited by Zaran

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