Jump to content

What's wrong with this script?


wholegrain

Recommended Posts

Posted
Scriptname _aaa_FiftyFifty Extends ObjectReference 


MiscObject Property Gold001 Auto
Int Property GoldAmount = 50 Auto


Event OnActivate(ObjectReference akActionRef)
 GoToState("Busy")
 If(akActionRef==(Game.Getplayer()))
  If(akActionRef.GetItemCount(Gold001)>=(GoldAmount))
   If(Utility.RandomInt(0,1))
akActionRef.AddItem(Gold001, GoldAmount) 
   Else 
akActionRef.RemoveItem(Gold001, GoldAmount)
   EndIf
  Else
   Debug.MessageBox("Not enough gold")
  Endif 
 Endif
 GoToState("")
EndEvent

State Busy
Event OnActivate(ObjectReference akActionRef)
;
EndEvent
EndState

Why isn't this script working. This script was meant to give or remove 50 gold from the player inventory whenever he clicked on an object, but it keeps saying "Not enough gold" and not doing anything even though I have 1901 gold inside my inventory. What's wrong?

Posted

If(akActionRef.GetItemCount(Gold001)>=(GoldAmount))

 

What is that supposed to be checking?  Right now, you're comparing the ObjectID for the object you activate to the amount of gold you want to give the player (in this case, 50 gold).  That won't work.

Posted

checking if the player has more than 50 gold.


If(PlayerRef.GetItemCount(50) >= (GoldAmount) 

would this work?

Scriptname _aaa_FiftyFifty Extends ObjectReference 


MiscObject Property Gold001 Auto
Int Property GoldAmount = 50 Auto


Event OnActivate(ObjectReference akActionRef)
 GoToState("Busy")
 If(akActionRef==(Game.Getplayer()))
  If(PlayerRef.GetItemCount(50) >= (GoldAmount) 
   If(Utility.RandomInt(0,1))
akActionRef.AddItem(Gold001, GoldAmount) 
   Else 
akActionRef.RemoveItem(Gold001, GoldAmount)
   EndIf
  Else
   Debug.MessageBox("Not enough gold")
  Endif 
 Endif
 GoToState("")
EndEvent

State Busy
Event OnActivate(ObjectReference akActionRef)
;
EndEvent
EndState
Posted

 

If(akActionRef.GetItemCount(Gold001)>=(GoldAmount))

 

I'm fairly sure you don't need to have "GoldAmount" in ( and ) there.

 

Edit: try your original code but with

If(akActionRef.GetItemCount(Gold001)>=GoldAmount)
If that doesn't work, try printing akActionRef.GetItemCount(Gold001) to screen somewhere. In the "Not enough gold" box maybe.
Posted

wait that doesn't even compile.


I will try this:

Scriptname gamble_script extends ObjectReference  

MiscObject Property Gold001 Auto
Int Property GoldAmount = 50 Auto


Event OnActivate(ObjectReference akActionRef)
 GoToState("Busy")
 If(akActionRef==(Game.Getplayer()))
  If(akActionRef.GetItemCount(Gold001)>=GoldAmount)
   If(Utility.RandomInt(0,1))
akActionRef.AddItem(Gold001, GoldAmount)
   Else
akActionRef.RemoveItem(Gold001, GoldAmount)
   EndIf
  Else
   Debug.MessageBox("Not enough gold")
  Endif
 Endif
 GoToState("")
EndEvent

State Busy
Event OnActivate(ObjectReference akActionRef)
;
EndEvent
EndState;
Posted

 

checking if the player has more than 50 gold.

If(PlayerRef.GetItemCount(50) >= (GoldAmount) 

would this work?

Scriptname _aaa_FiftyFifty Extends ObjectReference 


MiscObject Property Gold001 Auto
Int Property GoldAmount = 50 Auto


Event OnActivate(ObjectReference akActionRef)
 GoToState("Busy")
 If(akActionRef==(Game.Getplayer()))
  If(PlayerRef.GetItemCount(50) >= (GoldAmount) 
   If(Utility.RandomInt(0,1))
akActionRef.AddItem(Gold001, GoldAmount) 
   Else 
akActionRef.RemoveItem(Gold001, GoldAmount)
   EndIf
  Else
   Debug.MessageBox("Not enough gold")
  Endif 
 Endif
 GoToState("")
EndEvent

State Busy
Event OnActivate(ObjectReference akActionRef)
;
EndEvent
EndState

 

 

I do not think so ;)

 

If the variable is always 50:
 
Why global and above all as Auto
If there is no quest with the properties, it is quite nonsensical.
If there is a quest for it, just declaration but no values - otherwise also nonsensical.
 
If GoldAmount is ALWAYS 50, then it is easier to compare than PlayerRef.GetItemCount(50)  >= 50.
Why variable, if at all times the same value?
Posted

What do you mean by fill?


Wait, do I need to do something else to attach Gold001 to the gold inside the player inventory. I thought you could just access it via a script.

Posted

What do you mean by fill?

Wait, do I need to do something else to attach Gold001 to the gold inside the player inventory. I thought you could just access it via a script.

 

He means - your script in CK (as a quest, magic effect - whatever).
Properties - Auto fill - or - manually.
 
He means precisely the "MiscObject Property Gold001 Auto"
 
Where does that come from?

 

Posted

I just attached a script to an activator item.

You need to go into properties on the script in the creation kit and set Gold001 to whatever gold is.
Posted

Gold001 is supposed to be the gold inside the player's inventory? How do I link Gold001 to the gold inside the player's inventory?

Give me a moment and I'll grab some screenshots to show you.
Posted

Gold001 is supposed to be the gold inside the player's inventory? How do I link Gold001 to the gold inside the player's inventory?

 

 

If(akActionRef.GetItemCount(Gold001)>=GoldAmount)

 

Your own script. ?! ;) 

Posted

I am seeing Gold001 MiscObject Gold001 (0000000F)

 

Do I need to change 0000000F to something else?


 

Gold001 is supposed to be the gold inside the player's inventory? How do I link Gold001 to the gold inside the player's inventory?

 

 

If(akActionRef.GetItemCount(Gold001)>=GoldAmount)

 

Your own script. ?! ;) 

 

 

I just asked someone to write a script that would give me or remove 50 gold from my inventory when clicking an item.

Posted

I am seeing Gold001 MiscObject Gold001 (0000000F)

 

Do I need to change 0000000F to something else?

 

 

 

Gold001 is supposed to be the gold inside the player's inventory? How do I link Gold001 to the gold inside the player's inventory?

 

 

If(akActionRef.GetItemCount(Gold001)>=GoldAmount)

 

Your own script. ?! wink.png

 

 

I just asked someone to write a script that would give me or remove 50 gold from my inventory when clicking an item.

 

post-1144974-0-86988100-1483922664_thumb.png

It should look something like this

Posted

I am seeing Gold001 MiscObject Gold001 (0000000F)

 

Do I need to change 0000000F to something else?

 

Gold001 is supposed to be the gold inside the player's inventory? How do I link Gold001 to the gold inside the player's inventory?

 

 

If(akActionRef.GetItemCount(Gold001)>=GoldAmount)

 

Your own script. ?! ;) 

 

 

I just asked someone to write a script that would give me or remove 50 gold from my inventory when clicking an item.

 

 

MiscObject Property Gold001 Auto

 

Gold001 is just a name, a variable.

The value of this variable must be in the Quest / Magiceffekt / etc. With properties.
 
It can be gold 0000000f or other things - your decision
Posted

Isn't this how it's supposed to be?

 

 


 

I am seeing Gold001 MiscObject Gold001 (0000000F)
 
Do I need to change 0000000F to something else?
 

 

Gold001 is supposed to be the gold inside the player's inventory? How do I link Gold001 to the gold inside the player's inventory?

 
 
If(akActionRef.GetItemCount(Gold001)>=GoldAmount)
 
Your own script. ?! wink.png

 

 
I just asked someone to write a script that would give me or remove 50 gold from my inventory when clicking an item.

 

attachicon.gifCapture2.PNG
It should look something like this

 

 

Yeah, that's what I got basically. The question is if scripts can be attached to an activator. Do I need to make a Quest script for it to work or something?

post-1030654-0-62938500-1483922771_thumb.png

Posted

Ok, I fixed it.

 

Used:

 

Game.GetPlayer().GetGoldAmount()

 

and now it works.

 

Thanks guys.

 

Also, if you can create nif for backgammon board, checker board and playing card deck. Please, let me know.

Archived

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

  • Recently Browsing   0 members

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