Jump to content

Custom character/items (Help needed with item scripting)


Recommended Posts

RetroMikeLoadout_zpsvynurw3e.png

This will be my first mod for DST. The basic idea is this. RetroMike is a "Game Hopper", a character able to enter and travel between game worlds in his sleep. He is able to summon items from different games through the use of his "Dream" powers. For the most part things have gone pretty smoothly. The extended mod character template was super helpful and I even managed to make custom sounds despite the available tutorials having some holes in them. Scripting however is a huge weak area for me, so I'll be asking for help as I hit walls. 

NOTE: This character is still being balanced. I want to end up with a fun and unique play-style that feels fresh but isn't overly easy or hard. I'm also going to match the art style to the best of my abilities. The name however will not be starting with a W, because he is a rogue element and doesn't belong to this game world. 

Dream Meter: This acts as the crafting source for all of Retro's special items and abilities. Summoning items from other games will drain his Dream power. Additionally some items must be sustained with dream energy or they will eventually break from use. Dream energy is replenished over time.

DreamPower_zps64qpuxcy.png

RetroMike's Flatcap: Affectionately referred to as armor, he never goes out without it.

retrocap_zpspeyiih3s.png

Watt's Axe (Secret of Mana): One of the Mana weapons. A handy weapon, it also makes quick work of rocks and trees. 

wattsaxe_zpsq7pobu88.png

The 1-Up (Super Mario Brothers): This works exactly as you would expect. If you have one in your possession when you die it will revive you with full stats. 

Oneup_zpsxlwneplq.png

The Morning Star (Little Nemo: The Dream Master): The royal scepter of King Morpheus. Very effective against monsters and shadows but weak against all other mobs. It acts as a light source when held and has a tiny sanity aura.

Morningstar_zpssw9c1yvb.png

Gnat Swatter (Mario Paint: Gnat Attack): Highly effective vs insects (bees, mosquitos and dragonfly) dealing 100 dmg. All other mobs take 1 dmg.

swatter_zpsfmmgndki.png

Summons Materia (Final Fantasy 7): Retro's strongest item. It summons fat chocobo to crush a target, dealing massive damage. It is destroyed after 1 use.

Pokemon Trainer's Bag (Pokemon): W.I.P This will be made if I am able to make the backpack behave as intended. I want it to have a "berry pouch" that keeps food stuffs fresh.See this thread for details. 


Gold Coins (Super Mario Brothers): A crafted ingredient needed to make the 1-Up 

 

 

I've got more items from other games I would like to make for this character. I'm open to suggestions. Keep in mind I'm limiting items to 1 (maybe 2) per franchise to keep it diverse.

Big thanks to everyone who has helped me out on this so far. :D 

 

Edited by RetroMike
Link to comment
Share on other sites

I might be able to grab you a template for the axe but I can't at the moment.

For making objects glow, it's pretty simple.

under the CreateEntity section you need a line that says

inst.entity:AddLight()

and a section underneath the animstates that says

    inst.Light:Enable(true)
    inst.Light:SetRadius(1)
    inst.Light:SetFalloff(0.66)
    inst.Light:SetIntensity(0.66)
    inst.Light:SetColour(255 / 255, 255 / 255, 255/ 255)

you can change the numbers here to whatever you want to adjust the glow appearance. Radius is how wide the light is, falloff has to do with realism in the fade, intensity is how bright, and color is RGB, so for each fraction you put a number somewhere between 0 and 255 in the first part. First fraction is red, second is blue, third is green. the example I posted would have a white light. yellow is a combination between red and green, etc.

and somewhere below for sanity:

    local function onblink(staff, pos, caster)
    if caster.components.sanity ~= nil then
        caster.components.sanity:DoDelta(TUNING.SANITY_SMALL)
    end
    staff.components.finiteuses:Use(1) 
end
 

you can change the tuning value to whatever. This won't make holding the item give sanity, but will give sanity whenever it's used. I'd suggest looking at the hat codes for the tophat dapperness code for other sanity affects

 

 

 

 

Link to comment
Share on other sites

4 minutes ago, mf99k said:

I might be able to grab you a template for the axe but I can't at the moment.

For making objects glow, it's pretty simple.

Not so like that, also needs the separated light prefab. If not, It will happen like the yellow amulet, Will bright, but only for you, but no another ones.

Link to comment
Share on other sites

Just now, Neutral_Steve said:

Not so like that, also needs the separated light prefab. If not, It will happen like the yellow amulet, Will bright, but only for you, but no another ones.

I think it might depend on what you're making with the code, with creatures it works.

Link to comment
Share on other sites

Awesome, I'll give that a shot. I'm still digging into other prefabs/scripts to see what, if anything, I can figure out. I've just never been able to get a grasp on even the simplest coding stuff so it's a struggle. Once I get a chance to work on this over the weekend I'll let you know if it worked out  Thanks much!

Link to comment
Share on other sites

Thanks to your suggestions I was able to get both an aura of light and a small sanity boost when equipped. So that knocks a few things of the to do list :D Very much appreciated!

Now I just need to figure out how to turn this useless staff into a custom projectile slinging death machine and that will be another item completed. I was going to update my main post with things that have been completed but I don't seem to have that ability. Unless i'm just not looking in the right place.

Link to comment
Share on other sites

Also, I like his face, has some kind of disgusted and annoyed face.

Btw, for craftings, you should put this on your modmain.lua

local Ingredient = GLOBAL.Ingredient
local Recipe = GLOBAL.Recipe
local RECIPETABS = GLOBAL.RECIPETABS
local TECH = GLOBAL.TECH

Also. This is the craft of my monster hide!

local monster_vest_recipe = AddRecipe("monster_vest",{ Ingredient("armorwood", 1), Ingredient("monstermeat", 14), Ingredient("silk", 8)},
RECIPETABS.WAR, TECH.SCIENCE_TWO, nil, nil, nil, 1, "warren_builder", "images/inventoryimages/monster_vest.xml"
,  "monster_vest.tex")

That warren_builder is for make you character being the only to craft that item. So, he needs that tag, on the common_postinit of your character.lua

then. this is an example craft

local youritemnamerecipe_recipe = AddRecipe("youritemname",{ Ingredient("armorwood", 1), Ingredient("monstermeat", 14), Ingredient("silk", 8)},
RECIPETABS.SURVIVAL, TECH.SCIENCE_TWO, nil, nil, nil, 1, "yourcharacter_builder", "images/inventoryimages/youritem.xml"
,  "youritem.tex")

Note, TECH.MAGIC_ONE doesn't exist, TECH.MAGIC_TWO is the prehatistator an TECH.MAGIC_THREE is the manipulator.

Edited by Neutral_Steve
edited somethin
Link to comment
Share on other sites

12 hours ago, Neutral_Steve said:

Also, I like his face, has some kind of disgusted and annoyed face.

Btw, for craftings, you should put this on your modmain.lua

local Ingredient = GLOBAL.Ingredient
local Recipe = GLOBAL.Recipe
local RECIPETABS = GLOBAL.RECIPETABS
local TECH = GLOBAL.TECH

Also. This is the craft of my monster hide!

local monster_vest_recipe = AddRecipe("monster_vest",{ Ingredient("armorwood", 1), Ingredient("monstermeat", 14), Ingredient("silk", 8)},
RECIPETABS.WAR, TECH.SCIENCE_TWO, nil, nil, nil, 1, "warren_builder", "images/inventoryimages/monster_vest.xml"
,  "monster_vest.tex")

That warren_builder is for make you character being the only to craft that item. So, he needs that tag, on the common_postinit of your character.lua

then. this is an example craft

local youritemnamerecipe_recipe = AddRecipe("youritemname",{ Ingredient("armorwood", 1), Ingredient("monstermeat", 14), Ingredient("silk", 8)},
RECIPETABS.SURVIVAL, TECH.SCIENCE_TWO, nil, nil, nil, 1, "yourcharacter_builder", "images/inventoryimages/youritem.xml"
,  "youritem.tex")

Note, TECH.MAGIC_ONE doesn't exist, TECH.MAGIC_TWO is the prehatistator an TECH.MAGIC_THREE is the manipulator.

Brilliant! I had been trying to dissect some mods I had pulled down but I was missing some key knowledge on how to implement the code I was trying to mine. Thanks to you I now have working recipes for all 3 of the items. Once again thank you very much for the help!

Looks like I'm down to my last 3 hurdles.

-Making the mushroom function as listed in the OP if possible

-Making the Morning star function as listed in the OP if possible

-Learning how to add those sweet swinging animations to the axe. Mf99K mentioned above that they might know of a template for this so I've got my fingers crossed :)

Edited by RetroMike
Link to comment
Share on other sites

34 minutes ago, RetroMike said:

Brilliant! I had been trying to dissect some mods I had pulled down but I was missing some key knowledge on how to implement the code I was trying to mine. Thanks to you I now have working recipes for all 3 of the items. Once again thank you very much for the help!

Looks like I'm down to my last 3 hurdles.

-Making the mushroom function as listed in the OP if possible

-Making the Morning star function as listed in the OP if possible

-Learning how to add those sweet swinging animations to the axe. Mf99K mentioned above that they might know of a template for this so I've got my fingers crossed :)

For the mushroom, I don't think you can make it prevent death unless you edit the event, what you could do is make it do similar to red amulet in singleplayer, you die then revives you instantly.

I tried the revive instantly and it did work

inst.components.inventoryitem.keepondeath = true --To keep the mushroom on death

inst:DoPeriodicTask(1, function() if owner:HasTag("playerghost") then owner:PushEvent("respawnfromghost") end end) 
-- Every 1 second checks if the player is dead, if he is revives him, You'd have to do onpickup and ondrop to make sure this task doesn't keep happening even after losing the mushroom.. I ain't sure if there's a better way than this.

 

Edited by Aquaterion
Link to comment
Share on other sites

I'm guessing - inst.components.inventoryitem.keepondeath - only applies to equipped items yes? I was kind of hopping I could have it auto use from your inventory but It's starting to look like I will have to make this an equitable item. That or make it res on Haunt like the DST Red amulet variant. Either way valuable info. I'll give this a shot later when I have some more time to tinker. Thanks :)

Link to comment
Share on other sites

2 hours ago, RetroMike said:

I'm guessing - inst.components.inventoryitem.keepondeath - only applies to equipped items yes? I was kind of hopping I could have it auto use from your inventory but It's starting to look like I will have to make this an equitable item. That or make it res on Haunt like the DST Red amulet variant. Either way valuable info. I'll give this a shot later when I have some more time to tinker. Thanks :)

So I decided to try and make this work how I mentioned and I did manage it!;

In the main function (usually called fn) put these:

and add these outside before it:

Spoiler

 

    inst.components.inventoryitem:SetOnDroppedFn(ondropped)
    inst.components.inventoryitem:SetOnPickupFn(onpickup)

    inst.lastowner = nil
    inst:DoPeriodicTask(1,
    function()
        if inst.components.inventoryitem.owner ~= nil then
             inst.lastowner = inst.components.inventoryitem.owner
        end
    end)


 

Functions:

Spoiler

 

local function ondropped(inst)
        local mushtimelimit = 0
        if mushtimelimit <= 10 then
            inst.mushtask = inst:DoPeriodicTask(1,
            function()
                if inst.lastowner ~= nil then
                    local lastholder = inst.lastowner
                    mushtimelimit = mushtimelimit + 1
                    if lastholder:HasTag("playerghost") then
                        --inst.SoundEmitter:PlaySound("1UP-SOUND-FILE-LOCATION")
                        lastholder:PushEvent("respawnfromghost", {cause = "oneup"}) -- Could not get cause to work properly..
                        lastholder.components.health.currenthealth = lastholder.components.health.maxhealth
                        lastholder.components.sanity.current = lastholder.components.sanity.max
                        lastholder.components.hunger.current = lastholder.components.hunger.max
                        lastholder.components.talker:Say("It's OK, I had an extra life!")
                        inst.mushtask:Cancel()
                        inst:Remove()
                    end
                end
            end)
        end
end

local function onpickup(inst)
        if inst.mushtask ~= nil then
            inst.mushtask:Cancel()
        end
end

 

 

It kinda looks weird in forum so I'm going to attach it too. (Make sure to read all the comments :p )

I made it so when the mushroom is dropped, whether on death or not, it checks if the last owner of the mushroom dies in the next 10 seconds, if he/she does, it revives him/her and gets consumed.

^I also added a commented version that checks if the player is a "retromike", so not every player could do it

1upmushroom.lua

Edited by Aquaterion
Link to comment
Share on other sites

Freakin perfect, your comments were super easy to follow and I love the addition of the line spoken on resurrection. I plugged everything in and it worked perfectly. I geeked out pretty hard when testing. :D

Looks like all I need to tackle now is the Morningstar weapon functionality (I can provide a .zip of the mod if anyone wants to tinker with it) and the optional animation for Watt's Axe.

Everyone has been super helpful, I gotta find a way to return the favor sometime.

Edited by RetroMike
Link to comment
Share on other sites

9 minutes ago, RetroMike said:

Looks like all I need to tackle now is the Morningstar weapon functionality (I can provide a .zip of the mod if anyone wants to tinker with it) and the optional animation for Watt's Axe.

I think I can do the morning star. If you're interesed. pm me.

Link to comment
Share on other sites

53 minutes ago, Neutral_Steve said:

I had only 1 issue, and it's the projectile doesn't do the loop animation, or the animation works bad.

Well, It's done. I changed some things from the morningstar.lua

Morningstar Thingies.rar

I checked it out to see how you did it, pretty much the same but I think you forgot the damage multiplier on shadow/monster targets

retro all you gotta do is add this below inst.components.weapon:SetProjectile;

inst.components.weapon:SetOnAttack(function(inst, attacker, target)
  --attacker.SoundEmitter:PlaySound("dontstarve/wilson/fireball_explo") Sound on Firing if any
  if target:HasTag("monster") or target:HasTag("shadow") then
	target.components.combat:GetAttacked(inst, 20, nil) 
	--20 is the value of extra damage
  end
end)

 

 

Edited by Aquaterion
Link to comment
Share on other sites

36 minutes ago, Aquaterion said:

I checked it out to see how you did it, pretty much the same but I think you forgot the damage multiplier on shadow/monster targets

retro all you gotta do is add this below inst.components.weapon:SetProjectile;


inst.components.weapon:SetOnAttack(function(inst, attacker, target)
  --attacker.SoundEmitter:PlaySound("dontstarve/wilson/fireball_explo") Sound on Firing if any
  if target:HasTag("monster") or target:HasTag("shadow") then
	target.components.combat:GetAttacked(inst, 20, nil) 
	--20 is the value of extra damage
  end
end)

 

 

Ah, I forget that.

Link to comment
Share on other sites

Yo!  Sorry for the delayed reply, I've been working on a project for TF2 and it just devoured my day. I haven't yet had a chance to check this out but I will as soon as I am able, might not get to it until tomorrow though.

Seriously, can't thank you all enough for the help! It's been really cool to see this unfold and learn more about the process. 

 

UPDATE:  Alright I got this suckers installed and the issue with the animation was all my own fault. I must have done something wonky when I built the spriter file, so I redid the whole thing with a new animation name and updated the prefab accordingly, it worked like a charm! I also plugged in the damage multiplier and it worked perfectly as well. Aside from some optional crap like axe animation and maybe some sound effects my to-do list has been completed. I owe you all one!

I also managed to get minimap icons working and made the Morningstars attack rate less spammy. More like a blow dart in execution. 

Edited by RetroMike
Link to comment
Share on other sites

Hit another wall with my recipes. I attempted to put a life ingredient requirement on one of my recipes but it crashes the game. I pulled Ingredient(CHARACTER_INGREDIENT.HEALTH, 40)  from the Reviver recipe so I figured it should work fine, I was wrong. I'd also like ot know if other character stats (sanity and hunger) can be used as ingredients.

The crash doesn't post an on screen log, it tells me to check my log file, however there is no log.txt generated. Maybe because I don't have DS, just DST? 

Link to comment
Share on other sites

40 minutes ago, RetroMike said:

Hit another wall with my recipes. I attempted to put a life ingredient requirement on one of my recipes but it crashes the game. I pulled Ingredient(CHARACTER_INGREDIENT.HEALTH, 40)  from the Reviver recipe so I figured it should work fine, I was wrong. I'd also like ot know if other character stats (sanity and hunger) can be used as ingredients.

The crash doesn't post an on screen log, it tells me to check my log file, however there is no log.txt generated. Maybe because I don't have DS, just DST? 

Gladly I have the solution for that, 

Ingredient(GLOBAL.CHARACTER_INGREDIENT.HEALTH, 40)

Also, for remove sanity and hunger just change the HEALTH to SANITY or HUNGER respectively.

Edited by Neutral_Steve
Changed "amount" to "40"
Link to comment
Share on other sites

2 hours ago, RetroMike said:

The crash doesn't post an on screen log, it tells me to check my log file, however there is no log.txt generated. Maybe because I don't have DS, just DST? 

The new name for the log file is client_log.txt.

Link to comment
Share on other sites

22 hours ago, Neutral_Steve said:

Gladly I have the solution for that, 

Ingredient(GLOBAL.CHARACTER_INGREDIENT.HEALTH, 40)

Also, for remove sanity and hunger just change the HEALTH to SANITY or HUNGER respectively.

Does this work on custom stats? because it crashes me when I try it ;-; I'm guessing its cause of a missing texture, but I've got no clue where the texture would go

Edited by Aquaterion
Link to comment
Share on other sites

1 hour ago, Aquaterion said:

Does this work on custom stats? because it crashes me when I try it ;-; I'm guessing its cause of a missing texture, but I've got no clue where the texture would go

Nope, Wissphar's mod have only 105 of sanity and he can craft his items without problems, I put all the recipes on the Modmain, so, if your character has the recipes on his character.lua remove the global.

Link to comment
Share on other sites

1 hour ago, Neutral_Steve said:

Nope, Wissphar's mod have only 105 of sanity and he can craft his items without problems, I put all the recipes on the Modmain, so, if your character has the recipes on his character.lua remove the global.

Huh Sorry I didn't understand that correctly.. My mod adds a stat to EVERY character, let's say its called "energy" doing GLOBAL.CHARACTER_INGREDIENT.ENERGY crashed me

Link to comment
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
 Share

×
  • Create New...