Scripting Help, Please

Post » Sun Jul 31, 2011 9:07 am

Greetings, Experienced Scripters

Could someone please give me ahand with this script?
[I didn't write it - it's something I found in a mod that was not implemented].

Begin _2DR_pipescript       Float timer Short controlvarShort OnPCEquipIf ( MenuMode == 1 )	ReturnEndif    If ( OnPCEquip == 1 )	Set OnPCEquip To 0	If ( Player ->GetItemCount, "aa_mc_weed" == 0 )	set controlvar to -1	MessageBox "You Equipped the pipe, however you need Pipeweed to smoke."	ElseIf ( Player ->GetItemCount, "aa_mc_weed" >= 1 )            MessageBox "You take several moments to relax, and enjoy your pipe."            PlaySound, "Pipe"		  Player->removeitem "aa_mc_weed" 1            Set controlvar To 1	Endif	ElseIf ( controlvar == 1 );;If ( controlvar == 1 )		Player -> AddSpell, "aa_mc_pipereactions"		set controlvar to -1;;	Endif	ElseIf ( controlvar == -1 );;If ( controlvar == -1 )		Set timer to ( timer + GetSecondsPassed )		if timer > 10		Player -> RemoveSpell, "aa_mc_pipereactions"		set controlvar to 0		endif	EndifEndifEnd


This script works fine the FIRST time it is run.
[Player equips pipe, if the pipeweed check is positive the spell (a curse) is applied, and removed after 10 sec.]

However, equipping the pipe a second time results in the spell NOT being removed as intended.
[I added the controlvar line to the "You need pipeweed to smoke" portion so I could at least get rid of the spell by equipping the pipe with no pipeweed in inventory...]

But, for some reason, the second time the script is run (assuming more than one "pipeweed" ingredient in inventory), it fails to move on to the "removespell" section -- and I cannot figure out why.

Any ideas or suggestions would be greatly appreciated.

DARoot
User avatar
Beast Attire
 
Posts: 3456
Joined: Tue Oct 09, 2007 5:33 am

Post » Sun Jul 31, 2011 12:12 pm

I was getting a little confused by the blocks commented out, so I removed them for my own clarity. anyway, I noticed that you hadn't reset your timer to 0, and that might be da root of your problem. (sorry :))


Try this:
Begin _2DR_pipescript       Float timer Short controlvarShort OnPCEquipIf ( MenuMode == 1 )        ReturnEndif    If ( OnPCEquip == 1 )        Set OnPCEquip To 0        If ( Player ->GetItemCount, "aa_mc_weed" == 0 )        set controlvar to -1        MessageBox "You Equipped the pipe, however you need Pipeweed to smoke."        ElseIf ( Player ->GetItemCount, "aa_mc_weed" >= 1 )            MessageBox "You take several moments to relax, and enjoy your pipe."            PlaySound, "Pipe"                  Player->removeitem "aa_mc_weed" 1            Set controlvar To 1        Endif       If ( controlvar == 1 )               Player -> AddSpell, "aa_mc_pipereactions"                set controlvar to -1     Endif        If ( controlvar == -1 )                Set timer to ( timer + GetSecondsPassed )                if timer > 10                Player -> RemoveSpell, "aa_mc_pipereactions"                set controlvar to 0                Set timer to 0                endif        EndifEndifEnd


Also, I'm unsure why you're running the timer to remove the spell when you have no weed, but if that's not needed you might change it to set controlvar to 2 when you do have weed and change that timer block accordingly.
User avatar
Penny Wills
 
Posts: 3474
Joined: Wed Sep 27, 2006 6:16 pm

Post » Sun Jul 31, 2011 6:29 pm

AHA! Nevermind.

Added a "Set Timer to 0" line before the spell add/remove stuff, and now it works just as advertised, time after time...
Begin _3DR_pipescript       Float timer Short controlvarShort OnPCEquipIf ( MenuMode == 1 )	ReturnEndif    If ( OnPCEquip == 1 )	Set OnPCEquip To 0	If ( Player ->GetItemCount, "aa_mc_weed" == 0 )	set controlvar to -1	MessageBox "You Equipped the pipe, however you need Pipeweed to smoke."	ElseIf ( Player ->GetItemCount, "aa_mc_weed" >= 1 )            MessageBox "You take several moments to relax, and enjoy your pipe."            PlaySound, "Pipe"	Player->removeitem "aa_mc_weed" 1	Set timer to 0            Set controlvar To 1	Endif	ElseIf ( controlvar == 1 )		Player -> AddSpell, "aa_mc_pipereactions"		set controlvar to -1	ElseIf ( controlvar == -1 )		Set timer to ( timer + GetSecondsPassed )		if timer > 10		Player -> RemoveSpell, "aa_mc_pipereactions"		set controlvar to 0		endif	EndifEndifEnd


Thank you for your patience and attention.

DARoot

[Quick editorial note] - Thanks, Neildarkstar! Great minds think alike, obviously (did we just ninja each other?)
And yeah, I get that "da root" stuff all the time...
Could be worse, though -- I once knew a dentist whose name was Dr. Payne...
User avatar
DarkGypsy
 
Posts: 3309
Joined: Tue Jan 23, 2007 11:32 am


Return to III - Morrowind