Esse script coloca o player em uma fila. Quando entrar outros 5 jogadores na fila, é criada uma party e todos são teleportados para a dungeon. Lembrando que a diferença de nível entre os jogadores é de no máximo 50 levels.
- Adicione uma nova tabela em seu banco de dados
CREATE TABLE `dungeon_finder` (`id` INT(8) AUTO_INCREMENT PRIMARY KEY, `player_id` INT(255))
- Talkactions
function onSay(cid, words, param, channel) if(param == "join") then query = db.getResult("SELECT * FROM `dungeon_finder` WHERE `player_id` = " .. getPlayerGUID(cid) .. "") if(getPlayerStorageValue(cid, CONFIG.DUNGEON_STORAGE) > 1) then if(getPlayerStorageValue(cid, CONFIG.DUNGEON_STORAGE) > os.time()) then doPlayerSendCancel(cid, "You can't join queue with deserter debuff.") doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF) return true end end if(CONFIG.AREA) then if(not(isInArea(getPlayerPosition(cid), (CONFIG.AREA).FROMPOS, (CONFIG.AREA).TOPOS))) then doPlayerSendCancel(cid, "You're not in required area to join the queue.") doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF) return true end end if(CONFIG.PZ_REQUIRED) then if(not(getTilePzInfo(getPlayerPosition(cid)))) then doPlayerSendCancel(cid, "You're not in protection zone to join the queue.") doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF) return true end end if(CONFIG.REQUIRED_LEVEL) then if(getPlayerLevel(cid) < CONFIG.REQUIRED_LEVEL) then doPlayerSendCancel(cid, "You don't have required level to join the queue. The minimum level to join the queue is " .. CONFIG.REQUIRED_LEVEL .. ".") doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF) return true end end if(CONFIG.SKULL) then if(getPlayerSkullType(cid) >= CONFIG.SKULL) then doPlayerSendCancel(cid, "Murderers are not allowed to join the queue.") doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF) return true end end if(CONFIG.IN_FIGHT) then if(getCreatureCondition(cid, CONDITION_INFIGHT)) then doPlayerSendCancel(cid, "You can't be in combat in order to join the queue.") doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF) return true end end if(isInParty(cid)) then doPlayerSendCancel(cid, "You can't join queue while you are in party group.") doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF) return true end if(query:getID() == 0) then doPlayerSendCancel(cid, "You are already listed in queue.") doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF) return true end db.executeQuery("INSERT INTO `dungeon_finder` SET `player_id` = " .. getPlayerGUID(cid) .. ";") doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_BLUE) doCreatureSay(cid, "You've beed queued in dungeon finder - random mode.", TALKTYPE_ORANGE_1) elseif(param == "remove") then query = db.getResult("SELECT * FROM `dungeon_finder` WHERE `player_id` = " .. getPlayerGUID(cid) .. "") if(query:getID() == -1) then doPlayerSendCancel(cid, "You are not listed in the queue.") doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF) return true end db.executeQuery("DELETE FROM `dungeon_finder` WHERE `player_id` = " .. getPlayerGUID(cid) .. ";") doCreatureSay(cid, "You've beed removed from queue.", TALKTYPE_ORANGE_1) doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_RED) end return true end
- GlobalEvents
local DUNGEONS = { [1] = {NAME = "Test dungeon", LEVEL = 30, POS = {x = 450, y = 357, z = 15}}, } local condition = createConditionObject(CONDITION_INFIGHT) setConditionParam(condition, CONDITION_PARAM_TICKS, 15000) function onThink(cid, interval) DUNGEON = DUNGEONS[math.random(1, table.maxn(DUNGEONS))] players = {} for i = 1, 1000 do if(table.maxn(players) == 5) then break end query = db.getResult("SELECT * FROM `dungeon_finder` WHERE `id` = " .. i .. ";") if(query:getID() > -1) then pid = getPlayerByName(getPlayerNameByGUID(query:getDataInt("player_id"))) if(getPlayerStorageValue(pid, CONFIG.DUNGEON_STORAGE) > 1) then return true end if(getPlayerLevel(pid) > DUNGEON.LEVEL and getPlayerLevel(pid) < DUNGEON.LEVEL + 50) then table.insert(players, getPlayerGUID(pid)) end query:free() end end if(table.maxn(players) == 5) then for i = 1, 5 do pid = getPlayerByName(getPlayerNameByGUID(players)) if(i == 1) then doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, "You were chosen to be a dungeon guide.") addEvent(doCreatureSay, 15200, pid, "You and your team were teleported to the " .. DUNGEON.NAME .. ".", TALKTYPE_ORANGE_1) for j = 2, 5 do lid = getPlayerByName(getPlayerNameByGUID(players[j])) doPlayerInviteToParty(pid, lid) end else doPlayerJoinParty(pid, getPlayerByName(getPlayerNameByGUID(players[1]))) end delay = 0 for i = 1, 15 do addEvent(doPlayerSendTextMessage, delay + 1000, pid, MESSAGE_STATUS_CONSOLE_BLUE, "A dungeon group for you has been found. You'll be teleported to the dungeon in " .. 15 - i .. " seconds.") delay = delay + 1000 end doAddCondition(pid, condition) addEvent(doTeleportThing, 15000, pid, DUNGEON.POS) addEvent(doSendMagicEffect, 15000, DUNGEON.POS, CONST_ME_TELEPORT) db.executeQuery("DELETE FROM `dungeon_finder` WHERE `player_id` = " .. players .. ";") if(CONFIG.QUIT_POS) then setPlayerStorageValue(pid, 9001, getPlayerPosition(pid).x) setPlayerStorageValue(pid, 9002, getPlayerPosition(pid).y) setPlayerStorageValue(pid, 9003, getPlayerPosition(pid).z) end setPlayerStorageValue(pid, CONFIG.DUNGEON_STORAGE, 1) end end return true end
- CreatureEvents
function onLogout(cid) query = db.getResult("SELECT * FROM `dungeon_finder` WHERE `player_id` = " .. getPlayerGUID(cid) .. ";") if(query:getID() == -1) then return true end db.executeQuery("DELETE FROM `dungeon_finder` WHERE `player_id` = " .. getPlayerGUID(cid) .. ";") return true end function onLeaveParty(cid) if(getPlayerStorageValue(cid, CONFIG.DUNGEON_STORAGE) == 1) then setPlayerStorageValue(cid, CONFIG.DUNGEON_STORAGE, -1) if(CONFIG.DESERTER_DEBUFF_TIME) then setPlayerStorageValue(cid, CONFIG.DUNGEON_STORAGE, os.time() + CONFIG.DESERTER_DEBUFF_TIME) doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You've been marked with deserter debuff for " .. CONFIG.DESERTER_DEBUFF_TIME / 3600 .. " hour/s. For this time you can't join the queue again.") end TMP_POS = CONFIG.QUIT_POS and {x = getPlayerStorageValue(cid, 9001), y = getPlayerStorageValue(cid, 9002), z = getPlayerStorageValue(cid, 9003)} or getPlayerMasterPos(cid) doTeleportThing(cid, TMP_POS) doSendMagicEffect(TMP_POS, CONST_ME_TELEPORT) for i = 9001, 9003 do setPlayerStorageValue(cid, i, -1) end end return true end lib: CONFIG = { AREA = false, -- if false then everyone can join queue everywhere, if you want certain area add AREA = {FROMPOS = {}, TOPOS = {}} PZ_REQUIRED = false, -- requirement of standing in pz, if you don't want it just set PZ_REQUIRED = false REQUIRED_LEVEL = 30, -- required level to join the queue, if you don't want it just set REQUIRED_LEVEL = false SKULL = 1, -- skull that is not acceptable while joining queue, if you want players join with skulls just set SKULL = false IN_FIGHT = true, -- if player is in fight he can't join the queue, IN_FIGHT = false to disable QUIT_POS = false, -- if you want player to go back to his previous position (from which he got teleported to the dungeon) set QUIT_POS = true, if set to false it'll teleport player to his temple DESERTER_DEBUFF_TIME = 1800, -- 60 = 1 min, 3600 = 1h DUNGEON_STORAGE = 9005 }
- Agora nas sources (c++)
- luascript.cpp
- Procure por:
//doPlayerJoinParty(cid, lid) lua_register(m_luaState, "doPlayerJoinParty", LuaScriptInterface::luaDoPlayerJoinParty);
- E insira isto depois:
//doPlayerInviteToParty(cid, pid) lua_register(m_luaState, "doPlayerInviteToParty", LuaScriptInterface::luaDoPlayerInviteToParty);
- E procure por:
int32_t LuaScriptInterface::luaDoPlayerJoinParty(lua_State* L) { //doPlayerJoinParty(cid, lid) ScriptEnviroment* env = getEnv(); Player* leader = env->getPlayerByUID(popNumber(L)); if(!leader) { errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushboolean(L, false); } Player* player = env->getPlayerByUID(popNumber(L)); if(!player) { errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushboolean(L, false); } g_game.playerJoinParty(player->getID(), leader->getID()); lua_pushboolean(L, true); return 1; }
- E insira isto depois:
int32_t LuaScriptInterface::luaDoPlayerInviteToParty(lua_State* L) { //doPlayerInviteToParty(cid, pid) ScriptEnviroment* env = getEnv(); Player* leader = env->getPlayerByUID(popNumber(L)); if(!leader) { errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushboolean(L, false); } Player* player = env->getPlayerByUID(popNumber(L)); if(!player) { errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushboolean(L, false); } g_game.playerInviteToParty(player->getID(), leader->getID()); lua_pushboolean(L, true); return 1; }
- Agora em creatureevent.h
- Procure por:
CREATURE_EVENT_PREPAREDEATH,
- E insira isto depois
CREATURE_EVENT_LEAVEPARTY
- Procure por:
-
bool playerLogout(Player* player, bool forceLogout);
- E insira isto depois:
uint32_t executeLeaveParty(Player* player);
- Procure por:
uint32_t executePrepareDeath(Creature* creature, DeathList deathList);
- E insira isto depois:
uint32_t executeLeaveParty(Player* player);
- creatureevent.cpp
- Procure por:
-
else if(tmpStr == "preparedeath") m_type = CREATURE_EVENT_PREPAREDEATH;
- Insira isto logo em seguida:
else if(tmpStr == "leaveparty") m_type = CREATURE_EVENT_LEAVEPARTY;
- Procure por:
case CREATURE_EVENT_PREPAREDEATH: return "onPrepareDeath";
- E insira isto logo após:
case CREATURE_EVENT_LEAVEPARTY: return "onLeaveParty";
- Busque por:
case CREATURE_EVENT_PREPAREDEATH: return "cid, deathList";
- Insira isto logo em seguida:
case CREATURE_EVENT_LEAVEPARTY: return "cid";
- Busque essa função:
uint32_t CreatureEvent::executeFollow(Creature* creature, Creature* target)...
- E insira isso, após a função acima:
uint32_t CreatureEvent::executeLeaveParty(Player* player) { //onLeaveParty(cid) if(m_interface->reserveEnv()) { ScriptEnviroment* env = m_interface->getEnv(); #ifdef __DEBUG_LUASCRIPTS__ std::stringstream desc; desc << player->getName(); env->setEventDesc(desc.str()); #endif env->setScriptId(m_scriptId, m_interface); env->setRealPos(player->getPosition()); lua_State* L = m_interface->getState(); m_interface->pushFunction(m_scriptId); lua_pushnumber(L, env->addThing(player)); bool result = m_interface->callFunction(1); m_interface->releaseEnv(); return result; } else { std::cout << "[Error - CreatureEvent::executeAdvance] Call stack overflow." << std::endl; return 0; } }
- game.cpp
- Altere esse bloco
bool Game::playerLeaveParty(uint32_t playerId) { Player* player = getPlayerByID(playerId); if(!player || player->isRemoved()) return false; if(!player->getParty() || player->hasCondition(CONDITION_INFIGHT)) return false; return player->getParty()->leave(player); }
- Para esse:
bool Game::playerLeaveParty(uint32_t playerId) { Player* player = getPlayerByID(playerId); if(!player || player->isRemoved()) return false; if(!player->getParty() || player->hasCondition(CONDITION_INFIGHT)) return false; CreatureEventList leavePartyEvents = player->getCreatureEvents(CREATURE_EVENT_LEAVEPARTY); for(CreatureEventList::iterator it = leavePartyEvents.begin(); it != leavePartyEvents.end(); ++it) (*it)->executeLeaveParty(player); return player->getParty()->leave(player); }
Todos os créditos vão para Tekman, pela autoria do código.