Apresentação: Após ver que muitos usuários tinham interesse em um sistema de Trade de Points in-game resolvi trazer um sistema totalmente completo para vocês.
Funcionamento:
- Player 1 após adquirir os Points, pode iniciar uma negociação com o Player 2 através do comando /tradepoints Player 2, Quantidade.
- Será aberto uma Janela de Trade com o item referente aos Points.
- Após ambos aceitarem a negociação será realizado a troca de Points pelo item requisitado.
Algumas Imagens:
Instalação:
-
Sources > Luascript.cpp
Spoiler
//doTradeOrbs(cid, target, points) lua_register(m_luaState, "doTradeOrbs", LuaInterface::luaDoTradeOrbs);
-
Sources > Luascript.cpp
Spoiler
int32_t LuaInterface::luaDoTradeOrbs(lua_State* L) { ScriptEnviroment* env = getEnv(); int quantidade = popNumber(L); Player* target = env->getPlayerByUID(popNumber(L)); Player* player = env->getPlayerByUID(popNumber(L)); if(!player || !target) { errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushboolean(L, false); return 1; } Item* Orb = new Item(7722);; Orb->addRef(); char buffer[150]; sprintf(buffer, "You see %d Collapser Orbs.", quantidade); Orb->setSpecialDescription(buffer); Orb->setSubType(1); player->transferContainer.__addThing(NULL, Orb); player->transferContainer.setParent(player); if(!g_game.internalStartTrade(player, target, Orb)) Orb->onTradeEvent(ON_TRADE_CANCEL, player, NULL); g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_WRAPS_BLUE); return false; }
-
Sources > Luascript.h
Spoiler
static int32_t luaDoTradeOrbs(lua_State* L);
-
Server > Data > Lib > 050-function
Spoiler
function getAccountPoints(cid) local res = db.getResult('select `premium_points` from accounts where name LIKE \''..getPlayerAccount(cid)..'\'') return res:getDataInt("premium_points") < 0 and 0 or res:getDataInt("premium_points") end function doPlayerAddPoints(cid, quant) return db.query("UPDATE `accounts` SET `premium_points` = '".. getAccountPoints(cid) + quant .."' WHERE `name` LIKE '"..getPlayerAccount(cid).."'") end function doAccountRemovePoints(cid, count) return db.query("UPDATE `accounts` SET `premium_points` = '".. getAccountPoints(cid) - count .."' WHERE `name` LIKE '"..getPlayerAccount(cid).."'") end
-
Server > Data > Creaturescripts > Scripts >Trade_Orbs.lua
Spoiler
function CompleteTrade(fromplayer, toplayer, points) if getPlayerItemCount(toplayer, 7722) >= 1 and getAccountPoints(fromplayer) >= points then doAccountRemovePoints(fromplayer, points) doPlayerRemoveItem(toplayer, 7722, 1) doPlayerAddPoints(toplayer, points) doPlayerSendTextMessage(toplayer, MESSAGE_STATUS_WARNING, "You have received ".. points .." Collapser Orbs.") return true end end function CollapserOrbs(item) return tonumber(string.match(getItemDescriptions(item.uid).special, "You see (%w+) Collapser Orbs.")) end function onTradeAccept(cid, target, item, targetItem) if isPlayer(cid) and isPlayer(target) then if (item.itemid == 7722 and targetItem.itemid == 7722) then doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You cannot trade points for points.") doPlayerSendTextMessage(target, MESSAGE_STATUS_WARNING, "You cannot trade points for points.") return false end if item.itemid == 7722 then local points = CollapserOrbs(item) addEvent(CompleteTrade, 1, cid, target, points) end if targetItem.itemid == 7722 then local points = CollapserOrbs(targetItem) addEvent(CompleteTrade, 1, target, cid, points) end end return true end
-
Server > Data > Creaturescripts > Creaturescripts.xml
Spoiler
<event type="tradeaccept" name="Points_Trade" event="script" value="Trade_Orbs.lua"/>
-
Server > Data > Creaturescripts > Scripts > Login.lua
Spoiler
registerCreatureEvent(cid, "Points_Trade")
-
Server > Data > Talkactions > Scripts > Points_Trade.lua
Spoiler
function onSay(cid, words, param, channel) local t = string.explode(param, ",") local target = getCreatureByName(t[1]) local points = tonumber(t[2]) if(param == '') then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.") end if (target ~= nil and target ~= cid) and isPlayer(target) and not isPlayerGhost(target) then if (points ~= nil) and (type(points) == 'number') and (points>0) then if (getAccountPoints(cid) >= points) then doTradeOrbs(cid, target, points) else doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You do not have enough points.") end else doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid param specified.") end else doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid param specified.") end return true end
-
Server > Data > Talkactions > Talkactions.xml
Spoiler
<talkaction words="/tradepoints" log="yes" event="script" value="Trade_Points.lua"/>
Créditos:
Todo o sistema foi feito completamente por mim: Vítor Subhi.