Trying to create a command to upgrade the amount of homes a player can have

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

jawa2828

Member
Nov 26, 2024
1
0
1
49
This is what I have so far. It is taking the payment correctly, but for some reason it is not upgrading the rank of the player at all. The player's rank just stays constant.

command /upgradehomes:
description: Upgrade your home level for a high fee.
permission: skript.upgradehomes
permission message: &cYou do not have permission to use this command!
trigger:
# Define ranks
clear {_ranks::*}
add "default" to {_ranks::*}
add "level1" to {_ranks::*}
add "level2" to {_ranks::*}
add "level3" to {_ranks::*}
add "level4" to {_ranks::*}
add "level5" to {_ranks::*}
add "level6" to {_ranks::*}
add "level7" to {_ranks::*}
add "level8" to {_ranks::*}
add "level9" to {_ranks::*}

# Define costs
clear {_costs::*}
add 80000 to {_costs::*}
add 200000 to {_costs::*}
add 400000 to {_costs::*}
add 600000 to {_costs::*}
add 850000 to {_costs::*}
add 1100000 to {_costs::*}
add 1400000 to {_costs::*}
add 1800000 to {_costs::*}
add 2500000 to {_costs::*}

# Determine current rank
set {_currentRank} to "default" # Default to "default" if no rank is found
loop {_ranks::*}:
if player has permission "essentials.sethome.multiple.%loop-value%":
set {_currentRank} to "%loop-value%"
stop loop

# Debugging message for current rank
send "&7[DEBUG] Found current rank: %{_currentRank}%."

# Find the current rank's index in the rank list
set {_nextRankIndex} to -1 # Initialize to -1, so the first valid rank is 0
set {_index} to 0 # Start from index 0
loop {_ranks::*}:
if loop-value is {_currentRank}:
set {_nextRankIndex} to {_index}
stop loop
set {_index} to {_index} + 1 # Manually increment the index

# Debugging message for next rank index
send "&7[DEBUG] Next rank index: %{_index}%."

# Check if current rank is the last one
if {_nextRankIndex} >= size of {_ranks::*} - 1:
send "&aYou already have the maximum home rank (Level 9, 20 homes)!"
stop

# Get the next rank
set {_nextRankIndex} to {_nextRankIndex} + 1
set {_nextRank} to {_ranks::%{_nextRankIndex}%}

# Debugging message for next rank
send "&7[DEBUG] Next rank: %{_nextRank}%."

# Get cost for the next rank
set {_cost} to {_costs::%{_nextRankIndex}%}

# Check if the player has enough money
if player's balance is greater than or equal to {_cost}:
remove {_cost} from player's balance
execute console command "lp user %player% permission set essentials.sethome.multiple.%{_nextRank}% true"
execute console command "lp user %player% permission unset essentials.sethome.multiple.%{_currentRank}%"
execute console command "lp user %player% permission reload" # Reload permissions

# Get the new home limit
set {_nextHomes} to {_nextRankIndex + 2}

send "&aCongratulations! You've upgraded to home %{_nextRank}% for $%{_cost}%."
send "&eYou can now set up to %{_nextHomes}% homes!"
else:
send "&cYou do not have enough money to upgrade! You need $%{_cost}%. Please try again later."


I don't think that {_index} is being found correctly but I don't know how to fix it
 
This is what I have so far. It is taking the payment correctly, but for some reason it is not upgrading the rank of the player at all. The player's rank just stays constant.

command /upgradehomes:
description: Upgrade your home level for a high fee.
permission: skript.upgradehomes
permission message: &cYou do not have permission to use this command!
trigger:
# Define ranks
clear {_ranks::*}
add "default" to {_ranks::*}
add "level1" to {_ranks::*}
add "level2" to {_ranks::*}
add "level3" to {_ranks::*}
add "level4" to {_ranks::*}
add "level5" to {_ranks::*}
add "level6" to {_ranks::*}
add "level7" to {_ranks::*}
add "level8" to {_ranks::*}
add "level9" to {_ranks::*}

# Define costs
clear {_costs::*}
add 80000 to {_costs::*}
add 200000 to {_costs::*}
add 400000 to {_costs::*}
add 600000 to {_costs::*}
add 850000 to {_costs::*}
add 1100000 to {_costs::*}
add 1400000 to {_costs::*}
add 1800000 to {_costs::*}
add 2500000 to {_costs::*}

# Determine current rank
set {_currentRank} to "default" # Default to "default" if no rank is found
loop {_ranks::*}:
if player has permission "essentials.sethome.multiple.%loop-value%":
set {_currentRank} to "%loop-value%"
stop loop

# Debugging message for current rank
send "&7[DEBUG] Found current rank: %{_currentRank}%."

# Find the current rank's index in the rank list
set {_nextRankIndex} to -1 # Initialize to -1, so the first valid rank is 0
set {_index} to 0 # Start from index 0
loop {_ranks::*}:
if loop-value is {_currentRank}:
set {_nextRankIndex} to {_index}
stop loop
set {_index} to {_index} + 1 # Manually increment the index

# Debugging message for next rank index
send "&7[DEBUG] Next rank index: %{_index}%."

# Check if current rank is the last one
if {_nextRankIndex} >= size of {_ranks::*} - 1:
send "&aYou already have the maximum home rank (Level 9, 20 homes)!"
stop

# Get the next rank
set {_nextRankIndex} to {_nextRankIndex} + 1
set {_nextRank} to {_ranks::%{_nextRankIndex}%}

# Debugging message for next rank
send "&7[DEBUG] Next rank: %{_nextRank}%."

# Get cost for the next rank
set {_cost} to {_costs::%{_nextRankIndex}%}

# Check if the player has enough money
if player's balance is greater than or equal to {_cost}:
remove {_cost} from player's balance
execute console command "lp user %player% permission set essentials.sethome.multiple.%{_nextRank}% true"
execute console command "lp user %player% permission unset essentials.sethome.multiple.%{_currentRank}%"
execute console command "lp user %player% permission reload" # Reload permissions

# Get the new home limit
set {_nextHomes} to {_nextRankIndex + 2}

send "&aCongratulations! You've upgraded to home %{_nextRank}% for $%{_cost}%."
send "&eYou can now set up to %{_nextHomes}% homes!"
else:
send "&cYou do not have enough money to upgrade! You need $%{_cost}%. Please try again later."


I don't think that {_index} is being found correctly but I don't know how to fix it
The main issue I see is the type of variables you're using. A variable such as {_example} will not be persistent (Local Variable) and the data of that variable will be lost in other sections of your code.

Example:
Code:
command var1 [<number>]:
   trigger:
      set {_num} to arg-1
      broadcast "The number chosen is.. %{_num}%!"

command vartest:
   trigger:
      broadcast "{_num} in this code returns: %{_num}% (Local Variable)"
I strongly recommend checking out this tutorial on different types of variables then consider changing your code to use the correct variable types in order to save and use the data you want to store properly: Skript Variables Tutorial