Help with armor equip and unequip bugs

  • 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.
Apr 12, 2017
36
0
0
24
On my small private server, I have created special armor which when all pieces are equipped, the player is given a potion effect. One of my player's found that if you spam click the armor with just your mouse it registers as putting armor on without taking it off, and if you spam click with an item it registers the armor as it being taken off without it being put on. This is an issue as it could make it possible to recieve the potion effect without actually wearing the armor.
NWu0Vzq.png

yOZvb2x.png

W1qPT8N.png

Hqvznjx.png

code_language.skript:
on armor equip:
    if lore of event-item contains "&b&l&nReinforced":
        add 1 to {resistance.%player%}
        send "&b&n%{resistance.%player%}%/4 Pieces Equipped!"
        if {resistance.%player%} is 4:
            apply resistance tier 1 to player for 99 days ambient true
            stop
on armor unequip:
    if lore of event-item contains "&b&l&nReinforced":
        remove 1 from {resistance.%player%}
        send "&b&n%{resistance.%player%}%/4 Pieces Equipped!"
        remove resistance from player
 
What about something like this?

code_language.skript:
on armor equip:
    wait 10 ticks
    if lore of player's helmet contains "&b&l&nReinforced":
        if lore of player's chestplate contains "&b&l&nReinforced":
            if lore of player's leggings contains "&b&l&nReinforced":
                if lore of player's boots contains "&b&l&nReinforced":
                    send "RESISTANCE" to player
                    apply resistance tier 1 to player for 99 days ambient true
                    set {resistance::%player%} to true

on armor unequip:
    wait 10 ticks
    if {resistance::%player%} is true:
        if lore of player's helmet does not contain "&b&l&nReinforced":
            remove resistance from player
            set {resistance::%player%} to false
            send "NO MORE RESISTANCE"
        if lore of player's chestplate does not contain "&b&l&nReinforced":
            remove resistance from player
            set {resistance::%player%} to false
            send "NO MORE RESISTANCE"
        if lore of player's leggings does not contain "&b&l&nReinforced":
            remove resistance from player
            set {resistance::%player%} to false
            send "NO MORE RESISTANCE"
        if lore of player's boots does not contain "&b&l&nReinforced":
            remove resistance from player
            set {resistance::%player%} to false
            send "NO MORE RESISTANCE"
 
Last edited:
What about something like this?

code_language.skript:
on armor equip:
    wait 10 ticks
    if lore of player's helmet contains "&b&l&nReinforced":
        if lore of player's chestplate contains "&b&l&nReinforced":
            if lore of player's leggings contains "&b&l&nReinforced":
                if lore of player's boots contains "&b&l&nReinforced":
                    send "RESISTANCE" to player
                    apply resistance tier 1 to player for 99 days ambient true
                    set {resistance::%player%} to true

on armor unequip:
    wait 10 ticks
    if {resistance::%player%} is true:
        if lore of player's helmet does not contain "&b&l&nReinforced":
            remove resistance from player
            set {resistance::%player%} to false
            send "NO MORE RESISTANCE"
        if lore of player's chestplate does not contain "&b&l&nReinforced":
            remove resistance from player
            set {resistance::%player%} to false
            send "NO MORE RESISTANCE"
        if lore of player's leggings does not contain "&b&l&nReinforced":
            remove resistance from player
            set {resistance::%player%} to false
            send "NO MORE RESISTANCE"
        if lore of player's boots does not contain "&b&l&nReinforced":
            remove resistance from player
            set {resistance::%player%} to false
            send "NO MORE RESISTANCE"
I will have to try it out later, it looks like it would work better!
 
Hi, I do similar stuff like this on my own small server, we have a lot of custom features that are reliant on RPG-style features like this (set bonuses, in this case). The function I use for this type of stuff that I've found very useful is this:

code_language.skript:
function hasSetBonus(lore: text, p: player, itemsNeeded: number = 4) :: boolean:
    set {_numPieces} to 0
    loop ({_p}'s helmet, {_p}'s chestplate, {_p}'s leggings and {_p}'s boots):
        if loop-value's lore contains "%{_lore}%":
            add 1 to {_numPieces}
    if {_numPieces} >= {_itemsNeeded}:
        return true
    else:
        return false

That's from memory so it might not be perfect but I'm sure you get the idea. With it you can see whether or not the player is wearing all four pieces with hasSetBonus(player, "&b&l&nReinforced"). You might not need that last optional argument, but I use it because some of our armor sets only require three pieces to gain the set bonus. You could also add another function that returns the number of pieces in a set they're wearing, or just update this function to do that. Whatever works for you, but it's really useful for set bonus systems and helps prevent errors like this where you're counting up manually and relying on events firing properly. Avoid trusting your players wherever possible!
 
Hi, I do similar stuff like this on my own small server, we have a lot of custom features that are reliant on RPG-style features like this (set bonuses, in this case). The function I use for this type of stuff that I've found very useful is this:

code_language.skript:
function hasSetBonus(lore: text, p: player, itemsNeeded: number = 4) :: boolean:
    set {_numPieces} to 0
    loop ({_p}'s helmet, {_p}'s chestplate, {_p}'s leggings and {_p}'s boots):
        if loop-value's lore contains "%{_lore}%":
            add 1 to {_numPieces}
    if {_numPieces} >= {_itemsNeeded}:
        return true
    else:
        return false

That's from memory so it might not be perfect but I'm sure you get the idea. With it you can see whether or not the player is wearing all four pieces with hasSetBonus(player, "&b&l&nReinforced"). You might not need that last optional argument, but I use it because some of our armor sets only require three pieces to gain the set bonus. You could also add another function that returns the number of pieces in a set they're wearing, or just update this function to do that. Whatever works for you, but it's really useful for set bonus systems and helps prevent errors like this where you're counting up manually and relying on events firing properly. Avoid trusting your players wherever possible!
Thank you so much! Unfortunately, im still a noob to functions and it is returning an error:
code_language.skript:
on armor equip:
    set {_equipped} to hasSetBonus(&b&l&nReinforced, player, 4)
    if {_equipped} is true:
        send "Duration Activated"
        apply resistance tier 1 to player for 99 days ambient true
       

function hasSetBonus(lore: text, p: player, itemsNeeded: number = 4) :: boolean:
    set {_numPieces} to 0
    loop ({_p}'s helmet, {_p}'s chestplate, {_p}'s leggings and {_p}'s boots):
        if loop-value's lore contains "%{_lore}%":
            add 1 to {_numPieces}
    if {_numPieces} >= {_itemsNeeded}:
        return true
    else:
        return false
the error that keeps returning states that "Functions cannot be used here (or there is a problem with your arguments)." and the error occurs on line 2. I have tried a few different things but im not able to get it to work. Thanks!
 
Thank you so much! Unfortunately, im still a noob to functions and it is returning an error:
code_language.skript:
on armor equip:
    set {_equipped} to hasSetBonus(&b&l&nReinforced, player, 4)
    if {_equipped} is true:
        send "Duration Activated"
        apply resistance tier 1 to player for 99 days ambient true
      

function hasSetBonus(lore: text, p: player, itemsNeeded: number = 4) :: boolean:
    set {_numPieces} to 0
    loop ({_p}'s helmet, {_p}'s chestplate, {_p}'s leggings and {_p}'s boots):
        if loop-value's lore contains "%{_lore}%":
            add 1 to {_numPieces}
    if {_numPieces} >= {_itemsNeeded}:
        return true
    else:
        return false
the error that keeps returning states that "Functions cannot be used here (or there is a problem with your arguments)." and the error occurs on line 2. I have tried a few different things but im not able to get it to work. Thanks!
Set line 2 to
code_language.skript:
set {_equipped} to hasSetBonus("&b&l&nReinforced", player, 4)
 
Set line 2 to
code_language.skript:
set {_equipped} to hasSetBonus("&b&l&nReinforced", player, 4)
Thank you! I thought I already tried that, but apparently not.
[doublepost=1530466696,1530466451][/doublepost]After trying to test the new code, I have found that the custom loop thing is not looping the lore properly. I have created a code to test it:
code_language.skript:
on right click:
    loop (player's helmet, player's chestplate, player's leggings, player's boots):
        send "%loop-value's lore%" to player
    send "%lore of player's chestplate%" to player
The code shows how the loop returns the lore and how non-loops return it. The loops are returning <none>, while the non-loop is returning the proper lore.
 
You could just loop the slot numbers instead, should be more reliable. That may actually be how I did it on my server as well, can't remember. You'd do that by replacing the loop with this:
code_language.skript:
loop integers from 36 to 39:
    if lore of slot loop-value of {_p} contains {_lore}:
       add 1 to {_numPieces}
 
Status
Not open for further replies.