Get integer from lore

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the community!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

GamingGeek

Supporter
Aug 1, 2017
46
0
0
Skript Version: Skript 2.2
Skript Author: Mirreski
Minecraft Version: 1.8.8

I'm trying to make a banknotes skript and I want players to be able to rightclick and redeem the banknote. I was thinking that if the amount of money the banknote is worth is in the name/lore, then there might be a way to use that in the command (/eco give <player> [amount goes here]) e.g. lore of player's held item as an integer, so removing everything that isn't an integer and insert it into the command.
 
code_language.skript:
set {_lore} to "Test 5"
set {_lore::*} to split {_lore} at " "
set {_integer} to {_lore::2}
 
on rightclick with paper:
code_language.skript:
    if the name of player's tool contains "bank note":
        set {_mon::*} to line 1 of the lore of the player's tool split at "$"
        set {_mon::2} to {_mon::2} parsed as an integer
        add {_mon::2} to player's balance
 
Last edited by a moderator:
code_language.skript:
#If unknown format, and the format changes
set {_ints::*} to (split (join (split lore of player's tool at "||") with " ") at " ") where [string input parsed as an int is set]

#If not unknown
set {_int} to first element out of (lore of player's tool parsed as "Format %int%")
 
set {_ints::*} to (split (join (split lore of player's tool at "||") with " ") at " ") where [string input parsed as an int is set]
You know that you don't need make it one line, it'll just make it slower at parse-time.
 
You know that you don't need make it one line, it'll just make it slower at parse-time.
It takes longer/about the same when split into multiple lines. It doesn't really matter anyway, the parse time is under half a second even on low spec hardware (this was tested on a raspi3)
Mo51c7E.png
 
Thanks! I managed to get it working. Here's the working code:
code_language.skript:
on rightclick holding paper:
    if name of player's held item contains "Banknote":
        set {_amount::*} to line 1 of the lore of the player's held item split at "$"
        execute console command "/eco give %player% %{_amount::2}%"
        remove held item from player
 
Status
Not open for further replies.