HuatsonOT(DXPv3)
TFS: 0.3.6
I need to create a trade system on my server, with these functions.
1- when the player presses on the specific item, a window will open.
2-Where the player can exchange the items he owns, for items he can create.
3-next to the item he wants to craft will have a description of the item he needs.
um exemplo de como eu gostaria
I have the code of an exchange system similar to what I want, but it needs some changes
SERVER
data\creaturescripts\scripts\opcodes
data\actions\scripts\Basic\Quests
CLIENTE
modules\game_held
TFS: 0.3.6
I need to create a trade system on my server, with these functions.
1- when the player presses on the specific item, a window will open.
2-Where the player can exchange the items he owns, for items he can create.
3-next to the item he wants to craft will have a description of the item he needs.
um exemplo de como eu gostaria
I have the code of an exchange system similar to what I want, but it needs some changes
SERVER
data\creaturescripts\scripts\opcodes
Lua:
local op_crea = {
OPCODE_SKILL_BAR = opcodes.OPCODE_SKILL_BAR,
OPCODE_POKEMON_HEALTH = opcodes.OPCODE_POKEMON_HEALTH,
OPCODE_BATTLE_POKEMON = opcodes.OPCODE_BATTLE_POKEMON,
OPCODE_FIGHT_MODE = opcodes.OPCODE_FIGHT_MODE,
OPCODE_WILD_POKEMON_STATS = opcodes.OPCODE_WILD_POKEMON_STATS,
OPCODE_REQUEST_DUEL = opcodes.OPCODE_REQUEST_DUEL,
OPCODE_ACCEPT_DUEL = opcodes.OPCODE_ACCEPT_DUEL,
OPCODE_YOU_ARE_DEAD = opcodes.OPCODE_YOU_ARE_DEAD,
OPCODE_DITTO_MEMORY = opcodes.OPCODE_DITTO_MEMORY,
}
function onExtendedOpcode(cid, opcode, buffer)
if opcode == op_crea.OPCODE_SKILL_BAR then
if buffer == "refresh" then
doOTCSendPlayerSkills(cid)
end
elseif opcode == op_crea.OPCODE_POKEMON_HEALTH then
if buffer == "refresh" then
doOTCSendPokemonHealth(cid)
end
elseif opcode == op_crea.OPCODE_BATTLE_POKEMON then
if buffer == "refresh" then
if #getCreatureSummons(cid) >= 1 then
doSendPlayerExtendedOpcode(cid, op_crea.OPCODE_BATTLE_POKEMON, tostring(getCreatureSummons(cid)[1]))
end
end
elseif opcode == op_crea.OPCODE_FIGHT_MODE then
setPlayerStorageValue(cid, storages.fightMode, tonumber(buffer))
elseif opcode == op_crea.OPCODE_WILD_POKEMON_STATS then
doSendPlayerExtendedOpcode(cid, op_crea.OPCODE_WILD_POKEMON_STATS, pokeStatus.getVity(tonumber(buffer)).."|"..pokeStatus.getAtk(tonumber(buffer)).."|"..pokeStatus.getSpAtk(tonumber(buffer)).."|"..pokeStatus.getDef(tonumber(buffer)).."|"..pokeStatus.getSpDef(tonumber(buffer)).."|"..pokeStatus.getSpeed(tonumber(buffer)))
--//Duel
elseif opcode == opcodes.OPCODE_REQUEST_DUEL then
--legenda: cid = player, sid = player convidado
local cut = string.explode(buffer, "/")
local pokeballsCount, sid = tonumber(cut[1]), getCreatureByName(cut[2])
if isCreature(sid) then
doIniteDuel(cid, sid, pokeballsCount)
end
elseif opcode == opcodes.OPCODE_ACCEPT_DUEL then
local p2 = getCreatureByName(buffer)
if isInvitedDuel(p2, cid) then
doPantinNoDuel(cid, p2, getPlayerStorageValue(p2, duelTable.infoBalls), 5)
end
elseif opcode == opcodes.OPCODE_DITTO_MEMORY then
local item = getPlayerSlotItem(cid, 8)
if item.uid == 0 then doSendMsg(cid, "Coloque seu shiny ditto no slot correto.") return true end
local pokeName = getItemAttribute(item.uid, "poke")
if pokeName ~= "Shiny Ditto" then return true end
if isInArray({"saveMemory1", "saveMemory2", "saveMemory3"}, buffer) then
local copyName = getItemAttribute(item.uid, "copyName")
if pokeName == copyName then doSendMsg(cid, "Transforme seu ditto primeiro.") return true end
if not fotos[doCorrectString(copyName)] then return true end
if isPokeInSlots(getItemAttribute(item.uid, "memoryDitto"), doCorrectString(copyName)) then doSendMsg(cid, "Esta copia já está salva em um slot.") return true end
if buffer == "saveMemory1" then
doItemSetAttribute(item.uid, "memoryDitto", saveSlot(getItemAttribute(item.uid, "memoryDitto"), 1, getItemInfo(fotos[doCorrectString(copyName)]).clientId)) -- getPortraitClientID(doCorrectString(copyName))))
elseif buffer == "saveMemory2" then
doItemSetAttribute(item.uid, "memoryDitto", saveSlot(getItemAttribute(item.uid, "memoryDitto"), 2, getItemInfo(fotos[doCorrectString(copyName)]).clientId))
elseif buffer == "saveMemory3" then
doItemSetAttribute(item.uid, "memoryDitto", saveSlot(getItemAttribute(item.uid, "memoryDitto"), 3, getItemInfo(fotos[doCorrectString(copyName)]).clientId))
end
elseif isInArray({"clearSlot1", "clearSlot2", "clearSlot3"}, buffer) then
if buffer == "clearSlot1" then
doItemSetAttribute(item.uid, "memoryDitto", saveSlot(getItemAttribute(item.uid, "memoryDitto"), 1, "?"))
elseif buffer == "clearSlot2" then
doItemSetAttribute(item.uid, "memoryDitto", saveSlot(getItemAttribute(item.uid, "memoryDitto"), 2, "?"))
elseif buffer == "clearSlot3" then
doItemSetAttribute(item.uid, "memoryDitto", saveSlot(getItemAttribute(item.uid, "memoryDitto"), 3, "?"))
end
elseif isInArray({"use1", "use2", "use3"}, buffer) then
local summons = getCreatureSummons(cid)
if #summons < 1 then doSendMsg(cid, "Coloque seu ditto para fora da pokeball.") return true end
local pokeToTransform = getSlot(getItemAttribute(item.uid, "memoryDitto"), tonumber(buffer:explode("use")[1]))
doCopyPokemon(summons[1], pokeToTransform, true)
end
local memory = getItemAttribute(item.uid, "memoryDitto")
if not memory or memory == nil then
doItemSetAttribute(item.uid, "memoryDitto", "?|?|?")
memory = getItemAttribute(item.uid, "memoryDitto")
end
local memoryOne, memoryTwo, memoryTree = memory:explode("|")[1], memory:explode("|")[2], memory:explode("|")[3]
local str = memoryOne .. "-".. memoryTwo .."-" .. memoryTree
doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_DITTO_MEMORY, str)
elseif opcode == opcodes.OPCODE_TV_CAM then -- TVCam
doCreatePrivateChannel(cid)
doInviteToPrivateChannel(cid, playerName)
doRemoveIntoPrivateChannel(cid, playerName)
if getGlobalStorageValue(globalsTV) == -1 then -- iniciar sistema
setGlobalStorageValue(globalsTV, "")
end
local action = buffer:explode("/")[1]
if action == "create" then
createChannel(cid, buffer)
elseif action == "close" then
closeInClientChannmel(cid)
elseif action == "watch" then
local playerToWatch = getCreatureByName(buffer:explode("/")[2])
if isCreature(playerToWatch) then
if getPlayerStorageValue(playerToWatch, storages.playerTVPass) ~= "" and getPlayerStorageValue(playerToWatch, storages.playerTVPass) ~= "notASSenha" then
doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_TV_CAM, "requestPass|" .. getPlayerStorageValue(playerToWatch, storages.playerTVPass) .. "|" .. buffer:explode("/")[2])
else
doWatch(cid, playerToWatch)
end
else
doSendMsg(cid, "Este player não está mais gravando.")
end
elseif action == "watchWithPass" then
local playerToWatch = getCreatureByName(buffer:explode("/")[2])
if isCreature(playerToWatch) then
doWatch(cid, playerToWatch)
else
doSendMsg(cid, "Este player não está mais gravando.")
end
elseif action == "errou" then
doSendMsg(cid, "Senha digitada incorreta.")
end
elseif opcode == opcodes.OPCODE_PLAYER_SHOW_AUTOLOOT then -- Autoloot
if buffer:find("load/") then
local itens = getAllItensAutoLoot()
doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_PLAYER_SHOW_AUTOLOOT, (isCollectAll(cid) and "yes" or "no") .. "|" .. itens .. "|" .. getAllItensInMyListToClient(cid))
elseif buffer:find("all") then
doCollectAll(cid, true)
doSendMsg(cid, "AutoLoot: (>Coletar tudo<) foi ativado.")
elseif buffer:find("no") then
doCollectAll(cid, false)
doSendMsg(cid, "AutoLoot: (>Coletar tudo<) foi desativado.")
else
doSaveItems(cid, buffer)
end
elseif opcode == 186 then
return getPlayerstorage(cid, 59467)
elseif opcode == opcodes.OPCODE_PLAYER_SHOW_ONLINE then -- Janela de onlines do ADM
doGetPlayersOnToADM(cid)
elseif opcode == opcodes.OPCODE_PLAYER_SHOW_TRADE_HELD then --- Token Machine
local op = tonumber(buffer:explode("-")[2])
local posP = getThingPos(cid)
local posMachine = {{x = 222, y = 430, z = 7}, {x = 221, y = 430, z = 7}}
if not doComparePositions(posMachine[1], posP) and not doComparePositions(posMachine[2], posP) then
doSendMsg(cid, "Fique de frente para a maquina.")
return true
end
if op == 1 then
if doPlayerRemoveItem(cid, 15645, 10) then
local tier = math.random(1, 1)
doPlayerAddRandomHeld(cid, tier)
else
doSendMsg(cid, "Necesitas de 10 Green Tokens.")
end
return true
elseif op == 2 then
if doPlayerRemoveItem(cid, 15645, 20) then
local tier = math.random(2, 2)
doPlayerAddRandomHeld(cid, tier)
else
doSendMsg(cid, "Necesitas de 20 Green Tokens.")
end
return true
elseif op == 3 then
if doPlayerRemoveItem(cid, 15645, 40) then
local tier = math.random(3, 3)
doPlayerAddRandomHeld(cid, tier)
else
doSendMsg(cid, "Necesitas de 40 Green Tokens.")
end
return true
elseif op == 4 then
if doPlayerRemoveItem(cid, 15644, 30) then
local tier = math.random(4, 4)
doPlayerAddRandomHeld(cid, tier)
else
doSendMsg(cid, "Necesitas de 30 Red Tokens.")
end
return true
elseif op == 5 then
if doPlayerRemoveItem(cid, 15644, 60) then
local tier = math.random(5, 5)
doPlayerAddRandomHeld(cid, tier)
else
doSendMsg(cid, "Necesitas de 60 Red Tokens.")
end
return true
elseif op == 6 then
if doPlayerRemoveItem(cid, 15646, 20) then
local tier = math.random(6, 6)
doPlayerAddRandomHeld(cid, tier)
else
doSendMsg(cid, "Necesitas de 20 Blue Tokens.")
end
return true
elseif op == 7 then
if doPlayerRemoveItem(cid, 15646, 40) then
local tier = math.random(7, 7)
doPlayerAddRandomHeld(cid, tier)
else
doSendMsg(cid, "Necesitas de 20 Blue Tokens.")
end
return true
elseif op == 8 then
if doPlayerRemoveItem(cid, 15646, 100) then
doPlayerAddItem(cid, 14188, 1)
else
doSendMsg(cid, "Necesitas de 100 Blue Tokens.")
end
return true
elseif op == 9 then
if doPlayerRemoveItem(cid, 15646, 80) then
doPlayerAddItem(cid, 12832, 1)
else
doSendMsg(cid, "Necesitas de 80 Blue Tokens.")
end
return true
elseif op == 9 then
if doPlayerRemoveItem(cid, 15646, 80) then
doPlayerAddItem(cid, 12832, 1)
else
doSendMsg(cid, "Necesitas de 80 Blue Tokens.")
end
return true
elseif op == 10 then
if doPlayerRemoveItem(cid, 15646, 60) then
doPlayerAddItem(cid, 12227, 1)
else
doSendMsg(cid, "Necesitas de 60 Blue Tokens.")
end
return true
elseif op == 11 then
if doPlayerRemoveItem(cid, 15644, 12) then
doPlayerAddItem(cid, 15130, 1)
else
doSendMsg(cid, "Necesitas de 12 Red Tokens.")
end
return true
elseif op == 12 then
if doPlayerRemoveItem(cid, 15644, 10) then
doPlayerAddItem(cid, 15677, 5)
doPlayerAddItem(cid, 15676, 5)
doPlayerAddItem(cid, 15678, 5)
doPlayerAddItem(cid, 15680, 5)
doPlayerAddItem(cid, 15673, 5)
doPlayerAddItem(cid, 15674, 5)
doPlayerAddItem(cid, 15675, 5)
doPlayerAddItem(cid, 15679, 5)
doPlayerAddItem(cid, 15681, 5)
else
doSendMsg(cid, "Necesitas de 10 Red Tokens.")
end
return true
elseif op == 13 then
if doPlayerRemoveItem(cid, 15644, 10) then
doPlayerAddItem(cid, 11641, 1)
else
doSendMsg(cid, "Necesitas de 10 red Tokens.")
end
elseif op == 14 then
if doPlayerRemoveItem(cid, 15644, 5) then
doPlayerAddItem(cid, 6569, 1)
else
doSendMsg(cid, "Necesitas de 5 red Tokens.")
end
return true
end
end
end
function getSlot(strings, slot)
local slot1, slot2, slot3 = strings:explode("|")[1], strings:explode("|")[2], strings:explode("|")[3]
local ret, flag = "", false
for a, b in pairs(fotos) do
if getItemInfo(fotos[a]).clientId == tonumber(slot1) and slot == 1 then
ret = doCorrectString(a)
flag = true
elseif getItemInfo(fotos[a]).clientId == tonumber(slot2) and slot == 2 then
ret = doCorrectString(a)
flag = true
elseif getItemInfo(fotos[a]).clientId == tonumber(slot3) and slot == 3 then
ret = doCorrectString(a)
flag = true
end
if flag then
break
end
end
return ret
end
function saveSlot(strings, slot, poke)
local slot1, slot2, slot3 = strings:explode("|")[1], strings:explode("|")[2], strings:explode("|")[3]
local finalSlots = (slot == 1 and poke .. "|" or slot1 .. "|") .. (slot == 2 and poke .. "|" or slot2 .. "|") .. (slot == 3 and poke .. "|" or slot3)
return finalSlots
end
function isPokeInSlots(strings, poke)
if not fotos[poke] then return false end
poke = getItemInfo(fotos[poke]).clientId
local slot1, slot2, slot3 = strings:explode("|")[1], strings:explode("|")[2], strings:explode("|")[3]
if tonumber(slot1) == poke then
return true
elseif tonumber(slot2) == poke then
return true
elseif tonumber(slot3) == poke then
return true
end
return false
end
data\actions\scripts\Basic\Quests
Lua:
function onUse(cid, item, frompos, item2, topos)
if item.itemid == 16177 then
doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_PLAYER_SHOW_TRADE_HELD, "open")
return true
end
if not isBrotherHoodMember(cid) then
doSendMsg(cid, "Você não é um membro da Duelist BrotherHood.")
return true
end
local citys = {
[13000] = "Saffron",
}
local playerRankBrother = getPlayerStorageValue(cid, storages.BrotherHoodMemberRANK)
local desc = getNPCDescByCity(citys[item.actionid], playerRankBrother)
if desc == nil then
doSendMsg(cid, "O desafio (".. playerRankBrother ..") desta cidade ja foi concluido.")
else
doSendMsg(cid, "O seu proximo desafio (".. playerRankBrother ..") " .. desc)
end
end
CLIENTE
modules\game_held
Lua:
function init()
connect(g_game, { onGameEnd = onGameEnd })
ProtocolGame.registerExtendedOpcode(137, function(protocol, opcode, buffer) show() end)
deadWindow = g_ui.displayUI('held')
deadWindow:hide()
end
function terminate()
disconnect(g_game, { onGameEnd = onGameEnd })
deadWindow:destroy()
end
function onGameEnd()
if deadWindow:isVisible() then
deadWindow:hide()
end
end
function show()
deadWindow:show()
deadWindow:raise()
deadWindow:focus()
end
function hide()
if deadWindow:isVisible() then
deadWindow:hide()
end
end
function sendRequestShow(op)
g_game.getProtocolGame():sendExtendedOpcode(137, "heldTrade-" .. op)
end
Code:
HeadlessWindow
id: memory
size: 230 420
anchors.centerIn: parent
@onEnter: modules.game_held.hide()
@onEscape: modules.game_held.hide()
focusable: false
UIButton
id: closeButton
@onClick: modules.game_held.hide()
anchors.top: parent.top
anchors.right: parent.right
margin-top: -3
margin-right: -2
size: 14 14
image-source: /images/ui/miniwindow_buttons
image-clip: 28 0 14 14
$hover:
image-clip: 28 14 14 14
$pressed:
image-clip: 28 28 14 14
UIWidget
id: iconDitto
size: 16 16
image-source: /images/game/skulls/blue_token
anchors.top: parent.top
anchors.left: parent.left
margin-left: 1
Label
id: windownName
!text: tr('> Maquina de Tokens <')
text-align: topleft
text-auto-resize: true
anchors.top: parent.top
anchors.left: parent.left
margin-left: 40
phantom: true
@onClick: modules.game_memory.hide()
Button
id: trade1
!text: tr('10 Green Tokens (Tier 1)')
width: 210
anchors.left: parent.left
anchors.top: parent.top
margin-top: 20
margin-left: 3
@onClick: modules.game_held.sendRequestShow(1)
Button
id: trade2
!text: tr('20 Green Tokens (Tier 2)')
width: 210
anchors.left: parent.left
anchors.top: trade1.top
margin-top: 28
margin-left: 3
@onClick: modules.game_held.sendRequestShow(2)
Button
id: trade3
!text: tr('40 Green Tokens (Tier 3)')
width: 210
anchors.left: parent.left
anchors.top: trade2.top
margin-top: 28
margin-left: 3
@onClick: modules.game_held.sendRequestShow(3)
Button
id: trade4
!text: tr('30 Red Tokens (Tier 4)')
width: 210
anchors.left: parent.left
anchors.top: trade3.top
margin-top: 28
margin-left: 3
@onClick: modules.game_held.sendRequestShow(4)
Button
id: trade5
!text: tr('60 Red Tokens (Tier 5)')
width: 210
anchors.left: parent.left
anchors.top: trade4.top
margin-top: 28
margin-left: 3
@onClick: modules.game_held.sendRequestShow(5)
Button
id: trade6
!text: tr('20 Blue Tokens (Tier 6)')
width: 210
anchors.left: parent.left
anchors.top: trade5.top
margin-top: 28
margin-left: 7
@onClick: modules.game_held.sendRequestShow(6)
Button
id: trade7
!text: tr('40 Blue Tokens (Tier 7)')
width: 210
anchors.left: parent.left
anchors.top: trade6.top
margin-top: 28
margin-left: 3
@onClick: modules.game_held.sendRequestShow(7)
Button
id: trade8
!text: tr('100 Blue Tokens (Mega box)')
width: 210
anchors.left: parent.left
anchors.top: trade7.top
margin-top: 28
margin-left: 3
@onClick: modules.game_held.sendRequestShow(8)
Button
id: trade9
!text: tr('80 Blue Tokens (MasterBall)')
width: 210
anchors.left: parent.left
anchors.top: trade8.top
margin-top: 28
margin-left: 3
@onClick: modules.game_held.sendRequestShow(9)
Button
id: trade10
!text: tr('60 Blue Tokens (ShinyBox)')
width: 210
anchors.left: parent.left
anchors.top: trade9.top
margin-top: 28
margin-left: 3
@onClick: modules.game_held.sendRequestShow(10)
Button
id: trade11
!text: tr('12 Red Tokens (Skate)')
width: 210
anchors.left: parent.left
anchors.top: trade10.top
margin-top: 28
margin-left: 3
@onClick: modules.game_held.sendRequestShow(11)
Button
id: trade12
!text: tr('10 Red Tokens (5x9 NewBalls)')
width: 210
anchors.left: parent.left
anchors.top: trade11.top
margin-top: 28
margin-left: 3
@onClick: modules.game_held.sendRequestShow(12)
Button
id: trade13
!text: tr('20 Red Tokens (Box+4)')
width: 210
anchors.left: parent.left
anchors.top: trade12.top
margin-top: 28
margin-left: 3
@onClick: modules.game_held.sendRequestShow(13)
Button
id: trade14
!text: tr('5 Red Tokens (Rare Candie)')
width: 210
anchors.left: parent.left
anchors.top: trade13.top
margin-top: 28
margin-left: 3
@onClick: modules.game_held.sendRequestShow(14)
Last edited: