Sign in to follow this  
zetake

Stat Penalty System

Recommended Posts

zetake    10

Hi, did anyone maybe made already system penalty such as Meat Effigy has?

Because I need it to health, hunger and sanity...

I started low and just used components: health(maxhealth), hunger(max) and sanit(max).

But these stats aren't being saved...

Any advice, ideas, suggestions, propositions?

Share this post


Link to post
Share on other sites
Ultroman    452
Posted (edited)

What kind of system are you wanting exactly? Is it for an item or an aura or will it be unique for one character or do you want to make a server mod pushing this system on all player characters?

The problem with the original game code is, health and sanity have two different penalty systems, and there is no penalty-system for hunger. The health penalty system works on a percentage basis in both DS and DST.

When it comes to the sanity penalty systems, they are very different between the two games, and are not percentage-based like health penalty system. In DS, the sanity penalty system is aura based, so you can only get sanity penalty from sanityaura components on entities around you, and instead of being percentage-based, it's value-based, so when you do GetPercent(true) it directly subtracts the penalty value from the maximum sanity value. Thus, it does not need to save the penalty value, since the auras are constantly re-tallied.

In DST the sanity system is percentage-based, BUT instead of being aura-based, it keeps a dictionary of modifiers (each with a value and a unique key) which it tallies up, and then when you do GetPercentWithPenalty() it directly subtracts the penalty value from the maximum sanity value. The only thing you can get a sanity penalty for in DST, is when spawning Waxwell's pets, and I'm guessing those pets go away when you exit and reenter the server, so they don't need to be saved.

Graphically, I'm not sure if the hunger badge is even set up to show penalty (the darkening of the background of the badge).

You are right that only the health penalty is actually saved.

 

Edited by Ultroman
  • Like 1

Share this post


Link to post
Share on other sites
zetake    10
Posted (edited)

For now I'm making mod for only DS...

I want penalty system(-some value to max chosen stat) when item will be crafted.

And when item will deplete, I want to return that value to max chosen stat.

I would like it with blacked stats image, but will do if components: health(maxhealth), hunger(max) and sanit(max) will save values...

BUT wait, I just did today overriding onsave and onload is some component, so I will be able to do this or even penalty...

BTW, any variable or tags added to item while playing aren't saved either... that is why I needed to change onsave and onload. XD

 

Edited by zetake

Share this post


Link to post
Share on other sites
Ultroman    452

Well, as long as you extend / chain OnSave and OnLoad on existing items, instead of just overwriting them, I'm happy.

Not sure how compatible this will be with everything else. In DS you have to keep in mind that there are Meat Effigys giving you max-health penalty, and you also need to consider the sanity-aura system. Just read lightly. Think a good deal about what you're doing, and see if you can think of ALL the ways in which your code can mess it up for the game and other mods, so you can make it as compatible with everything as humanly possible.

Godspeed!

Share this post


Link to post
Share on other sites
zetake    10
12 minutes ago, Ultroman said:

Well, as long as you extend / chain OnSave and OnLoad on existing items, instead of just overwriting them, I'm happy.

Nope, I'll override OnSave and OnLoad in components health, hunger and sanity, with chaining original OnSave and OnLoad...

I think you can't really attach max player stats to an item, especially when that item can be dropped or put into container...

And even if, it doesn't sound right to change max player stats everytime you load your game from an item that can be not close to you, and will not do it...

Or do you have a way to push event or load function from item that can be for exaple at the other end of the map.

Well, I don't think so, because that item won't be loaded, because map in there won't be loaded...

Share this post


Link to post
Share on other sites
Ultroman    452
23 minutes ago, zetake said:

I think you can't really attach max player stats to an item, especially when that item can be dropped or put into container...

And even if, it doesn't sound right to change max player stats everytime you load your game from an item that can be not close to you, and will not do it...

Or do you have a way to push event or load function from item that can be for exaple at the other end of the map.

Well, you can do one of two things:

  1. Attach a listener to the item, and listen to the "equipped" and "unequipped" events, which both get the owner passed as a parameter.
  2. And if that's not early enough, you can extend / chain the "onequip" and "onunequip" functions on the equippable component of the item.

Then you can easily apply and remove any modifiers you want. I don't know why you're talking about when the item is far away from the player. Aren't we talking about equippable items? You should really study exactly how all components on items work, before making a huge item-modifier mod, which is what I'm guessing you're doing. Apologies if I've misunderstood your questions and you have already done this.
 

24 minutes ago, zetake said:

Well, I don't think so, because that item won't be loaded, because map in there won't be loaded...

The entire map and all entities in it, including items, are loaded when the game starts. They're not all rendered, and I'm sure they're not all updated when players aren't close, but they ARE loaded and initialized.

  • Thanks 1

Share this post


Link to post
Share on other sites
zetake    10
Posted (edited)

No, my item isn't equippable... you sugested to not do another equip slot...

My item deplete in inventorybar, in container, on the ground; everywhere...

So, I can try later adding OnSave and OnLoad to that item and check if it's trigger, and then if it's trigger at the other end of the map.

BTW, my item is container and it's drop its content when depleted, but items aren't dropped when map isn't loaded...

I mean I didn't checked it with map, but when I put my item on shelf and leave Slanty Shanty, when I'm back after its depleting, it gives replacement item, but its content aren't on ground...

Is there alternative code to this:

			local pos = Vector3(self.inst.Transform:GetWorldPosition())
			item.Transform:SetPosition(pos:Get())

That will gets map pos without player/map loaded?

Or do I save these items to map instead of dropping them?

Edited by zetake

Share this post


Link to post
Share on other sites
zetake    10
Posted (edited)
9 hours ago, Ultroman said:

but they ARE loaded and initialized.

OnSave and OnLoad attached to item it's triggering always like you said. :D

In prefab fn:

	inst.OnSave = onsave
	inst.OnLoad = onload

So, I don't have to override OnSave and OnLoad in component when I can add my own...

But with a slow down when it's far away and with more slow down when it's far away and in container...

But I guess it will be in time anyway...

So, this thread problem is Solved, what about my second one?

I don't know nothing about adding items to savedata of map, but I'll learnt it if help isn't coming...

 

#EDIT : I can't get player to save... What I need from player prefab to save that will let me get player prefab after load?

Edited by zetake

Share this post


Link to post
Share on other sites
Ultroman    452
9 hours ago, zetake said:

OnSave and OnLoad attached to item it's triggering always like you said. :D

In prefab fn:


	inst.OnSave = onsave
	inst.OnLoad = onload

So, I don't have to override OnSave and OnLoad in component when I can add my own...

True. I did not know you had your own prefab when I wrote that.

With the code you showed, it should be saving your data. You might be getting confused with the load order, though. You see, when your prefab is getting instantiated, and all the components are added and initialized, no save-data has been loaded yet. So, AFAIK, if you try to read the data on the player in a post init function or in the fn() it won't have been loaded yet. Again, AFAIK, the data for a prefab is loaded just after the post init functions have been called, so you can only really see the final loaded variables on the first frame. So, if you want to print out a state, you need to delay that print until the first frame, using

inst:DoTaskInTime(0, function(inst)
	-- do your prints
end)

 

9 hours ago, zetake said:

But with a slow down when it's far away and with more slow down when it's far away and in container...

So, your item is a container, which depletes slowly, and when it is depleted it drops a bunch of items, but it also slows the player as long as they are far away from it, and it slows them even more while it is in a container? Is that about right?

9 hours ago, zetake said:

I don't know nothing about adding items to savedata of map, but I'll learnt it if help isn't coming...

What do you mean? If an item is in the world, it should be saved automatically in the world when you quit the game.  You shouldn't need to do anything special for that.

9 hours ago, zetake said:

#EDIT : I can't get player to save... What I need from player prefab to save that will let me get player prefab after load?

I don't understand what you're asking. Perhaps this is explained by my explanation of load order at the start of this post? Try to explain what you want to have happen, instead of what you have been trying to do. It's usually easier to find a solution, when you have a clear definition of the problem.

Share this post


Link to post
Share on other sites
zetake    10
Posted (edited)
2 hours ago, Ultroman said:

True. I did not know you had your own prefab when I wrote that.

It's not character prefab. XD You can add it to items too...

2 hours ago, Ultroman said:

your item is a container, which depletes slowly, and when it is depleted it drops a bunch of items=

Yes, but it's portable container like a backpack, and it's fueled and it is depleting when items are inside...

2 hours ago, Ultroman said:

but it also slows the player as long as they are far away from it, and it slows them even more while it is in a container? Is that about right?

No, (face palm my english...) I meant if item is far away from player when world is loading, it's loaded later and if item is in container it's loaded even later... (That is what prints showed) But I guess it's a matter of second, so it doesn't affect much...

2 hours ago, Ultroman said:

With the code you showed, it should be saving your data.

Yes, it's saves, but that's not a problem...

2 hours ago, Ultroman said:

What do you mean? If an item is in the world, it should be saved automatically in the world when you quit the game. 

I mean dropping function is based on played position and when there is no player item isn't dropped, but it's lost instead...

2 hours ago, Ultroman said:

I don't understand what you're asking. Perhaps this is explained by my explanation of load order at the start of this post? Try to explain what you want to have happen, instead of what you have been trying to do. It's usually easier to find a solution, when you have a clear definition of the problem.

I was attaching player prefab to item variable, but player prefab can't be saved in variable... This is stupid but in game worked...

So I need to take some value from player prefab and save it, then in load I need to find player by that value...

But I don't know what I can use... There isn't ID by some chance?

Or maybe I should just use GetPlayer() since it's DS and not DST...

I tried setting player as a parent of item with entity:GetParent() and entity:SetParent()

It works, but this isn't saved either...

I want to tie an item to a player....

I mean I need to have access to player prefab from item regardless of whereabouts of item.

And that player prefab must be the one that crafted that item...

Which means I need some ID of player, but doesn't know what it is...

Edited by zetake

Share this post


Link to post
Share on other sites
Ultroman    452

Well, as you said, this is DS, so there is only one player, the player is always there, and there will never be another player. It will always be GetPlayer(). It is true that during world generation, and therefore also initialization of your item, the player is not there. These are the cases where you delay doing your thing until the first frame, where the player is 100% sure to be there.

Share this post


Link to post
Share on other sites
zetake    10
Posted (edited)

I have made mistake in code and had to go second time on the end of the map... XD
GetPlater() works as expected...
And it doesn't need any deelaying, because item is looking for player not other way around.

And I think player has higher priority... because it worked, even if the item laid next to player...

Edited by zetake
  • Like 1

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