Ola galera xtibiaaana!.
Então meus amigos resolvi fazer um TV system aquele famoso sistema que o player cria uma channel(canal) e outros players poderão ver ele batalhando.
Estou retirando o máximo de bugs possíveis se você viu um bug não deixe de falar.
Vamos as explicações:
Primeiro o player cria uma channel usando o comando /tv(nome da channel) depois outro player ve sua channel na lista usando o comando /channel(list) logo ele quer entrar em sua channel então ele fala /channel(nome da channel).
Logo apos ele falar ele entra e começa a assistir mais depois ele quer sair então ele "desloga" e ele volta ao tempo.
Vamos a instalação.
Execute este comandos na sua database:
CREATE TABLE "tv" ( "name" Text NOT NULL, "player" INT NOT NULL, "conec" INT NOT NULL )
Vá em lib e crie um arquivo lua chamado de tv e coloque isto:
function createTv(cid, name) db.executeQuery("INSERT INTO `tv` (`name`, `player`, `conec`, `watch`) VALUES ('" .. name .. "', " .. getPlayerGUID(cid) .. ", 1, 0);") setPlayerStorageValue(cid, 23423, 1) doPlayerSave(cid) end function isTv(name) local tv = db.getResult("SELECT * FROM `tv` WHERE `name` = '".. name .."';") return tv:getID() ~= -1 and true or false end function getChannelPlayer(cid) return getPlayerStorageValue(cid, 23423) == 1 and true or getPlayerStorageValue(cid, 23423) == -1 and false end function getWatchingNameChannel(cid) return getPlayerStorageValue(cid, 44670) end local combat = createCombatObject() setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false) local conditi = createConditionObject(CONDITION_MUTED) setConditionParam(conditi, CONDITION_PARAM_TICKS, 10000*10000) local condition = createConditionObject(CONDITION_INVISIBLE) setConditionParam(condition, CONDITION_PARAM_TICKS, 200000) function enterInTv(cid, name) local function comparePos(pos, post) local pos = getThingPos(pos) local post = getThingPos(post) return pos.x == pos.x or pos.y == pos.y or pos.z == pos.z and false or true end local function fallowPlayer(cid, player) if not isPlayer(cid) or getPlayerStorageValue(cid, 44670) == -1 then return true end if comparePos(cid, player) then doTeleportThing(cid, getThingPos(player)) doAddCondition(cid, condition) doAddCondition(cid, conditi) setCombatCondition(combat, condition) end return addEvent(fallowPlayer, 1800, cid, player) and doPlayerSave(cid) end setPlayerStorageValue(cid, 44670, name) local tv = db.getResult("SELECT * FROM `tv` WHERE `name` = '".. name .."';") local guid = tv:getDataInt("player") local player = getPlayerByNameWildcard(getPlayerNameByGUID(guid)) return fallowPlayer(cid, player) end function exitChannel(cid) doRemoveCondition(cid, CONDITION_INVISIBLE) doRemoveCondition(cid, CONDITION_MUTED) doRemoveCondition(cid, COMBAT_PARAM_AGGRESSIVE) doTeleportThing(cid, getPlayerMasterPos(cid)) setPlayerStorageValue(cid, 44670, -1) doPlayerSave(cid) end function doShowListChannel(cid) local tv = db.getResult("SELECT * FROM `tv` WHERE `player` ORDER BY `conec`") str = "Channel Disponiveis:\n\n" if tv:getID() == -1 then doShowTextDialog(cid, 1387, "Não ha channel disponiveis") return true end while true do local conect = tv:getDataInt("conec") local player = tv:getDataInt("player") local channel = tv:getDataString("name") local players = getPlayerNameByGUID(player) str = str .. channel .. " -("..players..")\n\n" if not tv:next() then doShowTextDialog(cid, 1397, str) break end end end function getConectTv(name) local tv = db.getResult("SELECT * FROM `tv` WHERE `name` = '".. name .."';") return tv:getDataInt("conec") == 1 and true or tv:getDataInt("conec") == 0 and false end function setStatusTv(cid, on) if on == "on" then return db.executeQuery("UPDATE `tv` SET `conec` = 1 WHERE `player` = "..getPlayerGUID(cid)) end if on == "off" or on ~= "on" then local tv = db.getResult("SELECT * FROM `tv` WHERE `player` = '".. getPlayerGUID(cid) .."';") local channel = tv:getDataString("name") db.executeQuery("UPDATE `tv` SET `conec` = 0 WHERE `player` = "..getPlayerGUID(cid)) for i =1, #getPlayersOnline() do if getWatchingNameChannel(getPlayersOnline()[i]) == channel and getPlayersOnline()[i] ~= cid then exitChannel(getPlayersOnline()[i]) doPlayerSendTextMessage(getPlayersOnline()[i], MESSAGE_INFO_DESCR, "A channel foi desligada") end end end end
Vá em talkactions crie um arquivo Lua chamado de tv coloque isto:
function onSay(cid, words, param, channel) local item = 1949 ----Item que você precisa local bloqued = {"sair", "list", "on", "off"} ----- Nomes de channel que não pode ser usado if param == "" or param == " " then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Diga o nome da channel que você quer") and false end if param == "on" or param == "off" then return setStatusTv(cid, param) end for i = 1, #bloqued do str = "Nomes não podem ser ultlizados" str = ""..str.."\n"..bloqued[i].."" if param == bloqued[i] then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Este nome não pode ser ultilizado porque e um comando do sistema") and false end end if #param <= 4 and #param >= 10 then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "O nome da sua channel deve ser maior que 4 caracteres e menor que 10 caracters") and false end if getPlayerItemCount(cid, item) < 1 then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Você precisa de um "..getItemNameById(item).."") and false end if getChannelPlayer(cid) then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Você ja tem uma channel") and false end createTv(cid, param) doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Parabéns sua channel "..param.." foi criada") return true end
Vá em talkactions e crie um arquivo lua chamado de channel e coloque isto:
function onSay(cid, words, param, channel) if param == "" or param == " " then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Diga /channel(nome da channel para se conectar)\n/channel(list) Lista das channels\n/channel(sair para sair da channel)") and false end if param ~= "list" and param ~= "sair" then if not isTv(param) then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Não existe esta channel") and false end if not (getTilePzInfo(getCreaturePosition(cid))) then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Você so pode entrar em uma channel quando estiver em pz") return true end if getChannelPlayer(cid) then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Você não pode entrar uma tv porque você ja tem uma") return true end if getWatchingNameChannel(cid) ~= -1 then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Você esta conectado a uma channel") return true end if not getConectTv(param) then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Esta channel esta desativada") and false end enterInTv(cid, param) doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Você esta assitindo a channel "..param.."") return true end if param == "list" then return doShowListChannel(cid) end if param == "sair" then if getChannelPlayer(cid) then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Você não pode sair de sua propria tv use o comando /tv off para desativar sua channel") return true end if getWatchingNameChannel(cid) == -1 then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Você não esta conectado a uma channel") return true end exitChannel(cid) return true end return true end
Vá em talkactions.xml e coloque estas tags:
<talkaction words="/tv" event="script" value="tv.lua"/> <talkaction words="/channel" event="script" value="channel.lua"/>
Vá em creaturescripts e crie um arquivo lua chamado tv e coloque isto:
function onLogout(cid) if getChannelPlayer(cid) then local tv = db.getResult("SELECT * FROM `tv` WHERE `player` = '".. getPlayerGUID(cid) .."';") local channel = tv:getDataString("name") db.executeQuery("UPDATE `tv` SET `conec` = 0 WHERE `player` = "..getPlayerGUID(cid)) for i =1, #getPlayersOnline() do if getWatchingNameChannel(getPlayersOnline()[i]) == channel and getPlayersOnline()[i] ~= cid then exitChannel(getPlayersOnline()[i]) doPlayerSendTextMessage(getPlayersOnline()[i], MESSAGE_INFO_DESCR, "A channel foi desligada") end end doPlayerSendTextMessage(getPlayersOnline()[i], MESSAGE_INFO_DESCR, "Sua channel foi desativado ao você logar religue dizendo /tv on") return true end if getWatchingNameChannel(cid) ~= -1 then exitChannel(cid) return true end return true end function onAttack(cid, target) if getWatchingNameChannel(cid) ~= 1 then return false end return true end
Registre o evento colocando isto antes do ultimo return true:
registerCreatureEvent(cid, "tv") registerCreatureEvent(cid, "tv")
Coloque esta tags em creaturescripts.xml:
<event type="logout" name="tv" event="script" value="tv.lua"/> <event type="attack" name="attacktv" event="script" value="tv.lua"/>
Configurações
-------TALKS------
/tv(nome da channel) -- Cria nova channel
/channel(list) --- Exibe a lista de tv
/channel(name) -- Conecta a uma channel
/tv(on ou off) ----Liga e desliga uma channel.
-----Configurações Automáticas------
Ao deslogar sua channel e desligada
Quando esta dentro de uma channel não e possivel atacar
Quando esta dentro de uma channel você fica invisivel
Quando esta dentro de uma channel você fica muted.
Para sair de uma channel deslogue(Também existe a talk /channel(sair) só que ela ficou inutilizável ao colocar o sistema de muted)
Midia:
Ajude o tv system dizendo ideias e bugs para o sistema.
Estarei optimizando o sistema e retirandos bugs.