Sign in to follow this  
Fredson

Help, Item That Changes Stats

Recommended Posts

Fredson    3

is There a code to make an item when equipped change the character stats (health, sanity, hunger, running speed, etc ?) please i need help :(

Share this post


Link to post
Share on other sites
DarkXero    2889

A weapon would have the equippable component.

On the onequip and onunequip functions you can put function that change your character's stats.

onequip would hold the buffs.

onunequip would turn it back to normal.

Share this post


Link to post
Share on other sites
Fredson    3

its a hat but not itslef equipable, it just changes the skin of the character, if you want to i can give you the code

Share this post


Link to post
Share on other sites
Fredson    3

local Assets=

{

Asset("IMAGE", "images/inventoryimages/brandon.tex"),

Asset("ATLAS", "images/inventoryimages/brandon.xml")

}

local function OnPickup(inst)

if GetPlayer().components.maskswitch then

GetPlayer().components.maskswitch:SetMask("brandon")

end

inst:Remove()

return inst

end

local function fn()

local inst = CreateEntity()

inst.entity:AddTransform()

inst.entity:AddAnimState()

inst.entity:AddNetwork()

MakeInventoryPhysics(inst)

inst:AddComponent("inspectable")

inst:AddComponent("inventoryitem")

inst.components.inventoryitem.atlasname = "images/inventoryimages/brandon.xml"

inst.components.inventoryitem:SetOnPickupFn(OnPickup)

return inst

end

return Prefab( "common/inventory/brandon", fn, Assets)

Share this post


Link to post
Share on other sites
DarkXero    2889

This is weird, masks are consumables that disappear on pickup after affecting a component of the character?

 

Why don't you edit the component to give you stats based on which mask the component has stored.

Share this post


Link to post
Share on other sites
DarkXero    2889

SetHealth is not a function of inventoryitem.

 

You go to the component that activates effects when masks are picked up, and within the brandon part of the component, you put self.inst.components.health:SetMaxHealth(200) for example.

 

Have you modded anything before?

What are you trying to do, port a mod from single player into DST?

Share this post


Link to post
Share on other sites
DarkXero    2889

Oh alright. I see you modded a character and a custom weapon, pretty nice.

 

Where do you want your masks to appear?

Because one thing to do is to make masks as hats, so you can equip them in the headslot.

Another is to make the masks a consumable, that would switch your character from the jacket build into the brandon build.

 

That code makes your mask get removed on pickup, triggering a function on a nonexistant component.

We can make that component give jacket atributes, but how would we reflect what mask he's currently using?

Share this post


Link to post
Share on other sites
Isosurface    58

Instead of instantly inst:Remove(), why not make the mask a hat item with extremely short durability, or use DoTaskInTime to remove it after 0.1 second, after finishing setting health etc.

Share this post


Link to post
Share on other sites
Fredson    3

it has to change the stats while the mask is on, changing mask will result in different stats, richard mask is the default character stats

Share this post


Link to post
Share on other sites
DarkXero    2889

I wasn't creative enough.

I gave brandon more speed, and 100 damage with his fists.

Also gains 5 sanity per kill.

 

Also tweaked masks, you drop em on the floor, and you wear em right clicking them.

Also, now you have the masks.lua file where you put MakeMask("brandon") and generates the brandon mask.

 

Enjoy.

Jacket.zip

Share this post


Link to post
Share on other sites
Fredson    3

Thank you very much !! :33 but can you explain me what do i have to do to add future masks ? :-)

also how to remove attributes from other masks

Edited by Fredson

Share this post


Link to post
Share on other sites
DarkXero    2889

First, you add a MakeMask("Jake") in masks.lua.

 

Then, you go to the onbecome(inst, mask) and add if mask == "Jake".

Then, under that if, you put all the stats you want.

The stats in a mask should appear on the onbecomerichard function, to normalize the player.

Like how I included defaultdamage in Brandon first, then in Richard, setting it to 0.

 

For things like ListenForEvents, or periodic tasks, you will put a flag like inst.Jake = true, so when normalizing, you check for it and perform functions to cancel the previous ones, like RemoveEventCallback or task:Cancel() for tasks.

 

You will go from Richard to Mask, then from Mask to Richard to other Mask. Richard is restores everything.

It's easier this way, to avoid having a trillion checks from inbetween masks.

Share this post


Link to post
Share on other sites
Fredson    3

Thanks :)) okok so ill have to add this under remove special stats from mask, for each mask

-- removes special stats from masks	if inst.brandon then		inst.brandon = nil		inst:RemoveEventCallback("killed", onkilled)	endif inst.tony then		inst.tony = nil		inst:RemoveEventCallback("killed", onkilled)	endif inst.rasmus then		inst.rasmus = nil		inst:RemoveEventCallback("killed", onkilled)	end

Share this post


Link to post
Share on other sites
DarkXero    2889

Only if tony and rasmus have:

inst.tony = trueinst:ListenForEvent("killed", onkilled)inst.rasmus = trueinst:ListenForEvent("killed", onkilled)

The removal of callbacks are in richard to counter the masks, normalize them.

 

You may have something else in them, for example.

-- in richardif inst.rasmus then   inst.rasmus = nil   inst:RemoveEventCallback("attacked", onattacked)end-- in rasmusinst.rasmus = trueinst:ListenForEvent("attacked", onattacked)

Not necessarily the same event.

 

You can make tasks or watchworldstates too.

Share this post


Link to post
Share on other sites
Fredson    3

okok thank you soo much for helping me :) you saved this girl brain for exploding with .lua errors :SS

p.d: inst.components.combat.defaultdamage = 0 means he doesnt do damage ?

Share this post


Link to post
Share on other sites
DarkXero    2889

defaultdamage is the damage that you do with your fists.

 

And that is actually an error from my part, it should be 10, the unarmed damage value.

 

You should move the 100 from Brandon to Tony. I messed up the masks.

Edited by DarkXero

Share this post


Link to post
Share on other sites
Fredson    3

i got another issue i added tony today, it works fine but brando lost its abilities and acts just like richard

 

heres the code:

local function onkilled(inst, data)	inst.components.sanity:DoDelta(5)	inst.components.talker:Say("HAHAHA!")endlocal function onbecomerichard(inst)	-- normal stats	inst.components.health.maxhealth = 80	inst.components.health:DoDelta(0)	inst.components.hunger.max = 80	inst.components.hunger:DoDelta(0)	inst.components.sanity.max = 50	inst.components.sanity:DoDelta(0)	inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.25)	inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.25)	inst.components.combat.damagemultiplier = 2.0	inst.components.combat.defaultdamage = 0		-- removes special stats from masks	if inst.brandon then		inst.brandon = nil		inst:RemoveEventCallback("killed", onkilled)	end		if inst.tony then		inst.tony = nil		inst:RemoveEventCallback("killed", onkilled)	endendlocal function onbecome(inst, mask)	if mask == "brandon" then		-- normal stats overriden		inst.components.health.maxhealth = 50		inst.components.health:DoDelta(0)		inst.components.hunger.max = 50		inst.components.hunger:DoDelta(0)		inst.components.sanity.max = 50		inst.components.sanity:DoDelta(0)		inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 3)		inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 3)		inst.components.combat.damagemultiplier = 1.1		inst.components.combat.defaultdamage = 0				-- special mask stats that must be overriden when normalizing		inst.brandon = true		inst:ListenForEvent("killed", onkilled)	endendlocal function onbecome(inst, mask)	if mask == "tony" then		-- normal stats overriden		inst.components.health.maxhealth = 200		inst.components.health:DoDelta(0)		inst.components.hunger.max = 100		inst.components.hunger:DoDelta(0)		inst.components.sanity.max = 50		inst.components.sanity:DoDelta(0)		inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 0.9)		inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 0.9)		inst.components.combat.damagemultiplier = 1.5		inst.components.combat.defaultdamage = 100				-- special mask stats that must be overriden when normalizing		inst.tony = true		inst:ListenForEvent("killed", onkilled)	endend

Share this post


Link to post
Share on other sites
DarkXero    2889

The code should look like:

local function onkilled(inst, data)    inst.components.sanity:DoDelta(5)    inst.components.talker:Say("HAHAHA!")end local function onbecomerichard(inst)    -- normal stats    inst.components.health.maxhealth = 80    inst.components.health:DoDelta(0)    inst.components.hunger.max = 80    inst.components.hunger:DoDelta(0)    inst.components.sanity.max = 50    inst.components.sanity:DoDelta(0)    inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.25)    inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.25)    inst.components.combat.damagemultiplier = 2.0    inst.components.combat.defaultdamage = 0         -- removes special stats from masks    if inst.brandon then        inst.brandon = nil        inst:RemoveEventCallback("killed", onkilled)    end         if inst.tony then        inst.tony = nil        inst:RemoveEventCallback("killed", onkilled)    endend local function onbecome(inst, mask)    if mask == "brandon" then        -- normal stats overriden        inst.components.health.maxhealth = 50        inst.components.health:DoDelta(0)        inst.components.hunger.max = 50        inst.components.hunger:DoDelta(0)        inst.components.sanity.max = 50        inst.components.sanity:DoDelta(0)        inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 3)        inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 3)        inst.components.combat.damagemultiplier = 1.1        inst.components.combat.defaultdamage = 0                 -- special mask stats that must be overriden when normalizing        inst.brandon = true        inst:ListenForEvent("killed", onkilled)    end    if mask == "tony" then        -- normal stats overriden        inst.components.health.maxhealth = 200        inst.components.health:DoDelta(0)        inst.components.hunger.max = 100        inst.components.hunger:DoDelta(0)        inst.components.sanity.max = 50        inst.components.sanity:DoDelta(0)        inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 0.9)        inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 0.9)        inst.components.combat.damagemultiplier = 1.5        inst.components.combat.defaultdamage = 100                 -- special mask stats that must be overriden when normalizing        inst.tony = true        inst:ListenForEvent("killed", onkilled)    endend

Share this post


Link to post
Share on other sites
Fredson    3

ok i get it now, thanks again :)) also in this 

caster.components.sanity:DoDelta(-TUNING.SANITY_MED)

how can i make it just to lose 1 or 5 sanity per use ?

Share this post


Link to post
Share on other sites
DarkXero    2889

What do you mean per use.

You mean to get a sanity debuff when putting on a mask?

 

Then you put that line like

inst.components.sanity:DoDelta(-5)

inside a mask, like

    if mask == "tony" then        -- normal stats overriden        inst.components.health.maxhealth = 200        inst.components.health:DoDelta(0)        inst.components.hunger.max = 100        inst.components.hunger:DoDelta(0)        inst.components.sanity.max = 50        inst.components.sanity:DoDelta(0)        inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 0.9)        inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 0.9)        inst.components.combat.damagemultiplier = 1.5        inst.components.combat.defaultdamage = 100                  -- special mask stats that must be overriden when normalizing        inst.tony = true        inst:ListenForEvent("killed", onkilled)				-- one time use effects that don't need a counter on richard		inst.components.sanity:DoDelta(-5)    end

Share this post


Link to post
Share on other sites
Fredson    3

its for a teleport thing for rasmus but its set to medium and uses a lot of sanity

 

Edited by Fredson

Share this post


Link to post
Share on other sites

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
Sign in to follow this