Jump to content

[Mod Release] Mod Optimizations and Options


Recommended Posts

If you want character specific items to never be dropped, be it at death (ghosts have a inventory, it's just hidden, so it will keep the item forever) or specifically by the player, you can first add a tag to that item, such as "undroppable", then you have to change the Inventory:DropItem method to never drop items with this tag. There are two different approaches for this:

-snip-

Oh, that makes sense. Problem is the code that did something similar to this ( which overrides sollyz's, mitsuru's and haruz's leveling, adds and removes items ) was done by my friend, so I never knew how that worked. Thanks a lot for explaining!

Also part of the problem of why I think im messing up adding code to items and other characters to override something that already exists in them, like leveling.

I guess I'll use the api-friendly approach, just so star isnt the only one on the entire workshop to say "uses proper api"

 

The reader component just makes the character able to read (i.e., use) Wickerbottom's books.

Oh, makes sense. No idea why "reader" is a component and "insomniac" is a tag then though.

 

About the damage multiplier, I tested changing the damage multiplier of my character in game, and I was able to kill a spider in 5 hits unarmed. Though it's weird that it didn't change when you changed the base damage multiplier. Not sure why. I'm also not sure why putting maxhealth too low does nothing.

I need to see you code on this.

For the rest, I need to look at those characters' code, to know how they work, see why you can't change some things.

The stats thing being too low I think is maybe a problem with dedicated servers, as mitsuru's stat changes dont seem to do anything on my friend's dedicated server, but it does when hosted.

Thing is a spider has 100 health, 1 unarmed hit is 10 damage, and mitsuru's damage by default is 1.1 at lvl 1, and even if I changed the damage in my code it would always kill the spider in the same amount of hits. Using weapons instead of unarmed included.

It also looked like by default it wouldnt even apply the 1.1 damage multiplier and instead would apply something else, since all the time it would be the same amount of hits to kill a spider no matter the code, the damage, or what was used.

I think player damage was nerfed in DST, but even then, unless damage changes dont work altogether it shouldn't do that.

 

 

About the third leveling mechanism I have tried not even changing anything about seras' code and just replicating it, but even then nothing.

For now though, I have to go for 1 and a half hours, so I'll try testing all this later.

Link to comment
Share on other sites

In the end I just went around Seras' code, but I'm really at a loss, since I don't understand some of the things there. This is how the code is right now, doesn't crash, but doesn't do anything either:

 

It's because you put master_postinit inside the addExperienceSystem function. Being defined as a local function, it essentially only exists inside addExperienceSystem.

However, I'm not sure what you are trying to accomplish here. Calling AddPrefabPostInit already implies the entity "woodie" is created, which means its master_postinit has already been called.

Why not just execute directly the code inside the master_postinit, instead of putting it inside a function?

 

 

just so star isnt the only one on the entire workshop to say "uses proper api"

 

:lol:  

What he means by that is that he doesn't replace whole files of the game.

You can do that, any file you put inside the scripts folder in your mod's directory named the same as a game file will override it; but I highly recommend not doing it, your mod will get broken every update guarranteed, plus you lose some compatibility with other mods.

Edited by Jjmarco
Link to comment
Share on other sites

It's because you put master_postinit inside the addExperienceSystem function. Being defined as a local function, it essentially only exists inside addExperienceSystem.

However, I'm not sure what you are trying to accomplish here. Calling AddPrefabPostInit already implies the entity "woodie" is created, which means its master_postinit has already been called.

Why not just execute directly the code inside the master_postinit, instead of putting it inside a function?

What I don't know is if I need to execute the code inside the leveling system, inside the balanceWoodie function, separately, inside a separate master_postinit, modify the existing one...?

 

:lol:

What he means by that is that he doesn't replace whole files of the game.

You can do that, any file you put inside the scripts folder in your mod's directory named the same as a game file will override it; but I highly recommend not doing it, your mod will get broken every update guarranteed, plus you lose some compatibility with other mods.

Yea, I think I read that on rezecib's post of useful, the whole "dont replace base game files".

 

 

 

Also one problem with the undroppable stuff, it works. Problem is it can still be put inside a backpack and dropped, and I imagine it can then be transfered. I imagine it can also be given to other players by clicking on them, going to try that right now with Kuldiin. Thats why I wanted to do something similar to what Purswader does, where unless you are the character the item won't do anything for you.

 

Or maybe just make the item not be able to be unequipped and be on the hat slot at all times? That could also work...though it wouldn't work with Woodie, unless we want him to be forever the tree chopping man.

 

I guess that can be done by adding a tag to faroz like I do with the glasses, then checking for the tag, problem is, how would I go about checking if its faroz who equips the glasses inside faroz_gls.lua?

Something like...

 

local function balanceFarozGlasses(inst)    inst:AddTag("undroppable")    oldOnequip = onequip(inst, owner)    local function onequip(inst, owner)        oldOnequip(inst, owner)                if owner:HasTag("faroz") and inst.isWeared and not inst.isDropped then        saniup(inst)        else        inst.components.dapperness.dapperness = 0        end    endend

 

 

As for faroz's existing code in the original mod, in the glasses prefab:

local function saniup(inst)	if inst.isWeared and not inst.isDropped then		inst:AddComponent("dapperness")		inst.components.dapperness.dapperness = 1	endendlocal function onequip(inst, owner)         owner.AnimState:OverrideSymbol("swap_hat", "faroz_gls", "swap_hat")        owner.AnimState:Show("HAT")        owner.AnimState:Show("HAT_HAIR")        owner.AnimState:Hide("HAIR_NOHAT")        owner.AnimState:Hide("HAIR")				inst.isWeared = true		inst.isDropped = false		saniup(inst)end

Edited by DrSmugleaf
Link to comment
Share on other sites

What I don't know is if I need to execute the code inside the leveling system, inside the balanceWoodie function, separately, inside a separate master_postinit, modify the existing one...?

 

Just put the inside of master_postinit without the function definition, inside addLevelingSystem:

local function master_postinit(inst) -- remove this,         inst.experience = 0           updatestats(inst)           inst:ListenForEvent("entity_death", function(world, data) entitydeathfn(inst, data) end, TheWorld)             inst.OnSave = onsave      inst.OnPreLoad = onpreload         return inst -- this,end -- and this

Also one problem with the undroppable stuff, it works. Problem is it can still be put inside a backpack and dropped, and I imagine it can then be transfered. I imagine it can also be given to other players by clicking on them, going to try that right now with Kuldiin. Thats why I wanted to do something similar to what Purswader does, where unless you are the character the item won't do anything for you.   Or maybe just make the item not be able to be unequipped and be on the hat slot at all times? That could also work...though it wouldn't work with Woodie, unless we want him to be forever the tree chopping man.   I guess that can be done by adding a tag to faroz like I do with the glasses, then checking for the tag, problem is, how would I go about checking if its faroz who equips the glasses inside faroz_gls.lua? Something like...

 

We could make it so the item can never leave the character's inventory at any time, but we'll need to override a lot more functions...

About checking if the player equipping the item is indeed Faroz, it's more like this:

local function balanceFarozGlasses(inst)    inst:AddTag("undroppable")    local oldOnequip = inst.components.equippable.onequipfn -- the old onequip is stored in the equippable component of the item    local onequip = function(inst, owner) -- let's override it        if not owner.prefab = "faroz" then            return -- if wearer isn't Faroz, do absoluetly nothing        else            oldOnequip(inst, owner) -- else, execute the old onequip normally, which will apply the normal bonus Faroz should get from her glasses        end    end    inst.components.equippable.onequipfn = onequip -- now let's put the new onequip inside the equippable component of the itemend

To check if we are dealing with Faroz when equipping, you can use owner.prefab.

Link to comment
Share on other sites

We could make it so the item can never leave the character's inventory at any time, but we'll need to override a lot more functions...

About checking if the player equipping the item is indeed Faroz, it's more like this:

local function balanceFarozGlasses(inst)    inst:AddTag("undroppable")    local oldOnequip = inst.components.equippable.onequipfn -- the old onequip is stored in the equippable component of the item    local onequip = function(inst, owner) -- let's override it        if not owner.prefab = "faroz" then            return -- if wearer isn't Faroz, do absoluetly nothing        else            oldOnequip(inst, owner) -- else, execute the old onequip normally, which will apply the normal bonus Faroz should get from her glasses        end    end    inst.components.equippable.onequipfn = onequip -- now let's put the new onequip inside the equippable component of the itemend

To check if we are dealing with Faroz when equipping, you can use owner.prefab.

 

I tried that, spawned as faroz on a private server, put the glasses on a backpack, deleted my user session and chose woodie, when equipping it would still apply the sanity increase, so I tried doing this:

local function balanceFarozGlasses(inst)    inst:AddTag("undroppable")     local oldOnequip = inst.components.equippable.onequipfn    local onequip = function(inst, owner)        if not owner.prefab == "faroz" then		inst.components.dapperness.dapperness = -1        else            oldOnequip(inst, owner)        end    end    inst.components.equippable.onequipfn = onequipend

Would still apply the sanity increase to Woodie. It is running the function, as the glasses can't be dropped, but this last thing to check for faroz doesn't seem to work. Going to try finishing balancing faroz and maybe a few others and update if we don't manage to find a fix.

 

I'm guessing its not running my -1 sanity thing since its not inside the proper function or place?

 

 

 

Edit: Scrap that, its applying properly after I died as Woodie.

Edit 2 : scrap the scrapping, if you reload the world it raises woodies sanity again.

Edited by DrSmugleaf
Link to comment
Share on other sites

@DrSmugleaf, Try putting inst.components.equippable:Unequip(owner, GLOBAL.EQUIPSLOTS.HEAD) (assuming the glasses are equipped in the head slot) instead of return.

This will unequip the glasses as soon as someone other than Faroz tries to equip them.

 

Also, put print("test") inside the not-Faroz block, to see if the the condition works properly. Should show up in the console when you try to equip them.

 

If it fails, try changing the way the conditions are checked:

local function balanceFarozGlasses(inst)    inst:AddTag("undroppable")      local oldOnequip = inst.components.equippable.onequipfn    local onequip = function(inst, owner)        if owner.prefab == "faroz" then            oldOnequip(inst, owner) -- if player is Faroz, use old onequip        else            inst.components.equippable:Unequip(owner, GLOBAL.EQUIPSLOTS.HEAD)            owner.components.talker:Say("I can't wear this.")            -- else, unequip the glasses and make the character say an error message        end    end    inst.components.equippable.onequipfn = onequipend

Just noticed I wrote if not owner.prefab = "faroz" instead of if owner.prefab ~= "faroz" before, shame on me!

Edited by Jjmarco
Link to comment
Share on other sites

First method doesn't print anything. Well, it prints "component dapperness already exists!" doing this:

( Althought nothing seems to be showing up on console ever no matter what anytime anyways, lately )

local function balanceFarozGlasses(inst)    inst:AddTag("undroppable")     local oldOnequip = inst.components.equippable.onequipfn    local onequip = function(inst, owner)        if not owner.prefab == "faroz" then			inst.components.equippable:Unequip(owner, GLOBAL.EQUIPSLOTS.HEAD)			print("test")        else            oldOnequip(inst, owner)        end    end    inst.components.equippable.onequipfn = onequipend

Second method lets you put on the glasses, but it displays the message and they do nothing, as if they weren't equipped. This is all tested in a hosted server so I wouldn't think it would be desyncing.

 

On trying to remove them it doesnt let you with right click, but you can just left click them and drag them into your inventory.

 

Sooo...guess that works?

 

 

Also, sudden woodie crash of glorious, think it was because of a full moon, as it just crashed when I was writing this and it was dusk. I haven't modified anything about woodie's axe yet, just posting it here since I don't think its our problem but I'm not sure:

http://puu.sh/ftOh7/0b2f7a08b8.jpg

 

Edit: Log: http://pastebin.com/kv5SDCY0

Edited by DrSmugleaf
Link to comment
Share on other sites

Second method lets you put on the glasses, but it displays the message and they do nothing, as if they weren't equipped. This is all tested in a hosted server so I wouldn't think it would be desyncing.   On trying to remove them it doesnt let you with right click, but you can just left click them and drag them into your inventory.

 

That's weird... Is the character showing the glasses? The Unequip function is supposed to unequip the glasses, call the onunequip function associated with this item, then push the unequipped event.

If you're okay with it though, we can just leave it as is. :-)

 

About that Woodie crash, I think that's the mod's fault. There are many cases of this mod causing crashing when transforming, looking at the mod's discussion page.

Edited by Jjmarco
Link to comment
Share on other sites

That's weird... Is the character showing the glasses? The Unequip function is supposed to unequip the glasses, call the onunequip function associated with this item, then push the unequipped event.

If you're okay with it though, we can just leave it as is. :-)

 

About that Woodie crash, I think that's the mod's fault. There are many cases of this mod causing crashing when transforming, looking at the mod's discussion page.

 

The character was showing the glasses I believe.

I mean, the only bad thing about it is players will probably get confused when trying to unequip them, but I assume anyone who can add 1+1 together will try to left click them.

alright

SO, GREAT!

I assume I could do something similar with woodies axe, just unequipping the weapon slot instead?

 

Also quick question, do you want to be added to contributors to the mod on the workshop page? Because last few patches have all been like added x of y of stuffs of sorts "huge thanks to jjmarco on the klei forums!"

 

Going to try fixing the experience leveling system after I finish with faroz, thank you so much again for helping with yet another part of the mod!

Link to comment
Share on other sites

The character was showing the glasses I believe. I mean, the only bad thing about it is players will probably get confused when trying to unequip them, but I assume anyone who can add 1+1 together will try to left click them.

 

I can try to figure out another way, but for now, that works.

Think of it as a punishment for trying to equip a character specific item in the first place.  :lol:

 

I assume I could do something similar with woodies axe, just unequipping the weapon slot instead?

 

Yup.

 

Also quick question, do you want to be added to contributors to the mod on the workshop page? Because last few patches have all been like added x of y of stuffs of sorts "huge thanks to jjmarco on the klei forums!"

 

If you want to, I'll be honored :-)

My Steam profile

Link to comment
Share on other sites

So, apparently my mod doesn't work at all on dedicated servers. The only thing about it that seems to work is starting items, however everything works in hosted...Pretty lost here, tried checking to see if the mod is running on the server with if not GLOBAL.TheNet:GetIsClient() then, with if not GLOBAL.TheWorld.ismastersim then return inst else, with if Global.TheNet:GetIsClient() then... Even added a modoverride.lua to see if that did anything to help, and still nothing. Tried to put everything I apply on a function and then adding that to the world_network as a function, adding a function to check for the server then add the balances to the world_network... But it just won't do anything.

 

If anyone wants to see how the mod is done, here is the link

 

Yes, I have enabled the mod while testing on my own dedicated server, yet the only thing that worked was the starting items part of it.

Link to comment
Share on other sites

@DrSmugleaf, Since dedicated servers don't load some of the code, some mod code will crash on them. The best way to do this is to just test it and see what crashes, then separate that out into blocks like this:

if not GLOBAL.TheNet:IsDedicated() then-- code that crashes on dedicated serversend
Link to comment
Share on other sites

@Kzisor, doesn't the modoverride.lua go in the mod's folder and the modsettings.lua in C:\Program Files (x86)\Steam\SteamApps\common\Don't Starve Together Dedicated Server\mods? Every other mod on the server worked that way and said it was loaded, and some time ago ryuu's simple protection worked with the modoverride.lua in it's mods folder, going to change it around now though. Otherwise my starting items wouldn't work either I would think.

Link to comment
Share on other sites

The dapperness.lua is no longer needed, as the component has been merged into the 'equippable'-component. Now, having the dapperness.lua in your mod, may break the world, so it doesn't work anymore when the mod is turned off, and you enter the world again.

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