Hello.
Change Statedef values and stuff according to your own needs. This code is copy-paste-able. This code can be modified to have score increase instantly or have score increase incrementally (like a slot machine) -- just read the notes within it.
This code can be modified to have score increase and decrease for any condition you want -- it defaults to increasing score if your character hits an opponent and decreasing score if your character is hit by an opponent.
Credit-smedit, if you need this, use it; I am nobody; I am just a brain posting some code for everyone to use. Let me know if something breaks. This was working fine when I tested it.
Download these number images and follow the obvious steps. (http://www.justnopoint.com/lithues/.tangential/resources/numbers.rar)
Spoiler: Place this in the Statedef -2 (click to see content)
[state -2, Scoring System by RajaaBoy]
type = helper
trigger1 = !numhelper(10000)
name = "Scoring System by RajaaBoy"
ID = 10000
stateno = 10000
postype = p1
ownpal = 1
keyctrl = 0
size.xscale = 1.0
size.yscale = 1.0
supermovetime = 65535
pausemovetime = 65535
ignorehitpause = 1
;==================================================================================================================================================
; Scoring System by RajaaBoy
;==================================================================================================================================================
[Statedef 10000]
type = A
movetype = I
physics = N
ctrl = 0
velset = 0, 0
sprpriority = -65536
;========================< Essential State Controllers >========================
; Blank Animations
[state 10000, Change Animation]
type = changeanim
trigger1 = anim != 9999
value = 9999
; Bind to Parent (Optional)
[state 10000, Parent Bind]
type = bindtoparent
trigger1 = 1
pos = 0, -16
; Prevent Getting Hit
[state 10000, Vulnerability]
type = nothitby
trigger1 = 1
value = SCA
time = -1
; Return to This State if Miraculously Hit
[state 10000, Hit Override]
type = hitoverride
trigger1 = 1
attr = SCA,AA,AP,AT
stateno = stateno
slot = 0
time = -1
forceair = 0
;========================< Calculate Score >========================
; If you want the score to transfer between rounds, just change the varsets and varadds of var(0) and var(1) to parentvarsets and parentvaradds respectively --
; the variable triggers would need to be adjusted to be redirection triggers. "Var(0)" would become "parent,var(0)" and "var(1)" would become "parent,var(1)."
; The only variables that would need to changed to be root variables would be var(0) and var(1), everything else can remain the same.
; Alternatively, you can even leave var(0) and var(1) the same, and, instead, have var(0) constantly set to a value of its root variable.
; That way you wouldn't need to change the state controllers much, besides adding a "trigger1 = 1" to a varset that sets var(0) to your root's variable.
; Then you could just increase your root's variable from your root's states and the score would follow seamlessly.
; Reset Score at Beginning of Match
[state 10000, Reset Score]
type = varset
trigger1 = !time && !roundsexisted
var(0) = 0 + 0 * (var(59) := 0)
; Increase Score on Movehit (Change Triggers and Parameters Accordingly)
[state 10000, Increase Score]
type = varadd
trigger1 = root,movehit = 1 && var(59) = 0
var(0) = 152
; Decrease Score on Gethit (Change Triggers and Parameters Accordingly)
[state 10000, Decrease Score]
type = varadd
trigger1 = root,movetype = H && !root,hitover && root,stateno = [5000, 5199]
trigger1 = root,gethitvar(hitshaketime) && root,time <= 1 && var(59) = 0
var(0) = -72
; Allow the above state controllers to be activated again
[state 10000, Reset Controller Limiter]
type = varset
trigger1 = 1
var(59) = 0
; This limits the state controllers above to activating only during the tick that the score is changed.
; This state controller should contain the same triggers used to increase AND decrease var(0).
[state 10000, Controller Limiter]
type = varset
trigger1 = root,movehit = 1 && var(59) = 0
trigger2 = root,movetype = H && !root,hitover && root,stateno = [5000, 5199]
trigger2 = root,gethitvar(hitshaketime) && root,time <= 1 && var(59) = 0
var(59) = 1
;========================< Incrementally Calculate Score >========================
; Speed of Incrementation
[state 10000, Speed to Reach Actual Score]
type = varset
trigger1 = 1
fvar(0) = (var(0) - var(1)) / 96.0 ; change the divisor accordingly
; Optional:
; Use this variable in the Place Value section below.
; Replace var(0) with var(1) in the Place Value section below to have score increase incrementally instead of instantly.
[state 10000, Incrementally Increase Score]
type = varadd
trigger1 = var(0) != var(1)
var(1) = cond(var(0) > var(1), ceil(fvar(0)), floor(fvar(0)))
;========================< Prevent Score from Going out of Bounds >========================
; Keep Score bewteen 0 and 999,999,999
[state 10000, Limit Score]
type = varset
trigger1 = var(0) != [0, 999999999]
var(0) = cond(var(0) > 999999999, 999999999, 0)
[state 10000, Limit Score]
type = varset
trigger1 = var(1) != [0, 999999999]
var(1) = cond(var(1) > 999999999, 999999999, 0)
;========================< Detect Place Values >========================
[state 10000, Score For Ones Place]
type = varset
trigger1 = 1
var(2) = floor(var(0) / 1) % 10 ; * 1 ; uncomment to get exact amount of ones
; var(2) = floor(var(1) / 1) % 10 ; incrementally increase score
[state 10000, Score For Tens Place]
type = varset
trigger1 = 1
var(3) = floor(var(0) / 10) % 10 ; * 10 ; uncomment to get exact amount of tens
; var(3) = floor(var(1) / 10) % 10 ; incrementally increase score
[state 10000, Score For Hundreds Place]
type = varset
trigger1 = 1
var(4) = floor(var(0) / 100) % 10 ; * 100 ; uncomment to get exact amount of hundreds
; var(4) = floor(var(1) / 100) % 10 ; incrementally increase score
[state 10000, Score For Thousands Place]
type = varset
trigger1 = 1
var(5) = floor(var(0) / 1000) % 10 ; * 1000 ; uncomment to get exact amount of thousands
; var(5) = floor(var(1) / 1000) % 10 ; incrementally increase score
[state 10000, Score For Ten Thousands Place]
type = varset
trigger1 = 1
var(6) = floor(var(0) / 10000) % 10 ; * 10000 ; uncomment to get exact amount of ten thousands
; var(6) = floor(var(1) / 10000) % 10 ; incrementally increase score
[state 10000, Score For Hundred Thousands Place]
type = varset
trigger1 = 1
var(7) = floor(var(0) / 100000) % 10 ; * 100000 ; uncomment to get exact amount of hundred thousands
; var(7) = floor(var(1) / 100000) % 10 ; incrementally increase score
[state 10000, Score For Millions Place]
type = varset
trigger1 = 1
var(8) = floor(var(0) / 1000000) % 10 ; * 1000000 ; uncomment to get exact amount of millions
; var(8) = floor(var(1) / 1000000) % 10 ; incrementally increase score
[state 10000, Score For Ten Millions Place]
type = varset
trigger1 = 1
var(9) = floor(var(0) / 10000000) % 10 ; * 10000000 ; uncomment to get exact amount of ten millions
; var(9) = floor(var(1) / 10000000) % 10 ; incrementally increase score
[state 10000, Score For Hundred Millions Place]
type = varset
trigger1 = 1
var(10) = floor(var(0) / 100000000) % 10 ; * 100000000 ; uncomment to get exact amount of hundred millions
; var(10) = floor(var(1) / 100000000) % 10 ; incrementally increase score
[state 10000, Score For Billions Place]
type = varset
trigger1 = 1
var(11) = floor(var(0) / 1000000000) % 10 ; * 1000000000 ; uncomment to get exact amount of billions
; var(11) = floor(var(1) / 1000000000) % 10 ; incrementally increase score
;========================< Display Score on Screen >========================
; The following code assumes your number fonts have dimensions of 8x8 and are aligned at 0,0 on the axis
; Your air file should have 10 animations that represent numbers 0 - 9 respectively.
; The animations in the air files should be numbered logically. Meaning, they must all have the same basic multiple, like this:
; Sequence A: 10000, 10001, 10002, 10003, 10004, etc
; Sequence B: 10000, 10005, 10010, 10015, 10020, etc
; If you chose Sequence A, then you would simply add the variable that corresponds to the place value for your explod to 10000, like so:
; anim = 10000 + var(2) ; ones place
; If var(2) is 1, then it will add 1 to 10000 and the animation that represents the number 1 will be played.
; If you chose Sequence B, then you would simply multiply the variable that corresponds to the place value for your explod by 5, and then you would add it to 10000, like so:
; anim = 10000 + 5 * var(2) ; ones place
; If var(2) is 1, then it will add 5 to 10000 and the animation that represents the number 1 will be played.
; For this code snippet, we will use Sequence A from above.
; Constantly destroys explods so that their animations can change.
; For Some Reason, modifyexplod doesn't allow the changing of explods' animations
[state 10000, Reset]
type = removeexplod
trigger1 = 1
[state 10000, Ones]
type = explod
trigger1 = !numexplod(0)
anim = 10000 + var(2)
ID = 0
postype = left
pos = cond(teamside = 1, 72, 312), ceil((1.33 * gameheight / gamewidth) * 0) ; top left of screen for player 1, top right for player 2
bindtime = 1
facing = 1
ownpal = 0
sprpriority = -65536
pausemovetime = -1
supermovetime = -1
[state 10000, Tens]
type = explod
trigger1 = !numexplod(1)
anim = 10000 + var(3)
ID = 1
postype = left
pos = cond(teamside = 1, 64, 304), ceil((1.33 * gameheight / gamewidth) * 0) ; top left of screen for player 1, top right for player 2
bindtime = -1
facing = 1
ownpal = 0
sprpriority = -65536
pausemovetime = -1
supermovetime = -1
[state 10000, Hundreds]
type = explod
trigger1 = !numexplod(2)
anim = 10000 + var(4)
ID = 2
postype = left
pos = cond(teamside = 1, 56, 296), ceil((1.33 * gameheight / gamewidth) * 0) ; top left of screen for player 1, top right for player 2
bindtime = -1
facing = 1
ownpal = 0
sprpriority = -65536
pausemovetime = -1
supermovetime = -1
[state 10000, Thousands]
type = explod
trigger1 = !numexplod(3)
anim = 10000 + var(5)
ID = 3
postype = left
pos = cond(teamside = 1, 48, 288), ceil((1.33 * gameheight / gamewidth) * 0) ; top left of screen for player 1, top right for player 2
bindtime = -1
facing = 1
ownpal = 0
sprpriority = -65536
pausemovetime = -1
supermovetime = -1
[state 10000, Ten Thousands]
type = explod
trigger1 = !numexplod(4)
anim = 10000 + var(6)
ID = 4
postype = left
pos = cond(teamside = 1, 40, 280), ceil((1.33 * gameheight / gamewidth) * 0) ; top left of screen for player 1, top right for player 2
bindtime = -1
facing = 1
ownpal = 0
sprpriority = -65536
pausemovetime = -1
supermovetime = -1
[state 10000, Hundred Thousands]
type = explod
trigger1 = !numexplod(5)
anim = 10000 + var(7)
ID = 5
postype = left
pos = cond(teamside = 1, 32, 272), ceil((1.33 * gameheight / gamewidth) * 0) ; top left of screen for player 1, top right for player 2
bindtime = -1
facing = 1
ownpal = 0
sprpriority = -65536
pausemovetime = -1
supermovetime = -1
[state 10000, Millions]
type = explod
trigger1 = !numexplod(6)
anim = 10000 + var(8)
ID = 6
postype = left
pos = cond(teamside = 1, 24, 264), ceil((1.33 * gameheight / gamewidth) * 0) ; top left of screen for player 1, top right for player 2
bindtime = -1
facing = 1
ownpal = 0
sprpriority = -65536
pausemovetime = -1
supermovetime = -1
[state 10000, Ten Millions]
type = explod
trigger1 = !numexplod(7)
anim = 10000 + var(9)
ID = 7
postype = left
pos = cond(teamside = 1, 16, 256), ceil((1.33 * gameheight / gamewidth) * 0) ; top left of screen for player 1, top right for player 2
bindtime = -1
facing = 1
ownpal = 0
sprpriority = -65536
pausemovetime = -1
supermovetime = -1
[state 10000, Hundred Millions]
type = explod
trigger1 = !numexplod(8)
anim = 10000 + var(10)
ID = 8
postype = left
pos = cond(teamside = 1, 8, 248), ceil((1.33 * gameheight / gamewidth) * 0) ; top left of screen for player 1, top right for player 2
bindtime = -1
facing = 1
ownpal = 0
sprpriority = -65536
pausemovetime = -1
supermovetime = -1
[state 10000, Billions]
type = explod
trigger1 = !numexplod(9)
anim = 10000 + var(11)
ID = 9
postype = left
pos = cond(teamside = 1, 0, 240), ceil((1.33 * gameheight / gamewidth) * 0) ; top left of screen for player 1, top right for player 2
bindtime = -1
facing = 1
ownpal = 0
sprpriority = -65536
pausemovetime = -1
supermovetime = -1
;========================< Reset Score System >========================
[state 10000, Destroy Explod]
type = removeexplod
trigger1 = time >= 65535
[state 10000, Destroy Helper]
type = destroyself
trigger1 = time >= 65535
;========================< Debug Information >========================
[state 10000, Display System]
type = displaytoclipboard
trigger1 = 1
text = "Score = %d / %d / %f || RajaaBoy \n"
params = var(0), var(1), fvar(0)
[state 10000, Display System]
type = appendtoclipboard
trigger1 = 1
text = "Place Values = %d,%d,%d,%d,%d,%d,"
params = var(11), var(10), var(9), var(8), var(7), var(6)
[state 10000, Display System]
type = appendtoclipboard
trigger1 = 1
text = "%d,%d,%d,%d"
params = var(5), var(4), var(3), var(2)
Added some more detailed notes about what variables actually need to be changed for the score to reset between rounds. Answer is to just constantly set var(0) to a variable by your root.
I don't feel like typing up code tutorial style for this, but getting decimals for this is done by a similar method. It's as simple as:
; Float Value as Score
[state 10000, Score value]
type = varset
trigger1 = 1
fvar(0) = 123.456 - floor(123.456) ; "123.456" should be whatever value you want for your score, this is just an example
; Calculate Number of Tenths
[state 10000, Score for Tenths Place]
type = varset
trigger1 = 1
var(0) = floor(fvar(0) * 10) % 10
; Calculate Number of Hundredths
[state 10000, Score for Hundredths Place]
type = varset
trigger1 = 1
var(1) = floor(fvar(0) * 100) % 10
; Calculate Number of Thousandths
[state 10000, Score for Thousandths Place]
type = varset
trigger1 = 1
var(2) = floor(fvar(0) * 1000) % 10
Negatives numbers are as simple as adjusting the limiter and adding a negative operator when the subject variable's value is below 0. Adjusting the explods is up to you.
Hope that helps even further.
Edit:
Eh, I'm generous, so I'll add a watered-down version that displays decimals. Value is based on pos y to give an example of how it works. That's as far as I'm going with this code! Hope it's useful to you all:
Spoiler: Watered-down Version to display Decimals (click to see content)
;=========================================================================
; Scoring System by RajaaBoy
;=========================================================================
[Statedef 10000]
type = A
movetype = I
physics = N
ctrl = 0
velset = 0, 0
sprpriority = -65536
;========================< Essential State Controllers >========================
; Blank Animations
[state 10000, Change Animation]
type = changeanim
trigger1 = anim != 9999
value = 9999
; Bind to Parent (Optional)
[state 10000, Parent Bind]
type = bindtoparent
trigger1 = 1
pos = 0, -16
; Prevent Getting Hit
[state 10000, Vulnerability]
type = nothitby
trigger1 = 1
value = SCA
time = -1
; Return to This State if Miraculously Hit
[state 10000, Hit Override]
type = hitoverride
trigger1 = 1
attr = SCA,AA,AP,AT
stateno = stateno
slot = 0
time = -1
forceair = 0
;========================< Calculate Score >========================
; Calculate Score
[state 10000, Get Score]
type = varset
trigger1 = 1
fvar(0) = -pos y
;========================< Prevent Score from Going out of Bounds >========================
; Keep Score bewteen 0 and 999
[state 10000, Limit Score]
type = varset
trigger1 = fvar(0) != [0, 999]
fvar(0) = cond(fvar(0) > 999, 999, 0)
;========================< Calculate Decimals >========================
[state 10000, Get Decimal]
type = varset
trigger1 = 1
fvar(1) = fvar(0) - floor(fvar(0))
;========================< Detect Place Values >========================
[state 10000, Score For Ones Place]
type = varset
trigger1 = 1
var(0) = floor(fvar(0) / 1) % 10 ; * 1 ; uncomment to get exact amount of ones
[state 10000, Score For Tens Place]
type = varset
trigger1 = 1
var(1) = floor(fvar(0) / 10) % 10 ; * 10 ; uncomment to get exact amount of tens
[state 10000, Score For Hundreds Place]
type = varset
trigger1 = 1
var(2) = floor(fvar(0) / 100) % 10 ; * 100 ; uncomment to get exact amount of hundreds
;========================< Detect Decimal Place Values >========================
[state 10000, Score For Tenths Place]
type = varset
trigger1 = 1
var(3) = floor(fvar(1) * 10) % 10
[state 10000, Score For Hundredths Place]
type = varset
trigger1 = 1
var(4) = floor(fvar(1) * 100) % 10
[state 10000, Score For Thousandtha Place]
type = varset
trigger1 = 1
var(5) = floor(fvar(1) * 1000) % 10
;========================< Display Score on Screen >========================
; The following code assumes your number fonts have dimensions of 8x8 and are aligned at 0,0 on the axis
; Your air file should have 10 animations that represent numbers 0 - 9 respectively.
; The animations in the air files should be numbered logically. Meaning, they must all have the same basic multiple, like this:
; Sequence A: 10000, 10001, 10002, 10003, 10004, etc
; Sequence B: 10000, 10005, 10010, 10015, 10020, etc
; If you chose Sequence A, then you would simply add the variable that corresponds to the place value for your explod to 10000, like so:
; anim = 10000 + var(2) ; ones place
; If var(2) is 1, then it will add 1 to 10000 and the animation that represents the number 1 will be played.
; If you chose Sequence B, then you would simply multiply the variable that corresponds to the place value for your explod by 5, and then you would add it to 10000, like so:
; anim = 10000 + 5 * var(2) ; ones place
; If var(2) is 1, then it will add 5 to 10000 and the animation that represents the number 1 will be played.
; For this code snippet, we will use Sequence A from above.
; Constantly destroys explods so that their animations can change.
; For Some Reason, modifyexplod doesn't allow the changing of explods' animations
[state 10000, Reset]
type = removeexplod
trigger1 = 1
[state 10000, Ones]
type = explod
trigger1 = !numexplod(0)
anim = F10000 + var(0)
ID = 0
postype = left
pos = cond(teamside = 1, 72, 248), ceil((1.33 * gameheight / gamewidth) * 0) ; top left of screen for player 1, top right for player 2
bindtime = 1
facing = 1
ownpal = 0
sprpriority = -65536
pausemovetime = -1
supermovetime = -1
[state 10000, Tens]
type = explod
trigger1 = !numexplod(1)
anim = F10000 + var(1)
ID = 1
postype = left
pos = cond(teamside = 1, 64, 240), ceil((1.33 * gameheight / gamewidth) * 0) ; top left of screen for player 1, top right for player 2
bindtime = -1
facing = 1
ownpal = 0
sprpriority = -65536
pausemovetime = -1
supermovetime = -1
[state 10000, Hundreds]
type = explod
trigger1 = !numexplod(2)
anim = F10000 + var(2)
ID = 2
postype = left
pos = cond(teamside = 1, 56, 232), ceil((1.33 * gameheight / gamewidth) * 0) ; top left of screen for player 1, top right for player 2
bindtime = -1
facing = 1
ownpal = 0
sprpriority = -65536
pausemovetime = -1
supermovetime = -1
[state 10000, Period]
type = explod
trigger1 = !numexplod(100)
anim = F10000
ID = 100
postype = left
pos = cond(teamside = 1, 77, 253), ceil((1.33 * gameheight / gamewidth) * 4) ; top left of screen for player 1, top right for player 2
bindtime = -1
facing = 1
ownpal = 0
sprpriority = -65536
scale = 0.35, 0.35
pausemovetime = -1
supermovetime = -1
[state 10000, Tenths]
type = explod
trigger1 = !numexplod(3)
anim = F10000 + var(3)
ID = 3
postype = left
pos = cond(teamside = 1, 80, 256), ceil((1.33 * gameheight / gamewidth) * 0) ; top left of screen for player 1, top right for player 2
bindtime = -1
facing = 1
ownpal = 0
sprpriority = -65536
pausemovetime = -1
supermovetime = -1
[state 10000, Hundredths]
type = explod
trigger1 = !numexplod(4)
anim = F10000 + var(4)
ID = 4
postype = left
pos = cond(teamside = 1, 88, 264), ceil((1.33 * gameheight / gamewidth) * 0) ; top left of screen for player 1, top right for player 2
bindtime = -1
facing = 1
ownpal = 0
sprpriority = -65536
pausemovetime = -1
supermovetime = -1
[state 10000, Thousandths]
type = explod
trigger1 = !numexplod(5)
anim = F10000 + var(5)
ID = 5
postype = left
pos = cond(teamside = 1, 96, 272), ceil((1.33 * gameheight / gamewidth) * 0) ; top left of screen for player 1, top right for player 2
bindtime = -1
facing = 1
ownpal = 0
sprpriority = -65536
pausemovetime = -1
supermovetime = -1
;========================< Reset Score System >========================
[state 10000, Destroy Explod]
type = removeexplod
trigger1 = time >= 65535
[state 10000, Destroy Helper]
type = destroyself
trigger1 = time >= 65535
;========================< Debug Information >========================
[state 10000, Display System]
type = displaytoclipboard
trigger1 = 1
text = "Score = %f / %f || RajaaBoy \n"
params = fvar(0), fvar(1)
[state 10000, Display System]
type = appendtoclipboard
trigger1 = 1
text = "Place Values = %d,%d,%d || %d,%d,%d,"
params = var(2), var(1), var(0), var(3), var(4), var(5)