Skip to content

Instantly share code, notes, and snippets.

@loopyd
Last active March 21, 2022 10:23
Show Gist options
  • Save loopyd/008de95bfe00af09e0265871870c42ce to your computer and use it in GitHub Desktop.
Save loopyd/008de95bfe00af09e0265871870c42ce to your computer and use it in GitHub Desktop.
[YAGPDB] Simple RPG
{{/* SimpleRPG - YAGPDB Script by saber7ooth#6911 */}}
{{/* Enemy dad-abase (ahaha) - Now that you now how it works, ya can add more! */}}
{{$enemyDB := cslice
(sdict "Enemy" "Dragon" "Odds" (cslice 1 250) "SuccessMessage" "You managed to defeat the dragon!" "FailMessage" "You were burnt to a crisp while trying to murder the dragon..." "SuccessFlag" (sdict "AddSlain" 1) "FailFlag" (sdict "AddDefeated" 1) )
(sdict "Enemy" "Pegasus" "Odds" (cslice 1 250) "SuccessMessage" "You managed to kill it before it flew away!" "FailMessage" "The pegasus flew away..." "SuccessFlag" (sdict "AddSlain" 1) "FailFlag" (sdict "Nothing" 0))
(sdict "Enemy" "Unicorn" "Odds" (cslice 1 250) "SuccessMessage" "You managed to kill it and take it's prismatic horn!" "FailMessage" "The pegasus flew away..." "SuccessFlag" (sdict "AddSlain" 1) "FailFlag" (sdict "AddDamage" 1))
(sdict "Enemy" "Fairy Queen" "Odds" (cslice 1 250) "SuccessMessage" "You successfully defeated the Fairy Queen and stole her treasures!" "FailMessage" "You got paralyzed by the Fairy Queen. You were tortured in her dungeon..." "SuccessFlag" (sdict "AddSlain" 1 "AddTreasure" 1) "FailFlag" (sdict "AddDamage" 1)) }}
{{/* Template to find an enemy to fight based on its odds. */}}
{{ define "findEnemy"}}
{{- $dot := . -}}
{{- .Set "Found" false -}} {{- $roll := 1 -}}
{{- range $i, $v := .EnemyDB -}}
{{- if eq $dot.Found false -}}
{{- $roll = (randInt 1 (index $v.Odds 1) ) -}}
{{- if and (ge $roll 1) (le $roll (index $v.Odds 0) ) -}}
{{- $dot.Set "Out" $v }} {{ $dot.Set "Found" true -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if eq .Found false -}}
{{- template "findEnemy" . -}}
{{- end -}}
{{- end -}} πŸšΆβ€β™‚οΈ You went out searching for a **battle**! {{- template "findEnemy" $a := sdict "EnemyDB" $enemyDB }} {{ $a = $a.Out }}
βš” You found a... **{{$a.Enemy}}** ! {{- $roll := randInt 1 100 }} {{ $aa := sdict}}
{{if and (ge $roll 1) (le $roll 50 ) }}
{{- printf "😎 %s" $a.SuccessMessage }}
{{- $aa = $a.SuccessFlag }}
{{- else }}
{{- printf "πŸ™ %s" $a.FailMessage }}
{{- $aa = $a.FailFlag }}
{{end }}
{{- $s := 0 }} {{ $t := 0 }} {{ $dot := .}}
{{range $k, $v := $aa}}
{{- if eq $k "AddSlain" }}
{{- if not ($s = toInt (dbGet $dot.User.ID "Kills").Value) }}
{{- dbSet $dot.User.ID "Kills" (str 0) -}} {{- $s = 0 -}}
{{- end -}}
{{- $s = add $s $v }} {{- dbSet $dot.User.ID "Kills" (str $s) -}}
πŸ† You now have **{{ $s }}** kills!
{{- else if eq $k "AddDefeated" }}
{{- if not ($s = toInt (dbGet $dot.User.ID "Deaths").Value) }}
{{- dbSet $dot.User.ID "Deaths" (str 0)}}
{{- $s = 0 -}}
{{- end}}
{{- $s = add $s $v }}
{{- dbSet $dot.User.ID "Deaths" (str $s) -}}
☠ You now have **{{ $s }}** deaths!
{{- else if eq $k "AddTreasure" }}
{{- if not ($s = toInt (dbGet $dot.User.ID "Treasures").Value) }}
{{- dbSet $dot.User.ID "Treasures" (str 0) }}
{{- $s = 0 -}}
{{- end}}
{{- $s = add $s $v }}
{{- dbSet $dot.User.ID "Treasures" (str $s) -}}
πŸŽ‡ You now have **{{ $s }}** treasures!
{{- else if eq $k "AddDamage" }}
{{- if not ($s = toInt (dbGet $dot.User.ID "HP").Value) }}
{{- if not ($t = toInt (dbGet $dot.User.ID "MaxHP").Value) }}
{{- dbSet $dot.User.ID "MaxHP" (str 20) }}
{{- dbSet $dot.User.ID "HP" (str 20) }}
{{- $s = 20 -}}
{{- else}}
{{- $s = toInt (dbGet .User.ID "MaxHP").Value }}
{{- dbSet $dot.User.ID "HP" (str $s) -}}
{{- end}}
{{- end}}
{{- $t = sub $s $v }}
{{- if lt $t 0 }}
{{- $t = toInt (dbGet $dot.User.ID "MaxHP").Value }} {{- $s = $t -}} ☠ Your HP dropped below zero! You have died and your HP has been restored. HP: (__**0**__ / ** **{{- $s }}**)
{{- else}} 😩 You took **{{ $v }}** points of damage! HP: (**{{ $t }}** / **{{ $s }}**)
{{- end}}
{{- dbSet $dot.User.ID "HP" $s -}}
{{- end}}
{{end}}
@ZekeBXG
Copy link

ZekeBXG commented Mar 21, 2022

Hey man, this is ZBXG. I just wanted to say that this is very amazing, thanks for making this! Sorry to say this but I'm gonna have to use my old code, but I will use this to get ideas and improve further on. Again, thanks for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment