Discord Thread Parsing as integer makes conditions not work

  • 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 comminuty!

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

This thread came from the skUnity Discord. You can't reply to it here but if you join the skUnity Discord, you'll be able to post a reply there. The thread link is part of the thread's message.
Status
Not open for further replies.

skUnity Discord

Site Manager
Aug 5, 2023
12,755
0
0
The skUnity Discord
discord.gg
code_language.skript:
on load:
  set {pistol} to 1 of wooden hoe named "&ePistol"
  set {_lore::*} to " ||&r&fPistol's Stats:||&r&fDamage: 6||&r&fFire Rate: 0.5||&r&fAmmunition: 300/300||&r&fClip: 10||&r&fReload Time: 1.5|| " split at "||"
  loop size of {_lore::*} times:
    set line loop-number of {pistol}'s lore to {_lore::%loop-number%}

  set {pistol::max_targets} to 1
  set {pistol::fire_rate} to 0.5
  set {pistol::damage} to 6
  set {pistol::clip} to 10
  set {pistol::ammunition} to 300
  set {pistol::reload_time} to 1.5

on left-click with wooden hoe:
  line 2 of player's tool's lore contains "&fPistol's Stats"
  cancel event
  broadcast "[LC] Lore contains" #!
 
  if {pistol::clip::%player's uuid%} != 10:
    broadcast "[LC] reloading" #!
    gun_reload(player, "pistol")

Posted by: x8ight from the skUnity Discord. View the thread on skUnity Discord here
 
code_language.skript:
function gun_reload(player: player, gun: text):
  set {_ammunition_absolute::*} to line 5 of {_player}'s tool's lore split at " "
  set {_ammunition::*} to {_ammunition_absolute::2} split at "/"
  broadcast "[RF] split (%{_ammunition::1}%/%{_ammunition::2}%)" #!
 
  if ("{_ammunition::1}" parsed as integer) <= 0:
    send "Out of ammunition!" to {_player}
    broadcast "[RF] out of ammo" #!
    stop
 
  else if ("{_ammunition::1}" parsed as integer) >= {%{_gun}%::clip}:
    set {%{_gun}%::clip::%{_player}'s uuid%} to {%{_gun}%::clip}
    set line 5 of {_player}'s tool's lore to "&r&fAmmunition: %("{_ammunition::1} - {%{_gun}%::clip}" parsed as integer)%/%{%{_gun}%::ammunition}%"
    broadcast "[RF] refil 10" #!
 
  else:
    set {%{_gun}%::clip::%{_player}'s uuid%} to ("{_ammunition::1}" parsed as integer)
    set line 5 of {_player}'s tool's lore to "&r&fAmmunition: 0/%{%{_gun}%::ammunition}%"
    broadcast "[RF] refil remaining" #!
 
  set {%{_gun}%::delay::%{_player}'s uuid%} to {%{_gun}%::reload_time}
  broadcast "[RF] set delay" #!
  wait "{%{_gun}%::reload_time} seconds" parsed as timespan
  broadcast "[RF] waited" #!
  delete {%{_gun}%::delay::%{_player}'s uuid%}
  broadcast "[RF] deleted" #!
  send "Reloaded!" to {_player}
anything marked with
#!
is there for debugging
When I reload a new gun, it splits the lore correctly, and broadcasts "300/300", but then skips the conditions and goes straight to the final else, and sets the remaining ammo to 0/300

Then, if I reload again it successfuly splits again, broadcasting "0/300", but the condition checking if the ammo is 0 doesnt work and it goes to the last else again.
A seperate issue is that it only sets the delay, and doesnt do anything under the 6th last line; doesn't wait and broadcast that it waited or delete the delay.

Posted by: x8ight from the skUnity Discord.
 
code_language.skript:
vb
set {_lore::*} to " ||&r&fPistol's Stats:||&r&fDamage: 6||&r&fFire Rate: 0.5||&r&fAmmunition: 300/300||&r&fClip: 10||&r&fReload Time: 1.5|| " split at "||"
  loop size of {_lore::*} times:
    set line loop-number of {pistol}'s lore to {_lore::%loop-number%}

Im really curious to know WHY you did it this way?
you could literally have done
vb
set {_lore::*} to "a", "b" and "c"
set {item} to wooden hoe named "name" with lore {_lore::*}
that said, i highly HIGHLY do not recommend using LORE for storing data.
You should be using something like NBT for storing data (numbers), so then no parsing is required

Posted by: shanebee from the skUnity Discord.
 
look very closely at this bit in your code:

"{_ammunition::1}" parsed as integer




Posted by: bluelhf from the skUnity Discord.
 
while i do understand your position, i also highly recommend not doing what you're doing.
You're putting a lot of stress on the server for no reason.
Parsing is a lot of work for the server to do, and if you have many players with many guys, its going to cause unnecessary strain.
i do hope in the future you take this advice

Posted by: shanebee from the skUnity Discord.
 
eh i bet it'll be fine
i'm more concerned about how much work it takes to Write the parsing code
shane has spent all this effort making a cool nbt system it'd be a shame not to use it :emoji_frowning:

Posted by: bluelhf from the skUnity Discord.
 
Status
Not open for further replies.