gunabuse Posted January 8, 2017 Share Posted January 8, 2017 I would like to make a script that gives 50 gold 50% of the time and removes 50 gold 50% of the time and that works whenever the player activate the object the script is attached to. Link to comment Share on other sites More sharing options...
NexusComa Posted January 8, 2017 Share Posted January 8, 2017 Scriptname _aaa_FiftyFifty Extends ObjectReference ;* Fifty gold, fifty percent of the time MiscObject Property Gold001 Auto Actor Property PlayerRef Auto Int Property Gold Auto ; Event OnInit() GoToState("Done") EndEvent ; Event OnActivate(ObjectReference akActionRef) If(akActionRef==(PlayerRef)) If(PlayerRef.GetItemCount(Gold001)>=(Gold)) If(Utility.RandomInt(0,1)==(0)) PlayerRef.AddItem(Gold001, Gold) Else PlayerRef.RemoveItem(Gold001, Gold) EndIf Else ; Debug.Notification("Not enough gold") Endif Endif GoToState("Done") EndEvent ; State Done ;do nothing EndState ; Link to comment Share on other sites More sharing options...
gunabuse Posted January 8, 2017 Author Share Posted January 8, 2017 Wait, what is Gold001 and where is it defined? Sorry, I am a complete newb. lol Link to comment Share on other sites More sharing options...
gunabuse Posted January 8, 2017 Author Share Posted January 8, 2017 Scriptname _aaa_FiftyFifty Extends ObjectReference ;* Fifty gold, fifty percent of the time MiscObject Property Gold001 50 Actor Property PlayerRef Auto Int Property Gold Auto ; Event OnInit() GoToState("Done") EndEvent ; Event OnActivate(ObjectReference akActionRef) If(akActionRef==(PlayerRef)) If(PlayerRef.GetItemCount(50)>=(Gold)) If(Utility.RandomInt(0,1)==(0)) PlayerRef.AddItem(50, Gold) Else PlayerRef.RemoveItem(50, Gold) EndIf Else ; Debug.Notification("Not enough gold") Endif Endif GoToState("Done") EndEvent ; State Done ;do nothing EndState ;Shouldn't it be like this? Link to comment Share on other sites More sharing options...
gunabuse Posted January 8, 2017 Author Share Posted January 8, 2017 (edited) Scriptname _aaa_FiftyFifty Extends ObjectReference ;* Fifty gold, fifty percent of the time MiscObject Property Gold001 Auto Actor Property PlayerRef Auto Int Property Gold = 50 Auto ; Event OnInit() GoToState("Done") EndEvent ; Event OnActivate(ObjectReference akActionRef) If(akActionRef==(PlayerRef)) If(PlayerRef.GetItemCount(Gold001)>=(Gold)) If(Utility.RandomInt(0,1)==(0)) PlayerRef.AddItem(Gold001, Gold) Else PlayerRef.RemoveItem(Gold001, Gold) EndIf Else ; Debug.Notification("Not enough gold") Endif Endif GoToState("Done") EndEvent ; State Done ;do nothing EndState ; Shouldn't it be like this actually? Edited January 8, 2017 by gunabuse Link to comment Share on other sites More sharing options...
FrankFamily Posted January 8, 2017 Share Posted January 8, 2017 The thing about "Int Property Gold Auto" is that you can give the property any value later in ck and change it without needing to change and recompile the script. If you are going to do "Int Property Gold = 50 Auto" no need to make it a property, and even more, no need to have a variable, if you are going to write the value in script you might aswell just write it where its used. You fill (or autofill in this case) Gold001 with the gold object in ck Why the state stuff? Currently it goes oninit and after running to state "done", never exists it but doesn't matter since there's nothing there, so it's just picking the function from the empty state. Unless i'm missing somthing i'd just remove the whole state thing. You could do a busy state to avoid simultaneous runs of the script if the player clicks a lot of times on the activator for example, but the current, afaik, does nothing. Something like this is what i mean: Event something() gotostate("busy") ;do all the long stuff gotostate("") ; i.e. back to empty state where the full function is. endevent state Busy Event something() ; here do nothing but event declaration is needed to overwrite the one in the empty state Endevent endstateBasically i'd do it like this: Scriptname _aaa_FiftyFifty Extends ObjectReference MiscObject Property Gold001 Auto Int Property GoldAmount 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 Link to comment Share on other sites More sharing options...
gunabuse Posted January 8, 2017 Author Share Posted January 8, 2017 yeah, the script doesn't work... I will try yours. Link to comment Share on other sites More sharing options...
gunabuse Posted January 8, 2017 Author Share Posted January 8, 2017 Scriptname _aaa_FiftyFifty Extends ObjectReference MiscObject Property Gold001 AutoInt Property GoldAmount = 50 AutoEvent 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("")EndEventState BusyEvent OnActivate(ObjectReference akActionRef);EndEventEndState Link to comment Share on other sites More sharing options...
gunabuse Posted January 8, 2017 Author Share Posted January 8, 2017 Ok, it doesn't work either. It keeps saying Not enough gold over and over again even though I have 1901 gold in my inventory. Link to comment Share on other sites More sharing options...
gunabuse Posted January 9, 2017 Author Share Posted January 9, 2017 Hey, how do you get the amount of gold from the player's inventory? It says I have 0 Gold001. Link to comment Share on other sites More sharing options...
Recommended Posts