• 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!

Lua Add battle and Protection

Forkz

Member
Joined
Jun 29, 2020
Messages
182
Solutions
1
Reaction score
24
Hi otlanders,
I was trying to add battle and protection to use the item and I'm not getting it to work.

protect = false = if the player is in PZ area he can use the item.
battle = true = If the player is out of PZ he will have to be without battle to use the item


Lua:
function onUse(cid, item, frompos, item2, topos)
local config = {
    removeItem = false,
    storage = 10000,
    exhaustedtime = 5
}
local pos = getTownTemplePosition(getPlayerTown(cid))
local playerPos = getCreaturePosition(cid)
local levelplayer = 8

    if (os.time() < getPlayerStorageValue(cid, config.storage)) then
        doPlayerSendTextMessage(cid, 26, "Você deve aguardar " .. getPlayerStorageValue(cid, config.storage) - os.time() .. " segundos para usar o golden falcon.")
        return true
    end
    if config.removeItem then
        doRemoveItem(item.uid)
    end
    doPlayerSendTextMessage(cid, 25, "Você chegou usando o Golden Falcon.")
    doSendMagicEffect(playerPos, CONST_ME_POFF)
    doTeleportThing(cid, pos)
    doSendMagicEffect(pos, CONST_ME_TELEPORT)
    setPlayerStorageValue(cid, config.storage, os.time() + config.exhaustedtime)
return true
end
 

Alberto Cabrera

Active Member
Joined
Sep 17, 2020
Messages
44
Solutions
14
Reaction score
48
Location
México
Lua:
local config = {
    removeItem = false,
    storage = 10000,
    exhaustedtime = 5,
    protect = false, -- if it is true, you need to be in the protection zone
    battle = false, -- if it's true you need to be without a battle
    level = 8
}

function onUse(cid, item, frompos, item2, topos)
    if getPlayerLevel(cid) < config.level then
        return doPlayerSendCancel(cid, "Você precisa ser nível " .. config.level .." ou mais.")
    end
    if config.protect then
        if not getTilePzInfo(frompos) then
            return doPlayerSendTextMessage(cid, 26, "Você precisa estar em uma zona de proteção.")
        end
    end
    if config.battle then
        if isPlayerPzLocked(cid) then
            return doPlayerSendTextMessage(cid, 26, "Você tem que estar sem batalha para usar o item.")
        end
    end
    if (os.time() < getPlayerStorageValue(cid, config.storage)) then
        return doPlayerSendTextMessage(cid, 26, "Você deve aguardar " .. getPlayerStorageValue(cid, config.storage) - os.time() .. " segundos para usar o golden falcon.")
    end
    if config.removeItem then
        doRemoveItem(item.uid, 1)
    end

    local pos = getTownTemplePosition(getPlayerTown(cid))
    doPlayerSendTextMessage(cid, 25, "Você chegou usando o Golden Falcon.")
    doSendMagicEffect(frompos, CONST_ME_POFF)
    doTeleportThing(cid, pos)
    doSendMagicEffect(pos, CONST_ME_TELEPORT)
    setPlayerStorageValue(cid, config.storage, os.time() + config.exhaustedtime)
    return true
end
 
Last edited:

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,803
Solutions
431
Reaction score
3,935
Lua:
local config = {
    removeItem = false,
    storage = 10000,
    exhaustedtime = 5,
    protect = false, -- if it is true, you need to be in the protection zone
    battle = false, -- if it's true you need to be without a battle
    level = 8
}

function onUse(cid, item, frompos, item2, topos)
    if getPlayerLevel(cid) < config.level then
        return doPlayerSendCancel(cid, "Você precisa ser nível " .. config.level .." ou mais.")
    end
    if config.protect then
        if not getTilePzInfo(frompos) then
            return doPlayerSendTextMessage(cid, 26, "Você precisa estar em uma zona de proteção.")
        end
    end
    if config.battle then
        if isPlayerPzLocked(cid) then
            return doPlayerSendTextMessage(cid, 26, "Você tem que estar sem batalha para usar o item.")
        end
    end
    if (os.time() < getPlayerStorageValue(cid, config.storage)) then
        return doPlayerSendTextMessage(cid, 26, "Você deve aguardar " .. getPlayerStorageValue(cid, config.storage) - os.time() .. " segundos para usar o golden falcon.")
    end
    if config.removeItem then
        doRemoveItem(item.uid, 1)
    end

    local pos = getTownTemplePosition(getPlayerTown(cid))
    doPlayerSendTextMessage(cid, 25, "Você chegou usando o Golden Falcon.")
    doSendMagicEffect(frompos, CONST_ME_POFF)
    doTeleportThing(cid, pos)
    doSendMagicEffect(pos, CONST_ME_TELEPORT)
    setPlayerStorageValue(cid, config.storage, os.time() + config.exhaustedtime)
    return true
end
I think he meant entirely out of battle instead of the pz lock.
Everything else looks great! 👍

if getCreatureCondition(cid, CONDITION_INFIGHT) then
 
OP
OP
Forkz

Forkz

Member
Joined
Jun 29, 2020
Messages
182
Solutions
1
Reaction score
24
I put battle = true
But when I leave the PZ and the player is with the battle, he teleports the same, even managed with the fight.


Lua:
battle = true, -- if it's true you need to be without a battle   
     if config.battle then
        if getCreatureCondition(cid, CONDITION_INFIGHT) then
            return doPlayerSendTextMessage(cid, 26, "Você tem que estar sem batalha para usar o item.")
        end
    end
Post automatically merged:

I think he meant entirely out of battle instead of the pz lock.
Everything else looks great! 👍

if getCreatureCondition(cid, CONDITION_INFIGHT) then
it's not working, the player teleports the same, it seems he doesn't check if the player has "fight" or "not" :(
Post automatically merged:

Solution
Lua:
if hasCreatureCondition(cid, CONDITION_INFIGHT) then
 
Last edited:
Top