Jump to content

Photo

Script delay on MGEF

script delay magic effect

  • Please log in to reply
2 replies to this topic

#1
Mattiewagg

Mattiewagg

    Is Female?!

  • Supporter
  • PipPipPipPipPip
  • 5,544 posts

So I have a script to damage the player's stamina when a weapon is swung. The condition is on the spell the MGEF (no duration, no area, hide in UI, script archetype) is attached to, and it registers correctly.

 

However, when I swing my fists, or sword, the stamina damage registers but is delayed by about a second. I want the values to be modifiable, but not if there is this much delay. This doesn't happen if I just use. This is the script on the MGEF:

Scriptname FFDamageFatigueScript extends activemagiceffect  

GlobalVariable Property FFUseUS Auto 
{FightingFatigueUseUserSettings}

GlobalVariable Property FFOneHandDam Auto 
{Amount of stamina drain for one handed attacks, if FFUseUS is enabled.}

GlobalVariable Property FFTwoHandDam Auto 
{Amount of stamina drain for two handed attacks, if FFUseUS is enabled.}

Actor Property PlayerREF Auto 

Event OnEffectStart(Actor akTarget, Actor akCaster)

	If FFUseUS.GetValue()

		If PlayerREF.GetEquippedItemType(0) >= 0 && PlayerREF.GetEquippedItemType(0) <= 4 || PlayerREF.GetEquippedItemType(1) >= 0 && PlayerREF.GetEquippedItemType(1) <= 4

			;if user settings enabled and player has 1handed or hand to hand
			PlayerREF.DamageAV("Stamina", FFOneHandDam.GetValueInt())

		ElseIf PlayerREF.GetEquippedItemType(0) >= 5 && PlayerREF.GetEquippedItemType(0) <= 6 || PlayerREF.GetEquippedItemType(1) >= 5 && PlayerREF.GetEquippedItemType(1) <= 6

			;if user settings enabled and player has 2 handed 
			PlayerREF.DamageAV("Stamina", FFTwoHandDam.GetValueInt())

		EndIf 

	Else

		If PlayerREF.GetEquippedItemType(0) >= 0 && PlayerREF.GetEquippedItemType(0) <= 4 || PlayerREF.GetEquippedItemType(1) >= 0 && PlayerREF.GetEquippedItemType(1) <= 4

			;user settings not enabled
			PlayerREF.DamageAV("Stamina", 10)

		ElseIf PlayerREF.GetEquippedItemType(0) >= 5 && PlayerREF.GetEquippedItemType(0) <= 6 || PlayerREF.GetEquippedItemType(1) >= 5 && PlayerREF.GetEquippedItemType(1) <= 6

			PlayerREF.DamageAV("Stamina", 25)

		EndIf 

	EndIf 

EndEvent

Is there something I'm doing that is blatantly wrong? (I know DamageAV is slower than DamageActorValue, but would that really affect it this much?)

 

And if you do it too many times in a row it doesn't even register the extra hits.


Edited by Matthiaswagg, 13 September 2014 - 05:19 AM.


#2
lofgren

lofgren

    Resident poster

  • Supporter
  • PipPipPipPipPip
  • 3,408 posts

Well there are quite a few conditions there that have to be checked before the script decides to execute. You might consider moving those conditions into condition functions on the magic effect and creating multiple effects on the same spell (one for two handed weapons, one for one handed weapons or unarmed).

 

GetValue is much faster than GetValueInt. You can cast the float value retrieved by GetValue() to an int if you need an int, although I don't think you do since DamageActorValue takes a float so the engine is just converting your int to a float. You might as well just get the value of the global as a float rather than cast it to an int and then back to a float.

 

Faster still than GlobalVariable.GetValue() is to just use GlobalVariable.Value. Getting a property just refers to a number stored by the game, while GetValue() executes a function. This will also reduce any issues you might be having due to multithreading.

 

Also this might be a silly question, but why do you need to know if user settings are enabled? Why not just assume that user settings are enabled, but make the default user settings 10 and 25? That will reduce your conditions by one.


Edited by lofgren, 13 September 2014 - 06:53 AM.


#3
Mattiewagg

Mattiewagg

    Is Female?!

  • Supporter
  • PipPipPipPipPip
  • 5,544 posts

Well there are quite a few conditions there that have to be checked before the script decides to execute. You might consider moving those conditions into condition functions on the magic effect and creating multiple effects on the same spell (one for two handed weapons, one for one handed weapons or unarmed).

 

GetValue is much faster than GetValueInt. You can cast the float value retrieved by GetValue() to an int if you need an int, although I don't think you do since DamageActorValue takes a float so the engine is just converting your int to a float. You might as well just get the value of the global as a float rather than cast it to an int and then back to a float.

 

Faster still than GlobalVariable.GetValue() is to just use GlobalVariable.Value. Getting a property just refers to a number stored by the game, while GetValue() executes a function. This will also reduce any issues you might be having due to multithreading.

 

Also this might be a silly question, but why do you need to know if user settings are enabled? Why not just assume that user settings are enabled, but make the default user settings 10 and 25? That will reduce your conditions by one.

True, true. I'll try that. Thanks.







Also tagged with one or more of these keywords: script delay, magic effect

IPB skins by Skinbox
Page loaded in: 1.014 seconds