• TibiaFace

    Tibiaface | Una comunidad Open Tibia donde encontras : mapas, scripts, Otserver, npc y amigos etc ...

    .
    demo menumenu

    Afiliados



    Votar:

    [Utilidad] Funciones Interesantes para su Servidor. [onLook, Kill and Death Count, Bank, Health, Etc]

    Compartir:

    Ver el tema anterior Ver el tema siguiente Ir abajo  Mensaje (Página 1 de 1.)

    SoyFabi

    SoyFabi
    Miembro
    Miembro

    Saludos a toda la comunidad de TibiaFace, hace mucho tiempo que no hacia un Aporte al foro, quize compartir unos codigos muy utiles para que su servidor sea mas ordinario y conveniente a los jugadores.


    Ten en cuenta que son para 1.X.

    Se trata de algunos atajos y simplicidad en algunos detalles como es en este caso:


    Cuando nosotros hablamos con un NPC, siempre tenemos que escribir "hi trade", pero ya eso se acabo. Con colocar este codigo, automaticamente el player escribira por si solo.


    [Utilidad] Funciones Interesantes para su Servidor. [onLook, Kill and Death Count, Bank, Health, Etc] Screen50


    Vamonos a Data/Events/Scripts y abrimos el archivo Player.lua /


    Una vez dentro del archivo ("Player.lua"), encontraremos la function:

    Código:
    function Player:onLook(thing, position, distance)

    Abajo de esa funcion colocaremos esto:


    Código:
    -- Look Shop and Deposit All NPC --
     local NPC_BANKER = "Vauter"
     
     if (thing:isNpc() and thing:getName() == NPC_BANKER and distance <= 3) then
     local description = "You are depositing with " .. thing:getDescription(distance)
     self:say("hi", TALKTYPE_PRIVATE_PN, false, thing)
     self:say("deposit all", TALKTYPE_PRIVATE_PN, false, thing)
     self:say("yes", TALKTYPE_PRIVATE_PN, false, thing)
     self:sendTextMessage(MESSAGE_INFO_DESCR, description)
     elseif (thing:isNpc() and distance <= 3) then
     local description = "Are you talking to " .. thing:getDescription(distance)
     self:say("hi", TALKTYPE_PRIVATE_PN, false, thing)
     self:say("trade", TALKTYPE_PRIVATE_PN, false, thing)
     self:sendTextMessage(MESSAGE_INFO_DESCR, description)
     return false
     end

    Cambiamos el nombre del Bankero es decir, donde dice Vauter le pondremos el nombre del NPC (Bank).


    Código:
    local NPC_BANKER = "Vauter"

    Una vez hecho el paso, ahora al dar look a los NPC, automaticamente estaremos dialogando.

    Otra function que me parece interesante es la si alguien te da look, podras saber quien te esta observando:

    [Utilidad] Funciones Interesantes para su Servidor. [onLook, Kill and Death Count, Bank, Health, Etc] Screen44

    Debajo de la function que hemos puesto antes, pondremos esto:

    Código:
    -- Look Inspecting --
     if thing:isPlayer() and not self:getGroup():getAccess() then
        thing:sendTextMessage(MESSAGE_STATUS_DEFAULT,"The player ["..
        self:getName() .. '] looking at you.')
     end

    Otra cosa mas seria la posicion, en algunos casos a la hora de encontrar bugs y no sabemos la posicion, con esta function podremos saber:
    [Utilidad] Funciones Interesantes para su Servidor. [onLook, Kill and Death Count, Bank, Health, Etc] Screen45

    Colocaremos esto:
    Código:
    -- Look Position --
     local position = thing:getPosition()
     description = string.format(
     "%s\nPosition: [X: %d], [Y: %d], [Z: %d].",
     description, position.x, position.y, position.z
     )
     self:sendTextMessage(MESSAGE_INFO_DESCR, description)

    Recomiendo dejar esta function en lo ultimo del onLook para que se posicione.


    Luego un detalle especial seria en los monsters, cuando estamos matando un Monsters y queremos saber cuanto de vida le queda no queda de otra que improvisar.


    Con esta function podremos saber el porcentage que le queda de vida.

    [Utilidad] Funciones Interesantes para su Servidor. [onLook, Kill and Death Count, Bank, Health, Etc] Screen46

    Colocaremos esta function:

    Código:
    -- Look Show Health Monster in Percentage --
     if thing:isCreature() and thing:isMonster() then
      description = "".. description .."\nHealth: ["..math.floor((thing:getHealth() /
      thing:getMaxHealth()) * 100).."%]"
      self:sendTextMessage(MESSAGE_INFO_DESCR, description)
     end

    Para combinar la vida, tambien queremos saber cuanto de experiencia nos otorga el monster, en el level que estamos.

    Colocaremos esto debajo:

    Código:
    -- Look Experience Monsters --
     if thing:isCreature() and thing:isMonster() then
            local exp = thing:getType():getExperience() -- get monster experience
            exp = exp * Game.getExperienceStage(self:getLevel()) -- apply experience stage multiplier
            if configManager.getBoolean(configKeys.STAMINA_SYSTEM) then -- check if stamina system is active on the server
                local staminaMinutes = self:getStamina()
                if staminaMinutes > 2340 and self:isPremium() then -- 'happy hour' check
                    exp = exp * 1.5
                elseif staminaMinutes <= 840 then -- low stamina check
                    exp = exp * 0.5
                end
            end
            description = string.format("%s\nEstimated of Exp: [%d]", description, exp)
     self:sendTextMessage(MESSAGE_INFO_DESCR, description)
        end

    Por lo que todo combinado quedaria asi:

    [Utilidad] Funciones Interesantes para su Servidor. [onLook, Kill and Death Count, Bank, Health, Etc] Screen47

    Esto no acaba aqui, otra cosa que nos gusta saber es cuantas frags o muertes llevamos por ejemplo:

    [Utilidad] Funciones Interesantes para su Servidor. [onLook, Kill and Death Count, Bank, Health, Etc] Screen48

    Para colocar esta function, tenemos que irnos a Data/CreatureScripts/ creamos un archivo (*lua*), y le renombramos a killdeathcount.

    Dentro del archivo killdeathcount, colocaremos esto:
    Código:
    local killStorage = 3000
    local deathStorage = 3001
    local toMostDamage = true
    local toKiller = true
    function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
        if not creature:isPlayer() then return true end
        if creature then
            if killer and killer:isPlayer() and toKiller then
                local killAmount = killer:getStorageValue(killStorage)
                if killAmount == -1 then killAmount = 0 end
                killer:setStorageValue(killStorage, killAmount + 1)
            end
            if mostDamageKiller and mostDamageKiller:isPlayer() and toMostDamageKiller then
                local killAmount = mostDamageKiller:getStorageValue(killStorage)
                if killAmount == -1 then killAmount = 0 end
                mostDamageKiller:setStorageValue(killStorage, killAmount + 1)
            end
            local deathAmount = creature:getStorageValue(deathStorage)
            if deathAmount == -1 then deathAmount = 0 end
            creature:setStorageValue(deathStorage, deathAmount + 1)
        end
        return true
    end

    Luego en Creaturescripts.XML añadiremos esto:
    Código:
    <event type="death" name="KillDeathCount" script="killdeathcount.lua"/>

    Una vez hemos hecho los dos pasos, ahora entraremos al archivo login.lua, que se encuentra en la misma carpeta es decir

    Data/CreatureScripts/Scripts/login.lua



    Mayormente en algunas ocasiones se encuentra en la carpeta others /

    Una vez ingresado dentro del archivo login.lua

    Colocaremos esto:
    Código:
    player:registerEvent('KillDeathCount')

    Luego como es de costumbre en onLook colocaremos abajo:
    Código:
    -- Look KILL AND DEATH --
     if thing:isPlayer() then
     local killStorage = 3000
     local deathStorage = 3001
     local killAmount, deathAmount = thing:getStorageValue(killStorage), thing:getStorageValue(deathStorage)
     if killAmount == -1 then killAmount = 0 end
     if deathAmount == -1 then deathAmount = 0 end
     description = description .. '\nKilled: [' ..killAmount..'] and ' .. 'Dieds: ['..deathAmount..']'
     self:sendTextMessage(MESSAGE_INFO_DESCR, description)
     end

    PD: Les dejo un Revscripts para TFS, solo copien y peguen, en algunas casos los servidores no traen la carpeta Data/Scripts.

    Código:
    local killStorage = 3000
    local deathStorage = 3001
    local toMostDamage = true
    local toKiller = true

    local event = CreatureEvent("KillandCount")
    function event.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
        if not creature:isPlayer() then return true end
        if creature then
            if killer and killer:isPlayer() and toKiller then
                local killAmount = killer:getStorageValue(killStorage)
                if killAmount == -1 then killAmount = 0 end
                killer:setStorageValue(killStorage, killAmount + 1)
            end
            if mostDamageKiller and mostDamageKiller:isPlayer() and toMostDamageKiller then
                local killAmount = mostDamageKiller:getStorageValue(killStorage)
                if killAmount == -1 then killAmount = 0 end
                mostDamageKiller:setStorageValue(killStorage, killAmount + 1)
            end
            local deathAmount = creature:getStorageValue(deathStorage)
            if deathAmount == -1 then deathAmount = 0 end
            creature:setStorageValue(deathStorage, deathAmount + 1)
        end
        return true
    end

    event:register()


    local eventLogin = CreatureEvent("KillandCountLogin")
    function eventLogin.onLogin(player)
     player:registerEvent("KillandCount")
     return true
    end

    eventLogin:register()

    Bueno para terminar el Aporte algo adicional que queria compartir que me parece genial, es que sin necesidad de tener dinero encima, pondremos comprar con NPC con la cuenta del Banco, algunos servidores viejos no traen esta funcion y por ello es que quize compartirla.

    Primero que todo ingresaremos a los sources.

    Buscaremos el archivo protocolgame.cpp

    Una vez dentro, buscaremos la linea llamada:
    Código:
    void ProtocolGame::sendSaleItemList(const std::list<ShopInfo>& shop)

    Remplazaremos esta linea:
    Código:
    msg.add<uint64_t>(player->getMoney());

    Por esta:
    Código:
    msg.add<uint32_t>(player->getMoney() + player->getBankBalance());

    Ahora compilamos... una vez compilado ahora nos iremos a los modulos de los NPC, es decir Data/Npc/Lib y veremos un archivo llamado NPC.lua.

    Una vez dentro de archivo NPC.lua, nos iremos a lo ultimo del archivo y pegaremos esto:
    Código:
    function Player.removeTotalMoney(self, amount)
     local moneyCount = self:getMoney()
     local bankCount = self:getBankBalance()

     if amount <= moneyCount then
     self:removeMoney(amount)
     return true

     elseif amount <= (moneyCount + bankCount) then
     if moneyCount ~= 0 then
     self:removeMoney(moneyCount)
     local remains = amount - moneyCount
     self:setBankBalance(bankCount - remains)
     self:sendTextMessage(MESSAGE_INFO_DESCR, ("Paid %d from inventory and %d gold from bank account.\n-Your account balance is-\n[%d gold]"):format(moneyCount, amount - moneyCount, self:getBankBalance()))
     return true
     else
     self:setBankBalance(bankCount - amount)
     self:sendTextMessage(MESSAGE_INFO_DESCR, ("Paid %d gold from bank account.\n-Your account balance is-\n[%d gold]"):format(amount, self:getBankBalance()))
     return true
     end
     end
     return false
    end

    Por lo que ahora no necesitaremos dinero en el Backpack, podremos viajar en el barco y negociar:

    Ejemplo al comprar:
    [Utilidad] Funciones Interesantes para su Servidor. [onLook, Kill and Death Count, Bank, Health, Etc] Screen49





    Bueno esto seria todo, se me hizo muy largo el aporte de lo que yo esperaba, pero merecera la pena.

    Cualquier duda comenta y tratare de ayudarlo sin problemas.

    Por si se me quedo un codigo o error por parte mio, disculpen, hace mucho tiempo que no hago un Post. [Utilidad] Funciones Interesantes para su Servidor. [onLook, Kill and Death Count, Bank, Health, Etc] 1f601

    Suerte! [Utilidad] Funciones Interesantes para su Servidor. [onLook, Kill and Death Count, Bank, Health, Etc] 1f60b

    2 participantes

    akane

    akane
    Miembro
    Miembro
    está muy bueno el script que descuenta el dinero del banco, sobre todo para ahorrar slots en la bp :3

    2 participantes

    Ver el tema anterior Ver el tema siguiente Volver arriba  Mensaje (Página 1 de 1.)

    Permisos de este foro:
    No puedes responder a temas en este foro.

     

    BienvenidosTibiaFace es una comunidad de Open Tibia. Para participar debes estar registrado (click para Regístrate).