Jump to content

[LE] simple gamble script


gunabuse

Recommended Posts



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

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


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

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
endstate

Basically 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

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

Link to comment
Share on other sites

  • Recently Browsing   0 members

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