• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

RevScripts Protection items, smart script

Lbtg

Intermediate OT User
Joined
Nov 22, 2008
Messages
2,334
Reaction score
144
Healthy happy meaningfull life!


i want to ask if someone could make such script please :)


so a revscript for 1.3+++

in script i shoud be aible to add infinite lines for different items with different configs. physical and all elemental protection i shoud be aible to add in config,

Example of 2 configs

[1] itemid=22222; removeitemonuse=false; protectionammount=10%; protectiontype=death; protectiontime=10(min); effectonuseitem=44; effectonprotectiondissapear=33; messagesent=''you gained 10% Death protection for 10 minutes''; storageidwhileworking=66200;

[2] itemid=33333; removeitemonuse=false; protectionammount=20%; protectiontype=physical; protectiontime=15(min); effectonuseitem=88; effectonprotectiondissapear=77; messagesent=''you gained 20% Physical protection for 15 minutes''; storageidwhileworking=66200;


if player has used some item, and its working, and trying click the item again it shoud give cancel effect + message saying ''bonus protection is still active on you!''



I hope someone can give some time for this, i think alot people would like such script :) maybe i wrong, but i would be very happy for such one :))
 
Lua:
local protectionItems = {
    [22222] = {
        protectionType = "death",
        percent = 10,
        duration = 10, -- in minutes
        removeOnUse = false,
        effectOnUse = 44,
        effectOnExpire = 33,
        message = "You gained 10% protection against death for 10 minutes",
        storageId = 66200
    },
    [33333] = {
        protectionType = "physical",
        percent = 20,
        duration = 15, -- in minutes
        removeOnUse = false,
        effectOnUse = 88,
        effectOnExpire = 77,
        message = "You gained 20% physical protection for 15 minutes",
        storageId = 66201
    }
}

local protectionTypes = {
    ["physical"] = COMBAT_PHYSICALDAMAGE,
    ["energy"] = COMBAT_ENERGYDAMAGE,
    ["earth"] = COMBAT_EARTHDAMAGE,
    ["fire"] = COMBAT_FIREDAMAGE,
    ["ice"] = COMBAT_ICEDAMAGE,
    ["holy"] = COMBAT_HOLYDAMAGE,
    ["death"] = COMBAT_DEATHDAMAGE
}

local combatTypes = {
    [COMBAT_PHYSICALDAMAGE] = "physical",
    [COMBAT_ENERGYDAMAGE] = "energy",
    [COMBAT_EARTHDAMAGE] = "earth",
    [COMBAT_FIREDAMAGE] = "fire",
    [COMBAT_ICEDAMAGE] = "ice",
    [COMBAT_HOLYDAMAGE] = "holy",
    [COMBAT_DEATHDAMAGE] = "death"
}

local function applyProtection(player, item, itemConfig)
    local storageValue = player:getStorageValue(itemConfig.storageId)
    if storageValue > os.time() then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "The bonus protection is still active for you!")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    player:setStorageValue(itemConfig.storageId, os.time() + (itemConfig.duration * 60))
    player:sendTextMessage(MESSAGE_STATUS_SMALL, itemConfig.message)
    player:getPosition():sendMagicEffect(itemConfig.effectOnUse)

    if itemConfig.removeOnUse then
        item:remove(1)
    end
    return true
end

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemId = item:getId()
    local itemConfig = protectionItems[itemId]

    if not itemConfig then
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return true
    end

    local success = applyProtection(player, item, itemConfig)
    if success and itemConfig.removeOnUse then
        item:remove(1)
    end
    return true
end

for itemId, _ in pairs(protectionItems) do
    action:id(itemId)
end
action:register()

local function damageCalculator(player, primaryDamage, primaryType, secondaryDamage, secondaryType)
    for _, itemConfig in pairs(protectionItems) do
        local storageValue = player:getStorageValue(itemConfig.storageId)
        if storageValue > os.time() then
            if combatTypes[primaryType] == itemConfig.protectionType then
                primaryDamage = primaryDamage - (primaryDamage * (itemConfig.percent / 100))
            end
            if combatTypes[secondaryType] == itemConfig.protectionType then
                secondaryDamage = secondaryDamage - (secondaryDamage * (itemConfig.percent / 100))
            end
        end
    end
    return primaryDamage, secondaryDamage
end

local healthChange = CreatureEvent("onHealthChange_protection")

function healthChange.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    primaryDamage, secondaryDamage = damageCalculator(creature, primaryDamage, primaryType, secondaryDamage, secondaryType)
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

healthChange:register()

local manaChange = CreatureEvent("onManaChange_protection")

function manaChange.onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    primaryDamage, secondaryDamage = damageCalculator(creature, primaryDamage, primaryType, secondaryDamage, secondaryType)
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

manaChange:register()

local creatureevent = CreatureEvent("ProtectionItemsSmartScript")

function creatureevent.onLogin(player)
    player:registerEvent("onHealthChange_protection")
    player:registerEvent("onManaChange_protection")
    return true
end

creatureevent:register()
 
Back
Top