Jump to content

[Tutorial] Creating a "handslot-equippable-item" from scratch


Malacath
 Share

Recommended Posts

Hello,

First thing, I wanted to let you know that this is a great tutorial! Everything worked perfectly. The only issue I am having is getting my swap image to show up in game and I am unsure why that is. Could you give me some suggestions on how I can fish this problem?

Link to comment
Share on other sites

@Aurata,not really. There are many small things that could have gone wrong, so check every little detail with the tutorial, folder structure, spelling mistakes, and also check the log file. A common mistake is the following folder structure:

mymod\exported\myitem\swap_myitem\swap_myitem\swap_myitem.png 

There is twice a folder named "swap_myitem" and that has to be like this!

 

If you don't manage after sincerely trying you can upload the mod in a *.zip file and I can take a look.

Link to comment
Share on other sites

@Aurata,not really. There are many small things that could have gone wrong, so check every little detail with the tutorial, folder structure, spelling mistakes, and also check the log file. A common mistake is the following folder structure:

mymod\exported\myitem\swap_myitem\swap_myitem\swap_myitem.png 

There is twice a folder named "swap_myitem" and that has to be like this!

 

If you don't manage after sincerely trying you can upload the mod in a *.zip file and I can take a look.

 

Thank you @Malacath! I was able to fix the problem by doing what I explained. I just posted for others who make the same mistake as me.

Link to comment
Share on other sites

@Malacath, I was unable to get the two animations in the same file as of now but I will still keep trying after I am able to get the images to show. Right now I can't get the Eyebone to display. I think it might have something to do with my code but I'm not sure how to fix it. How do I check if an item is equipped because what I have now doesn't seem to work.

 

Here's my code:

local dir = inst.AnimState:GetCurrentFacing()if (inst.components.equippable:IsEquipped()) then    if (dir == 1) then        inst.AnimState:OverrideSymbol("swap_object", "swap_chester_eyebone_backward", "swap_chester_eyebone_backward")    else        inst.AnimState:OverrideSymbol("swap_object", "swap_chester_eyebone_forward", "swap_chester_eyebone_forward")    endend
Edited by BaconAndRibs
Link to comment
Share on other sites

@BaconAndRibs, it doesn't work because you are accessing the same entity all the time. In your code there is only one inst, and I assume that that is the weapon since you (presumably) don't crash on inst.components.equippable:IsEquipped(). So instead you want to get the owner

local owner = inst.components.inventoryitem.owner

And access the AnimState of this guy.

Link to comment
Share on other sites

@Malacath, Aaaahhhh, so I had to change it to owner instead of inst. Thank you. I can now get it to show the seperate image when I equip it facing that direction but how do I change the image if the the player has already equipped it and just changes direction. Do I have to have an event listener to check if the player changes the direction while still having it equipped?

 

This is the code that makes it show properly when I equip it facing up otherwise it shows the other image:

local function onequip(inst, owner)    local dir = owner.AnimState:GetCurrentFacing()    -- local owner = inst.components.inventoryitem.owner    if (owner) then        if (dir == 1) then            owner.AnimState:OverrideSymbol("swap_object", "swap_chester_eyebone_backward", "swap_chester_eyebone_backward")        else            owner.AnimState:OverrideSymbol("swap_object", "swap_chester_eyebone_forward", "swap_chester_eyebone_forward")        end    end    owner.AnimState:Show("ARM_carry")    owner.AnimState:Hide("ARM_normal")end

Here is the mod so far if you want to test it to see if I need to change something somewhere.

Attack of the Chester.zip

 

 

 

Link to comment
Share on other sites

@BaconAndRibs, the only thing I can think about is modifying the player stategraph or doing a periodic task to check every frame. But I don't really have the time to try it myself. If you try it with a task then don't forget to cancel the task.

-- In OnEquipinst.task = inst:DoPeriodicTask(0, UpdateAnim)-- In OnUnEquipinst.task:Cancel()isnt.task = nil

And function UpdateAnim will check the facing and change the animation accordingly. It's easy but really suboptimal.

 

@ZupaleX, that's only if you want to ovveride the default pivot, which is not necessary if you want to make just a weapon. If you want to do an armor or helmet then you need to do it.

Link to comment
Share on other sites

But when I was not doing it, then the item was floating away from the hand of my character as if the pivot was on the top left corner of the picture. I had to move it and overwrite it for the item to be displayed at the proper place.

So I am confused now.

Link to comment
Share on other sites

@Malacath, Thank you, I had to change the UpdateAnim to this:

inst.task = inst:DoPeriodicTask(0, function()    local dir = owner.AnimState:GetCurrentFacing()        if (dir == 1) then        owner.AnimState:OverrideSymbol("swap_object", "swap_chester_eyebone_backward", "swap_chester_eyebone_backward")    else        owner.AnimState:OverrideSymbol("swap_object", "swap_chester_eyebone_forward", "swap_chester_eyebone_forward")    endend)

But after a bit of changes it works! I was thinking though, would using an event listener for the change in the direction be more efficient than checking every frame to see if it changed or is the periodic task method better?

 

@ZupaleX, You do have to overwrite the default pivot in order for the image to show properly in the hand. Otherwise the image floats to the side. Also check that the image is scaled to the right size because if not it will seem really small in the players hand.

Edited by BaconAndRibs
Link to comment
Share on other sites

@ZupaleX, I'm confused as well. Never did that and still don't do it. But I will write it in the tutorial to make sure noone has problems.

 

@BaconAndRibs, yes, an EventListener is definitely more efficient. But I don't know if an according even is pushed anywhere in the code, so it's up to you to either find that event or use PostInit's to create it yourself.

Link to comment
Share on other sites

Alright disregard all my stuff, fixed everything

 

 

 

How did you actually fix it? I'm having the same problem :/  

 

The item appears in the inventory and in the ground when dropped, but not when i'm supposed to be holding it.

Link to comment
Share on other sites

I narrowed it down to the folder order as I believe it should be,

 

--exported

    --lightsaber

        --swap_lightsaber

            --swap_lightsaber

                ->swap_lightsaber.png

            ->swap_lightsaber.scml

 

Also, in your lightsaber script, you have

owner.AnimState:OverrideSymbol("swap_object", "swap_lightsaber", "lightsaber")

but I believe it should be

owner.AnimState:OverrideSymbol("swap_object", "swap_lightsaber", "swap_lightsaber")

I have tested this and it seemed to have worked. You may have to resize the image in order for it to show proper but it shows up in the players hand.

 

Here is the folder with the fixes:

cory_the_desperate_nerd.zip

Edited by BaconAndRibs
Link to comment
Share on other sites

I narrowed it down to the folder order as I believe it should be,

 

--exported

    --lightsaber

        --swap_lightsaber

            --swap_lightsaber

                ->swap_lightsaber.png

            ->swap_lightsaber.scml

 

Also, in your lightsaber script, you have

owner.AnimState:OverrideSymbol("swap_object", "swap_lightsaber", "lightsaber")

but I believe it should be

owner.AnimState:OverrideSymbol("swap_object", "swap_lightsaber", "swap_lightsaber")

I have tested this and it seemed to have worked. You may have to resize the image in order for it to show proper but it shows up in the players hand.

 

Here is the folder with the fixes:

attachicon.gifcory_the_desperate_nerd.zip

 

 

I tried to make the changes that you described but it didn't work (i've checked I didn't find differences).

So i swaped your file with mine since i suppose there are no changes apart from that so, Thank you anyways. I'm sure I'll spot what was wrong. URRRRRRR AWESOME ! :grin:

 

 

EDIT: I'm trying to resize the image in the spriter file, but is not working, I save the file, and i recreates the anim file etc. but in game the weapon stays small as it was :/

Edited by Gryfuz
Link to comment
Share on other sites

You must resize the actual image. Resizing it in spriter will not work. Just resize the png in the folder and it will automatically change the size in game.

I might also mention that the scml file must be out side the swap_lightsaber folder that has the png in it. That is one of the other changes I made.

Edited by BaconAndRibs
Link to comment
Share on other sites

I might also mention that the scml file must be out side the swap_lightsaber folder that has the png in it. That is one of the other changes I made.

 

Yes you refered that before and somehow the problem was there i didn't check but i think that after make change i had to rebuild the anim file, cause the files before were different there when i opened the zip file.

 

 

Thanks for the type of the image. I tough it would work resizing on spriter cause it worked when i did for the ground_myitem but seems like is not like that. Thank you mate it worked a lot! 

 

 

 

Btw one last favor if you don't mind x) (sorry). I would like to make my weapon glow at least enough for charlie do not atack (maybe as much as willow's lighter? or lower) I've tried to take some coding of the lighter file and the torch file but i think I didn't inser them well. Do you know how can I do this?

One more time thank you ^^

One more time sorry x)

Link to comment
Share on other sites

@Gryfuz, I was able to make the lightsaber have a small bit of light as you requested but you could change it around to suit your needs(e.g. bigger amount of light or smaller amount of light). You just have to change the radius or whatever else you want in the lightsaber script.

 

All I had to add was,

local function lightOn(inst)    inst.Light:Enable(true)    inst.Light:SetRadius(2)    --[[ This causes it to crash for some reason. Not really sure why though.    inst.Light:SetFallOff(1)    --]]    inst.Light:SetIntensity(.5)    inst.Light:SetColour(1,1,1)endlocal function lightOff(inst)    inst.Light:Enable(false)end

And just call those functions in the onequip() and onunequip() functions.

 

I also had to add this in the fn() function.

inst.entity:AddLight()inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh")inst.AnimState:SetRayTestOnBB(true)

Here is the folder with the changes.

cory_the_desperate_nerd.zip

 

Edited by BaconAndRibs
Link to comment
Share on other sites

@Gryfuz, I was able to make the lightsaber have a small bit of light as you requested but you could change it around to suit your needs(e.g. bigger amount of light or smaller amount of light). You just have to change the radius or whatever else you want in the lightsaber script.

 

All I had to add was,

local function lightOn(inst)    inst.Light:Enable(true)    inst.Light:SetRadius(2)    --[[ This causes it to crash for some reason. Not really sure why though.    inst.Light:SetFallOff(1)    --]]    inst.Light:SetIntensity(.5)    inst.Light:SetColour(1,1,1)endlocal function lightOff(inst)    inst.Light:Enable(false)end

And just call those functions in the onequip() and onunequip() functions.

 

I also had to add this in the fn() function.

inst.entity:AddLight()inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh")inst.AnimState:SetRayTestOnBB(true)

Here is the folder with the changes.

attachicon.gifcory_the_desperate_nerd.zip

 

 

Gosh !! 

 

Wow man, thank you, I don't know what to say x) you did it all :/  I'm so gratefull, i've been in trouble trying to do it. Thanks !! :grin:

 

 

EDIT1 I think fallout factor was crashing because it's supposed to work in limited items, since my sword doesnt have durability it crashed i guess 

that's what i understood from here

http://dontstarveapi.com/utility/light/

but since i'm a noob it's just a guess and probably wrong xD

Edited by Gryfuz
Link to comment
Share on other sites

I believe your right about the fallout factor. I wasn't aware they had an API documentation. I'll have to go through that, might help me out. Thanks!

 

 

Btw x) 

 

I did my character  to lose sanity faster nearby hounds but sometimes the game crashes, just in a specific situation.

 

I have it written more detailed here: (last posts)

http://forums.kleientertainment.com/topic/56174-how-to-increase-damage-against-hounds/

 

if you don't mind to have a look x) I'm struggling cause i don't find the mistake

Link to comment
Share on other sites

I know I'm a little late to this, but something in my mod went wrong. However, everything else seems to be and order and this appears to be somewhat simple issue.

 As seen in this image: http://i.imgur.com/0t936A8.png the custom item is far off from the hand and actually being held, even though in the Spriter program I made sure to move the pivot point on the handle. (it is still acting as the the movable pivot is in the default location in the top-left)

I'm not quite sure how to fix this, I've tried redoing that certain step and manually editing the swap_item.scml file (although the contents of the file confuse me) but the character still grabs onto the top-left.

 

Any suggestions? :(

 

Here's a link to the mod so far (Sorry, I couldn't figure out how to use the attachment function.) : https://copy.com/FjXyXvtT3z49khZj

 

And all artworks in the screenshot/mod are place-holder and were never really meant to be seen, but I'm out of options here.

The sword art is from the "Taronci" mod on the DST workshop.

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