How i use eventhandler into an other class ?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
ZoomSlayer2
Posts: 10
Joined: Wed Oct 05, 2022 6:34 am

How i use eventhandler into an other class ?

Post by ZoomSlayer2 »

Ok so i want to use this eventhandler class:

Code: Select all

Class RButtonMousePressedEventHandler : EventHandler
{
			override bool InputProcess(InputEvent e) 
			{
				if (e.type == InputEvent.Type_RButtonDown)
				{
					A_GiveInventory("SniperZoomed",1);
					A_ZoomFactor(2,ZOOM_INSTANT);
					return ResolveState("FireZoomed");
				}
				if (e.type == InputEvent.Type_RButtonUp)
				{
					A_TakeInventory("SniperZoomed",1);
					A_ZoomFactor(1,ZOOM_INSTANT);
					return ResolveState(null);
				}
				return Super.OnInputEvent(e);
			}
}
into my sniper rifle class, in the altfire:

Code: Select all

Altfire:
    TNT1 A 0
	{
	
	}
	Goto Ready;
How i could do that ?
lemonTasteIceTea+
Posts: 16
Joined: Sun Oct 02, 2022 12:57 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Arch
Graphics Processor: nVidia with Vulkan support

Re: How i use eventhandler into an other class ?

Post by lemonTasteIceTea+ »

pretty sure you don't need to put it in your sniper rifle class
just make a file named mapinfo and define it in there

Code: Select all

gameinfo {
	addEventHandlers = "RButtonMousePressedEventHandler"
}
even though it says gameinfo in the code, mapinfo has a block thingy called gameinfo
lemonTasteIceTea+
Posts: 16
Joined: Sun Oct 02, 2022 12:57 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Arch
Graphics Processor: nVidia with Vulkan support

Re: How i use eventhandler into an other class ?

Post by lemonTasteIceTea+ »

just saw you used resolvestate which idk if it works or not on your end but just in case it doesn't you can use this

Code: Select all

	Ready:
		PISG A 1 a_WeaponReady();
		TNT1 A 0 {
					A_TakeInventory("SniperZoomed",1);
					A_ZoomFactor(1,ZOOM_INSTANT);
				 }
		loop;
		
		Altfire:
		TNT1 A 0 {
					A_GiveInventory("SniperZoomed",1);
					A_ZoomFactor(2,ZOOM_INSTANT);
					return ResolveState("FireZoomed");
				   }
		goto Ready;
ZoomSlayer2
Posts: 10
Joined: Wed Oct 05, 2022 6:34 am

Re: How i use eventhandler into an other class ?

Post by ZoomSlayer2 »

Actually, i want a system who, when a press tthe rbutton mouse, pass in zoom mode, and when i release the rbutton mouse, return in normal mode.
And i want to use an InputEvent, but i don't really know how to do that
lemonTasteIceTea+
Posts: 16
Joined: Sun Oct 02, 2022 12:57 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Arch
Graphics Processor: nVidia with Vulkan support

Re: How i use eventhandler into an other class ?

Post by lemonTasteIceTea+ »

try doing the first thing i said the second thing is in case that doesn't work
ZoomSlayer2
Posts: 10
Joined: Wed Oct 05, 2022 6:34 am

Re: How i use eventhandler into an other class ?

Post by ZoomSlayer2 »

None of them work correctly.
ZoomSlayer2
Posts: 10
Joined: Wed Oct 05, 2022 6:34 am

Re: How i use eventhandler into an other class ?

Post by ZoomSlayer2 »

What i want is a simple code in zscript who use inventory system.
When a press r mouse button, he passed in zoomed mode, and when i repress r mouse button, he released the zoomed mode.
And if a shoot in zoomed mode, he stayed in zoomed mode.
Post Reply

Return to “Scripting”