Mods / CAN Effects

Category: #Library #Other
Author: KenigVovan
Side: Both
Created: Jun 18th 2022 at 12:59 PM
Last modified: Jan 4th at 3:43 PM
Downloads: 10092
Follow Unfollow 67

Latest file for v1.20.0-rc.6:
effectshud_0.2.13.zip 1-click install


Adds ability to apply different effects to player and track them in HUD (key L by default to open/close).

By default available effects:

  • regeneration - recover health over time, 0.08hp per second by default every tier
  • walkspeed - boost player's movespeed, +25% of walkspeed every tier
  • strengthmelee - increase player's melee damage, +25% of aditional damage every tier
  • miningspeed - increase player's mining speed, +25% of speed every tier
  • thorns - damage attacker on their every hit, 0.09 damage per hit per tier
  • firedamageimmune - protects player from any fire damage
  • safefall - negates fall damage
  • forgetting - instant effect which lets player to use .charsel 1 more time
  • extendedmaxbreath - increase player's max breath capacity, 2. tier increase it by 2, 3. by 3...
  • invisibility - make player invisible to other player, only items in handes should be visible
  • cantemporalcharge - lowers speed of temporal stability drops and speed up restoration
  • walkslow - reduces player's movespeed, -25% of walkspeed every tier
  • miningslow - reduces mining speed, -25% of speed every tier
  • weakmelee - reduces player's melee damage, -25% of melee damage every tier
  • bleeding - player gets piercing  damage every second, 0.08hp per second per tier
  • weight buff (for weight mod) - additional weight, +1000 per tier

 

You can also register your own effects, but it require some additional code.

For fast testing you can use GUI by Shift + L, where you can select effect, player, tier and duration.


Used in:


Some code examples if you want to apply effects in code.

Set effect on player using command:

/ef effectName durationInMins tier nickname (just for debug, requres creative mode)


If you want to apply effect on the player in the code:

create new Effect:

MiningSlowEffect ef = new MiningSlowEffect();

set duration:

ef.SetExpiryInRealMinutes(3);

apply effect on entity:

effectshud.src.effectshud.ApplyEffectOnEntity(entity, efslow);

(or using AddEffect of EBEffectsAffected - player's EntityBehavior)

You can set it's tier or duration with (SetExpiryInTicks,SetExpiryInRealMinutes and others)


To check if Entity has effect or get instance of applied effect you can use method below:

entity.EntityHasEffect(effectId); - to check if entity has active effect with provided id

entity.TryGetEntityEffect(effectId, out Effect); - try to get Effect with effectId


To register you own effect in StartServerSide you need to call and provide typeId of effect and class

RegisterEntityEffect("myEffectTypeId", typeof(myEffectClass));

in StartClientSide: (typeId again, true if effect is positive, true if it's icon should be rendered in HUD)

RegisterClientEffectData("myEffectTypeId", true, true); - effect is positive will have tierNp.png overlay added if tier is > 0, the second true set
that we want it to be drawn in HUD
RegisterClientEffectData("myEffectTypeId", true, false); - this one is positive, but won't be rendered


Config:

TICK_EVERY_SECONDS - will change how long is tick in real seconds, for now it's 1 real second and for now can not be changed by config.


Icons are from https://game-icons.net/

Inspired and uses parts of goxmeor 's BuffStuff - https://mods.vintagestory.at/show/mod/633

Version For Game version Downloads Release date Changelog Download 1-click mod install*
v0.2.13 215 Jan 4th at 3:43 PM Show effectshud_0.2.13.zip Install now
v0.2.12 103 Dec 29th 2024 at 6:43 PM Show effectshud_0.2.12.zip Install now
v0.2.11 843 Jun 22nd 2024 at 3:39 PM Show effectshud_0.2.11.zip Install now
v0.2.10 883 Jan 14th 2024 at 1:42 PM Show effectshud_0.2.10.zip Install now
v0.2.9 932 Oct 23rd 2023 at 2:57 PM Show effectshud_0.2.9.zip Install now
v0.2.8 223 Oct 20th 2023 at 3:06 PM Show effectshud_0.2.8.zip Install now
v0.2.7 175 Oct 18th 2023 at 4:46 PM Show effectshud_0.2.7.zip Install now
v0.2.6 160 Oct 17th 2023 at 8:10 PM Show effectshud_0.2.6.zip Install now
v0.2.5 859 Jun 19th 2023 at 4:30 PM Show effectshud_v0.2.5.zip Install now
v0.2.4 219 Jun 18th 2023 at 9:42 AM Show effectshud_v0.2.4.zip Install now
v0.2.3 503 May 14th 2023 at 3:04 PM Show effectshud_v0.2.3.zip Install now
v0.2.2 265 May 10th 2023 at 3:42 PM Show effectshud_v0.2.2.zip Install now
v0.2.1 813 Apr 8th 2023 at 9:36 AM Show effectshud_v0.2.1.zip Install now
v0.2.0 465 Mar 1st 2023 at 7:30 PM Show effectshud_v0.2.0.zip Install now
v1.0.10 210 Apr 8th 2023 at 9:14 AM Show effectshud_v1.0.10.zip Install now
v1.0.8 563 Jan 31st 2023 at 5:43 PM Show effectshud_v1.0.8.zip Install now
v1.0.7 502 Nov 13th 2022 at 2:21 PM Show effectshud_v1.0.7.zip Install now
v1.0.6 410 Jul 11th 2022 at 2:04 PM Show effectshud_v1.0.6.zip Install now
v1.0.4 320 Jul 1st 2022 at 7:43 PM Show effectshud_v1.0.4.zip Install now
v1.0.5 262 Jul 10th 2022 at 9:59 AM Show effectshud_v1.0.5.zip Install now
v1.0.3 269 Jun 25th 2022 at 1:37 PM Show effectshud_v1.0.3.zip Install now
v1.0.2 259 Jun 25th 2022 at 9:50 AM Show effectshud_v1.0.2.zip Install now
v1.0.1 290 Jun 19th 2022 at 10:53 AM Show effectshud_v1.0.1.zip Install now
v1.0.0 292 Jun 18th 2022 at 1:00 PM Show effectshud_v1.0.0.zip Install now

22 Comments (oldest first | newest first)

💬 KenigVovanAuthor, Jan 4th at 3:50 PM

Snowfious

fixed in last version

💬 Snowfious, Dec 31st 2024 at 10:06 PM

Oh, apologies for not providing more detail. But this issue is actually from your Simple alchemy mod. Image with less details is with Alchemy on, but second one is with alchemy turned off but having this mod still turned on.

1st image

https://imgur.com/a/JKeHSqP

2nd image

https://imgur.com/a/7GqDUUJ

💬 KenigVovanAuthor, Dec 30th 2024 at 12:18 PM

Snowfious

what exactly isn't working?

💬 Snowfious, Dec 29th 2024 at 8:24 PM

It would seem this mod causes conflict issues with Extra Info; any way to give it more compatibility?

💬 KenigVovanAuthor, Jan 15th 2024 at 4:35 PM

Edel_Recke Yanazake

you both missed comment section for another mod or?

💬 Edel_Recke, Jan 14th 2024 at 7:54 PM

Why is the Crosshairs changed? That's really annoying; especially because of the percentage display (which I can't assign anything to anyway and have ignored so far)!
Can i change this?

💬 AzuliBluespots, Jan 14th 2024 at 3:19 PM

Wait, does nickname works in mp and can it be set individually? It shows up indefinitely?

💬 Telemachus, Oct 23rd 2023 at 5:07 PM

Yup, that fixed it. Thanks!

KenigVovan

💬 KenigVovanAuthor, Oct 23rd 2023 at 2:57 PM

Telemachus

try 0.2.9

💬 Telemachus, Oct 23rd 2023 at 1:50 PM

Receiving this crash after updating from v0.2.5 to v0.2.8

 

💬 KenigVovanAuthor, Oct 20th 2023 at 3:12 PM

I'll look at new effects later, 
bool removedAfterDeath is added to Effect,
with font color/outline I'll take a look as well

💬 Frepo, Oct 20th 2023 at 12:12 PM

Some suggestions for the mod.

New default effects
GlowEffect - Makes the player emit a light, could be this eerie blue/green light that you have for a short while after you died. Higher tier = stronger light effect. VERY handy since it allows you to equip e.g. a shield while still having light i dark caves.
SpelunkerEffect - Makes the player see outlines of ore blocks/chest/translocators through walls. Might be hard to accomplish, but would be very cool. Higher tier = longer "sight radius".
BlindnessEffect - Renders a black filter over the entire screen. Higher tier = more opacity.
JumpEffect - Allows the player to jump higher. Higher tier = increased jump height. (for quality of life this effect should also secure you from taking fall damage from jumping, something similar to safefall. safefallDistance = jumpHeight)
WarmthEffect - Keeps you warm during cold winter nights. Higher tier = incresed bonus to body temperature (or some sort of protection in degrees like clothing has)

New property
DeathPermeable - [type: boolean] if true makes the effect stay after death.

About the hud graphics - Maybe try and change the font color for the timer. It's very hard to see in dark areas when the color is black. I have to look up at the sky to read how much time left. And when the sky is dark at night that wont help either.
Perhaps use green color for positive effects, and red color for negative. Or if possible, keep black color but with white outline, or try inverted (white font with black outline), see whatever works best. 

💬 Frepo, Oct 17th 2023 at 8:23 PM

Excellent! Ty for quick fix

💬 KenigVovanAuthor, Oct 17th 2023 at 8:12 PM

Frepo

fixed, tier change not in effect's constructor didn't update damagePerTick, so it had default value everytime here

💬 Frepo, Oct 17th 2023 at 1:27 PM

Looks like setting a tier for the bleeding effect doesn't work correctly. The effect seems to always be tier 1 regardless if I try to set it to something else. Perhaps this is the same for other effects as well, that I don't know. I have only tested bleeding so far.
I've tested tier 1, 3 and 20, and you still take 0,05 damage/tick (at least according to the damage log, and what I can se by hovering over my health bar while bleeding).

The code
BleedingEffect effectBleed = new BleedingEffect();
effectBleed.SetExpiryInRealMinutes(1);
effectBleed.tier = 20;
effectshud.src.effectshud.ApplyEffectOnEntity(__instance, effectBleed);

// tier 20 should result in 1 hp damage/tick

💬 Frepo, Oct 15th 2023 at 1:39 PM

Man, this mod sounds great! I've been longing for some "potion effects" for this game.
I've never used someone else's framework before. How do I get access to it in my source code? (visual studio 2022 community)
Do I have to unpack your mod? If so, must I place the unpacked stuff any place special? I figured I must reference your dll-file in my project. Is that enough or do I need to add your whole project to my solution?
Thanks in advance!

💬 KenigVovanAuthor, Jul 3rd 2022 at 6:44 PM

No problems with addons

If you mean to add OnEntityRevive, OnFallToGround, OnInteract, OnEntityReceiveDamage and others from EntityBehavior - i have it in a plan. To make a base for effects like vampirism, protections against(fire, fall, arrows, melee atacks), damage reflection etc.

I'll place source files on git in few days, but it's a mess now

 

💬 jakecool19, Jul 3rd 2022 at 3:50 PM

Would you be ok with mods that add on to this framework? For example adding more hooks to the base Buff class?

💬 KenigVovanAuthor, Jul 1st 2022 at 7:48 AM

The main point (at least for now) was to prepare effects handling for potions items.

Mod uses EntityBehavior so it might be expand on other entities, but Effects implementations could require some changes.
(because default Effects here use "Stats" of the player and i'm not 100% sure it's the same with other Entities)

💬 jakecool19, Jun 30th 2022 at 7:21 PM

Amazing work! I have been hoping we would get a proper status effect system for this game for quite awhile. What is the ultimate finished goal for this one? Will it just be for players, or will it work with all entities?

💬 KenigVovanAuthor, Jun 19th 2022 at 8:33 AM

It is WIP.
Mod for HUD on which effects (picture of buff/debuff) can be drawn. 
it uses player's WatchedAttributes to track updates.

You can register effect to show by:
RegisterEffect(string watchedBranch, string effectWatchedName, bool showTime, string effectDurationWatchedName, string [] domainAndPath, Vintagestory.API.Common.Func needToShow)

example of use for "miningSpeedMul" in stats:
effectshud.src.effectshud.RegisterEffect("stats", "miningSpeedMul", false, "", new string[] { "canmods:effects/slowmining1", "canmods:effects/slowmining2", "canmods:effects/slowmining3" }, checkminigSpeedMul);

checkminigSpeedMul here is function which is called on branch update and return number of picture which shoud be drawn, if -1 is return that means that effect is not active

public int checkminigSpeedMul()
{
      var t2 = capi.World.Player.Entity.Stats["miningSpeedMul"];
      var t = t2.GetBlended();
      if (t < 0.35)
      {
          return 2;
      }
      else if (t < 0.5)
      {
          return 1;
      }
      else if (t < 0.85)
      {
          return 0;
      }
      return -1;
}

Display of the time is not functinal yet, so choose false for showTime, if you want to try it.

Pictures size used is 64x64.

For HUD to show press "L"

💬 DemonBigj781, Jun 19th 2022 at 2:07 AM

whats this?

(edit comment delete)