Ir para conteúdo
Entre para seguir isso  
Socket

PVP Control

Recommended Posts

Socket    0
Socket

PVP Control

Nome do Sistema: PVP Control

Nome do Autor: Socket

Servidor Testado: crying damson 6pl1

Descrição: Um sistema de controle de pvp em que o player pode configurá-lo como quiser.

 

[spoiler=Idéia]

Cara esse sistema de guild war se procurar tu ja encontra pelo menos parte dele, uma coisa que acho interessante é um script que me parece simples mas bem funcional, o lance de pvp, com um comando por exemplo !pvp level, 100 ae só atacaria jogadores level 100+, pvp marked, só atacar jogadores com skull, pvp guild, atacar jogadores da guild, pvp war, atacar somente jogarores rivais da war. Para listar as opções só digitar !pvp, isso ja existe em um ot serv e funciona muito bem.

 

 

  • Instalação

Primeiramente, istale o Flag System desenvolvido também por mim que pode ser encontrado aqui.

 

Crie um arquivo chamado ppvp.lua em data/lib com esse conteúdo:

 

--[[ PVP Lib System 1.0 by Socket ]]

-- FLAGS, you can use any powers of base 2:

PVP_FLAG_LEVEL    = 2 ^ 0
PVP_FLAG_GUILD    = 2 ^ 1
PVP_FLAG_PARTY    = 2 ^ 2
PVP_FLAG_SKULL    = 2 ^ 3
PVP_FLAG_WHITE    = 2 ^ 4
PVP_FLAG_YELLOW    = 2 ^ 5
PVP_FLAG_RED    = 2 ^ 6
PVP_FLAG_BLACK    = 2 ^ 7
PVP_FLAG_MAX    = 7     -- Last exponent

PVP_CONFIG = {
   PVP_FLAGS_CALLBACK = { -- Callback for each flag (PVP_PLAYER object, target)
       [PVP_FLAG_LEVEL] = function(self, uid)
           return getPlayerLevel(uid) > getPlayerStorageValue(cid, self.CONFIG.LEVEL_STORAGE)
       end,

       [PVP_FLAG_GUILD] = function(self, uid)
           return getPlayerGuildId(self.cid) ~= getPlayerGuildId(uid)
       end,

       [PVP_FLAG_PARTY] = function(self, uid)
           return getPlayerParty(self.cid) ~= getPlayerParty(uid)
       end,

       [PVP_FLAG_SKULL] = function(self, uid)
           return getPlayerSkullType(uid) > SKULL_NONE
       end,

       [PVP_FLAG_WHITE] = function(self, uid)
           return getPlayerSkullType(uid) == SKULL_WHITE
       end,

       [PVP_FLAG_YELLOW] = function(self, uid)
           return getPlayerSkullType(uid) == SKULL_YELLOW
       end,

       [PVP_FLAG_RED] = function(self, uid)
           return getPlayerSkullType(uid) == SKULL_RED
       end,

       [PVP_FLAG_BLACK] = function(self, uid)
           return getPlayerSkullType(uid) == SKULL_BLACK
       end,
   },

   FLAG_STORAGE = 36517,
   LEVEL_STORAGE = 36518
}

PVP_PLAYER = {
   PLAYER_PVP_FLAGS = {},
   CONFIG = PVP_CONFIG
}

function PVPPlayer(cid)
   local newP = setmetatable({cid = cid}, {__index = PVP_PLAYER})

   newP:LoadFlags()
   return newP
end

function PVP_PLAYER:LoadFlags()
   self.PLAYER_PVP_FLAGS = Flags.Load(self.cid, self.CONFIG.FLAG_STORAGE, PVP_FLAG_MAX)
end

function PVP_PLAYER:SaveFlags()
   Flags.Save(self.cid, self.CONFIG.FLAG_STORAGE, self.PLAYER_PVP_FLAGS)
end

function PVP_PLAYER:HasFlag(flag)
   return Flags.Has(self.cid, self.CONFIG.FLAG_STORAGE, PVP_FLAG_MAX, flag)
end

function PVP_PLAYER:AddFlag(flag)
   Flags.Add(self.cid, self.CONFIG.FLAG_STORAGE, PVP_FLAG_MAX, flag)
   self:LoadFlags()
   self:SaveFlags()
end

function PVP_PLAYER:RemoveFlag(flag)
   Flags.Remove(self.cid, self.CONFIG.FLAG_STORAGE, PVP_FLAG_MAX, flag)
   self:LoadFlags()
   self:SaveFlags()
end

function PVP_PLAYER:GetCallback(flag)
   return self.CONFIG.PVP_FLAGS_CALLBACK[flag]
end

function PVP_PLAYER:CanAttack(uid)
   if(not isPlayer(uid)) then return true end

   for index, flag in ipairs(self.PLAYER_PVP_FLAGS) do
       if(self:HasFlag(flag)) then
           local callback = self:GetCallback(flag)

           if(not callback(self, uid)) then
               return false
           end
       end
   end

   return true
end

Crie um arquivo chamado ppvp.lua em data/talkactions/scripts com esse conteúdo:

 

local TALK_CONFIG = {
   FYI_MESSAGE = {"Welcome to the PPVP Config.\nCommand:\n  !ppvp [param]%s", "This is your PPVP Details:%s"}, -- !ppvp and !ppvp check command message, do not remove %s.
   SKULL_MESSAGE = "You can use just one of these skull pvp flag:%s", -- !ppvp skull command message, do not remove %s.

   ERROR_MESSAGE = "You can't use this. Type !ppvp for help.",

   CAN_USE = function(cid) -- Here you can add a condition to use it, something like "just vip players can use".
       return true
   end
}

local FLAG_CALLBACK = { -- Callbacks for enable/disable a flag (player, flag called, param [not used on default callback])
   DEFAULT = function(cid, flag) -- Default callback, e.g: enabling PVP_FLAG_GUILD (when !ppvp guild is called)
       local player = PVPPlayer(cid)

       if(player:HasFlag(flag)) then
           player:RemoveFlag(flag)
       else
           player:AddFlag(flag)
       end

       return true
   end,

   LEVEL = function(cid, flag, param) -- Level callback, e.g: enabling PVP_FLAG_LEVEL, and setting a storage (when !ppvp level n is called)
       local player, level = PVPPlayer(cid), tonumber(param)

       if(not player:HasFlag(flag) and not level) then
           doPlayerSendCancel(cid, TALK_CONFIG.ERROR_MESSAGE)

           return true
       end

       if(player:HasFlag(flag) and not level) then
           player:RemoveFlag(flag)
       else
           player:RemoveFlag(flag)
           player:AddFlag(flag)
           setPlayerStorageValue(cid, player.CONFIG.LEVEL_STORAGE, level)
       end

       return true
   end
}

local PARAM_CALLBACK = { -- Callbacks that tells script what to do when player use the talkaction (player id, param, PARAM_CONFIG table)
   DEFAULT = function(cid, param, config) -- Default callback, e.g: !ppvp guild/!ppvp level n
       function SHOW_INFO()
           local append, form = "", "\n    \t %s: %s"

           for i, v in ipairs(config) do
               append = append .. form:format(v[1], v[4])
           end

           append = append .. "\n" .. form:format("skull", "Use this to get more information.")

           doPlayerPopupFYI(cid, TALK_CONFIG.FYI_MESSAGE[1]:format(append))

           return true
       end

       local flagName, flag = param:match("(%a+)")

       if(not flagName) then return SHOW_INFO() end

       local param = param:match(flagName .. "(.+)")

       for i, v in ipairs(config) do
           if(v[1] == flagName) then
               flag = v
           end
       end

       return flag and flag[3](cid, flag[2], param) or SHOW_INFO()
   end,

   SKULL = function(cid, param, config) -- Skull callback, e.g: !ppvp skull any/!ppvp skull yellow
       local player, param, config = PVPPlayer(cid), param:match("skull%s*(.+)"), config["skull"]
       local used = false

       for i, v in ipairs(config) do
           if(v[1] == param) then
               if(player:HasFlag(v[2])) then
                   player:RemoveFlag(v[2])
               else
                   player:AddFlag(v[2])
               end

               used = true
           elseif(v[1] ~= param and player:HasFlag(v[2])) then
               player:RemoveFlag(v[2])
               used = true
           end
       end

       if(not used) then
           local append, form = "", "\n  \t %s: %s"

           for i, v in ipairs(config) do
               append = append .. form:format(v[1], v[3])
           end

           doPlayerPopupFYI(cid, TALK_CONFIG.SKULL_MESSAGE:format(append))
       end

       return true
   end,

   CHECK = function(cid, param, config) -- Check callback, when !ppvp check is called.
       function PARSE_LIST(cid, pplayer, config, p)
           local append, form = "", "\n  \t %s"

           for i, v in ipairs(config) do
               if(pplayer:HasFlag(v[2])) then
                   local msg = p and (v[5] or v[4]) or v[3]

                   for tag in msg:gmatch("%[(.-)%]") do
                       local callback = v[tag]

                       if(callback) then
                           msg = msg:gsub("%["..tag.."%]", callback(cid, pplayer) or tag)
                       end
                   end

                   append = append .. form:format(msg)
               end
           end

           return append
       end

       local pplayer = PVPPlayer(cid)
       local append = PARSE_LIST(cid, pplayer, config, true) .. "\n"

       for i, v in pairs(config) do
           if(type(i) ~= "number") then
               append = append .. PARSE_LIST(cid, pplayer, v)
           end
       end

       doPlayerPopupFYI(cid, (#append == 1) and "You don't have any pvp flag." or TALK_CONFIG.FYI_MESSAGE[2]:format(append))

       return true
   end
}

-- Main configuration table, there is two configuration modes:

-- First (simple) (on this mode, the param callback is PARAM_CALBACK.DEFAULT):
--    {PARAM,    FLAG_ID, CALLBACK, MSG [, MSG_OP [, ...]]}
--[[
   string         PARAM         = talkaction param
   number         FLAG_ID     = flag constant
   function     CALLBACK    = FLAG_CALLBACK callback
   string         MSG            = message used on !ppvp and !ppvp check*
   string         MSG_OP        = message used on !ppvp check
   function    ...            = functions used on PARSE** (cid, PVP_PLAYER object)

   * if MSG_OP is defined, MSG will appear on !ppvp and MSG_OP will appear on !ppvp check
   ** parse system, e.g: "You will just attack [sEX] persons."    then you define on table:
       SEX = function(cid, pplayer)
           local sex = {
               [0] = "female",
               [1] = "male"
           }

           return sex[getPlayerSex(cid)]
       end

       then, [sEX] on MSG or MSG_OP will be replaced by the return value from the function SEX
]]
-- Second (complex):
--   [FIRST_PARAM] = {
--        CALLBACK = PARAM_CALLBACK callback,

--        {PARAM, FLAG_ID, MSG [, MSG_OP [, ... ]]}

local PARAM_CONFIG = {
   {"level",     PVP_FLAG_LEVEL,     FLAG_CALLBACK.LEVEL,     "Use with another param L, where L is the minimum level to attack.", "You can just attack players of level [MLVL] or higher.", MLVL = function(cid, pplayer) return pplayer.PVP_LEVEL end},
   {"guild",     PVP_FLAG_GUILD,     FLAG_CALLBACK.DEFAULT,    "You can't attack any member from your guild."},
   {"party",     PVP_FLAG_PARTY,     FLAG_CALLBACK.DEFAULT,    "You can't attack any member from your party."},

   ["skull"] = {
       CALLBACK = PARAM_CALLBACK.SKULL,

       {"any",     PVP_FLAG_SKULL,     "You can just attack players with some skull."},
       {"white",     PVP_FLAG_WHITE,        "You can just attack players with white skull."},
       {"yellow",     PVP_FLAG_YELLOW,     "You can just attack players with yellow skull."},
       {"red",     PVP_FLAG_RED,         "You can just attack players with red skull."},
       {"black",     PVP_FLAG_BLACK,     "You can just attack players with black skull."}
   },

   ["check"] = {CALLBACK = PARAM_CALLBACK.CHECK}
}


function onSay(cid, words, param)
   local config, callback = PARAM_CONFIG[param:match("(%a+)")]

   if(config) then
       callback = config.CALLBACK
   end

   return TALK_CONFIG.CAN_USE(cid) and (callback or PARAM_CALLBACK.DEFAULT)(cid, param, PARAM_CONFIG) or true
end

Crie um arquivo chamado ppvp.lua em data/creaturescripts/scripts com esse conteúdo:

 

function onAttack(cid, target)
   return PVPPlayer(cid):CanAttack(target)
end

function onCast(cid, target)
   return PVPPlayer(cid):CanAttack(target)
end

function onAreaCombat(cid, tileItem, tilePosition, isAggressive)
   return PVPPlayer(cid):CanAttack(tileItem)
end

function onCombat(cid, target)
   return PVPPlayer(cid):CanAttack(target)
end

Em data/talkactions/talkactions.xml adicone a tag:

 

<talkaction words="!ppvp" event="script" value="ppvp.lua"/>

Em data/creaturescripts/creaturescripts.xml adcione as tags:

 

<event type="attack" name="pvpAttack" event="script" value="ppvp.lua"/>
<event type="cast"     name="pvpCast" event="script" value="ppvp.lua"/>
<event type="areacombat" name="pvpAreaCombat" event="script" value="ppvp.lua"/>
<event type="combat" name="pvpCombat" event="script" value="ppvp.lua"/>

Em data/creaturescripts/creaturescripts.xml, no arquivo login.lua antes de:

 

return true

Adcione:

 

registerCreatureEvent(cid, "pvpAttack")
registerCreatureEvent(cid, "pvpCast")
registerCreatureEvent(cid, "pvpAreaCombat")
registerCreatureEvent(cid, "pvpCombat")

Qualquer bug/erro, poste aqui.

 

Atenciosamente, Socket.

Editado por Socket

Compartilhar este post


Link para o post
Oneshot    24
Oneshot

Ótimo trabalho como sempre, Socket, não esperava menos de você. Obrigado também por contribuir com o "Dê sua idéia".

 

Aprovado!

Você receberá V$ 120 como remuneração.

Seu script recebeu nota A+.

Editado por Garou

Compartilhar este post


Link para o post
iuniX    4
iuniX

Muito bom mesmo, como garou disse, não esperava menos de você. Tem mostrado trabalhos cada vez melhores. Rep+

Compartilhar este post


Link para o post
Sphex    0
Sphex

simples, útil e bem feito, parabéns, vai ajudar bastante.

 

@edit:

membros leigos não vão conseguir instalar o script corretamente, você errou ao colocar o local do arquivo creaturescript, veja:

Crie um arquivo chamado ppvp.lua em data/lib/creaturescripts com esse conteúdo:

lib/creaturescripts não existe... rsrs, espero que arrume

 

mais uma coisa que encontrei:

Em data/creaturescripts/creaturescripts.xml, no arquivo login.lua antes de:
veja com atenção...

 

@edit²:

aqui o sistema não funcionou legal, parece que instalei tudo corretamente, veja a imagem:

p.s: quando eu digo !ppvp aparece aquela janelinha e um pequeno tutorial de como usar o sistema, mas quando eu digito !ppvp skull, party, guild ou level, da esses erros ae...

2uzymgx.png

Editado por Sphex

Compartilhar este post


Link para o post
decosiqueira    0
decosiqueira

Cara muito bom mesmo esse script, era exatamente isso que eu precisava, valeu mesmo.

Compartilhar este post


Link para o post
Socket    0
Socket
simples, útil e bem feito, parabéns, vai ajudar bastante.

 

@edit:

membros leigos não vão conseguir instalar o script corretamente, você errou ao colocar o local do arquivo creaturescript, veja:

lib/creaturescripts não existe... rsrs, espero que arrume

 

mais uma coisa que encontrei:veja com atenção...

 

@edit²:

aqui o sistema não funcionou legal, parece que instalei tudo corretamente, veja a imagem:

p.s: quando eu digo !ppvp aparece aquela janelinha e um pequeno tutorial de como usar o sistema, mas quando eu digito !ppvp skull, party, guild ou level, da esses erros ae...

2uzymgx.png

 

Obrigado pelo local errado, quanto ao errro:

 

  • Instalação

Primeiramente, istale o Flag System desenvolvido também por mim que pode ser encontrado aqui.

 

Atenciosamente, Socket.

Compartilhar este post


Link para o post
hayashii    0
hayashii

Cara,daora esse script ASEKaepokAOEKpask

Eh estilo TibiaRpgBrasil (um server foda)

O Foda,eh q quando falo,por exemplo:

!ppvp level 1000

So que n acontece nada '-'

Em nenhuma dessas talkactions da certo,testei com todas

!ppvp party

!ppvp guild

!ppvp skull white

Nenhuma da certo D=

Minha distro eh Crystal Server,mais o mais foda,eh q n aparece nenhum erro no distro :0

Compartilhar este post


Link para o post
fabianobn    0
fabianobn

Up@

Use o comando: !ppvp check

 

Que você saberá como esta o estado do pvp ^^!

Compartilhar este post


Link para o post
hayashii    0
hayashii

Voce nao esta entendendo,nao ta funcionando ;@

Compartilhar este post


Link para o post
Conde2    0
Conde2

Socket tem um erro no seu script

 

[PVP_FLAG_LEVEL] = function(self, uid)

return getPlayerLevel(uid) > getPlayerStorageValue(cid, self.CONFIG.LEVEL_STORAGE)

end,

Compartilhar este post


Link para o post
designmaster    1
designmaster

amei esse script cara,

vo bota no meu ot *_*

Compartilhar este post


Link para o post
Visitante
Este tópico está impedido de receber novos posts.
Entre para seguir isso  
  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×