Jump to content

Random-effect potion?


DaisukeKamina

Recommended Posts

I'm building a rather detailed magic shop mod with some slightly offbeat touches. One of these is a potion with random effects. Currently I have it assigning one of ten possible spells via a script effect, but the code is currently non-functional (again). I know the if loop used to assign the spell works, because I've had it happen before, but in trying to get it onto a potion I've yet again broken the script. I'll post what I have so far; if anyone can correct me I'd greatly appreciate it! (Probably in the form of a small easter egg in the mod.)

 

short kanpai

short drink

 

begin ScriptEffectStart

set kanpai to GetRandomPercent

set drink to -1

 

messageBox "Daisuke's Magicka Liqueurs. Here's to your magicka, but be warned- anything can happen! Don't be a goblin- consume Daisuke's Magicka Liqueurs responsibly.", "Down the hatch!", "Ummm..."

 

set drink to GetButtonPressed

if drink == 0

set kanpai to GetRandomPercent

if kanpai < 10

player.addspell DaisukeMagickaLiqueur1

elseif (kanpai >=10 && kanpai < 20)

player.addspell DaisukeMagickaLiqueur2

elseif (kanpai >=20 && kanpai < 30)

player.addspell DaisukeMagickaLiqueur3

elseif (kanpai >=30 && kanpai < 40)

player.addspell DaisukeMagickaLiqueur4

elseif (kanpai >=40 && kanpai < 50)

player.addspell DaisukeMagickaLiqueur5

elseif (kanpai >=50 && kanpai < 60)

player.addspell DaisukeMagickaLiqueur6

elseif (kanpai >=60 && kanpai < 70)

player.addspell DaisukeMagickaLiqueur7

elseif (kanpai >=70 && kanpai < 80)

player.addspell DaisukeMagickaLiqueur8

elseif (kanpai >=80 && kanpai < 90)

player.addspell DaisukeMagickaLiqueur9

elseif (kanpai >=90 && kanpai < 100)

player.addspell DaisukeMagickaLiqueur10

endif

messageBox "The flavors of ectoplasm, moon-sugar and daedra venin dissolved in alcohol are subtle and the fine flecks of Welkynd Stone suspended in the liquid crackle in your mouth as they dissolve. The effect is something like a punch to the brain, but you are suffused with energy and you can feel sparks behind your eyes."

endif

 

if drink == 1

messageBox "They say discretion is the better part of valor. They also say you're a wuss."

endif

end

 

It's implemented as a magic effect, but I want it to offer the prompt (like the poisoned foods) and give the player a chance to back out. I've made bits of it work, but the whole thing has never worked at one time. Big ol' pain in the butt.

Link to comment
Share on other sites

The spells being added... are they spells, diseases, abilities, lesser powers, greater powers? AddSpell in the case of abilities and diseases will add the spell as a current effect, for all the others it will add that spell to the player's spellbook.

In any case, you might want to use AddSpellNS ... it's a silent version that doesn't spam the effect... unless you intend that behavior. AddSpell also affects the base ID which can be a problem unless you've got something like this which is, I hope, player only.

 

What sort of specific problems are you having?

Link to comment
Share on other sites

I've got them set up as abilities- I was basing my work on the Poisoned Apple, figuring that was probably the way to do it. The trouble is, I'm working on transferring the effect over to a proper potion from a script object, so the menus aren't working right just yet. Am I gonna have to write a separate script to call those, or what? I would've followed the working model more closely, but a lot of it is behind-the-scenes (probably a script calling a script or something), so no code for me. Also, the reason I don't use AddSpellNS is that I'm very new to scripting, so I'm trying to avoid getting into OBSE just yet. Edited by DaisukeKamina
Link to comment
Share on other sites

Well, the major problem is that MessageBox takes a full frame to execute and, until a button is pressed (which could take as long as 15 frames or so), will return -1 (or another MessageBox is executed resetting the first MessageBox).

You have to take that into account that the iteration through your script that calls MessageBox will NOT be the iteration through your script in which you get the answer from the user. ScriptEffectStart is ran only on the first frame of a scripted magic effect as is ScriptEffectFinish (except the last frame)... what you'll want to do is split your script up into seperate sections. Put your initial code in ScriptEffectStart and call your first MessageBox. Then, in ScriptEffectUpdate (which runs over and over until the scripted effect finishes), you would poll GetButtonPressed and do nothing on -1 or something on >-1.

 

For reference, see here.

Edited by Astymma
Link to comment
Share on other sites

I'm just thinking aloud here, but couldn't you just place the ten spells into a list, and deliver the random spell that way? Much like random spawning loot.
Link to comment
Share on other sites

scriptname DaisukeMagickaLiqueurScript

 

short kanpai

short drink

short choose

 

begin ScriptEffectUpdate

set choose to 0

set drink to -2

if choose == 0

messageBox "Daisuke's Magicka Liqueurs. Here's to your magicka, but be warned- anything can happen! Don't be a goblin- consume Daisuke's Magicka Liqueurs responsibly.", "Down the hatch!", "Ummm..."

set choose to 1

elseif choose == 1

set drink to GetButtonPressed

if drink > -1

if drink == 0

set kanpai to GetRandomPercent

if kanpai < 10

player.addspell DaisukeMagickaLiqueur1

elseif kanpai >=10 && kanpai < 20

player.addspell DaisukeMagickaLiqueur2

elseif kanpai >=20 && kanpai < 30

player.addspell DaisukeMagickaLiqueur3

elseif kanpai >=30 && kanpai < 40

player.addspell DaisukeMagickaLiqueur4

elseif kanpai >=40 && kanpai < 50

player.addspell DaisukeMagickaLiqueur5

elseif kanpai >=50 && kanpai < 60

player.addspell DaisukeMagickaLiqueur6

elseif kanpai >=60 && kanpai < 70

player.addspell DaisukeMagickaLiqueur7

elseif kanpai >=70 && kanpai < 80

player.addspell DaisukeMagickaLiqueur8

elseif kanpai >=80 && kanpai < 90

player.addspell DaisukeMagickaLiqueur9

elseif kanpai >=90 && kanpai < 100

player.addspell DaisukeMagickaLiqueur10

endif

messageBox "The flavors of ectoplasm, moon-sugar and daedra venin dissolved in alcohol are subtle and the fine flecks of Welkynd Stone suspended in the liquid crackle in your mouth as they dissolve. The effect is something like a punch to the brain, but you are suffused with energy and you can feel sparks behind your eyes."

endif

if drink == 1

messageBox "They say discretion is the better part of valor. They also say you're a wuss."

endif

endif

endif

end

 

This is the new script. The if loop still isn't working, and more importantly I don't know how to make the potion not be consumed unless you choose yes. When it triggers, it works, but right now it's not triggering.

Link to comment
Share on other sites

"...and more importantly I don't know how to make the potion not be consumed unless..."

 

Had this problem awhile back, it seems to be hardcoded. The solution I used to solve my problem was to make the potion a misc item, and from thereout simulate the rest. This seems to be the only workaround, and would make your life a lot easier.

 

Pros;

-Use an OnEquip block to activate, whether in menu or gamemode.

-Choose to use it or not.

-Circumvent all hardcoded trouble around potions, to make whatever you want.

Cons;

-Not in the potion part of the menu.

 

 

 

Lucifer

Link to comment
Share on other sites

"...and more importantly I don't know how to make the potion not be consumed unless..."

 

Had this problem awhile back, it seems to be hardcoded. The solution I used to solve my problem was to make the potion a misc item, and from thereout simulate the rest. This seems to be the only workaround, and would make your life a lot easier.

 

Pros;

-Use an OnEquip block to activate, whether in menu or gamemode.

-Choose to use it or not.

-Circumvent all hardcoded trouble around potions, to make whatever you want.

Cons;

-Not in the potion part of the menu.

 

 

 

Lucifer

 

That's actually what I was trying originally; it also means I can use the original object (the disused Magicka Potion item) for it. The only con is exactly as you said. I guess I ought to try it with the new script, see what happens.

 

Edit: CTDs!

 

scriptname DaisukeMagickaLiqueurScript

 

short kanpai

short drink

short choose

 

begin onEquip

set choose to 0

set drink to -2

if choose == 0

messageBox "Daisuke's Magicka Liqueurs. Here's to your magicka, but be warned- anything can happen! Don't be a goblin- consume Daisuke's Magicka Liqueurs responsibly.", "Down the hatch!", "Ummm..."

set choose to 1

endif

end

 

begin menumode

if choose == 1

set drink to GetButtonPressed

if drink > -1

if drink == 0

set kanpai to GetRandomPercent

if kanpai < 10

player.addspell DaisukeMagickaLiqueur1

elseif kanpai >=10 && kanpai < 20

player.addspell DaisukeMagickaLiqueur2

elseif kanpai >=20 && kanpai < 30

player.addspell DaisukeMagickaLiqueur3

elseif kanpai >=30 && kanpai < 40

player.addspell DaisukeMagickaLiqueur4

elseif kanpai >=40 && kanpai < 50

player.addspell DaisukeMagickaLiqueur5

elseif kanpai >=50 && kanpai < 60

player.addspell DaisukeMagickaLiqueur6

elseif kanpai >=60 && kanpai < 70

player.addspell DaisukeMagickaLiqueur7

elseif kanpai >=70 && kanpai < 80

player.addspell DaisukeMagickaLiqueur8

elseif kanpai >=80 && kanpai < 90

player.addspell DaisukeMagickaLiqueur9

elseif kanpai >=90 && kanpai < 100

player.addspell DaisukeMagickaLiqueur10

endif

messageBox "The flavors of ectoplasm, moon-sugar and daedra venin dissolved in alcohol are subtle and the fine flecks of Welkynd Stone suspended in the liquid crackle in your mouth as they dissolve. The effect is something like a punch to the brain, but you are suffused with energy and you can feel sparks behind your eyes."

player.removeitem DaisukeMagickaLiqueur 1

endif

if drink == 1

messageBox "They say discretion is the better part of valor. They also say you're a wuss."

endif

endif

endif

end

 

That's the latest script; I've got to be putting it in the wrong kind of block or something, because they 'no' choice returns its message box now, but it CTDs when the message boxes close.

Edited by DaisukeKamina
Link to comment
Share on other sites

Behold, a rewritten script;

 

scn DaisukeMagickaLiqueurScript

short Button
short ButtonPressed

begin OnEquip
messagebox "Daisuke's Magicka Liqueurs. Here's to your magicka, but be warned- anything can happen! Don't be a goblin- consume Daisuke's Magicka Liqueurs responsibly.", "Down the hatch!", "Ummm..."
set ButtonPressed to 1
end

begin MenuMode
if ButtonPressed == 1
	set Button to GetButtonPressed
	if Button == -1
		return
	elseif Button == 0
		player.addspell DaisukeMagickaLiqueurLeveledSpell
		messagebox "The flavors of ectoplasm, moon-sugar and daedra venin dissolved in alcohol are subtle and the fine flecks of Welkynd Stone suspended in the liquid crackle in your mouth as they dissolve. The effect is something like a punch to the brain, but you are suffused with energy and you can feel sparks behind your eyes."
		player.removeitem DaisukeMagickaLiqueur 1
		set ButtonPressed to 0
	elseif Button == 1
		messageBox "They say discretion is the better part of valor. They also say you're a wuss."
		set ButtonPressed to 0
	endif
endif
end

 

First thing you need to do, is to put all your spells in one leveled-spell called DaisukeMagickaLiqueurLeveledSpell. Once you did that, paste this exact script over the previous one, to be attached to the flask misc-item.

 

That should work right away.....

 

Mind you though, I have not tested it. I just wrote it completely textbook, so it should work just fine...

 

I suggest you go test it, and let's just hope for the best ;)

 

 

 

Lucifer

Link to comment
Share on other sites

Behold, a rewritten script;

 

First thing you need to do, is to put all your spells in one leveled-spell

 

 

Amazing what thinking aloud can do.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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