Jump to content

Scripting Trouble for Vampires


EndgameV

Recommended Posts

Hi Im just having a bit of trouble writing one of my first papyrus script.

 

My aim is that when the player, as a vampire, equips an item with the script attached the item is supposed to remove the players sun damage according to what stage of vampirism they are at when equipped and restore it when unequipped.

 

Scriptname Daywalkerscript extends ObjectReference Conditional  

int Daywalker

Spell Property VampireSunDamage01  Auto 

Spell Property VampireSunDamage02  Auto 

Spell Property VampireSunDamage03  Auto 

Spell Property VampireSunDamage04  Auto 

Event OnEquip(ObjectReference akActionRef)
Daywalker = 1
       if (Game.GetPlayer().GetSpell(VampireSunDamage01))
	Game.GetPlayer().RemoveSpell(VampireSunDamage01)
	Daywalker = 1
endif

       if (Game.GetPlayer().GetSpell(VampireSunDamage02))
	Game.GetPlayer().RemoveSpell(VampireSunDamage02)
	Daywalker = 2
endif

       if (Game.GetPlayer().GetSpell(VampireSunDamage03))
	Game.GetPlayer().RemoveSpell(VampireSunDamage03)
	Daywalker = 3
endif

       if (Game.GetPlayer().GetSpell(VampireSunDamage04))
	Game.GetPlayer().RemoveSpell(VampireSunDamage04)
	Daywalker = 4
endif

EndEvent

Event OnUnequip(ObjectReference akActionRef)
Daywalker = 1
if Daywalker = 1
	Game.GetPlayer().AddSpell(VampireSunDamage01)
	Daywalker = 0
endif

if Daywalker = 2
	Game.GetPlayer().AddSpell(VampireSunDamage02)
	Daywalker = 0
endif
       
if Daywalker = 3
	Game.GetPlayer().AddSpell(VampireSunDamage03)
	Daywalker = 0
endif
       
if Daywalker = 4
	Game.GetPlayer().AddSpell(VampireSunDamage04)
	Daywalker = 0
endif

EndEvent

 

The way ive done it makes sense to me but the compiler doesnt like it, something to with the variables.

 

Help?

Link to comment
Share on other sites

There were quite a few problems with your script.

- declaring the script as conditional when you don't use any conditional properties

- you should use "=" to set the value of a variable, but you should use "==" to compare the value of a variable.

- GetSpell is used to query books (and it requires SKSE). HasSpell is used to query actors.

- Setting "Daywalker = 1" at the beginning of your Equip and Unequip blocks.

- repeated use of Game.GetPlayer is inefficient. It's better to use a variable (faster execution).

- when you're doing similar stuff repeatedly, it can be neater to use an array or formlist (see my example)

 

OK, I haven't tried compiling this but hopefully it will work. You will need to assign your 4 spells to the array property "VSD" using the Properties button.

 

 

Scriptname Daywalkerscript extends ObjectReference

Spell[] Property VSD Auto
Actor player
int i

Event OnInit()
player = Game.GetPlayer()
EndEvent

Event OnEquip(ObjectReference akActionRef)
i = VSD.length
while i > 0 && akActionRef == player
	i -= 1
       	if player.HasSpell(VSD[i])
		player.RemoveSpell(VSD[i])
		Return
	endif
endwhile
EndEvent

Event OnUnequip(ObjectReference akActionRef)
if i > -1 && akActionRef == player
	player.AddSpell(VSD[i])
endif
EndEvent

Edited by steve40
Link to comment
Share on other sites

Thanks a lot for your help Steve, the script does compile and ive added all the spells to the properties. Still doesnt work like i want it to but im still hunting through the creation kit for all the spells that cause sun damage so I'll get back to you on that.

 

Thanks again for the papyrus help, makes me miss oblivion's coding language

Link to comment
Share on other sites

  • Recently Browsing   0 members

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