Jump to content

Photo

Script Question : How to Setting Spell Interval Time?

scrippt magic interval time construction set cs script spell

  • Please log in to reply
9 replies to this topic

#1
wolfdol

wolfdol

    Regular

  • Members
  • PipPip
  • 85 posts

I'm not from English-speaker world. please understand my broken english :)

 

I've made a script that intend to restore health when player's HP falls below 50%, 30%. (Less Hp, More Heal)

 

the script is as follow

 

----------------------------------------------------------------------------------------------------------------------------------------------

Scn WolfHeartRestore

 

Float CurrentHealth

Float BaseHealthLv01

Float BaseHealthLV02

Short Source

Short Target

 

Begin Gamemode

  set CurrentHealth to Player.GetAv Health

  set BaseHealthLV01 to GetBaseAv Health * 0.5

  set BaseHealthLV02 to GetBaseAv Health * 0.3

 

  if Player.GetItemCount (Item) >= 1 && BaseHealthLv01 >= CurrentHealth

      Source.moveto PlayerRef

      Source.Cast (Heal Spell Lv01) PlayerRef

      return

   endif

 

  if Player.GetitemCount (item) >= 1 && BaseHealthLv02 > CurrentHealth

    Source.Moveto PlayerRef

    Source.Caset (Heal Spell Lv02) PlayerRef

    Return

  endif

end

-----------------------------------------------------------------------------------------------------------------------------------------------

 

There are two problem.

 

first, If Hp falls below 50%,  Ref 'Source' Cast Heal spell repeatly without any Interval time. So Player never die :(

 

Second, when Hp falls below 30%, Ref Cast both Heal Spell 01 and 02. It's not intended :(

 

I would like to asking if i can make interval time of casting and if i can make only 1 spell working.

 

thx :)



#2
lubronbrons

lubronbrons

    I am L

  • Supporter
  • PipPipPipPip
  • 1,906 posts

a suggestion

scn WolfHeartRestore

float interval
float pcHpFrag
ref Source ;what is this for ?

Begin Gamemode
	if interval > 0
		Let interval -= GetSecondsPassed
	elseif Player.GetItemCount (item)
		Let pcHpFrag := Player.GetAV Health / Player.GetMaxAV Health
		;'I would like only 1 spell working.'
		if pcHpFrag < 0.3 ;'restore health when pc HP falls below 30%. PRIORITY (Less Hp, More Heal)'
			Source.MoveTo PlayerRef
			Source.Cast (healStrong) PlayerRef
			;'I would like interval time of casting'
			Let interval := 10 ;10 seconds
		elseif pcHpFrag < 0.5 ;'restore health when pc HP falls below 50%'
			Source.MoveTo PlayerRef
			Source.Cast (healWeak) PlayerRef
			;'I would like interval time of casting'
			Let interval := 5 ;5 seconds
		endif
	endif
end

Edited by lubronbrons, 14 March 2018 - 03:23 PM.


#3
wolfdol

wolfdol

    Regular

  • Members
  • PipPip
  • 85 posts

Thank You L :)

 

Your suggetion was very helpful and I achieve my purpose :)

 

But there were some unexpected problems - Ref 'source' cast twice not once :(

 

do you know any function about it?



#4
lubronbrons

lubronbrons

    I am L

  • Supporter
  • PipPipPipPip
  • 1,906 posts

Glad it worked! Your welcome, happy to help. Great! You noticed I preferred to be called L :wink:
Hmm...
Maybe there is double reference assignment in your edit?
How you assign that variable 'Source' ? I need to know how you did it, maybe the problem is there
(that's why I wrote 'what is this for' in the code)

 

EDIT : I have another suggestion, I've revised the code (see below). Now it should prevent double cast even if there is two or more references (I think)

scn WolfHeartRestore

float interval
float pcHpFrag
ref Source ;what is this for ?

Begin Gamemode
	if interval > 0
		Let interval -= GetSecondsPassed
		return
	elseif Player.GetItemCount (item) == 0
		return
	elseif Player.IsSpellTarget (healStrong) || Player.IsSpellTarget (healWeak)
		return
	endif
	Let pcHpFrag := Player.GetAV Health / Player.GetMaxAV Health
	;'I would like only 1 spell working.'
	if pcHpFrag < 0.3 ;'restore health when pc HP falls below 30%. PRIORITY (Less Hp, More Heal)'
		Source.MoveTo PlayerRef
		Source.Cast (healStrong) PlayerRef
		;'I would like interval time of casting'
		Let interval := 10 ;10 seconds
	elseif pcHpFrag < 0.5 ;'restore health when pc HP falls below 50%'
		Source.MoveTo PlayerRef
		Source.Cast (healWeak) PlayerRef
		;'I would like interval time of casting'
		Let interval := 5 ;5 seconds
	endif
end

Edited by lubronbrons, 14 March 2018 - 11:57 PM.


#5
wolfdol

wolfdol

    Regular

  • Members
  • PipPip
  • 85 posts

'Source' is Reference Editor ID of Activator.

 

I placed 'Source' in cell and check 'persistent reference' and 'initially disabled'.

 

Unfortunately, this guy 'Source' still cast twice

 

I resolved it by change spell type to Ability and use 'IsSpellTarget == 0' command.

 

thank for your help. you save a noob from frustration :smile:

 

ps. Your mod 'Instant Kill' Series looks like good data for script study for my mod. thx again XD


Edited by wolfdol, 15 March 2018 - 09:27 AM.


#6
lubronbrons

lubronbrons

    I am L

  • Supporter
  • PipPipPipPip
  • 1,906 posts

ahh I see... so you did a workaround

no prob happy to help~!

Welcome to modding world,,,,,



#7
Contrathetix

Contrathetix

    merry within reason

  • Supporter
  • PipPipPipPip
  • 2,126 posts

Sorry about the late post, but I was wondering how/whether it would work to have a constant healing effect on the player (for example as an ability) and then adjust the magnitude of the healing effect on the spell using scripts to make it dynamic. I have not tested that, and obviously checking player health percentage every n frames might or might not affect performance. As an idea, maybe something like this (untested, but just to illustrate the idea):

scriptname WolfHeartRestoreSpellScript

short UpdateCounter
float HealEffectMagnitude

begin _ScriptEffectUpdate

    if ( UpdateCounter < 60 ) ; update every 61 frames or somesuch
        let UpdateCounter += 1
        return
    endif

    let UpdateCounter := 0

    ; magnitude scaled in range [0, 100] in a linear fashion depending on actor health,
    ; with the effect being of magnitude 0 at full health and 100 at no health,
    ; probably not the best choice but should do as an example

    let HealEffectMagnitude :=  100 * ( 1 - ( ( GetAV Health ) / ( GetMaxAV Health ) ) )

    ; using the SetNthEffectItemMagnitude, I cannot remember how to use it exactly,
    ; I think it should accept a float (or not), and a spell (I think?) and that
    ; the first effect might be located at index 0 but I am not sure,
    ; needs someone to test maybe...

    ; SetNthEffectItemMagnitude [nuMagnitude:int] [magicItem:ref] [whichEffect:int]
    SetNthEffectItemMagnitude HealEffectMagnitude WolfHeartRestoreSpell 0

end

I can try testing it later if I find the time, but maybe something like that could also be an option? It would also remove the need to use any activators to cast the spell and the like, allowing the entire dynamic healing spell mechanism to be packed into one spell and one spell effect script. It would also work on actors other than the player, as well, because by running the script as a spell effect, the actor value checks could be run on the target actor.

 

Edit: Fixed the block name to ScriptEffectUpdate instead of GameMode. :blush:


Edited by Contrathetix, 17 March 2018 - 01:21 PM.


#8
wolfdol

wolfdol

    Regular

  • Members
  • PipPip
  • 85 posts

Sorry about late reply

 

I wrote a new Script for testing your sugguestion althought I can't write in same way because of kind of item used - Misitem(can't use scripteffectupdate as far as i know)

 

anyway, my script not worked. Magnitude didn't change regardless of Health rate :sad:

 

can you know what problem is?

 

 This is my script

---------------------------------------------------

 

SCN wolfHeartRestore02

 

short UpdateCount

Float HealMagnitude

 

Begin Gamemode

If UpdateCount < 60

  Set Updatecount to Updatecount + 1

  return

endif

 

if Player.GetEquipped WolfHeart(MisItem) == 0

  Player.RemoveSpell WolfHeartPassiveLeveled(Heal, Abillity)

  return

else

  Player.Addspell WolfHeartPassiveLeveled(Heal, Abillity)

  set UpdateCount to 0

  set HealMagnitude to 100 * (1 - ((GetAv Health) / (GetMaxAv Health)))

  SetNthEffectItemMagnutude Healmagnitude WolfHeartPassiveLeveled 0

endif

end

-------------------------------------------------------------------------------------------------------


Edited by wolfdol, 25 March 2018 - 03:40 AM.


#9
Contrathetix

Contrathetix

    merry within reason

  • Supporter
  • PipPipPipPip
  • 2,126 posts

Hi, also apologies for the late reply, I have been busy with other things.  :blush:  I did some testing last weekend or a week ago, and dynamically scaling healing spell is possible to implement, even as a single ability with a single script effect and also a single healing effect. Based on some testing, however, I can say the script I posted above does not work, unfortunately, because it modifies the spell effet item itself and has no effect on current active effects, apparently. So to be able to adjust the magnitude of an effect on a character, it is necessary to either re-apply the effect after each update or manipulate the currently applied active spell effect on the character. OBSE offers the necessary commands for listing and filtering the effects with scripts to find the correct active effect to set the magnitude for.

 

I have created a concept test that works, that scales the spell magnitude. When I have sorted out some stuff, I will upload it for you somewhere so you can check how it works. I do not know how a misc item would work, exactly, but I found a spell/ability to be a lot cleaner. The concept test also works on every character or creature, it does not have to be player.


Edited by Contrathetix, 05 April 2018 - 11:53 AM.


#10
Contrathetix

Contrathetix

    merry within reason

  • Supporter
  • PipPipPipPip
  • 2,126 posts

Apologies for the delay again. The concept test mod should be available here if it helps. The spell (an ability) has a script effect and a healing effect. The script effect uses OBSE functions to find the current active healing effect (from the ability) and then adjusts the active effect magnitude based on the current health percentage of the actor the abiltity has been applied to. It should work also on actors other than the player, but I have not tested it.

 

Hopefully that helps a bit. :thumbsup:


Edited by Contrathetix, 26 November 2019 - 12:21 PM.






Also tagged with one or more of these keywords: scrippt, magic, interval, time, construction set, cs, script, spell

Page loaded in: 1.056 seconds