brunomaidana 11 #1 Posted February 9, 2021 Olá, venho compartilhar um sistema de VIP, para dar aquele upgrade no seu servidor. Lembrando que o sistema não é de minha autoria, porem eu adicionei algumas funções extras e converti pra atual versão RevScript. Baseado e compatível com o OTSERVER OTBR. Para começar vamos executar um comando MySQL na sua database. ALTER TABLE `accounts` ADD COLUMN `viplastday` int(10) NOT NULL DEFAULT 0 AFTER `lastday`, ADD COLUMN `vipdays` int(11) NOT NULL DEFAULT 0 AFTER `lastday`; Agora, vá até a pasta data/lib e crie um arquivo chamado vip_system.lua e adicione o script dentro. Spoiler local config = { -- true = para o player ser teleportado após o termino da vip -- false = para o player não ser teleportado useTeleport = true, -- posição para onde o player ira ser teleportado expirationPosition = Position(32359, 31780, 7), -- true = para o player receber a mensagem de termino -- false = para o player nao receber a mensagem useMessage = true, expirationMessage = 'Your vip days ran out.', expirationMessageType = MESSAGE_STATUS_WARNING } if not VipData then VipData = { } end function Player.onRemoveVip(self) if config.useTeleport then self:teleportTo(config.expirationPosition) self:setDirection(SOUTH) config.expirationPosition:sendMagicEffect(CONST_ME_TELEPORT) end if config.useMessage then self:sendTextMessage(config.expirationMessageType, config.expirationMessage) end local outfitsToDelete = {963, 965, 967, 969, 971, 973, 975, 962, 964, 966, 968, 970, 972, 974} -- outfits ids local mountsToDelete = {168, 169, 170} -- mounts id for i = 1, #outfitsToDelete do self:removeOutfit(outfitsToDelete[i]) end for i = 1, #mountsToDelete do self:removeMount(mountsToDelete[i]) end local currentSex = self:getSex() local playerOutfit = self:getOutfit() playerOutfit.lookAddons = 0 if currentSex == PLAYERSEX_FEMALE then playerOutfit.lookType = 136 else playerOutfit.lookType = 128 end self:setOutfit(playerOutfit) end function Player.addAddonMount(self) local outfitsToUpgrade = {963, 965, 967, 969, 971, 973, 975, 962, 964, 966, 968, 970, 972, 974} -- add outfits ids local mountsToUpgrade = {168, 169, 170} -- add mounts ids if self:getVipDays() > 0 then for i = 1, #outfitsToUpgrade do local outfit = self:hasOutfit(outfitsToUpgrade[i],3) if outfit == false then self:addOutfitAddon(outfitsToUpgrade[i],3) end end for i = 1, #mountsToUpgrade do local outfit = self:hasMount(mountsToUpgrade[i]) if outfit == false then self:addMount(mountsToUpgrade[i]) end end end end function Player.getVipDays(self) return VipData[self:getId()].days end function Player.getLastVipDay(self) return VipData[self:getId()].lastDay end function Player.isVip(self) return self:getVipDays() > 0 end function Player.addInfiniteVip(self) local data = VipData[self:getId()] data.days = 0xFFFF data.lastDay = 0 db.query(string.format('UPDATE `accounts` SET `vipdays` = %i, `viplastday` = %i WHERE `id` = %i;', 0xFFFF, 0, self:getAccountId())) end function Player.addVipDays(self, amount) local data = VipData[self:getId()] local amount = math.min(0xFFFE - data.days, amount) if amount > 0 then if data.days == 0 then local time = os.time() db.query(string.format('UPDATE `accounts` SET `vipdays` = `vipdays` + %i, `viplastday` = %i WHERE `id` = %i;', amount, time, self:getAccountId())) data.lastDay = time else db.query(string.format('UPDATE `accounts` SET `vipdays` = `vipdays` + %i WHERE `id` = %i;', amount, self:getAccountId())) end data.days = data.days + amount end return true end function Player.removeVipDays(self, amount) local data = VipData[self:getId()] if data.days == 0xFFFF then return false end local amount = math.min(data.days, amount) if amount > 0 then db.query(string.format('UPDATE `accounts` SET `vipdays` = `vipdays` - %i WHERE `id` = %i;', amount, self:getAccountId())) data.days = data.days - amount if data.days == 0 then self:onRemoveVip() end end return true end function Player.removeVip(self) local data = VipData[self:getId()] if data.days == 0 then return end data.days = 0 data.lastDay = 0 self:onRemoveVip() db.query(string.format('UPDATE `accounts` SET `vipdays` = 0, `viplastday` = 0 WHERE `id` = %i;', self:getAccountId())) end function Player.loadVipData(self) local resultId = db.storeQuery(string.format('SELECT `vipdays`, `viplastday` FROM `accounts` WHERE `id` = %i;', self:getAccountId())) if resultId then VipData[self:getId()] = { days = result.getDataInt(resultId, 'vipdays'), lastDay = result.getDataInt(resultId, 'viplastday') } result.free(resultId) return true end VipData[self:getId()] = { days = 0, lastDay = 0 } return false end function Player.updateVipTime(self) local save = false local data = VipData[self:getId()] local days, lastDay = data.days, data.lastDay local daysBefore = days if days == 0 or days == 0xFFFF then if lastDay ~= 0 then lastDay = 0 save = true end elseif lastDay == 0 then lastDay = os.time() save = true else local time = os.time() local elapsedDays = math.floor((time - lastDay) / 86400) if elapsedDays > 0 then if elapsedDays >= days then days = 0 lastDay = 0 else days = days - elapsedDays lastDay = time - ((time - lastDay) % 86400) end save = true end end if save then if daysBefore > 0 and days == 0 then self:onRemoveVip() end db.query(string.format('UPDATE `accounts` SET `vipdays` = %i, `viplastday` = %i WHERE `id` = %i;', days, lastDay, self:getAccountId())) data.days = days data.lastDay = lastDay end end Após fazer isso, abra o arquivo lib.lua e adicione na ultima linha. dofile('data/lib/vip_system.lua') Pronto, agora vamos até a pasta data/scripts/custom. Essa pasta vamos usar para adicionar o restante dos arquivos, e caso você tenha que restaurar seu repositório, ficara mais fácil transferir os arquivo. Primeiramente vamos ao item que será usado para adicionar o vip ao player. Dentro da pasta custom crie um arquivo chamado vip_scroll.lua e adicione o script dentro. Spoiler local days = 30 --dias que da de vip local vip = Action() function vip.onUse(player, item, fromPosition, target, toPosition, isHotkey) if Tile(player:getPosition()):hasFlag(TILESTATE_PROTECTIONZONE) then player:addVipDays(days) item:remove(1) player:remove() -- need kick player to add functions (outfit, mounts, and exp) else player:sendCancelMessage("You can't use this when you're in a fight and in protection zone.") player:getPosition():sendMagicEffect(CONST_ME_POFF) end return true end vip:id(16101) -- id vip scroll vip:register() Agora vamos criar os comandos para os player e para o administrador, crie outro arquivo chamado vip_godTalkaction.lua e adicione o script dentro. Spoiler local vipGod = TalkAction("/vip") function vipGod.onSay(player, words, param) if not player:getGroup():getAccess() then return true end local params = param:split(',') if not params[2] then player:sendTextMessage(MESSAGE_INFO_DESCR, string.format('Player is required.\nUsage:\n%s <action>, <name>, [, <value>]\n\nAvailable actions:\ncheck, adddays, addinfinite, removedays, remove', words)) return false end local targetName = params[2]:trim() local target = Player(targetName) if not target then player:sendCancelMessage(string.format('Player (%s) is not online. Usage: %s <action>, <player> [, <value>]', targetName, words)) return false end local action = params[1]:trim():lower() if action == 'adddays' then local amount = tonumber(params[3]) if not amount then player:sendCancelMessage('<value> has to be a numeric value.') return false end target:addVipDays(amount) player:sendCancelMessage(string.format('%s received %s vip day(s) and now has %s vip day(s).', target:getName(), amount, target:getVipDays())) elseif action == 'removedays' then local amount = tonumber(params[3]) if not amount then player:sendCancelMessage('<value> has to be a numeric value.') return false end target:removeVipDays(amount) player:sendCancelMessage(string.format('%s lost %s vip day(s) and now has %s vip day(s).', target:getName(), amount, target:getVipDays())) elseif action == 'addinfinite' then target:addInfiniteVip() player:sendCancelMessage(string.format('%s now has infinite vip time.', target:getName())) elseif action == 'remove' then target:removeVip() player:sendCancelMessage(string.format('You removed all vip days from %s.', target:getName())) elseif action == 'check' then local days = target:getVipDays() player:sendCancelMessage(string.format('%s has %s vip day(s).', target:getName(), (days == 0xFFFF and 'infinite' or days))) else player:sendTextMessage(MESSAGE_INFO_DESCR, string.format('Action is required.\nUsage:\n%s <action>, <name>, [, <value>]\n\nAvailable actions:\ncheck, adddays, addinfinite, removedays, remove', words)) end return false end vipGod:separator(" ") vipGod:register() Agora crie outro arquivo chamado vip_playerTalkaction.lua e adicione: Spoiler local vip = TalkAction("!vip") function vip.onSay(player, words, param) local days = player:getVipDays() if days == 0 then player:sendCancelMessage('You do not have any vip days.') else player:sendCancelMessage(string.format('You have %s vip day%s left.', (days == 0xFFFF and 'infinite amount of' or days), (days == 1 and '' or 's'))) end return false end vip:register() Agora vamos para a parte final do sistema, vá até a pasta data/scripts/creaturescripts/others e abra o arquivo login.lua, procure pela linha function playerLogin.onLogin(player) e logo abaixo adicione. player:loadVipData() player:updateVipTime() player:addAddonMount() Pronto, o sistema esta finalizado. Agora algumas funções extras. Adicionar 20% de EXP para o player VIP. Vá até a pasta data/events/scripts e abra o arquivo player.lua, procure pela linha function Player:onGainExperience(source, exp, rawExp), vá até o final dessa function e ANTES do return exp adicione: if self:isVip() then exp = exp * 1.2 -- 20% exp end Adicionar 20% de LOOT para o player VIP. Vá até a pasta data/events/scripts e abra o arquivo monster.lua, dentro da function Monster:onDropLoot(corpse). Procure por local item = corpse:createLootItem(monsterLoot, boolCharm) e ANTES adicione: local vipPercentLoot = 0 if player and player:isVip() then local percent = 20 -- 20% mais loot if percent then vipPercentLoot = (percent / 100) end end monsterLoot[i].chance = monsterLoot[i].chance + (monsterLoot[i].chance * vipPercentLoot) Pronto! Logo adicionarei mais eventos e sistemas que fiz a conversão. Creditos: Printer e Numm / Otland 9 Majesty, dougdogtown, Eduardo Dantas and 6 others reacted to this Share this post Link to post
Majesty 1,755 #2 Posted February 9, 2021 Muito obrigado pela sua contribuição, seu conteúdo foi aprovado!Nós do OTServ Brasil agradecemos, seu conteúdo com certeza ajudará a muitos outros. Você recebeu +1 REP! Share this post Link to post
dougdogtown 6 #3 Posted February 24, 2021 @brunomaidana Funcionou perfeitamente ! +Rep Share this post Link to post