Jump to content

Script ho involves target’s health


VikingII

Recommended Posts

I’m asking for these two things because I am tired to find in TESCS wiki something related with health, getting almost nothing.

 

1) I have a simple spell ho teleport any NPC to a jail, but I want to add a limitation whereby the script only triggers if the enemy’s health lowers above 10%, otherwise the script won’t work. (I don’t want this to be used to defeat enemies by sending them easily to prison).

 

2) Also I want to restore the enemy’s health after his capture. For this part I thought add a restoration spell by the editor, but I think there will be a better way to do it by scripting.

 

This is the spell, and it works fine in my tests. It only needs the health part.

 

scn JailManager

ref Prisoner
short Button
short Control

begin ScriptEffectStart
if (Control == 0)
	MessageBox "Jail Tasks", "Send to jail", "Release prisoner", "never mind"
	set Control to 1
endif
end


Begin GameMode
if (Control == 1)
Set Button to GetButtonPressed
	If (Button == -1)
    		Return
	elseIf (Button == 0)
; sends a NPC to jail,
		set Prisoner to GetSelf
		moveto JailMarker
		messagebox "This enemy have been thrown into your jail!"
		set Control to 2
	elseif (Button == 1)
; releases the NPC in one of three destinations of the ship (he will walk his way to his place).
		if (ABVesselDeck.getDisabled == 0)
			set Prisoner to GetSelf
			moveto ABMapMarker
			messagebox "This person have been released!"
			set Control to 2
			elseif (ICVesselDeck.getDisabled == 0)
			set Prisoner to GetSelf
			moveto ICMapMarker
			messagebox "This person have been released!"
			set Control to 2
    			elseif (LWVesselDeck.getDisabled == 0)
			set Prisoner to GetSelf
			moveto LWMapMarker
			messagebox "This person have been released!"
			set Control to 2
		endif
	endIf
endIf
endif
end 

 

The spell is to give some life to the jail at the deeper deck of my ship by putting them some random criminals. But also it allows the player to put almost any NPC (because the spell is no-harm and it not pretends to changes the NPC behavior or AI).

 

Any correction to optimize the script is highly welcome!

Link to comment
Share on other sites

Are you sure that spell works fine? It shouldn't, because it is using GameMode Block in a Magic Effect Script...

 

Ideally, you should switch the "GameMode" block to a "ScriptEffectUpdate" Block.

 

 

Optimizations first...

 

 

 

scn JailManager

short Button
short Control

begin ScriptEffectStart
if (Control == 0)
	MessageBox "Jail Tasks", "Send to jail", "Release prisoner", "never mind"
	set Control to 1
endif
end


Begin ScriptEffectUpdate
if (Control == 1)
Set Button to GetButtonPressed
	If (Button == -1)
    		Return
	elseIf (Button == 0)
; sends a NPC to jail,
		moveto JailMarker
		messagebox "This enemy have been thrown into your jail!"
	elseif (Button == 1)
; releases the NPC in one of three destinations of the ship (he will walk his way to his place).
		if (ABVesselDeck.getDisabled == 0)
			moveto ABMapMarker
			elseif (ICVesselDeck.getDisabled == 0)
			moveto ICMapMarker
    			elseif (LWVesselDeck.getDisabled == 0)
			moveto LWMapMarker
		endif
                       MessageBox "This person has been released!"
	endIf
               Set Control to 2
endIf
endif
end 

 

 

 

 

The 10% remaining part can be done like this...

 

 

 

Scn JailManager

Short Button
Short Control

Short BaseHealth
Short CurrentHealth

Begin ScriptEffectStart

    Set BaseHealth to GetBaseAv Health
    Set CurrentHealth to GetAv Health

    If CurrentHealth > BaseHealth * 0.1
         Message "This enemy has too much health!"
         dispel <name of spell>
    endif

    ;;;;Continue with script

 

 

 

As for setting their health back to normal...

 

this line should do the trick. Set it anywhere you want...

 

SetAv Health BaseHealth

 

I would recommend putting it here...

 

 

 

; sends a NPC to jail,
                       SetAv Health BaseHealth
		moveto JailMarker
		messagebox "This enemy have been thrown into your jail!"

 

 

 

 

Hope this helps ;)

Edited by WarRatsG
Link to comment
Share on other sites

Thanks you WarRatsG!

 

Yes, my previous scripts worked perfectly in all situations that I have been tested (if its syntax is wrong, I suppose that it will fail in other situations...). I never scripted before, I have been taking notes from wiki and scripts from similar mods, tweaking them to fits in my mod... so, you optimization is most welcome! :teehee:

 

The health check works perfectly in all situations

 

Only the restore health do not works in any situation I’ve tested (with named NPC and no named NPC, and triggering the script many times even in jail, also I tried to putting the line in other stages of the script). I think is a matter of tweaking it, but I don’t have any clue of how.

Link to comment
Share on other sites

Their health won't restore?

 

That makes no sense to me. Honestly, I have no idea why that is.

 

Does the script look like this:

 

 

 

scn JailManager

short Button
short Control

Short BaseHealth
Short CurrentHealth

Begin ScriptEffectStart

       Set BaseHealth to GetBaseAv Health
       Set CurrentHealth to GetAv Health

       If CurrentHealth > BaseHealth * 0.1
            Message "This enemy has too much health!"
            dispel <name of spell>
       endif

       if (Control == 0)
               MessageBox "Jail Tasks", "Send to jail", "Release prisoner", "never mind"
               set Control to 1
       endif
end


Begin ScriptEffectUpdate
    if (Control == 1)
       Set Button to GetButtonPressed
               If (Button == -1)
               Return
               elseIf (Button == 0)
; sends a NPC to jail,
                       SetAv Health BaseHealth
                       moveto JailMarker
                       messagebox "This enemy have been thrown into your jail!"
               elseif (Button == 1)
; releases the NPC in one of three destinations of the ship (he will walk his way to his place).
                       if (ABVesselDeck.getDisabled == 0)
                               moveto ABMapMarker
                       elseif (ICVesselDeck.getDisabled == 0)
                               moveto ICMapMarker
                       elseif (LWVesselDeck.getDisabled == 0)
                               moveto LWMapMarker
                       endif
                       MessageBox "This person has been released!"
               endIf
               Set Control to 2
       endIf
    endif
end 

 

 

Link to comment
Share on other sites

The whole script works perfectly: NPCs resist the arrest until they almost die, they are sending to the JailMarker and I can release them on the selected locations.

 

Only the restore health is not working.

 

I figured that there is another problem with my mod: the jail has a SubSpace (that inhibits the NPC AI). But I removed the subspace and the restore health continues not working. I am out of ideas. At least it’s a minor problem because the script works in the most important things.

Link to comment
Share on other sites

What if this piece:

; sends a NPC to jail,
                       SetAv Health BaseHealth
                       moveto JailMarker
                       messagebox "This enemy have been thrown into your jail!"
               elseif (Button == 1)

 

was changed to:

; sends a NPC to jail,
                       SetAv CurrentHealth BaseHealth
                       moveto JailMarker
                       messagebox "This enemy have been thrown into your jail!"
               elseif (Button == 1)

Link to comment
Share on other sites

I think I may know, but I'm not sure.

 

SetAv changes the BASE actor value. This might mean that it effectively does nothing, because we are not increasing or decreasing the base health anyway.

 

I think that you could heal them by simply creating a spell that heals for 10000 points, has 0 cost and it's school is novice, then using this command instead...

 

Cast <EditorID of spell>

 

Let me know how it goes.

Link to comment
Share on other sites

Striker879, I thank you for your optimization and the health checks, that is the most important and I think I will not put the 'restore health' part, because I was thinking that it is better to let the player the open option to cast a restoration spell on the prisoner, only if he want. :thumbsup:

 

WarRatsG, the editor doesn’t allow me to save the 'cast <spell>' because it needs a reference. Also I have already tested to cast a double spell (a spell that contains the script 'go to jail', and a restoration spell), but it works erratically, the first time the prisoner appears with 10% of his health, and when I re-cast the spell in the jail, he appears with the health restored ¿?...

 

I thank all the help with scripting because I learned while trying. :blush:

Link to comment
Share on other sites

  • Recently Browsing   0 members

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