Small problem with an MWSE script

Post » Tue Feb 12, 2013 7:49 pm

I'm getting an error that says "BAD OBJECT POINTER" on my latest script. I've isolated the exact line that's causing the problem, and now I'm trying to figure out why. Here's the script. The lines that are commented out are the ones causing the error.

Spoiler
Begin FEZ_SpellScript
; MWSE script to fez npcs
; global script, started when equipping fez
; checks to see what npcs have been fezzed, or if the fez spell has been cast on the npc
; spell is attached to fez, and available in the player's spell inventory while fez is equipped

Short FEZtrigger
Short FEZstate
Short rand

Long npctarget
Long tmp

if ( MenuMode )
return
endif

ifx ( FEZtrigger ) ;don't reset target if target is currently being fezzed
else
setx npctarget to xGetPCTarget
endif

if ( npctarget == 0 ) ;player is not looking at anything
return
endif

setx tmp to npctarget->xRefType
if ( tmp != 1598246990 ) ;if not type "NPC_"
return
endif

xSetRef npctarget
set tmp to GetHealth
if ( tmp < 1 ) ;npc is dead, so return
return
endif

xSetRef npctarget
set tmp to ( GetSpellEffects "FEZ_curseSpell" )
if ( tmp == 0 ) ;no spell effect detected
return
else ;get fezzed
set FEZtrigger to 1
endif

xSetRef npctarget
set tmp to ( GetItemCount "FEZ_dinky_cursed" )
if ( tmp )
set FEZstate to 0 ;NPC is already fezzed
else
set FEZstate to 1 ;NPC is not fezzed
endif

xSetRef npctarget
RemoveSpellEffects "FEZ_curseSpell"

ifx ( FEZstate ) ;state == 1, transform them

npctarget->xEquip "FEZ_dinky_cursed"

PlaySound "conjuration hit"

; xSetRef npctarget
; set tmp to ( GetItemCount "FEZ" )
; if ( tmp )
; Messagebox "Did my fez get smaller?"
; set FEZtrigger to 0
; return
; endif

Set rand to Random 100
xSetRef npctarget
set tmp to GetRace "Argonian"
if ( rand > 90 )
if ( tmp )
MessageBox "Did it get warmer in here?"
else
MessageBox "Why do I feel a draft?"
endif
elseif ( rand > 80 )
if ( tmp )
MessageBox "Jokes on you. I make this look good."
else
Messagebox "My hair! What have you done to it?"
endif
elseif ( rand > 70 )
Messagebox "How interesting, a tiny hat."
elseif ( rand > 60 )
Messagebox "Ha ha, very funny."
elseif ( rand > 50 )
Messagebox "Ah, what is it? Get it off. Get it off!"
elseif ( rand > 40 )
Messagebox "I sure hope you're pleased with yourself."
elseif ( rand > 30 )
Messagebox "Where did this hat come from?"
elseif ( rand > 20 )
Messagebox "I'll get you back for this."
else
MessageBox "What the?"
endif

set FEZtrigger to 0
return

else ;state == 0, change them back
; first remove the items

xSetRef npctarget
set tmp to ( GetItemCount "FEZ_dinky_cursed" )
ifx ( tmp )
npctarget->xRemoveItem "FEZ_dinky_cursed" tmp
set tmp to ( tmp - tmp )
endif

; now equip dummy armor and clothing to refresh their inventory

npctarget->xAddItem "FEZ_dinky_cursed" 1
npctarget->xRemoveItem "FEZ_dinky_cursed" 1

PlaySound "conjuration hit"

; xSetRef npctarget
; set tmp to ( GetItemCount "FEZ" )
; if ( tmp )
; Messagebox "And now my fez is restored. How are you doing that?"
; set FEZtrigger to 0
; return
; endif

Set rand to Random 100
xSetRef npctarget
set tmp to GetRace "Argonian"
if ( rand > 90 )
if ( tmp )
Messagebox "You were just jealous that I looked better in a fez than you."
else
Messagebox "Ok, now stop it. You're mussing up my hair."
endif
elseif ( rand > 80 )
if ( tmp )
Messagebox "The fez, it is gone. Why is life so cruel?"
else
Messagebox "Thank goodness, my hair is back."
endif
elseif ( rand > 70 )
Messagebox "Dignity restored. Thank you."
elseif ( rand > 60 )
Messagebox "Well, that was certainly an interesting experience."
elseif ( rand > 50 )
Messagebox "How are you doing that?"
elseif ( rand > 40 )
Messagebox "Ok, that was fun. Now stop it."
elseif ( rand > 30 )
Messagebox "Don't ever do that again."
elseif ( rand > 20 )
Messagebox "And now it's gone. Finally. Now I can get on with my day."
else
MessageBox "Aw, I was just getting used to it."
endif

set FEZtrigger to 0

endif

End

So why does it return an error if I'm checking for a FEZ but not the FEZ_dinky_cursed? Especially when the dinky cursed fez does not exist in the game world until the PC fezzes someone, whereas the regular fez is something I've dropped on a couple npcs (which is why I want to make a check for it in case the player "shrinks" their fez.)
User avatar
Lavender Brown
 
Posts: 3448
Joined: Tue Jul 25, 2006 9:37 am

Return to III - Morrowind