Jump to content

Overriding an Update function


Recommended Posts

Hi modders,

 

I have a problem for a while now I didn't find how to solve it yet. I hope no one asked for that on the forum because I searched for a solution for a long time.

 

I would like to rewrite an Update function : my mod is a custom character and some things in the world are different for him.

I would like to create my own shadow creatures and make them spawn only while playing him. I took a look at sanitymonsterspawner.lua and that's the SanityMonsterSpawner:UpdateMonsters(dt) that I would like to change (I need to change the chances to spawn and the prefabs to spawn).

 

Same problem for the healthbadge.lua because he loses health from another thing and I need to update the badge when he's losing health (there's another condition for him, in addition with starving, freezing, overheating and on fire).

 

The only solution I found is to rewrite the entire file in my mod folder and I detect if that's my character or not because there is not a SetUpdateFn(fn) function or something like that.

But I guess that's not a good way to do it because it can create conflicts with other mods and with future updates, right ?

 

Any suggestion, please ?

Link to comment
Share on other sites

Same problem for the healthbadge.lua because he loses health from another thing and I need to update the badge when he's losing health

hint : look how other components using pushevent("healthdelta")

or just use

player.components.health:DoDelta(0)
after changing health, its do all job for you

 

and why you want rewrite entire file when rewriting one method is enough?

you can even do a check about your player character like

 

for components:

local SomeClass = requre("somepathto/someclass") local oldfn = SomeClass.WhatEverFunctionYouWantOVerride or nil function SomeClass:WhatEverFunctionYouWantOVerride(...)if player.prefab=="mysupercharacterprefabname" then-- do bad thingselse-- do vanilla bad thingsif oldfn and typeof(oldfn)=="function" then oldfn(self,...) endendendreturn SomeClass
Link to comment
Share on other sites

Thanks for your answers ^^

 

I already created a custom component to make my character lose health. There is an Update(dt) function that checks if the conditions are valid or not and if they are, I use the health:DoDelta function. It works well but the badge on the interface isn't actualized (I mean we don't see the down arrow which indicates to the player that he's actually losing health). That's why I had to rewrite the healthbadge file.

 

And about the shadow creatures I took a look at Elinor and the creator creates completely another spawner file, so I guess it's the best way to do it. 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...