Need help with conditions for this script

Post » Tue Sep 22, 2015 7:48 am

Hello, so, I want to make a script where, when the player activates a certain object, it checks to see if the player has in their inventory all the items on a formlist, and if they do, it will remove them all, and give them an item. So far I've got the script for removing the items and giving the item, but it will give the item regardless of whether it's removed anything or not. Because I haven't put any conditions in. You see I'm not quite sure how to do that. I know how to do a script that checks if the formlist 'hasform' with 'onitemadded', but not where the player has the items in their inventory. I know it's probably really similar and I feel a bit silly I can't figure it out, but I've been reading for ages on the creation kit wiki and it's just given me a headache :/ Hope someone can help me out with this :smile:

Here's my script I've got atm:

Scriptname HeroAmuletScript extends ObjectReference   Event OnActivate (ObjectReference akActionRef)game.getplayer().removeitem(amulet1)game.getplayer().removeitem(amulet2)game.getplayer().removeitem(amulet3)game.getplayer().removeitem(amulet4)game.getplayer().removeitem(amulet5)game.getplayer().removeitem(amulet6)game.getplayer().removeitem(amulet7)game.getplayer().removeitem(amulet8)game.getplayer().additem(amulet9)EndEvent Armor Property amulet1  Auto  Armor Property amulet2  AutoArmor Property amulet3  AutoArmor Property amulet4  AutoArmor Property amulet5  AutoArmor Property amulet6  AutoArmor Property amulet7  AutoArmor Property amulet8  AutoArmor Property amulet9  Auto  
User avatar
Ownie Zuliana
 
Posts: 3375
Joined: Thu Jun 15, 2006 4:31 am

Post » Tue Sep 22, 2015 1:35 pm

You just need to add a check to see if the player actually has all of the eight amulets before you remove them. Something like

Spoiler
Scriptname HeroAmuletScript extends ObjectReference   Event OnActivate (ObjectReference akActionRef)    ;storing the player in a variable is much faster than calling game.getplayer() every time    Actor player = game.getplayer()     if (player.getitemcount(amulet1) >= 1 \     && player.getitemcount(amulet2) >= 1 \     && player.getitemcount(amulet3) >= 1 \     && player.getitemcount(amulet4) >= 1 \     && player.getitemcount(amulet5) >= 1 \     && player.getitemcount(amulet6) >= 1 \     && player.getitemcount(amulet7) >= 1 \     && player.getitemcount(amulet8) >= 1 )        player.removeitem(amulet1)        player.removeitem(amulet2)        player.removeitem(amulet3)        player.removeitem(amulet4)        player.removeitem(amulet5)        player.removeitem(amulet6)        player.removeitem(amulet7)        player.removeitem(amulet8)        player.additem(amulet9)    endifEndEvent Armor Property amulet1  Auto  Armor Property amulet2  AutoArmor Property amulet3  AutoArmor Property amulet4  AutoArmor Property amulet5  AutoArmor Property amulet6  AutoArmor Property amulet7  AutoArmor Property amulet8  AutoArmor Property amulet9  Auto   
User avatar
Tom
 
Posts: 3463
Joined: Sun Aug 05, 2007 7:39 pm

Post » Tue Sep 22, 2015 2:19 pm

Thank you!! :) Yep that worked :) Can I ask one more question? If I want to put in the script a 'debug.messagebox' saying something like 'you don't have the required items' when the conditions aren't met, where in the script would that go? And like how would I write it? Would I have to do 'elseif' and then do all the getitemcount's again and put >=0 for them and then the debug.messagebox, or is there an easier way? Thanks :)

User avatar
Sarah Kim
 
Posts: 3407
Joined: Tue Aug 29, 2006 2:24 pm

Post » Tue Sep 22, 2015 10:40 am

just use an "else" statement. If the "if" conditions aren't true, your script will do whatever you put under the "else" statement instead.

http://www.creationkit.com/Statement_Reference#If_Statement

User avatar
Jeff Tingler
 
Posts: 3609
Joined: Sat Oct 13, 2007 7:55 pm

Post » Tue Sep 22, 2015 4:53 am

Okay thank you :)

User avatar
Dawn Porter
 
Posts: 3449
Joined: Sun Jun 18, 2006 11:17 am


Return to V - Skyrim