Jump to content

need help scripting


antopicio

Recommended Posts

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 ench
short doonce
begin GameMode
set ench to provafiammakatana1.getcurrentcharge
if ench <= 20 && doonce == 0
player.additemNS provanofiamma 1
player.equipitemNS provanofiamma
set doonce to 1
endif
end
begin GameMode
if ench > 2000
set doonce to 1
endif
end
for the main flaming model weapon and
scn prova2
float ench
begin onadd player
player.equipitemNS provanofiamma
player.removeitemNS provafiammakatana1 1
player.setequippedcurrentcharge 0 9
end
begin GameMode
set ench to provanofiamma.getcurrentcharge
if ench !=0
player.additem provafiammakatana1 1
player.equipitem provafiammakatana1
removeME
endif
end
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 by antopicio
Link to comment
Share on other sites

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 below

long ago my teacher give me script about enchantment, now I'm gonna share it

I 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 by lubronbrons
Link to comment
Share on other sites

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

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

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 one

and 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

about your problem ...

that's probably because zero divide

in math we all know that 0 (zero) is baddie

something 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 error

OR you can do something like this

Let curUses := eval(curCharge / enchCost)
Link to comment
Share on other sites

  • Recently Browsing   0 members

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