Jump to content

Recommended Posts

Credits go to @The Letter W for the art and concept.

We are trying to make a character ("elecman") who can cast lightning wherever he points. Using Kzisor's amazing keylistener component, this works well on a local game. ElecMan first does an emote, when the charge sound plays, the cursor position gets recorded and the player can let go to summon the lightning strike.

However, the server doesn't know the cursor position of the client.

Pardon me for the folly of this paragraph in advance. I have only two ideas how it could work, but no ideas how those themselves would work. Maybe a netvar could be used to communicate from server to client and back. Alternatively, the position could somehow be sent by the client automatically, which leads to a large number of consequential problems, so I'd rather not do this.

Do you have any idea how to solve this problem? Do you know any mods with similiar problems (not client-only)?

The mod in question: -removed-

Edited by Mobbstar
Removed file
7 hours ago, Mobbstar said:

Do you know any mods with similiar problems (not client-only)?

This is already done by the 'blinkstaff' (orange staff). The following code should point you in the right direction, it's all untested but it's good theory/starting place.

(Edit: This goes in your modmain.lua file.)

local function OnLightningStrike ( act )
	-- Call forth lightning strike at act.pos
	local inst = act.doer

	inst.SoundEmitter:KillSound("zapcharge_sound")
	
	print("ZEUS IS JEALOUS - elec man used lightning strike")
	inst.AnimState:PlayAnimation("punch")
		
	if GLOBAL.TheWorld then
		local pt = act.pos
		inst.components.playerlightningtarget:SetHitChance(0)
		GLOBAL.TheWorld:PushEvent("ms_sendlightningstrike",pt)
		inst.components.playerlightningtarget:SetHitChance(GLOBAL.TUNING.ELECMAN.LIGHTNING_HITCHANCE)
			
		if inst.components.hunger then
			inst.components.hunger:DoDelta(GLOBAL.TUNING.ELECMAN.FOOD_TO_ZAP)
		end
	end
end

AddAction( "LIGHTNING_STRIKE", "Strike", OnLightningStrike )

AddComponentAction( "POINT", "keyhandler", function( inst, doer, pos, actions, right )
		-- Can only do lightning strikes while chargetask is not nil.
		if inst.chargetask ~= nil and inst:HasTag( "[INSERT TAG HERE]" ) and right then
			table.insert( actions, ACTIONS.LIGHTNING_STRIKE )
		end
	end )

 

Edited by Kzisor

I looked at orange staff and couldn't understand it.

The staff uses blinkstaff component. In it the only function that teleports caster is ":Blink(pt, caster)" but this function is only called in onhauntorange() (ie: when you haunt the staff as a ghost).

Then there is "reticule" component. It uses blinkstaff_reticuletargetfn() to find walkable coordinate when item is being equipped. However, how does these two work together?

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
×
  • Create New...