fusion de fonction + retour de nombre d'item chargé et sauvegardé

This commit is contained in:
Mylloon 2021-07-01 20:41:49 +02:00
parent 9c8edbeafb
commit 23f895c63f

View file

@ -1,33 +1,37 @@
options: options:
tailleInventaire: 41 # 37 d'inventaire + 4 d'équipement + 1 seconde main tailleInventaire: 41 # 37 d'inventaire + 4 d'équipement + 1 seconde main
messageChangement: "&7Changement d'inventaire..." messagePreChangement: "&7Changement d'inventaire..."
messagePostChargement: "&7&l%{_n1}%&7 item sauvegardés et &l%{_n2}%&7 chargés."
on load: on load:
ScriptList("add", script) ScriptList("add", script)
on unload: on unload:
ScriptList("remove", script) ScriptList("remove", script)
function sauvegardeInventaire(player: player, gamemode: text): function inventaire(mode: text, player: player, gamemode: text) :: number:
set {_uuid} to uuid of {_player} set {_uuid} to uuid of {_player}
set {_count} to 0 set {_count} and {_nombreItems} to 0
if {_mode} is "chargement":
clear inventory of {_player}
loop {@tailleInventaire} times: loop {@tailleInventaire} times:
set {inv.%{_uuid}%.%{_gamemode}%::%{_count}%} to slot {_count} of inventory of {_player} set {_item} to slot {_count} of inventory of {_player}
add 1 to {_count} if {_mode} is "chargement":
set slot {_count} of inventory of {_player} to {inv.%{_uuid}%.%{_gamemode}%::%{_count}%}
function chargementInventaire(player: player, gamemode: text): else if {_mode} is "sauvegarde":
set {_uuid} to uuid of {_player} set {inv.%{_uuid}%.%{_gamemode}%::%{_count}%} to {_item}
set {_count} to 0
clear inventory of {_player}
loop {@tailleInventaire} times:
set slot {_count} of inventory of {_player} to {inv.%{_uuid}%.%{_gamemode}%::%{_count}%}
add 1 to {_count} add 1 to {_count}
if "%{_item}%" is not "<none>" or "air" or "0 air":
add 1 to {_nombreItems}
return {_nombreItems}
on gamemode change: on gamemode change:
if old gamemode of player is survival: if old gamemode of player is survival:
sauvegardeInventaire(player, "%old gamemode of player%") set {_n1} to inventaire("sauvegarde", player, "%old gamemode of player%")
send {@messageChangement} send {@messagePreChangement}
chargementInventaire(player, "creative") set {_n2} to inventaire("chargement", player, "creative")
send {@messagePostChargement}
else if gamemode of player is survival: else if gamemode of player is survival:
sauvegardeInventaire(player, "creative") set {_n1} to inventaire("sauvegarde", player, "creative")
send {@messageChangement} send {@messagePreChangement}
chargementInventaire(player, "%gamemode of player%") set {_n2} to inventaire("chargement", player, "%gamemode of player%")
send {@messagePostChargement}