Vagnerking
Active Member
I'm trying to create a market, and I need the item's uid to inform which exact item I'm selling (because it has different attributes)
I'm using tfs 0.4
I'm using tfs 0.4
Only items with UIDs defined in map editor (numbers up to 65535) have real UIDs (unique IDs). All Lua UIDs likeI'm trying to create a market, and I need the item's uid to inform which exact item I'm selling (because it has different attributes)
I'm using tfs 0.4
70001, 70002 are temporary UIDs in Lua. They may stay in Lua until server restart, but they may be also removed earlier.Game::internalGetThing to read 'position' on OTS - which may be on floor like X,Y,Z,stackpos, but also inside BP using special x,y,z,stackpos values - to read what player clicked in OTC.Perfect! Let me see if I understand. In OTCv8, I have functions in the item like this:Only items with UIDs defined in map editor (numbers up to 65535) have real UIDs (unique IDs). All Lua UIDs like70001,70002are temporary UIDs in Lua. They may stay in Lua until server restart, but they may be also removed earlier.
You cannot use 'UID' to implement some OTClient market with custom items.
It's opposite. You can 'use' any Item in OTC and it will send 'position' to OTS.Perfect! Let me see if I understand. In OTCv8, I have functions in the item like this:
item:getId() -- (spriteId, I think)
item:getPosition()
item:getStackPos()
Game.getInternalThing(player, position, index, clientId, type) on map/in BP can be used in OTS C++ Game::internalGetThing to get item that player sees in OTC.These are separate things. First you have to detect given "Item" in OTC-OTS communication.My question is... should it be saved as it is in the player_items table? Where only the item ID is saved, and the attributes would be saved as a blob in the "attributes" column.
int32_t LuaInterface::luaGetItemByPos(lua_State *L)
{
// getItemByPos(player, pos)
PositionEx pos;
popPosition(L, pos);
ScriptEnviroment *env = getEnv();
uint32_t playerUid = popNumber(L);
Player *player = env->getPlayerByUID(playerUid);
if (!player)
{
errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
lua_pushboolean(L, false);
return 1;
}
Item *realItem = nullptr;
if (pos.x == 0xFFFF)
{
if (pos.y & 0x40)
{
uint8_t cid = static_cast<uint8_t>(pos.y & 0x0F);
if (Container *container = player->getContainer(cid))
realItem = container->getItem(pos.z);
}
else
realItem = player->getInventoryItem((slots_t)pos.y);
}
if (!realItem)
{
errorEx(getError(LUA_ERROR_ITEM_NOT_FOUND));
lua_pushboolean(L, false);
return 1;
}
if (realItem->getUniqueId() == 0 && !realItem->isStackable())
realItem->setUniqueId(env->addThing(realItem));
lua_newtable(L);
// Here you can implement it however you like.
setField(L, "itemId", realItem->getID());
setField(L, "itemClientId", realItem->getClientID());
setField(L, "itemName", realItem->getName());
setField(L, "itemDescription", realItem->getDescription(0));
setField(L, "itemMaxCount", realItem->getItemCount());
setField(L, "itemUid", realItem->getUniqueId());
// I use this to prevent the user from selling container-type items with other items inside.
bool isContainer = realItem->isContainer();
setField(L, "itemIsContainer", isContainer);
setField(L, "itemCountInContainer", isContainer ? realItem->getContainer()->size() : 0);
return 1;
}
const Player* playerConst ... and the casting later ...
Player* player = env->getPlayerByUID(playerUid);
The UID is important because while the player is in the market choosing their item to sell, they can change the position of the items in their backpack or slot.Since you are able to get item by position, you no longer need to set/get unique uid for it.
fetch item by position,
add to DB,
delete in-game
Also, instead of:
you just do:C++:const Player* playerConst ... and the casting later ...
C++:Player* player = env->getPlayerByUID(playerUid);
Client side, you send the position of the item.The UID is important because while the player is in the market choosing their item to sell, they can change the position of the items in their backpack or slot.
Then usethey can change the position of the items in their backpack or slot
window:lock()The player can receive an item during the lock.
That's true, I think the most suitable/safe solution is to store/create the item's UID (only if it's not a stackable item).The player can receive an item during the lock.
How? Unless there is some special system on the server where you can give players items directly to their bp. Otherwise you can't pickup anything, use hotkeys, use other modules like store or npc trade or player trade. And if they do it on purpose then nothing really breaks, they just put wrong item with wrong price on the market, knowingly.The player can receive an item during the lock.
Very common mechanic on OTS, people get eg. coins for eg. staying online.How? Unless there is some special system on the server where you can give players items directly to their bp. Otherwise you can't pickup anything, use hotkeys, use other modules like store or npc trade or player trade. And if they do it on purpose then nothing really breaks, they just put wrong item with wrong price on the market, knowingly.
onItemChange event? If the item in the slot of the initial item that the player tries to sell changes, you can simply close the "Selling" window and leave info box that "Item changed, try again.".