Jump to content

AOE Effects on Friends and Foes


Recommended Posts

Hello! I'm trying to develop a supportive character for DST, I'm at a stage where the abilities are starting to get more complicated, and I have no clue how to code them.

The first ability I'm making is supposed to freeze all non-players in an AOE around my character.

The second ability I'm making is supposed to heal allies every second for a set amount, as well as grant night vision to everyone in the AOE, that doesn't wear off for a few seconds after leaving it.

Sorry if I'm asking for too much, I just don't know where to start. I just got back into modding after a long hiatus when I got burnt out.

Link to comment
Share on other sites

Howdy!

Ad second ability

[character.name.here].lua

Above main function (master_postinit):

local function friendsFOREVER(inst)

local pt = inst:GetPosition()
local range = 10  -- range of ability
local hps = 5 -- HP amount per tick
local frens = { "character" }

	local targets = TheSim:FindEntities(pt.x,pt.y,pt.z, range, frens)
		for _,ent in ipairs(targets) do
			inst.components.health:DoDelta(hps)		
		end          
end
local function BFFs(inst)
 	if not inst.components.health:IsDead() and not inst:HasTag("playerghost") then				
		friendsFOREVER(inst)	
	end
end

Inside master_postinit (somewhere in the lower section):

local toim = 2 -- time interval between every HP tick (seconds-ish, it's not 100% accurate)
inst:DoPeriodicTask(toim, BFFs, nil, inst)

In theory it should work, but my brain haven't developed properly in fetal life, so it might end with crash. Test it and let me know, coz I didn't do that myself.

Cheers!

Edit: Night vision stuff seems to be out of my reach, so I will leave it for professionals

Edited by Yakuzashi
  • Like 1
  • Sanity 2
Link to comment
Share on other sites

Granting night vision is pretty easy, you just need to call player.components.playervision:ForceNightVision(true) to enable it, and then player.components.playervision:ForceNightVision(false) to disable it. A simple way to do this is to create a task to automatically disable the night vision after a certain period of time when it is applied, and then every time you apply the AOE afterwards check for this task, cancel it if it exists, and then start it again. This will cause the night vision to never wear off as long as the AOE is in range and active, and then last for 5 more seconds after it isn't.

local function OnApply(player)
	player.components.playervision:ForceNightVision(true)
	if player._disablenightvisiontask ~= nil then
		player._disablenightvisiontask:Cancel()
	end
	--I set the wear-off time to 5 seconds, but it can be whatever you want.
	player._disablenightvisiontask =  player:DoTaskInTime(5, function(player)
		player.components.playervision:ForceNightVision(false)
      		player._disablenightvisiontask = nil
	end)
end

It isn't necessarily the most efficient way, but it's pretty easy implement.

Edited by Ziro2k
  • Like 1
Link to comment
Share on other sites

4 hours ago, Ziro2k said:

Granting night vision is pretty easy, you just need to call player.components.playervision:ForceNightVision(true) to enable it, and then player.components.playervision:ForceNightVision(false) to disable it. A simple way to do this is to create a task to automatically disable the night vision after a certain period of time when it is applied, and then every time you apply the AOE afterwards check for this task, cancel it if it exists, and then start it again. This will cause the night vision to never wear off as long as the AOE is in range and active, and then last for 5 more seconds after it isn't.


local function OnApply(player)
	player.components.playervision:ForceNightVision(true)
	if player._disablenightvisiontask ~= nil then
		player._disablenightvisiontask:Cancel()
	end
	--I set the wear-off time to 5 seconds, but it can be whatever you want.
	player._disablenightvisiontask =  player:DoTaskInTime(5, function(player)
		player.components.playervision:ForceNightVision(false)
      		player._disablenightvisiontask = nil
	end)
end

It isn't necessarily the most efficient way, but it's pretty easy implement.

This is actually exactly what I was looking for! I figured getting it to last longer outside the AOE would be easy, but I guess not. The way I was implementing Night Vision before was the make it a full moon. Hack workaround that broke tons of things, and also applied it to everyone on the server. It was terrible. Thanks for the help!

Link to comment
Share on other sites

9 hours ago, Ziro2k said:

Granting night vision is pretty easy, you just need to call player.components.playervision:ForceNightVision(true) to enable it, and then player.components.playervision:ForceNightVision(false) to disable it. A simple way to do this is to create a task to automatically disable the night vision after a certain period of time when it is applied, and then every time you apply the AOE afterwards check for this task, cancel it if it exists, and then start it again. This will cause the night vision to never wear off as long as the AOE is in range and active, and then last for 5 more seconds after it isn't.


local function OnApply(player)
	player.components.playervision:ForceNightVision(true)
	if player._disablenightvisiontask ~= nil then
		player._disablenightvisiontask:Cancel()
	end
	--I set the wear-off time to 5 seconds, but it can be whatever you want.
	player._disablenightvisiontask =  player:DoTaskInTime(5, function(player)
		player.components.playervision:ForceNightVision(false)
      		player._disablenightvisiontask = nil
	end)
end

It isn't necessarily the most efficient way, but it's pretty easy implement.

Actually, There is one problem I'm having with this. It seems the Night Vision is only getting applied on the server side, and not the client, so in darkness, although charlie can't attack them, clients still can't visually see. I think this is because I have this set up to run via an RPC, and I'm wondering if I need to implement a client RPC to successfully apply the night vision.

Link to comment
Share on other sites

7 hours ago, TheSkylarr said:

Actually, There is one problem I'm having with this. It seems the Night Vision is only getting applied on the server side, and not the client, so in darkness, although charlie can't attack them, clients still can't visually see. I think this is because I have this set up to run via an RPC, and I'm wondering if I need to implement a client RPC to successfully apply the night vision.

Ah, yes, you are correct. Playervision is a component that is used by both the server and client. You may notice that when you use this ability, you don't have the sanity drain from complete darkness, nor are you attacked by Charlie. That's the server-side of the component at work, as the server thinks that the client is able to see in the dark. The actual visual aspect of seeing in the dark is handled by the client. The server-to-client RPC API is still fairly new, and to be honest I'm not quite familiar with when it would be best to use it instead of traditional networked variables, because to me they seem to accomplish the same goal. I would assume that an RPC would be better for something that only needs to happen sparingly, or that needs to happen to multiple clients at once. I'd have to do more research on the subject.

Nevertheless, this can easily be achieved via a networked boolean variable, and this is also how Woodie's nightvision is handled when he enters his wear forms. There's a great pinned topic on how networked variables work and how to set them up if you want to look at it. Basically, you set it up on code that is ran by both client and server (so they are in sync) and then when you change the value on the server, this value is automatically changed on the client as well via the network, triggering a special event called a "dirty" event. "Dirty" just means that the value is changed, and is no longer in sync between client and server. On the client, you can listen for this "dirty" event and set ThePlayer.components.playervision:ForceNightVision(value) whenever it triggers, where value is the value of the netvariable. Does this make sense?

  • Like 1
Link to comment
Share on other sites

8 hours ago, Ziro2k said:

Ah, yes, you are correct. Playervision is a component that is used by both the server and client. You may notice that when you use this ability, you don't have the sanity drain from complete darkness, nor are you attacked by Charlie. That's the server-side of the component at work, as the server thinks that the client is able to see in the dark. The actual visual aspect of seeing in the dark is handled by the client. The server-to-client RPC API is still fairly new, and to be honest I'm not quite familiar with when it would be best to use it instead of traditional networked variables, because to me they seem to accomplish the same goal. I would assume that an RPC would be better for something that only needs to happen sparingly, or that needs to happen to multiple clients at once. I'd have to do more research on the subject.

Nevertheless, this can easily be achieved via a networked boolean variable, and this is also how Woodie's nightvision is handled when he enters his wear forms. There's a great pinned topic on how networked variables work and how to set them up if you want to look at it. Basically, you set it up on code that is ran by both client and server (so they are in sync) and then when you change the value on the server, this value is automatically changed on the client as well via the network, triggering a special event called a "dirty" event. "Dirty" just means that the value is changed, and is no longer in sync between client and server. On the client, you can listen for this "dirty" event and set ThePlayer.components.playervision:ForceNightVision(value) whenever it triggers, where value is the value of the netvariable. Does this make sense?

This makes a lot of sense to me actually, I thought the only way to do it was Client RPC's, but I noticed the game doesn't use ANY, so I knew there had to be someway else of it keeping track between both client and server. I'm gonna look into that topic, thanks for all the help you've been, you're amazing!

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