antopicio Posted June 8, 2016 Share Posted June 8, 2016 (edited) Hi i'm new to all the modding and scripting world and i'm trying to create a flaming sword that stop flaming when the item is no more enchanted for oblivion, but the script is not working and i can't understand why the script i used is: scn prova float enchshort doonce begin GameModeset ench to provafiammakatana1.getcurrentchargeif ench <= 20 && doonce == 0 player.additemNS provanofiamma 1player.equipitemNS provanofiammaset doonce to 1endifend begin GameMode if ench > 2000 set doonce to 1endifend for the main flaming model weapon and scn prova2 float ench begin onadd playerplayer.equipitemNS provanofiammaplayer.removeitemNS provafiammakatana1 1player.setequippedcurrentcharge 0 9end begin GameMode set ench to provanofiamma.getcurrentchargeif ench !=0 player.additem provafiammakatana1 1 player.equipitem provafiammakatana1removeMEendifend for the nonflaming model i'm probably using wrong the function getcurrentcharge, but i can't understand why ps i'm sorry about my english is not my first language Edited June 8, 2016 by antopicio Link to comment Share on other sites More sharing options...
lubronbrons Posted June 8, 2016 Share Posted June 8, 2016 (edited) Hi first, create new Quest from Menu -> Character >> Quest >> rightclick in left table >> choose 'New'name the quest as you like. then attach this script belowlong ago my teacher give me script about enchantment, now I'm gonna share itI didn't test the code, hope it works scn provaQuestScript ref weap float fQuestDelayTime float curCharge float enchCost short curUses short rmvFlameSwd short rmvNonFlame begin GameMode Let fQuestDelayTime := 1 ;make the script run check every 1 second if rmvFlameSwd Player.RemoveItemNS provafiammakatana1 1 Let rmvFlameSwd := 0 elseif rmvNonFlame Player.RemoveItemNS provanofiamma 1 Let rmvNonFlame := 0 endif ;check if player currently equip Flame blade if Player.GetEquippedObject 16 == provafiammakatana1 Let curCharge := Player.GetEquippedCurrentCharge 16 ;the equipped weapon current charge Let enchCost := GetEnchantmentCost ench ;the cost of the enchantment Let curUses := curCharge / (enchCost + 0.001) ;current charge / charge per use = remaining uses if curUses <= 0 Player.AddItemNS provanofiamma 1 Player.EquipItemNS provanofiamma Let rmvFlameSwd := 1 endif elseif Player.GetEquippedObject 16 == provanofiamma ;current player sword is the non-flame one Let curCharge := Player.GetEquippedCurrentCharge 16 Let enchCost := GetEnchantmentCost ench Let curUses := curCharge / (enchCost + 0.001) if curUses > 0 ;------------------------------------------------------->change this value as you see fit Player.AddItemNS provafiammakatana1 1 Player.EquipItemNS provafiammakatana1 Let rmvNonFlame := 1 endif endif end Edited June 9, 2016 by lubronbrons Link to comment Share on other sites More sharing options...
forli Posted June 9, 2016 Share Posted June 9, 2016 You can do better: no quest, but attach the script (object script) directly to the weapons.Advantages: it won't run when not necessary, it avoid some redundant calculations, and the script works for anyone who's wielding the weapon (including NCPs).You need 2 scripts: one for the discharged version (without flames) and one for the charged version (with flames) . Code for the "discharged" weapon: scn FlamingSwordDischargedScript ref owner ref ench float chargeCost short switchWeapon Begin OnEquip Let ench := GetEnchantment ;Calculate these once. They can't change while it's equipped. Let chargeCost := GetEnchantmentCost ench Let owner := GetContainer End Begin GameMode If IsEquipped == 0 ;Do nothing if not equipped Return ElseIf owner.IsRiding ;If the actor is riding, the add/remove commands won't work. Wait. Return ElseIf chargeCost == 0 ;Switch to "charged" version if the enchantment has no cost Let switchTime := 1 ElseIf switchWeapon != 2 ;If not switching or no weapon has been touched yet... Let switchWeapon := (GetCurrentCharge / chargeCost) >= 1 ;if true, there's enough charge for one or more uses. Switch to "charged" version EndIf If switchTime == 1 owner.AddItemNS provafiammakatana 1 owner.EquipItem2 provafiammakatana ;Don't forget the weapon was also equipped Let switchTime := 2 ElseIf switchTime == 2 RemoveMe ;RemoveMe is called in a separate frame from the add/equip commands, to avoid CTD EndIf End Code for the "charged" weapon: scn FlamingSwordChargedScript ref owner ref ench float chargeCost short switchWeapon Begin OnEquip Let ench := GetEnchantment ;Calculate these once. They can't change while it's equipped. Let chargeCost := GetEnchantmentCost ench Let owner := GetContainer End Begin GameMode If IsEquipped == 0 ;Do nothing if not equipped Return ElseIf owner.IsRiding ;If the actor is riding, the add/remove commands won't work. Wait. Return ElseIf chargeCost == 0 ;Keep the flaming version if the enchantment has no cost Return ElseIf switchWeapon != 2 ;If not switching or no weapon has been touched yet... Let switchWeapon := (GetCurrentCharge / chargeCost) >= 1 ;if true, there's not enough charge. Switch to "discharged" version EndIf If switchTime == 1 owner.AddItemNS provanofiamma 1 owner.EquipItem2 provanofiamma ;Don't forget the weapon was also equipped Let switchTime := 2 ElseIf switchTime == 2 RemoveMe ;RemoveMe is called in a separate frame from the add/equip commands, to avoid CTD EndIf End Link to comment Share on other sites More sharing options...
lubronbrons Posted June 9, 2016 Share Posted June 9, 2016 lol :laugh: long live~! Master Forli is here ! Hello teacher ! ...I'am still long way to go :teehee: hehe Link to comment Share on other sites More sharing options...
antopicio Posted June 9, 2016 Author Share Posted June 9, 2016 thank you very much, i'm going to try them, so getcurrentcharge applies to the item of the script when without reference?? Link to comment Share on other sites More sharing options...
lubronbrons Posted June 9, 2016 Share Posted June 9, 2016 yess.. when code executed like that means applied to themselfORif you still want 'that reference' you can do this Let theRef := GetSelf ; -or- Set theRef to GetSelf Link to comment Share on other sites More sharing options...
antopicio Posted June 9, 2016 Author Share Posted June 9, 2016 tried forli's code and it freezed my game XD, then with some little modification i made it work thanks now the code is like this scn FlamingSwordChargedScript ref owner ref ench float enchh float chargeCost short switchtime Begin OnEquip Let ench := GetEnchantment Let chargeCost := GetEnchantmentCost ench Let owner := GetContainer End Begin GameMode set enchh to player.getequippedcurrentcharge 16 If IsEquipped == 0 ;Do nothing if not equipped Return ElseIf chargeCost == 0 Return ElseIf switchtime != 2 if (enchh / chargeCost) <= 1 let switchTime := 1 endif EndIf If switchTime == 1 owner.AddItemNS provanofiamma 1 owner.EquipItem2 provanofiamma owner.setequippedcurrentcharge 0 16 Let switchTime := 2 ElseIf switchTime == 2 RemoveMe EndIf End scn FlamingSwordDischargedScript ref owner ref ench float charge float chargeCost short switchTime Begin OnEquip Let ench := GetEnchantment Let chargeCost := GetEnchantmentCost ench Let owner := GetContainer End Begin GameMode set charge to player.getequippedcurrentcharge 16 If IsEquipped == 0 Return ElseIf chargeCost == 0 Let switchTime := 1 ElseIf switchTime != 2 if (charge / chargeCost) >= 1 let switchtime := 1 endif EndIf If switchTime == 1 owner.AddItemNS provafiammakatana1 1 owner.EquipItem2 provafiammakatana1 owner.setequippedcurrentcharge charge 16 Let switchTime := 2 ElseIf switchTime == 2 RemoveMe EndIf End whit the (getcurrentcharge/chargecost) the freezed can't nderstand why =) Link to comment Share on other sites More sharing options...
lubronbrons Posted June 9, 2016 Share Posted June 9, 2016 ahh yeah this is my personal experience....the bad side of Object Script, is if you have that item more than one. the script will run more than oneand sometimes cause missbehave....so, if you using Master Forli's script . Make sure you only have one sword each,I don't know for sure. but for sure I did have bad experience with Object script Link to comment Share on other sites More sharing options...
antopicio Posted June 9, 2016 Author Share Posted June 9, 2016 yeah i've seen that, i had an almost working script but it added more than one sword at a time and i don't have a clue of the cause, btw thank you very much Link to comment Share on other sites More sharing options...
lubronbrons Posted June 9, 2016 Share Posted June 9, 2016 about your problem ...that's probably because zero dividein math we all know that 0 (zero) is baddiesomething like ' 0 / 3 ' or ' 5 / 0 ' will produce not desirable result (if you using MS excel it will say NA = Not Available)so .... for this fix, notice that in my script I wrote it like this Let curUses := curCharge / (enchCost + 0.001) see that ' 0.001 ' ? that trick will make the system avoid zero divide errorOR you can do something like this Let curUses := eval(curCharge / enchCost) Link to comment Share on other sites More sharing options...
Recommended Posts