help me PLZ! Need advice for scripting!

Post » Sun Jun 24, 2012 5:58 am

I'm trying to make a spell can change a large amount of item to others at once.
the problem is I don't know how to make the script to recognize the amount of item that player have.


first time I thought it's not big deal cos' I thought looping script can solve the problem. so I made this script



Ammo Property DraugrArrow Auto



Ammo Property PvSqSteelDraugrArrow Auto


int counter = 0 ;variable counter is undefined

EVENT OnEffectStart(Actor akTarget, Actor akCaster)
While counter <= 100


if caster.getItemCount(draugrarrow) >= 1
caster.removeItem(draugrarrow, 1, TRUE)
caster.addItem(PvSqSteelDraugrarrow, 1, FALSE)

EndIF

counter += 1 ;Shorthand for "counter = counter + 1"

EndWhile
endEVENT




and this worked very well... except the speed............... (the script changed a arrow one by one so it takes like a forever....)


so now I need solutions to make the script to recognize how many item player have(to change all items that player have at once) or to make my own scrip faster.

PLEAS HELP ME OUT!
User avatar
George PUluse
 
Posts: 3486
Joined: Fri Sep 28, 2007 11:20 pm

Post » Sat Jun 23, 2012 9:21 pm

Couldn't you just store the result from GetItemCount in an integer variable then call removeItem() and addItem() with that value? Something like:
Ammo Property DraugrArrow          AutoAmmo Property PvSqSteelDraugrArrow AutoEvent OnEffectStart(Actor akTarget, Actor akCaster)  int itemNum = caster.getItemCount(draugrarrow) ; stores number of DraugrArrow that the caster has.  If( itemNum > 0 ) ; While loop not needed anymore because item counter is known? Not sure.    ; The if block isn't absolutely necessary, but I figured, in the case that itemNum = 0, a simple comparison to zero was more    ; efficient than two separate function calls that would add and remove nothing.    caster.removeItem(draugrarrow, itemNum, true)    caster.addItem(PvSqSteelDraugrarrow, itemNum, false)  EndIfEndEvent

A few questions: Who do you want this script to apply to? Every actor or just the player?

Edit: Also, read http://www.gamesas.com/topic/1347469-how-to-ask-for-scripting-help/ by Cipscis on how to ask for scripting help. It's very informative and helps those that try to help you :)
User avatar
jessica robson
 
Posts: 3436
Joined: Mon Oct 09, 2006 11:54 am

Post » Sun Jun 24, 2012 3:38 am

it for just player but I used "caster" for in case!

thank you very much! the script worked perfectly!
oh and also thanks for advising me to see that post. i didn't know it has way to ask for scripting help.
User avatar
Mel E
 
Posts: 3354
Joined: Mon Apr 09, 2007 11:23 pm


Return to V - Skyrim