:: castSpellNPC
<<set $here = 'castSpellNPC'>>
<<set $ARGS = $location_var[$here]>>
<!-- ! Used for NPCs to cast a spell.-->
<!-- !-->
<!-- !   $larg(0) is the spell being cast-->
<!-- !	$larg(1) = Target Type ('opp','pcs')-->
<!-- !	 ARGS[2] = Target party member number-->
<!-- !	$larg(3) = Caster Type ('opp','pcs')-->
<!-- !	 ARGS[4] = Caster party member number-->
<!-- ! ARGS[5-n] are any parameters that need to be passed to the Spell-->
<!-- !-->
<!-- !	Example:-->
<!-- !		gs 'castSpell', 'teleport', 'CentralPark'-->
<<gs 'spellList'>>
<<set $spellSuccess = 1>>
<<set $SpellID = $location_var[$here][0]>>
<<set $SpellArgs = "">>
<<set $i = 5>>
<<warn 'JUMP MARKER ENCOUNTERED: :ArgLoopNPC'>>
<<if $i < arrsize('$ARGS')>>
	<<if $location_var[$here][$i] == ''>>
		<<set $SpellArgs += ", ARGS[$i]">>
	<<else>>
		<<set $SpellArgs += ", '$larg($i)'">>
	<</if>>
	<<set $i += 1>>
	<<warn 'JUMP COMMAND ENCOUNTERED: jump ArgLoopNPC'>>
<</if>>
<<set $i to null>>
<<set $manaCost = $spellMana[$SpellID]>>
<!-- FAILED TO CONVERT
	casterMana = dyneval('result=<<$larg(3)>>_mana[<<ARGS[4]>>]')
-----
	<<set $casterMana = dyneval('result=<<$larg(3)>>_mana[ERROR: FAILED TO CONVERT LITERAL: """<<ARGS[4]>>"""]')>>

-->
<<warn "CONVERSION ERROR 89d19472e575e0851aaa5a3bf7ebe2ab">>
<<if $casterMana >= $manaCost>>
	<<set '+$larg(3)+'_mana['+$larg(4)+'] -= $manaCost>>
	<<set $SpellExec = "gs 'spell', '$SpellID', 'spellSuccess', '$larg(1)', ARGS[2], ARGS[4]$SpellArgs">>
	<<SpellExec>>
<<else>>
	Not enough mana to cast the spell.
<</if>>
<<set $SpellID to null>>
<<set $SpellExec to null>>
<<set $spellSuccess to null>>
<<set $manaCost to null>>
<<set $casterMana to null>>
