Jump to content

Help with looping a script (Transmute Ore)


Recommended Posts

Posted

So I've been trying to make a mod today that basically changes the Transmute Ore Mineral Spell into a concentrated Spell.

 

I got that part working but the script is just being triggered once, no matter how long you have the spell active. So I tried looking into the script and some tutorials but I still don't know what the hell I am doing. Tried a ton of things but the compile script always gives me a "failed".

 

The script I am trying to mod is this one:

Scriptname transmuteMineralScript extends ActiveMagicEffect  
{script for spell to allow transmutation of ores}

import game

MiscObject Property Ore01  Auto  
{Lowest value ore}
MiscObject Property Ore02  Auto  
{Middle value ore}
MiscObject Property Ore03  Auto  
{Highest value ore}
Sound Property FailureSFX  Auto  
float property skillAdvancement = 15.0 auto
{How much to advance the skill?  Only works when spell actually transmutes something}
message property failureMSG auto


EVENT OnEffectStart(Actor akTarget, Actor akCaster)
	objectReference caster = akCaster
	if caster.getItemCount(Ore02) >= 1
		; favor the more valuable ore first
		caster.removeItem(Ore02, 1, TRUE)
		caster.addItem(Ore03, 1, FALSE)
		advanceSkill("alteration",skillAdvancement)
	elseif caster.getItemCount(Ore01) >= 1
		; if none of that, look for the base ore to upgrade
		caster.removeItem(Ore01, 1, TRUE)
		caster.addItem(Ore02, 1, FALSE)
		advanceSkill("alteration",skillAdvancement)
	else
		; caster must have had no valid ore
		FailureSFX.play(caster)
		failureMSG.show()
	endif
endEVENT

My guess is that I have to use a function after the second advanceSkill to make it loop back to the first "if caster.getIremCount" but I can't find which one. Maybe I am wrong and don't know what I am doing. I am not very experienced in scripting myself and can usually just slightly modify an existing script and I understand how this one works, just not how to loop it.

 

Can anyone help me with this? As said I am not very experienced but would like to learn more.

Posted

What do you mean for "looping it"? Converting all ores of all types in a single cast?

 

Tell me what is the behavior you want to accomplish and I will tell you the script.

Posted

Okay let's see if I can explain it.

 

What I want to achieve is make it repeat both the "if" and "elseif". So if you keep casting the spell it would turn silver ores to gold over time (in an interval of about 0.5 seconds is what I would want).

 

I've seen enough mods that instantly turn all ores into silver and gold, that's not what I want to make.

Posted

 

Scriptname transmuteMineralScript extends ActiveMagicEffect  
{script for spell to allow transmutation of ores}
 
import game
 
MiscObject Property Ore01  Auto  
{Lowest value ore}
MiscObject Property Ore02  Auto  
{Middle value ore}
MiscObject Property Ore03  Auto  
{Highest value ore}
Sound Property FailureSFX  Auto  
float property skillAdvancement = 15.0 auto
{How much to advance the skill?  Only works when spell actually transmutes something}
message property failureMSG auto
 
 
EVENT OnEffectStart(Actor akTarget, Actor akCaster)
objectReference caster = akCaster
 
if caster.getItemCount(Ore02) == 0 && caster.getItemCount(Ore01) == 0

   ; caster must have had no valid ore
   FailureSFX.play(caster)
   failureMSG.show()
endIf
 

while caster.getItemCount(Ore02) > 0 || caster.getItemCount(Ore01) > 0
 if caster.getItemCount(Ore02) > 0
   ; favor the more valuable ore first
   caster.removeItem(Ore02, 1, TRUE)
   caster.addItem(Ore03, 1, FALSE)
   advanceSkill("alteration",skillAdvancement)
 elseif caster.getItemCount(Ore01) > 0
   ; if none of that, look for the base ore to upgrade
   caster.removeItem(Ore01, 1, TRUE)
   caster.addItem(Ore02, 1, FALSE)
   advanceSkill("alteration",skillAdvancement)
 endif
 Utility.wait(1.0)
endWhile
endEVENT

 

This will re-trigger the change until all previous ores are converted. The conversion will happen once every second.

If you want it to go slower or faster change "Utility.want(1.0)" to something different.

 

Posted

Okay just for clarification, what does this line do?

while caster.getItemCount(Ore02) > 0 || caster.getItemCount(Ore01) > 0

I understand what you did with

if caster.getItemCount(Ore02) == 0 && caster.getItemCount(Ore01) == 0

which I believe is a check for if the player has no iron ore or silver ore.

Posted

The "IF" checks if you have items when your= first call the spell. And cast the message in case you miss the ores.

 

The second one if just the condition of the cycle, and it will continue as long as you have enough ores of any of the two types.

Posted

Did you have any error in the compilation?

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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