Need help with custom armor

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

  • 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.

Locutusque

Member
Nov 5, 2022
3
0
1
15
I'm trying to use a custom health system in skript. The problem im having is that the armor gives more or sometimes less than what its supposed to.


every 3 ticks:
loop all players:
if loop-player's boots is leather boots named "<dark green>Scout Boots":
set {defense.%loop-player's uuid%} to {defense.%loop-player's uuid%} + 2
set {maxhealth.%loop-player's uuid%} to {maxhealth.%loop-player's uuid%} + 20
set {speed.%loop-player's uuid%} to {speed.%loop-player's uuid%} + 100
set {health.%loop-player's uuid%} to {health.%loop-player's uuid%} + 20
wait 1 tick
set {defense.%loop-player's uuid%} to {defense.%loop-player's uuid%} - 2
set {maxhealth.%loop-player's uuid%} to {maxhealth.%loop-player's uuid%} - 20
set {speed.%loop-player's uuid%} to {speed.%loop-player's uuid%} - 100
set {health.%loop-player's uuid%} to {health.%loop-player's uuid%} - 20

is there a different approach that I could use for this?
 
Hi. First of all, please use list variables ({defense::%loop-player's uuid%}), as they're more versatile and are stored more efficiently (I believe).

One thing I notice with your code is that (without being able to see indents), you're waiting 1 tick within the loop. Please keep in mind that loops do not run all at once. They wait for one to finish before continuing onto the next one. Thus, within that loop, it'll wait 1 extra tick per player it's looping. This also means that you'll probably have several loops from several of the "every 3 ticks" event running at the same time, and as such will cause offsets like what you're likely experiencing. If you want to keep code similar, I'd have the wait 1 tick outside of the loop, and just loop all players again for the last 4 lines.

Also, if you're trying to have an offset or multiplier, I'd usually recommend keeping a separate variable ({defense.offset::%loop-player's uuid%}) so you can keep track of what exactly is the base value and what isn't.
 
Status
Not open for further replies.