YesNoOk
avatar

Score System (Read 16849 times)

Started by RajaaBoy, January 04, 2013, 03:20:11 pm
Share this topic:
Score System
New #1  January 04, 2013, 03:20:11 pm
  • ******
  • I will absolve you of your original colors.
    • www.bluehitbox.com
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.

Spoiler: Place this in the Statedef -2 (click to see content)

Code:

;==================================================================================================================================================
; 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)

Last Edit: February 10, 2013, 02:30:54 pm by Rajaa
Re: Score System
#2  January 04, 2013, 04:30:13 pm
  • ***
  • Come mighty warrior face me
    • Indonesia
    • Skype - Rizki291
finally you answered what i ask once thanks so helping =D
Re: Score System
#3  January 04, 2013, 04:48:00 pm
  • ******
  • I will absolve you of your original colors.
    • www.bluehitbox.com
Well, I needed to code it for a commission, so that was kinda some motivation. =p

I actually started this code in java and translated it to Mugen (where it became much longer because no arrays and only one control flow function, etc). =p
Re: Score System
#4  January 04, 2013, 06:32:25 pm
  • ****
  • Shakespear.
Bad ass.  I can see this working out very nicely in a full game.
Re: Score System
#5  January 04, 2013, 07:27:20 pm
  • ****
    • Brazil
    • Skype - adriano_gt2005@hotmail.com
    • www.facebook.com/groups/mortalkombatmugenkommunity/
Very interesting.
The sprites, the numbers should go in the SFF char?
And if I want to put in FIGHT.SFF?
Thanks for sharing
Re: Score System
#6  January 04, 2013, 07:36:47 pm
  • ******
  • I will absolve you of your original colors.
    • www.bluehitbox.com
The sprites can go either way, now that I think about it. Instead of placing them in the character, you can place them in the fightfx.sff, then make the corresponding animations in the fightfx.air, and then, finally, in the explods that display each place value, just change the anim parameter to resemble this: "anim = F(10000 + var(2))" and you should be good to go. That way you don't need to bother with inserting the sprites for every character. I assume you'd do that in a full game in which every character shares the same common states, even the -2 and -3 states.

This code is mostly bare bones and is simply used to set up a basis for anyone's score system. It's up to you if you want to use root variables so the score can transfer rounds and stuff. I played it safe and just used helper variables so people who copy-paste it won't mess up their character by overlapping variables and stuff.

With root variables being used, one could increase the score by just placing varadds throughout the various player states accordingly.

Glad some people find this useful.
Re: Score System
#7  January 04, 2013, 08:10:23 pm
  • ****
    • Brazil
    • Skype - adriano_gt2005@hotmail.com
    • www.facebook.com/groups/mortalkombatmugenkommunity/
Yes... very useful
thanx for help me.
Re: Score System
#8  January 04, 2013, 08:46:01 pm
  • ******
  • I will absolve you of your original colors.
    • www.bluehitbox.com
Considering the code even further, it can even be used to display numbers for pretty much any value. Just summon a couple of the helpers, make the "score variable" equal a constantly changing value like life, power ,or velocity, and you can pretty much just display any value you want. Could be useful for a lot of things.

I'm sure people will adapt it as they see fit.
Re: Score System
#9  January 05, 2013, 02:04:04 am
  • ***
  • Young Coder
    • USA
man i would love to see this in a full game no doubt. this is pretty amazing
mugen or nothin

Re: Score System
#10  January 05, 2013, 06:14:28 am
  • ******
  • I will absolve you of your original colors.
    • www.bluehitbox.com
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:

Code:
; 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)
Last Edit: January 05, 2013, 07:48:03 am by Rajaa
Re: Score System
#11  January 05, 2013, 10:38:49 am
  • ***
  • Come mighty warrior face me
    • Indonesia
    • Skype - Rizki291
=o one question what group in sff is it ?
like group 0 image 1
Re: Score System
#12  January 05, 2013, 11:16:38 am
  • ******
  • I will absolve you of your original colors.
    • www.bluehitbox.com
The index of the sprites in the .sff is up to you. It's pretty clear that I used 10000, though. O_O
Re: Score System
#13  January 05, 2013, 12:19:39 pm
  • ***
  • Come mighty warrior face me
    • Indonesia
    • Skype - Rizki291
sorry XD my bad