Creative+ Marketplace/"Auction house" (Guide)

sprinkler

Member
Joined
May 19, 2023
Messages
44
Set an initial value of "Slot" (SAVED) Variable to -1

chat event -> if contains @mp sell and if player not holding air call function "Sell" (1)

Function Sell (1): If Slot variable not equals 54, split player message into elements, get element from third index of the split (which is the price) , if element does NOT contain alphabets [ All characters from a to z] and if element is more than 0 and less than 9999999, Increase Slot by 1 -> set variable %player% item to Current Item.
Set variable combine text %player% combine 1 to "Name : %default%" and set variable combine text %player% combine 2 to "Price : [variable used to save output of third index]. Set variable %player% item edited to current item. Set variable Add item description, save output variable as %player% item edited, Put "%player% item edited" on the Item slot as well and on the text slot place %player% combine 1 variable. Then place another set variable add item description, place the "%player% item edited" on the output and item slot and %player% combine 2 in the text slot. Game action set container item place the chest location in location slot. %player% item edited in the item variable slot and Slot variable in the place where you put the slot number. Followed by placing four append element block. First append put "Items" array (Saved) and place %player% item variable to value. Second append place "Owner" array (SAVED) and set value to current name. Third append place "Price" array (SAVED) and set value to the third element we retrieved earlier from split text. Fourth append place "EditedItems" (SAVED) and set value to "%player% item edited" and place player action set item in hand (main hand) [ leave slot empty].

Player Event click inventory. Player if inventory name equals "MarketPlace". If player item NOT equals (Chest empty) [Prevents people from clicking empty slots]. Place set variable addition. Save the value of Clicked Slot + 1 to %player% temp [ Syncs the clicked slot and array index] [ Arrays starts at 1, chest slot starts at 0, hence the increment]. Get array element from "EditedItems", index as %player% temp, output as %player% check inv. If variable %player% check inv == Clicked slot. [ Explanation: While having the MarketPlace chest open, a player can click on HIS OWN inventory and that still will run the code, This check prevents it by checking if the clicked item is equal to the item in the array]. Get element Array name : "Owner", index as %player% temp and output as %player% check owner. If variable %player% check owner NOT EQUALS to Current name/default. Call function Buy (2) [ Dont forget to add cancel event at if inv name equals MarketPlace -> cancel.

Function Buy (2): Get element Array: "Price", index as %player% temp, output as %player% asking price. If variable %player% money (SAVED) more/equal to %player% asking price. Decrement %player% money by %player% asking price. Get element Array "Items", index as %player% temp , output as %player% buying item. Player action close inventory. Player action give variable ( %player% buying item). Game action Set container (Location : MarketPlace chest ). Slot as clicked slot. Spawn entity (Villager , loc at a hidden place, name as %player% check owner). Select object entities by condition by name equals %player% check owner. Increment %selected% money by %default% asking price. Player action Delete entity (SELECTION) . Select object default player. Four delete array blocks. Fill the chest with arrays: Item, Price, Owner, Edited Items and set the index to be %default% temp. Decrement Slot var by 1. Call Function: Refresher (3)

Function Refresher (3): Get length of array, array: Price, output var: array.len. Set variable slot.clicked to 0. Set var array.index to 1. Empty container (loc:MarketPlace chest). Call function RefreshLoop (4)

Function RefreshLoop (4): If variable compare array.index less/equal than array.len. Get element from array:EditedItems, index as array.index, output:var temp. Set container item, Item variable : var temp, location: Chest, slot: var slot.clicked. Increment slot.clicked by 1. Increment array.index by 1. Wait 0.5 tick. Call function RefreshLoop (4)

This is just a base code. I believe the code fully works, if it doesnt, likely due to any error while typing here. THIS IS NOT AN AUCTION. All arrays except Split message one , are SAVED. the global var "Slot" IS ALSO SAVED

Just a heads up, if your world contains other fast loops, it's better to increase the wait from 0.5 to 1 tick. if the chest is full, it will take just about 3 seconds to fully refresh (at 1 tick). You may add a condition to check If variable updating Not equals true-> open inv on the @mp view cmd.

Edit:
Credits to veddnt too for helping me out
 
Last edited:

deefer

Active member
Joined
May 22, 2023
Messages
458
Set an initial value of "Slot" (SAVED) Variable to -1

chat event -> if contains @mp sell and if player not holding air call function "Sell" (1)

Function Sell (1): If Slot variable not equals 54, split player message into elements, get element from third index of the split (which is the price) , if element does NOT contain alphabets [ All characters from a to z] and if element is more than 0 and less than 9999999, Increase Slot by 1 -> set variable %player% item to Current Item.
Set variable combine text %player% combine 1 to "Name : %default%" and set variable combine text %player% combine 2 to "Price : [variable used to save output of third index]. Set variable %player% item edited to current item. Set variable Add item description, save output variable as %player% item edited, Put "%player% item edited" on the Item slot as well and on the text slot place %player% combine 1 variable. Then place another set variable add item description, place the "%player% item edited" on the output and item slot and %player% combine 2 in the text slot. Game action set container item place the chest location in location slot. %player% item edited in the item variable slot and Slot variable in the place where you put the slot number. Followed by placing four append element block. First append put "Items" array (Saved) and place %player% item variable to value. Second append place "Owner" array (SAVED) and set value to current name. Third append place "Price" array (SAVED) and set value to the third element we retrieved earlier from split text. Fourth append place "EditedItems" (SAVED) and set value to "%player% item edited" and place player action set item in hand (main hand) [ leave slot empty].

Player Event click inventory. Player if inventory name equals "MarketPlace". If player item NOT equals (Chest empty) [Prevents people from clicking empty slots]. Place set variable addition. Save the value of Clicked Slot + 1 to %player% temp [ Syncs the clicked slot and array index] [ Arrays starts at 1, chest slot starts at 0, hence the increment]. Get array element from "EditedItems", index as %player% temp, output as %player% check inv. If variable %player% check inv == Clicked slot. [ Explanation: While having the MarketPlace chest open, a player can click on HIS OWN inventory and that still will run the code, This check prevents it by checking if the clicked item is equal to the item in the array]. Get element Array name : "Owner", index as %player% temp and output as %player% check owner. If variable %player% check owner NOT EQUALS to Current name/default. Call function Buy (2) [ Dont forget to add cancel event at if inv name equals MarketPlace -> cancel.

Function Buy (2): Get element Array: "Price", index as %player% temp, output as %player% asking price. If variable %player% money (SAVED) more/equal to %player% asking price. Decrement %player% money by %player% asking price. Get element Array "Items", index as %player% temp , output as %player% buying item. Player action close inventory. Player action give variable ( %player% buying item). Game action Set container (Location : MarketPlace chest ). Slot as clicked slot. Spawn entity (Villager , loc at a hidden place, name as %player% check owner). Select object entities by condition by name equals %player% check owner. Increment %selected% money by %default% asking price. Player action Delete entity (SELECTION) . Select object default player. Four delete array blocks. Fill the chest with arrays: Item, Price, Owner, Edited Items and set the index to be %default% temp. Decrement Slot var by 1. Call Function: Refresher (3)

Function Refresher (3): Get length of array, array: Price, output var: array.len. Set variable slot.clicked to 0. Set var array.index to 1. Empty container (loc:MarketPlace chest). Call function RefreshLoop (4)

Function RefreshLoop (4): If variable compare array.index less/equal than array.len. Get element from array:EditedItems, index as array.index, output:var temp. Set container item, Item variable : var temp, location: Chest, slot: var slot.clicked. Increment slot.clicked by 1. Increment array.index by 1. Wait 0.5 tick. Call function RefreshLoop (4)

This is just a base code. I believe the code fully works, if it doesnt, likely due to any error while typing here. THIS IS NOT AN AUCTION. All arrays except Split message one , are SAVED. the global var "Slot" IS ALSO SAVED
WAIT WAIT DID I JUST SEE A FLOATING NUMBER IN THE WAIT ACTION??? 0.5 TICKS??? BRO USE RECURSIVE FUNCTION U GONNA OVERFLOW ACTIONS WITHIN THE CODE ITSELF
 

deefer

Active member
Joined
May 22, 2023
Messages
458
btw @sprinkler did you know we can code ah with EI?

player chat -> if msg = @sell price -> set text truncate 0->12 = priceitm -> parse price -> spawn entity price -> select entity price -> slotglo += 1 -> %selected%slot = slotglo -> %selected%price = priceitm

for the removing items part, make a loop then spawn then delete the entity and extract the variables from there but this method is as slow as my brain becuz u cant sort it out
 

sprinkler

Member
Joined
May 19, 2023
Messages
44
btw @sprinkler did you know we can code ah with EI?

player chat -> if msg = @sell price -> set text truncate 0->12 = priceitm -> parse price -> spawn entity price -> select entity price -> slotglo += 1 -> %selected%slot = slotglo -> %selected%price = priceitm

for the removing items part, make a loop then spawn then delete the entity and extract the variables from there but this method is as slow as my brain becuz u cant sort it out
Still gotta have one array for storing owner name right? Or we could get it from the item description.
 

deefer

Active member
Joined
May 22, 2023
Messages
458
you know, when someone starts taking floating nunbers as values, the code might just go wrong
 

veddnt

Active member
Joined
Jun 2, 2023
Messages
201
btw @sprinkler did you know we can code ah with EI?

player chat -> if msg = @sell price -> set text truncate 0->12 = priceitm -> parse price -> spawn entity price -> select entity price -> slotglo += 1 -> %selected%slot = slotglo -> %selected%price = priceitm

for the removing items part, make a loop then spawn then delete the entity and extract the variables from there but this method is as slow as my brain becuz u cant sort it out
Yes, we can use EI for the code, i had a working prototype iirc
 

deefer

Active member
Joined
May 22, 2023
Messages
458
this bozo literally read my thread about EI then he acts like he knows more about it than I do
 
Top