Help with script

Post » Tue Dec 29, 2009 8:46 pm

Hi,
I have written a script to give "potions" to npc's (well, potion AI even with MCP isn't reliable enough to use it). All around it seems to work ok, but there is one problem - I tried to make so that npcs don't drink potions when they are paralized but it somehow doesn't work. So maybe some of you scripting gurus can spot some mistake in this script and give some insight :) . Here is the script:
begin ES_potionsshort doonceshort drinked_magshort drinked_fatshort drinked_hlshort mag_countshort fat_countshort hl_countshort var1short var2short var3float ini_magfloat cur_magfloat ini_fatfloat cur_fatfloat timerfloat mag_ratfloat fat_ratfloat hl_ratif ( MenuMode == 1 )	Returnendifif ( GetHealth < 1 )	returnendifif ( doonce == 0 )	set ini_mag to GetMagicka	set ini_fat to GetFatigue	set doonce to 1	if ( GetLevel < 10 ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;		if ( random100 < 60 )			set var1 to random, 3			set mag_count to ( var1 + 1 )		else			set mag_count to 0		endif		set random100 to random, 101		if ( random100 < 60 )			set var2 to random, 4			set fat_count to ( var2 + 1 )		else			set fat_count to 0		endif		set random100 to random, 101		if ( random100 < 60 )			set var3 to random, 4			set hl_count to ( var3 + 1 )		else			set hl_count to 0		endif	elseif ( GetLevel < 20 ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;		if ( random100 < 70 )			set var1 to random, 4			set mag_count to ( var1 + 1 )		else			set mag_count to 0		endif		set random100 to random, 101		if ( random100 < 70 )			set var2 to random, 5			set fat_count to ( var2 + 1 )		else			set fat_count to 0		endif		set random100 to random, 101		if ( random100 < 70 )			set var3 to random, 5			set hl_count to ( var3 + 1 )		else			set hl_count to 0		endif	elseif ( GetLevel < 30 ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;		if ( random100 < 75 )			set var1 to random, 4			set mag_count to ( var1 + 1 )		else			set mag_count to 0		endif		set random100 to random, 101		if ( random100 < 75 )			set var2 to random, 6			set fat_count to ( var2 + 1 )		else			set fat_count to 0		endif		set random100 to random, 101		if ( random100 < 75 )			set var3 to random, 6			set hl_count to ( var3 + 1 )		else			set hl_count to 0		endif	else ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;		if ( random100 < 85 )			set var1 to random, 5			set mag_count to ( var1 + 1 )		else			set mag_count to 0		endif		set random100 to random, 101		if ( random100 < 85 )			set var2 to random, 7			set fat_count to ( var2 + 1 )		else			set fat_count to 0		endif		set random100 to random, 101		if ( random100 < 85 )			set var3 to random, 7			set hl_count to ( var3 + 1 )		else			set hl_count to 0		endif	endifendifset timer to ( timer + GetSecondsPassed )if ( timer > 1.5 )	set timer to 0	set cur_mag to ( getmagicka )	set cur_fat to ( getfatigue )	set mag_rat to ( cur_mag / ini_mag )	set fat_rat to ( cur_fat / ini_fat )	set hl_rat to ( gethealthgetratio )	if ( GetEffect, sEffectParalyze != 1 ) ; <----- THERE	if ( mag_rat < 0.5 )	if ( drinked_mag < mag_count )		PlaySound3DVP, "restoration hit" 1.0, 0.8		ModCurrentMagicka, 70		set drinked_mag to ( drinked_mag + 1 )	endif	endif	if ( fat_rat < 0.66 )	if ( drinked_fat < fat_count )		PlaySound3DVP, "restoration hit" 1.0, 0.6		ModCurrentFatigue, 70		set drinked_fat to ( drinked_fat + 1 )	endif	endif	if ( hl_rat < 0.5 )	if ( drinked_hl < hl_count )		PlaySound3DVP, "restoration hit" 1.0, 1.0		ModCurrentHealth, 70		set drinked_hl to ( drinked_hl + 1 )	endif	endif	endifendifend


And one more thing - is there any limits on if-endif count (or deepness of if-endif structures). I had some problems with some of my longer scripts recently - these problems solved when I divided those scripts in shorter parts, so it would be nice to know.
User avatar
Ladymorphine
 
Posts: 3441
Joined: Wed Nov 08, 2006 2:22 pm

Post » Tue Dec 29, 2009 9:51 am

I've just given this some testing, and it seems that GetEffect has some inconsistency in how it works.


This expression is broken, it always returns 0 regardless of whether calling object is paralyzed or not:

if ( ( GetEffect, sEffectParalyze ) == 1 )	MessageBox, "Nay."endif


However, this expression works without issues:

short doonceset doonce to ( GetEffect, sEffectParalyze )if ( doonce == 1 )	MessageBox, "Yay!"endif


So you must use the GetEffect, sEffectParalyze function in a variable declaration, otherwise it will not work.
User avatar
Angus Poole
 
Posts: 3594
Joined: Fri Aug 03, 2007 9:04 pm

Post » Tue Dec 29, 2009 5:47 am

And one more thing - is there any limits on if-endif count (or deepness of if-endif structures). I had some problems with some of my longer scripts recently - these problems solved when I divided those scripts in shorter parts, so it would be nice to know.
There is definitely a limit, but it varies depending on how the ifs are structured and size of inner blocks code. Probably the more nesting, the faster limit reaching. A good way for testing is trying compiling with MWEdit; if a script does not compile but MWEdit does NOT find the error line, it is often a script length/too many nested ifs problem that would show at runtime.
User avatar
Sarah Evason
 
Posts: 3507
Joined: Mon Nov 13, 2006 10:47 pm

Post » Tue Dec 29, 2009 10:09 am

Thanks both of you. I almost forgot how PITA MW scripting can be sometimes.
User avatar
hannaH
 
Posts: 3513
Joined: Tue Aug 15, 2006 4:50 am


Return to III - Morrowind