Jump to content

Need help setting up an Event Handler.


silentDrew2

Recommended Posts

I need to start by saying I have already read the Event Handler Tutorial and all the documentation found here

http://geck.bethsoft.com/index.php?title=Event_Handling

 

So I know that in order to have a script that runs every time anyone in the game attacks anyone else in the game, I'll need to use the following code:

 

SetEventHandler "OnHit" NameOfScript

 

I just have no idea where I'm supposed to put it because strangely enough, none of the documentation actually bothers to mention that. So,

-Do I need to use a Object Script? A quest script?

-What kinds of Blocktypes allow "SetEventHandler"?

 

 

 

I'd like to be able to set the event handler once when the game loads.

 

- I know there used to be a "LoadGame" blocktype, is it still around?

--I tried using it with an otherwise empty script, but it wouldn't compile.

 

Link to comment
Share on other sites

You're right it seems missing some parts.

 

Create an Object Script like this:

Scn myOnHitEH

Ref rTarget
Ref rAttacker

Begin Function {rTarget, rAttacker}

; code to execute

End

Then you must register it in your main script, i.e. on a GetGameLoaded block, because it needs to be registered every game session.

You'll register it like this:

SetEventHandler "OnHitWith" myOnHitEH "first"::rTarget "second"::rAttacker

First and Second are filters, they are optional and don't need to be registered if you don't want to filter it.

Link to comment
Share on other sites

Just to further clarify/add to what Fallout2AM said: You actually need to register an event handler only once, as it persists and remains active for the duration of the game session. Use a quest script and toggle Start Game Enabled.

scn	OnHitHandlerRegisterSCR

begin GameMode
	if GetGameRestarted
		SetEventHandler "OnHit" myOnHitEH "ref"::rTarget "object"::rAttacker
	endif
end
Link to comment
Share on other sites

It's essentially a copy-paste from another thread I made. Long story short, I want to check a weapon for its equipped ammo type, and if it's a special ammo type, then it applies a damage boost. The problem is, I don't want it to glitch out and forget the original weapon's damage.

 

Is there a way to pull this off in a simpler way than abusing NVSE? I tried using conditions, but GetEquipped doesn't check for the ammo type.

 

And I definitely think I can do it with a quest, I just need to properly write the script.

 

EDIT: And now I actually have a script! Here it is.

scn WMTTESTSpecAmmoSCRIPT

ref formSpecialAmmoTypes
ref weapEquippedWeapon
short intDamageIsSet
short intWeaponOriginalDamage


begin GameMode

	if (weapEquippedWeapon != 0)
		if (formSpecialAmmoTypes == 0)
			set formSpecialAmmoTypes to WMTAllSpecialAmmoTypes
		endif

		if (Player.GetWeaponAmmo.IsInList formSpecialAmmoTypes)
			if (intDamageIsSet == 0)
				set intWeaponOriginalDamage to weapEquippedWeapon.GetAttackDamage
				player.SetAttackDamage (intWeaponOriginalDamage + (intWeaponOriginalDamage * 0.10))
				set intDamageIsSet to 1
			endif
		endif
	endif

end

begin OnEquip player

	if (player.GetEquippedObject 5 != 0)
		set weapEquippedWeapon to Player.GetEquippedObject 5
		set weapEquippedWeapon to weapEquippedWeapon.GetBaseForm
	endif

end

begin OnUnequip player

	if (player.GetEquippedObject 5 == 0)
		set weapEquippedWeapon to 0
	endif

end

Sadly, this script isn't saving for me, but I'm not sure where I went wrong. All my code seems pretty solid, and it checks out in Notepad++'s syntax checker.

Edited by ThatOtherUser
Link to comment
Share on other sites

Oh. Yes I've read that thread. When I read things like "I don't use NVSE because I'm afraid it glitches", it's better if I avoid to answer.

 

Event Handlers are NVSE (4.6beta3+).

 

I don't think you could risk an issue like that with NVSE, due to its not persistent nature, but anyway you can store every value you need if you feel it's risky.

Link to comment
Share on other sites

Oh. Yes I've read that thread. When I read things like "I don't use NVSE because I'm afraid it glitches", it's better if I avoid to answer.

 

Event Handlers are NVSE (4.6beta3+).

 

I don't think you could risk an issue like that with NVSE, due to its not persistent nature, but anyway you can store every value you need if you feel it's risky.

 

Yeah, I was worried moreso of immediately limiting usage of hte mod, but NVSE is so widespread, I shouldn't really worry about that. It's not so much the glitchiness, just ease of debugging in the future. And me f*#@ing up and putting a loophole in there that lets someone tote around a .22 silenced pistol that does 100k damage, thanks to them constantly cycling special ammo types in and out.

 

Anyway, does my script look okay? Still can't tell what's gone wrong with it, so I've moved on to other bits of the mod.

Edited by ThatOtherUser
Link to comment
Share on other sites

 


All my code seems pretty solid, and it checks out in Notepad++'s syntax checker.

I see both syntax errors (i.e. Player.GetWeaponAmmo.IsInList) and conceptual errors (i.e set weapEquippedWeapon to weapEquippedWeapon.GetBaseForm)

 

I suggest to install GECK PU, it should at least help you solving the first ones.

Link to comment
Share on other sites

 

All my code seems pretty solid, and it checks out in Notepad++'s syntax checker.

I see both syntax errors (i.e. Player.GetWeaponAmmo.IsInList) and conceptual errors (i.e set weapEquippedWeapon to weapEquippedWeapon.GetBaseForm)

 

I suggest to install GECK PU, it should at least help you solving the first ones.

 

 

Lesson learned in that respect: GECK doesn't like stacked functions. And I do have GECK Powered-Up, but I've only installed it through Nexus Mod Manager. I'll sort that out tonight.

 

So, I'll have to set up temp variables inside the functions, set those up with the references, then run the IsInList function.

 

Also, the weapEquippedWeapon is my paranoia kicking in :l. Will GetAttackDamage ALWAYS return the weapon's original damage, or will it return the weapon's damage after special ammo damage mods have been done? Because I'm using the BaseForm function to avoid custom ammo damage modification. It's security against people using some way to immediately equip both a weapon and ammo type at the same time, and create a loop of ever increasing damage.

 

 

EDIT: Also, GECK PU doesn't seem to be working. I launch it with geck-nv-nvse.exe, it launches GECK just fine, but it doesn't actually give me any errors when I try to save my script. And that's after I pasted the below code into my script. Any idea where the error is?

scn WMTTESTSpecAmmoSCRIPT

ref ammoSelectedAmmo
ref formSpecialAmmoTypes
ref weapEquippedWeapon
short intDamageIsSet
short intWeaponOriginalDamage


begin GameMode

	if (weapEquippedWeapon != 0)

		set ammoSelectedAmmo to Player.GetWeaponAmmo

		if (formSpecialAmmoTypes == 0)
			set formSpecialAmmoTypes to WMTAllSpecialAmmoTypes
		endif

		if (ammoSelectedAmmo.IsInList formSpecialAmmoTypes)
			if (intDamageIsSet == 0)
				set intWeaponOriginalDamage to weapEquippedWeapon.GetAttackDamage
				player.SetAttackDamage (intWeaponOriginalDamage + (intWeaponOriginalDamage * 0.10))
				set intDamageIsSet to 1
			endif
		endif
	endif

end

begin OnEquip player

	if (player.GetEquippedObject 5 != 0)
		set weapEquippedWeapon to Player.GetEquippedObject 5
		set weapEquippedWeapon to weapEquippedWeapon.GetBaseForm
	endif

end

begin OnUnequip player

	if (player.GetEquippedObject 5 == 0)
		set weapEquippedWeapon to 0
	endif

end
Edited by ThatOtherUser
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...