Postado Setembro 2, 2017 7 anos TKforumeiros, gostaria de solicitar um sistema de points, que seja reutilizável no futuro com site. Meu server é em SQL, mais futuramente vou passar para MYSQL, preciso de um sistema de points que funcione dentro do jogo por enquanto, e que seja adaptável pro futuro quando eu usar site, se for possível. Um sistema, em que o admin possa acrescentar o mesmo aos jogadores. O Sistema precisa funcionar com base em talk, baus e npc. /addpoints Kharsek, 15 (inclui pontos ao jogador apenas pelo admin) /delpoints Kharsek, 15 (deleta os pontos do jogador apenas pelo admin) /transfpoints Kharsek, 15 (transfere pontos entre jogadores) /onpoints 15 (adiciona pontos a todos jogadores online apenas pelo admin) Bau 1 - Um script para bau configurável, onde você determinar quais itens vão ser entregues, e por quantidade de pontos com um delay de 5 segundos para uso. "Você recebeu um {item} por {qtpoints} points. "Você não possui pontos suficientes para adquirir esse item". "Você deve esperar 5 segundos para clicar novamente" Bau 2 - Um script de um bau que dê points configuráveis, e só possa utilizar uma vez. "Parabéns! Você ganhou {quantidade} points. Um npc que tenha a mesma funcionalidade do Bau 1 para vender os itens, só que por npc -------- Versão 8.60 TFS 0.4 thx
Postado Setembro 3, 2017 7 anos Solução Como sempre aparece alguém pedindo algo semelhante, resolvi fazer um básico aqui. Primeiramente, adicione uma coluna à tabela players de sua database: ALTER TABLE `players` ADD `ot_points` INTEGER NOT NULL DEFAULT 0 Em seguida, crie um arquivo na pasta lib : systempoints.lua (ou qualquer nome de sua preferência) Mostrar conteúdo oculto --- System Points by Dwarfer function getPlayerPoints(cid) local query = db.getResult("SELECT `ot_points` FROM `players` WHERE `id` = " .. getPlayerGUID(cid) .. ";") if query:getID() == -1 then return true end local points = query:getDataInt("ot_points") query:free() return tonumber(points) end function doPlayerAddPoints(cid, count) db.executeQuery("UPDATE `players` SET `ot_points` = " .. getPlayerPoints(cid) + count .. " WHERE `id` = " .. getPlayerGUID(cid) .. ";") return true end function doPlayerRemovePoints(cid, count) local current = getPlayerPoints(cid) if current - count < 0 then return false else db.executeQuery("UPDATE `players` SET `ot_points` = " .. getPlayerPoints(cid) - count .. " WHERE `id` = " .. getPlayerGUID(cid) .. ";") end return true end function doTransferPoints(cid, count, name) local receiver = getPlayerByNameWildcard(name) local current = getPlayerPoints(cid) if current - count < 0 then return false else doPlayerAddPoints(receiver, count) doPlayerRemovePoints(cid, count) end return true end function doPlayersOnlineAddPoints(count) for _, pid in ipairs(getPlayersOnline()) do doPlayerAddPoints(pid, count) end end function mathtime(table) -- by dwarfer local unit = {"sec", "min", "hour", "day"} for i, v in pairs(unit) do if v == table[2] then return table[1]*(60^(v == unit[4] and 2 or i-1))*(v == unit[4] and 24 or 1) end end return "Error: Bad declaration in mathtime function." end Talkaction Em talkactions/scripts crie um arquivo: pointstalk.lua Mostrar conteúdo oculto local config = { ["/getpoints"] = {access = 3, func = getPlayerPoints, success = "Points: %d - Player: %s", error = ""}, ["/addpoints"] = {access = 3, func = doPlayerAddPoints, success = "You have added %d points to player %s.", error = ""}, ["/delpoints"] = {access = 3, func = doPlayerRemovePoints, success = "You have removed %d points from player %s.", error = "Not enough points to be removed."}, ["/transfpoints"] = {access = 0, func = doTransferPoints, success = "You have transfered %d points to player %s.", error = "Not enough points to be transferred."}, ["/onpoints"] = {access = 3, func = doPlayersOnlineAddPoints, success = "You have added %d points to all players online.", error = ""} } function onSay(cid, words, param, channel) local p = getPlayerPosition(cid) if words == "/helppoints" then local str = "" for i, v in pairs(config) do if getPlayerAccess(cid) >= v.access then str = str .. i .. "\n" end end doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Correct commands: \n"..str) doSendMagicEffect(p, CONST_ME_POFF) return true end if words == "/points" then doPlayerPopupFYI(cid, "You have " .. getPlayerPoints(cid) .. " points.") return true end if(param == '') then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.") doSendMagicEffect(p, CONST_ME_POFF) return true end local t = string.explode(param, ",") if config[words] and getPlayerAccess(cid) < config[words].access then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have permission to do this.") doSendMagicEffect(p, CONST_ME_POFF) return true end local tid = getPlayerByNameWildcard(t[1]) if words ~= "/onpoints" then if not tid then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player " .. t[1] .. " not found or is not online.") doSendMagicEffect(p, CONST_ME_POFF) return true end if not t[2] then t[2] = 1 end end if words ~= "/onpoints" and tonumber(t[2]) <= 0 then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Action allowed only with positive values.") doSendMagicEffect(p, CONST_ME_POFF) return true end if config[words] then local ret = config[words].func(words == "/transfpoints" and cid or "string" == type(t[1]) and tid or tonumber(t[1]), tonumber(t[2]) or nil, "string" == type(t[1]) and t[1] or nil) if(ret == false and config[words].error ~= "")then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, config[words].error) doSendMagicEffect(p, CONST_ME_POFF) return true end doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, config[words].success:format((words == "/getpoints" and config[words].func(tid)) or (words == "/onpoints" and tonumber(t[1])) or tonumber(t[2]), t[1])) doSendMagicEffect(p, CONST_ME_STUN) end return true end Adicione a tag em talkactions.xml: <talkaction words="/addpoints;/delpoints;/onpoints;/transfpoints;/helppoints;/points;/getpoints" event="script" value="pointstalk.lua"/> -- Como usar: -- /addpoints Dwarfer,10 -> adiciona 10 pontos ao player Dwarfer -- /delpoints Dwarfer,10 -> remove 10 pontos do player Dwarfer -- /getpoints Dwarfer -> mostrará quantos pontos o player tem -- /points --> mostrará quantos pontos o próprio player possui -- /transfpoints Dwarfer,10 -> transfere 10 pontos para o player Dwarfer -- /onpoints 10 -> adiciona 10 pontos a todos os players online -- /helppoints -> mostra como devem ser usados os comandos permitidos ao player Actions Baú que dá itens por pontos Em actions/scripts, crie um arquivo: chestitemspoints.lua Mostrar conteúdo oculto local t = { points = 20, items = {{2160, 5}, {2152, 7}, {2158, 3}}, time = {5, "sec"} } function onUse(cid, item, fromPosition, itemEx, toPosition) if getPlayerStorageValue(cid, 45450) - os.time() > 0 then return doPlayerSendCancel(cid, "You need to wait " .. t.time[1] .. " " .. t.time[2] .. " to use again.") end if doPlayerRemovePoints(cid, t.points) then local str = "You have received " for i = 1, #t.items do if isItemStackable(t.items[i][1]) then doPlayerAddItem(cid, t.items[i][1], t.items[i][2]) else for j = 1, tonumber(t.items[i][2]) do doPlayerAddItem(cid, t.items[i][1], 1) end end str = str .. t.items[i][2] .. " " .. getItemNameById(t.items[i][1]) .. "" .. (t.items[i][2] > 1 and "s" or "") .. "" .. (i ~= #t.items and ", " or ".") end doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, str) setPlayerStorageValue(cid, 45450, mathtime(t.time) + os.time()) else doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You need " .. t.points .. " points to get the rewards.") end return true end Configuração: local t = { points = 20, -- pontos necessários items = {{2160, 5}, {2152, 7}, {2158, 3}}, -- {id do item, quantidade} que será dado ao player time = {5, "sec"} -- tempo para usar o baú novamente } Em actions.xml, adicione a tag: <action actionid="ACTION_ID_DO_BAÚ" script="chestitemspoints.lua" /> Baú que dá pontos somente uma vez Em actions/scripts, crie um arquivo.lua: chestpoints.lua Mostrar conteúdo oculto local points = 15 function onUse(cid, item, fromPosition, itemEx, toPosition) if getPlayerStorageValue(cid, 45451) ~= -1 then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You already received your points.") end doPlayerAddPoints(cid, points) doCreatureSay(cid, "You have received " .. points .. " points!", TALKTYPE_ORANGE_1) setPlayerStorageValue(cid, 45451, 1) return true end Em actions.xml, adicione a tag: <action actionid="ACTION_ID_DO_BAÚ" script="chestpoints.lua" /> NPC Mostrar conteúdo oculto local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) local talkState = {} function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end function onThink() npcHandler:onThink() end function creatureSayCallback(cid, type, msg) if(not npcHandler:isFocused(cid)) then return false end local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid local shopWindow = {} local t = { [1111] = {buyprice = 1}, -- [id do item] = {buyprice = preço} [2222] = {buyprice = 10}, [3333] = {buyprice = 3} } local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks) if t[item] and doPlayerRemovePoints(cid, t[item].buyprice) then doPlayerAddItem(cid, item) selfSay("Here you go.", cid) else selfSay("You don't have "..t[item].buyprice.." points.", cid) end return true end if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then for var, ret in pairs(t) do table.insert(shopWindow, {id = var, subType = 0, buy = ret.buyprice, sell = 0, name = getItemNameById(var)}) end openShopWindow(cid, shopWindow, onBuy, onSell) end return true end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new()) E, antes que peça rsrsrs, um tile que só passa com certa quantidade de pontos. Movements Em movements/scripts crie um arquivo: tilepoints.lua Mostrar conteúdo oculto local points_needed = {remove = true, count = 15} function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor) if getPlayerPoints(cid) < points_needed.count then doPlayerSendCancel(cid, "You need " .. points_needed.count .. " points to pass.") doTeleportThing(cid, fromPosition) return true end if points_needed.remove then doPlayerRemovePoints(cid, points_needed.count) end end Em movements.xml: <movevent type="StepIn" actionid="ACTION_ID_DO_PISO" event="script" value="tilepoints.lua"/> Editado Setembro 3, 2017 7 anos por Dwarfer (veja o histórico de edições)
Postado Setembro 3, 2017 7 anos Autor Em 03/09/2017 em 19:44, Dwarfer disse: Como sempre aparece alguém pedindo algo semelhante, resolvi fazer um básico aqui. Primeiramente, adicione uma coluna à tabela players de sua database: ALTER TABLE `players` ADD `ot_points` INTEGER NOT NULL DEFAULT 0 Em seguida, crie um arquivo na pasta lib : systempoints.lua (ou qualquer nome de sua preferência) Mostrar conteúdo oculto Mostrar conteúdo oculto --- System Points by Dwarfer function getPlayerPoints(cid) local query = db.getResult("SELECT `ot_points` FROM `players` WHERE `id` = " .. getPlayerGUID(cid) .. ";") if query:getID() == -1 then return true end local points = query:getDataInt("ot_points") query:free() return tonumber(points) end function doPlayerAddPoints(cid, count) db.executeQuery("UPDATE `players` SET `ot_points` = " .. getPlayerPoints(cid) + count .. " WHERE `id` = " .. getPlayerGUID(cid) .. ";") return true end function doPlayerRemovePoints(cid, count) local current = getPlayerPoints(cid) if current - count < 0 then return false else db.executeQuery("UPDATE `players` SET `ot_points` = " .. getPlayerPoints(cid) - count .. " WHERE `id` = " .. getPlayerGUID(cid) .. ";") end return true end function doTransferPoints(cid, count, name) local receiver = getPlayerByNameWildcard(name) local current = getPlayerPoints(cid) if current - count < 0 then return false else doPlayerAddPoints(receiver, count) doPlayerRemovePoints(cid, count) end return true end function doPlayersOnlineAddPoints(count) for _, pid in ipairs(getPlayersOnline()) do doPlayerAddPoints(pid, count) end end function mathtime(table) -- by dwarfer local unit = {"sec", "min", "hour", "day"} for i, v in pairs(unit) do if v == table[2] then return table[1]*(60^(v == unit[4] and 2 or i-1))*(v == unit[4] and 24 or 1) end end return "Error: Bad declaration in mathtime function." end Talkaction Em talkactions/scripts crie um arquivo: pointstalk.lua Mostrar conteúdo oculto Mostrar conteúdo oculto local config = { ["/getpoints"] = {access = 3, func = getPlayerPoints, success = "Points: %d - Player: %s", error = ""}, ["/addpoints"] = {access = 3, func = doPlayerAddPoints, success = "You have added %d points to player %s.", error = ""}, ["/delpoints"] = {access = 3, func = doPlayerRemovePoints, success = "You have removed %d points from player %s.", error = "Not enough points to be removed."}, ["/transfpoints"] = {access = 0, func = doTransferPoints, success = "You have transfered %d points to player %s.", error = "Not enough points to be transferred."}, ["/onpoints"] = {access = 3, func = doPlayersOnlineAddPoints, success = "You have added %d points to all players online.", error = ""} } function onSay(cid, words, param, channel) local p = getPlayerPosition(cid) if words == "/helppoints" then local str = "" for i, v in pairs(config) do if getPlayerAccess(cid) >= v.access then str = str .. i .. "\n" end end doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Correct commands: \n"..str) doSendMagicEffect(p, CONST_ME_POFF) return true end if words == "/points" then doPlayerPopupFYI(cid, "You have " .. getPlayerPoints(cid) .. " points.") return true end if(param == '') then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.") doSendMagicEffect(p, CONST_ME_POFF) return true end local t = string.explode(param, ",") if config[words] and getPlayerAccess(cid) < config[words].access then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have permission to do this.") doSendMagicEffect(p, CONST_ME_POFF) return true end local tid = getPlayerByNameWildcard(t[1]) if words ~= "/onpoints" then if not tid then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player " .. t[1] .. " not found or is not online.") doSendMagicEffect(p, CONST_ME_POFF) return true end if not t[2] then t[2] = 1 end end if tonumber(t[2]) <= 0 then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Action allowed only with positive values.") doSendMagicEffect(p, CONST_ME_POFF) return true end if config[words] then local ret = config[words].func(words == "/transfpoints" and cid or "string" == type(t[1]) and tid or tonumber(t[1]), tonumber(t[2]) or nil, "string" == type(t[1]) and t[1] or nil) if(ret == false and config[words].error ~= "")then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, config[words].error) doSendMagicEffect(p, CONST_ME_POFF) return true end doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, config[words].success:format((words == "/getpoints" and config[words].func(tid)) or (words == "/onpoints" and tonumber(t[1])) or tonumber(t[2]), t[1])) doSendMagicEffect(p, CONST_ME_STUN) end return true end Adicione a tag em talkactions.xml: <talkaction words="/addpoints;/delpoints;/onpoints;/transfpoints;/helppoints;/points;/getpoints" event="script" value="pointstalk.lua"/> -- Como usar: -- /addpoints Dwarfer,10 -> adiciona 10 pontos ao player Dwarfer -- /delpoints Dwarfer,10 -> remove 10 pontos do player Dwarfer -- /getpoints Dwarfer -> mostrará quantos pontos o player tem -- /points --> mostrará quantos pontos o próprio player possui -- /transfpoints Dwarfer,10 -> transfere 10 pontos para o player Dwarfer -- /onpoints 10 -> adiciona 10 pontos a todos os players online -- /helppoints -> mostra como devem ser usados os comandos permitidos ao player Actions Baú que dá itens por pontos Em actions/scripts, crie um arquivo: chestitemspoints.lua Mostrar conteúdo oculto Mostrar conteúdo oculto local t = { points = 20, items = {{2160, 5}, {2152, 7}, {2158, 3}}, time = {5, "sec"} } function onUse(cid, item, fromPosition, itemEx, toPosition) if getPlayerStorageValue(cid, 45450) - os.time() > 0 then return doPlayerSendCancel(cid, "You need to wait " .. t.time[1] .. " " .. t.time[2] .. " to use again.") end if doPlayerRemovePoints(cid, t.points) then local str = "You have received " for i = 1, #t.items do if isItemStackable(t.items[i][1]) then doPlayerAddItem(cid, t.items[i][1], t.items[i][2]) else for j = 1, tonumber(t.items[i][2]) do doPlayerAddItem(cid, t.items[i][1], 1) end end str = str .. t.items[i][2] .. " " .. getItemNameById(t.items[i][1]) .. "" .. (t.items[i][2] > 1 and "s" or "") .. "" .. (i ~= #t.items and ", " or ".") end doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, str) setPlayerStorageValue(cid, 45450, mathtime(t.time) + os.time()) else doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You need " .. t.points .. " points to get the rewards.") end return true end Configuração: local t = { points = 20, -- pontos necessários items = {{2160, 5}, {2152, 7}, {2158, 3}}, -- {id do item, quantidade} que será dado ao player time = {5, "sec"} -- tempo para usar o baú novamente } Em actions.xml, adicione a tag: <action actionid="ACTION_ID_DO_BAÚ" script="chestitemspoints.lua" /> Baú que dá pontos somente uma vez Em actions/scripts, crie um arquivo.lua: chestpoints.lua Mostrar conteúdo oculto Mostrar conteúdo oculto local points = 15 function onUse(cid, item, fromPosition, itemEx, toPosition) if getPlayerStorageValue(cid, 45451) ~= -1 then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You already received your points.") end doPlayerAddPoints(cid, points) doCreatureSay(cid, "You have received " .. points .. " points!", TALKTYPE_ORANGE_1) setPlayerStorageValue(cid, 45451, 1) return true end Em actions.xml, adicione a tag: <action actionid="ACTION_ID_DO_BAÚ" script="chestpoints.lua" /> NPC Mostrar conteúdo oculto Mostrar conteúdo oculto local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) local talkState = {} function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end function onThink() npcHandler:onThink() end function creatureSayCallback(cid, type, msg) if(not npcHandler:isFocused(cid)) then return false end local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid local shopWindow = {} local t = { [1111] = {buyprice = 1}, -- [id do item] = {buyprice = preço} [2222] = {buyprice = 10}, [3333] = {buyprice = 3} } local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks) if t[item] and doPlayerRemovePoints(cid, t[item].buyprice) then doPlayerAddItem(cid, item) selfSay("Here you go.", cid) else selfSay("You don't have "..t[item].buyprice.." points.", cid) end return true end if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then for var, ret in pairs(t) do table.insert(shopWindow, {id = var, subType = 0, buy = ret.buyprice, sell = 0, name = getItemNameById(var)}) end openShopWindow(cid, shopWindow, onBuy, onSell) end return true end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new()) E, antes que peça rsrsrs, um tile que só passa com certa quantidade de pontos. Movements Em movements/scripts crie um arquivo: tilepoints.lua Mostrar conteúdo oculto Mostrar conteúdo oculto local points_needed = {remove = true, count = 15} function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor) if getPlayerPoints(cid) < points_needed.count then doPlayerSendCancel(cid, "You need " .. points_needed.count .. " points to pass.") doTeleportThing(cid, fromPosition) return true end if points_needed.remove then doPlayerRemovePoints(cid, points_needed.count) end end Em movements.xml: <movevent type="StepIn" actionid="ACTION_ID_DO_PISO" event="script" value="tilepoints.lua"/> nota 10, só o comando /onpoints 10 que não funcionou
Postado Setembro 3, 2017 7 anos Autor Em 03/09/2017 em 22:12, Dwarfer disse: Faltava uma coisinha, editei lá já. Deu certo, obg
Participe da conversa
Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.