Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

randompercentage and randomelement Script Commands #4189

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions asm/macros/event.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2133,3 +2133,34 @@
callnative ToggleGigantamaxFactor
.2byte \slot
.endm

@ Sets VAR_RESULT to one of the arguments (via setorcopyvar).
.macro randomelement element:req, elements:vararg
.set _randomelement_n, 0
.irp el, \element, \elements
.set _randomelement_n, _randomelement_n + 1
.endr
random _randomelement_n

.set _randomelement_n, 0
.irp el, \element, \elements
goto_if_ne VAR_RESULT, _randomelement_n, 1f
setorcopyvar VAR_RESULT, \el
goto 2f
1:
.set _randomelement_n, _randomelement_n + 1
.endr
2:
.endm

@ Sets VAR_RESULT to TRUE with probability 'percent', and FALSE
@ with probability '100% - percent'.
.macro randompercentage percent:req
random 100
goto_if_lt VAR_RESULT, \percent, 1f
setvar VAR_RESULT, FALSE
goto 2f
1:
setvar VAR_RESULT, TRUE
2:
.endm
Loading