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

Item cannot be used in cities

Mizakinha

New Member
Joined
Apr 18, 2021
Messages
35
Reaction score
4
Good morning people. I have a script on my server that is an item to summon monsters.

When the player uses the item, it will summon 3 monsters around the player for him to kill those monsters.

The problem is that the item can be summed up on the DP side and the monsters stay there and attack everyone. I would like to know if there is a way for me to make sure that this item can only be used away from cities, or in some specific area.

I can create a room and make sure that the item can only be used inside it. That way no novice player would die if someone uses that item close to him.

Does anyone know how I can make this item be used only in a specific area?

I'll leave the script here

Lua:
local KEY = {
    [1] = "Card Yokomon",
    [2] = "Card Koromon",
    [3] = "Card Sunmon",   
}
local config = {
    exaust_sto = 5555, -- Storage que contabiliza o exaust
    exaust_time = 60 -- Segundos de Exaust
    
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local NUMBER = math.random(1,3) -- Alterar o numero maximo pelo numero final da tabela.
    local NUMBER2 = math.random(1,3) -- Alterar o numero maximo pelo numero final da tabela.
    local NUMBER3 = math.random(1,3) -- Alterar o numero maximo pelo numero final da tabela.   
    local pos = getCreaturePosition(cid)
    local VALUE = KEY[NUMBER]
    local VALUE2 = KEY[NUMBER2]
    local VALUE3 = KEY[NUMBER3]
    local MONSTER_1 = VALUE
    local MONSTER_2 = VALUE2
    local MONSTER_3 = VALUE3
        if getTileInfo(getThingPos(cid)).protection then
            return doPlayerSendCancel(cid, "This item cannot be used in secure areas.") and doSendMagicEffect(getThingPos(cid), CONST_ME_POFF) and false
        else if not exhaustion.check(cid, config.exaust_sto) then
            doRemoveItem(item.uid, 1)
            exhaustion.set(cid, config.exaust_sto, config.exaust_time)
            doCreateMonster(MONSTER_1, pos)
            doCreateMonster(MONSTER_2, pos)
            doCreateMonster(MONSTER_3, pos)
            doSendMagicEffect(pos, CONST_ME_TELEPORT)   
            return true     
        else
            doPlayerSendTextMessage(cid, 27, "Exhaustion!! Wait ".. exhaustion.get(cid, config.exaust_sto) .." seconds.")
            doSendMagicEffect(pos, POFF)
            return false
        end
    end
    return true
end
 
Solution
tfs 0.3.6
Post automatically merged:
Lua:
local areasThatItemCannotBeUsed = {
    --{fromPosition, toPosition}
    --{top_left_corner, bottom_right_corner}
    --{{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}} -- 0 is top, 15 is bottom floor
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}},
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}},
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}}
}

local KEY = {
    [1] = "Card Yokomon",
    [2] = "Card Koromon",
    [3] = "Card Sunmon",   
}
local config = {
    exhaust_sto = 5555, -- Storage que contabiliza o exaust
    exhaust_time = 60, -- Segundos de Exaust
    monsterAmount = 3 -- amount of monsters to spawn
}
function onUse(cid, item...
Good morning people. I have a script on my server that is an item to summon monsters.

When the player uses the item, it will summon 3 monsters around the player for him to kill those monsters.

The problem is that the item can be summed up on the DP side and the monsters stay there and attack everyone. I would like to know if there is a way for me to make sure that this item can only be used away from cities, or in some specific area.

I can create a room and make sure that the item can only be used inside it. That way no novice player would die if someone uses that item close to him.

Does anyone know how I can make this item be used only in a specific area?

I'll leave the script here

Lua:
local KEY = {
    [1] = "Card Yokomon",
    [2] = "Card Koromon",
    [3] = "Card Sunmon",
}
local config = {
    exaust_sto = 5555, -- Storage que contabiliza o exaust
    exaust_time = 60 -- Segundos de Exaust
 
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local NUMBER = math.random(1,3) -- Alterar o numero maximo pelo numero final da tabela.
    local NUMBER2 = math.random(1,3) -- Alterar o numero maximo pelo numero final da tabela.
    local NUMBER3 = math.random(1,3) -- Alterar o numero maximo pelo numero final da tabela.
    local pos = getCreaturePosition(cid)
    local VALUE = KEY[NUMBER]
    local VALUE2 = KEY[NUMBER2]
    local VALUE3 = KEY[NUMBER3]
    local MONSTER_1 = VALUE
    local MONSTER_2 = VALUE2
    local MONSTER_3 = VALUE3
        if getTileInfo(getThingPos(cid)).protection then
            return doPlayerSendCancel(cid, "This item cannot be used in secure areas.") and doSendMagicEffect(getThingPos(cid), CONST_ME_POFF) and false
        else if not exhaustion.check(cid, config.exaust_sto) then
            doRemoveItem(item.uid, 1)
            exhaustion.set(cid, config.exaust_sto, config.exaust_time)
            doCreateMonster(MONSTER_1, pos)
            doCreateMonster(MONSTER_2, pos)
            doCreateMonster(MONSTER_3, pos)
            doSendMagicEffect(pos, CONST_ME_TELEPORT)
            return true  
        else
            doPlayerSendTextMessage(cid, 27, "Exhaustion!! Wait ".. exhaustion.get(cid, config.exaust_sto) .." seconds.")
            doSendMagicEffect(pos, POFF)
            return false
        end
    end
    return true
end
Here's adding what you want.
Lua:
local areasThatItemCannotBeUsed = {
    --{fromPosition, toPosition}
    --{top_left_corner, bottom_right_corner}
    --{{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}} -- 0 is top, 15 is bottom floor
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}},
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}},
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}}
}

local KEY = {
    [1] = "Card Yokomon",
    [2] = "Card Koromon",
    [3] = "Card Sunmon", 
}
local config = {
    exaust_sto = 5555, -- Storage que contabiliza o exaust
    exaust_time = 60 -- Segundos de Exaust
}
function onUse(cid, item, fromPosition, itemEx, toPosition)

    local check, pos = areasThatItemCannotBeUsed, toPosition
    for i = 1, #check do
        if pos.x >= check[i][1].x and pos.x <= check[i][2].x and pos.y >= check[i][1].y and pos.y <= check[i][2].y and pos.z >= check[i][1].z and pos.z <= check[i][2].z then
            doPlayerSendCancel(cid, "This item cannot be used inside of towns!")
            doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
            return true
        end
    end

    local NUMBER = math.random(1,3) -- Alterar o numero maximo pelo numero final da tabela.
    local NUMBER2 = math.random(1,3) -- Alterar o numero maximo pelo numero final da tabela.
    local NUMBER3 = math.random(1,3) -- Alterar o numero maximo pelo numero final da tabela. 
    local pos = getCreaturePosition(cid)
    local VALUE = KEY[NUMBER]
    local VALUE2 = KEY[NUMBER2]
    local VALUE3 = KEY[NUMBER3]
    local MONSTER_1 = VALUE
    local MONSTER_2 = VALUE2
    local MONSTER_3 = VALUE3
        if getTileInfo(getThingPos(cid)).protection then
            return doPlayerSendCancel(cid, "This item cannot be used in secure areas.") and doSendMagicEffect(getThingPos(cid), CONST_ME_POFF) and false
        else if not exhaustion.check(cid, config.exaust_sto) then
            doRemoveItem(item.uid, 1)
            exhaustion.set(cid, config.exaust_sto, config.exaust_time)
            doCreateMonster(MONSTER_1, pos)
            doCreateMonster(MONSTER_2, pos)
            doCreateMonster(MONSTER_3, pos)
            doSendMagicEffect(pos, CONST_ME_TELEPORT) 
            return true   
        else
            doPlayerSendTextMessage(cid, 27, "Exhaustion!! Wait ".. exhaustion.get(cid, config.exaust_sto) .." seconds.")
            doSendMagicEffect(pos, POFF)
            return false
        end
    end
    return true
end
And here is cleaning up your code
Lua:
local areasThatItemCannotBeUsed = {
    --{fromPosition, toPosition}
    --{top_left_corner, bottom_right_corner}
    --{{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}} -- 0 is top, 15 is bottom floor
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}},
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}},
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}}
}

local KEY = {
    [1] = "Card Yokomon",
    [2] = "Card Koromon",
    [3] = "Card Sunmon",   
}
local config = {
    exhaust_sto = 5555, -- Storage que contabiliza o exaust
    exhaust_time = 60, -- Segundos de Exaust
    monsterAmount = 3 -- amount of monsters to spawn
}
function onUse(cid, item, fromPosition, itemEx, toPosition)

    -- exhaust
    local playerPosition = getThingPosition(cid)
    if exhaustion.check(cid, config.exhaust_sto) then
        doPlayerSendTextMessage(cid, 27, "Exhaustion!! Wait ".. exhaustion.get(cid, config.exhaust_sto) .." seconds.")
        doSendMagicEffect(playerPosition, CONST_ME_POFF)
        return false
    end
    exhaustion.set(cid, config.exhaust_sto, config.exhaust_time)
    
    -- protection zone check
    if getTileInfo(getThingPos(cid)).protection then
        doPlayerSendCancel(cid, "This item cannot be used in secure areas.")
        doSendMagicEffect(playerPosition, CONST_ME_POFF)
        return true
    end
    
    -- city check
    local check, pos = areasThatItemCannotBeUsed, toPosition
    for i = 1, #check do
        if pos.x >= check[i][1].x and pos.x <= check[i][2].x and pos.y >= check[i][1].y and pos.y <= check[i][2].y and pos.z >= check[i][1].z and pos.z <= check[i][2].z then
            doPlayerSendCancel(cid, "This item cannot be used inside of towns!")
            doSendMagicEffect(playerPosition, CONST_ME_POFF)
            return true
        end
    end

    -- create monsters
    for i = 1, config.monsterAmount do
        doCreateMonster(KEY[math.random(#KEY)], playerPosition)
    end

    -- send effect and remove item
    doSendMagicEffect(playerPosition, CONST_ME_TELEPORT)
    doRemoveItem(item.uid, 1)
    return true
end
 
Here's adding what you want.
Lua:
local areasThatItemCannotBeUsed = {
    --{fromPosition, toPosition}
    --{top_left_corner, bottom_right_corner}
    --{{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}} -- 0 is top, 15 is bottom floor
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}},
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}},
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}}
}

local KEY = {
    [1] = "Card Yokomon",
    [2] = "Card Koromon",
    [3] = "Card Sunmon",
}
local config = {
    exaust_sto = 5555, -- Storage que contabiliza o exaust
    exaust_time = 60 -- Segundos de Exaust
}
function onUse(cid, item, fromPosition, itemEx, toPosition)

    local check, pos = areasThatItemCannotBeUsed, toPosition
    for i = 1, #check do
        if pos.x >= check[i][1].x and pos.x <= check[i][2].x and pos.y >= check[i][1].y and pos.y <= check[i][2].y and pos.z >= check[i][1].z and pos.z <= check[i][2].z then
            doPlayerSendCancel(cid, "This item cannot be used inside of towns!")
            doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
            return true
        end
    end

    local NUMBER = math.random(1,3) -- Alterar o numero maximo pelo numero final da tabela.
    local NUMBER2 = math.random(1,3) -- Alterar o numero maximo pelo numero final da tabela.
    local NUMBER3 = math.random(1,3) -- Alterar o numero maximo pelo numero final da tabela.
    local pos = getCreaturePosition(cid)
    local VALUE = KEY[NUMBER]
    local VALUE2 = KEY[NUMBER2]
    local VALUE3 = KEY[NUMBER3]
    local MONSTER_1 = VALUE
    local MONSTER_2 = VALUE2
    local MONSTER_3 = VALUE3
        if getTileInfo(getThingPos(cid)).protection then
            return doPlayerSendCancel(cid, "This item cannot be used in secure areas.") and doSendMagicEffect(getThingPos(cid), CONST_ME_POFF) and false
        else if not exhaustion.check(cid, config.exaust_sto) then
            doRemoveItem(item.uid, 1)
            exhaustion.set(cid, config.exaust_sto, config.exaust_time)
            doCreateMonster(MONSTER_1, pos)
            doCreateMonster(MONSTER_2, pos)
            doCreateMonster(MONSTER_3, pos)
            doSendMagicEffect(pos, CONST_ME_TELEPORT)
            return true  
        else
            doPlayerSendTextMessage(cid, 27, "Exhaustion!! Wait ".. exhaustion.get(cid, config.exaust_sto) .." seconds.")
            doSendMagicEffect(pos, POFF)
            return false
        end
    end
    return true
end
And here is cleaning up your code
Lua:
local areasThatItemCannotBeUsed = {
    --{fromPosition, toPosition}
    --{top_left_corner, bottom_right_corner}
    --{{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}} -- 0 is top, 15 is bottom floor
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}},
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}},
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}}
}

local KEY = {
    [1] = "Card Yokomon",
    [2] = "Card Koromon",
    [3] = "Card Sunmon",  
}
local config = {
    exhaust_sto = 5555, -- Storage que contabiliza o exaust
    exhaust_time = 60, -- Segundos de Exaust
    monsterAmount = 3 -- amount of monsters to spawn
}
function onUse(cid, item, fromPosition, itemEx, toPosition)

    -- exhaust
    local playerPosition = getThingPosition(cid)
    if exhaustion.check(cid, config.exhaust_sto) then
        doPlayerSendTextMessage(cid, 27, "Exhaustion!! Wait ".. exhaustion.get(cid, config.exhaust_sto) .." seconds.")
        doSendMagicEffect(playerPosition, CONST_ME_POFF)
        return false
    end
    exhaustion.set(cid, config.exhaust_sto, config.exhaust_time)
   
    -- protection zone check
    if getTileInfo(getThingPos(cid)).protection then
        doPlayerSendCancel(cid, "This item cannot be used in secure areas.")
        doSendMagicEffect(playerPosition, CONST_ME_POFF)
        return true
    end
   
    -- city check
    local check, pos = areasThatItemCannotBeUsed, toPosition
    for i = 1, #check do
        if pos.x >= check[i][1].x and pos.x <= check[i][2].x and pos.y >= check[i][1].y and pos.y <= check[i][2].y and pos.z >= check[i][1].z and pos.z <= check[i][2].z then
            doPlayerSendCancel(cid, "This item cannot be used inside of towns!")
            doSendMagicEffect(playerPosition, CONST_ME_POFF)
            return true
        end
    end

    -- create monsters
    for i = 1, config.monsterAmount do
        doCreateMonster(KEY[math.random(#KEY)], playerPosition)
    end

    -- send effect and remove item
    doSendMagicEffect(playerPosition, CONST_ME_TELEPORT)
    doRemoveItem(item.uid, 1)
    return true
end
it didn't work here. I edited the xyz positions, but it is still being used in the city: c
 
it didn't work here. I edited the xyz positions, but it is still being used in the city: c

Try this code
Edit the townRadius in config. its the amount of SQM around temple position of each town you cant use-

Lua:
local KEY = {
    [1] = "Card Yokomon",
    [2] = "Card Koromon",
    [3] = "Card Sunmon",   
}
local config = {
    exhaust_sto = 5555, -- Storage que contabiliza o exaust
    exhaust_time = 60, -- Segundos de Exaust
    monsterAmount = 3 -- amount of monsters to spawn
    townRadius = 1000 --1000sqm around town temple
}
function onUse(cid, item, fromPosition, itemEx, toPosition)

    -- exhaust
    local playerPosition = getThingPosition(cid)
    if exhaustion.check(cid, config.exhaust_sto) then
        doPlayerSendTextMessage(cid, 27, "Exhaustion!! Wait ".. exhaustion.get(cid, config.exhaust_sto) .." seconds.")
        doSendMagicEffect(playerPosition, CONST_ME_POFF)
        return false
    end
    exhaustion.set(cid, config.exhaust_sto, config.exhaust_time)
    
    -- protection zone check
    if getTileInfo(getThingPos(cid)).protection then
        doPlayerSendCancel(cid, "This item cannot be used in secure areas.")
        doSendMagicEffect(playerPosition, CONST_ME_POFF)
        return true
    end
    
    -- city check
    for _,town in pairs(Game.getTowns()) do
        if town:getTemplePosition():getDistance(toPosition) <= config.townRadius then
            doPlayerSendCancel(cid, "This item cannot be used inside of towns!")
            doSendMagicEffect(playerPosition, CONST_ME_POFF)
            return true
        end
    end

    -- create monsters
    for i = 1, config.monsterAmount do
        doCreateMonster(KEY[math.random(#KEY)], playerPosition)
    end

    -- send effect and remove item
    doSendMagicEffect(playerPosition, CONST_ME_TELEPORT)
    doRemoveItem(item.uid, 1)
    return true
end
 
Try this code
Edit the townRadius in config. its the amount of SQM around temple position of each town you cant use-

Lua:
local KEY = {
    [1] = "Card Yokomon",
    [2] = "Card Koromon",
    [3] = "Card Sunmon",  
}
local config = {
    exhaust_sto = 5555, -- Storage que contabiliza o exaust
    exhaust_time = 60, -- Segundos de Exaust
    monsterAmount = 3 -- amount of monsters to spawn
    townRadius = 1000 --1000sqm around town temple
}
function onUse(cid, item, fromPosition, itemEx, toPosition)

    -- exhaust
    local playerPosition = getThingPosition(cid)
    if exhaustion.check(cid, config.exhaust_sto) then
        doPlayerSendTextMessage(cid, 27, "Exhaustion!! Wait ".. exhaustion.get(cid, config.exhaust_sto) .." seconds.")
        doSendMagicEffect(playerPosition, CONST_ME_POFF)
        return false
    end
    exhaustion.set(cid, config.exhaust_sto, config.exhaust_time)
   
    -- protection zone check
    if getTileInfo(getThingPos(cid)).protection then
        doPlayerSendCancel(cid, "This item cannot be used in secure areas.")
        doSendMagicEffect(playerPosition, CONST_ME_POFF)
        return true
    end
   
    -- city check
    for _,town in pairs(Game.getTowns()) do
        if town:getTemplePosition():getDistance(toPosition) <= config.townRadius then
            doPlayerSendCancel(cid, "This item cannot be used inside of towns!")
            doSendMagicEffect(playerPosition, CONST_ME_POFF)
            return true
        end
    end

    -- create monsters
    for i = 1, config.monsterAmount do
        doCreateMonster(KEY[math.random(#KEY)], playerPosition)
    end

    -- send effect and remove item
    doSendMagicEffect(playerPosition, CONST_ME_TELEPORT)
    doRemoveItem(item.uid, 1)
    return true
end
now the card doesn't work, anywhere on the map.
 

Attachments

it didn't work here. I edited the xyz positions, but it is still being used in the city: c
Can you use this, and tell me what prints to console?
Lua:
local areasThatItemCannotBeUsed = {
    --{fromPosition, toPosition}
    --{top_left_corner, bottom_right_corner}
    --{{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}} -- 0 is top, 15 is bottom floor
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}},
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}},
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}}
}

local KEY = {
    [1] = "Card Yokomon",
    [2] = "Card Koromon",
    [3] = "Card Sunmon",   
}
local config = {
    exhaust_sto = 5555, -- Storage que contabiliza o exaust
    exhaust_time = 60, -- Segundos de Exaust
    monsterAmount = 3 -- amount of monsters to spawn
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    
    -- exhaust
    local playerPosition = getThingPosition(cid)
    if exhaustion.check(cid, config.exhaust_sto) then
        doPlayerSendTextMessage(cid, 27, "Exhaustion!! Wait ".. exhaustion.get(cid, config.exhaust_sto) .." seconds.")
        doSendMagicEffect(playerPosition, CONST_ME_POFF)
        return false
    end
    exhaustion.set(cid, config.exhaust_sto, config.exhaust_time)
    
    -- protection zone check
    if getTileInfo(getThingPos(cid)).protection then
        doPlayerSendCancel(cid, "This item cannot be used in secure areas.")
        doSendMagicEffect(playerPosition, CONST_ME_POFF)
        return true
    end
    
    -- city check
    local check, pos = areasThatItemCannotBeUsed, toPosition
    for i = 1, #check do
        print("-------")
        print("pos = (x = " .. pos.x .. ", y = " .. pos.y .. ", z = " .. pos.z .. ")")
        print("check1 = (x = " .. check[i][1].x .. ", y = " .. check[i][1].y .. ", z = " .. check[i][1].z .. ")")
        print("check2 = (x = " .. check[i][2].x .. ", y = " .. check[i][2].y .. ", z = " .. check[i][2].z .. ")")
        if pos.x >= check[i][1].x and pos.x <= check[i][2].x and pos.y >= check[i][1].y and pos.y <= check[i][2].y and pos.z >= check[i][1].z and pos.z <= check[i][2].z then
            print("Item cannot be used in this area!")
            doPlayerSendCancel(cid, "This item cannot be used inside of towns!")
            doSendMagicEffect(playerPosition, CONST_ME_POFF)
            return true
        end
    end
    
    -- create monsters
    for i = 1, config.monsterAmount do
        doCreateMonster(KEY[math.random(#KEY)], playerPosition)
    end
    
    -- send effect and remove item
    doSendMagicEffect(playerPosition, CONST_ME_TELEPORT)
    doRemoveItem(item.uid, 1)
    return true
end
 
você deveria ter nos dito qual servidor está usando ...
tfs 0.3.6
Post automatically merged:

Você pode usar isso e me dizer quais impressões devem ser consoladas?
[código = lua]
áreas locaisThatItemCannotBeUsed = {
- {fromPosition, toPosition}
- {top_left_corner, bottom_right_corner}
- {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}} - 0 é o topo, 15 é o piso inferior
{{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}},
{{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}},
{{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}}
}

KEY local = {
[1] = "Cartão Yokomon",
[2] = "Card Koromon",
[3] = "Cartão Sunmon",
}
configuração local = {
escape_sto = 5555, - Armazenamento que contabiliza o exaust
exausto_tempo = 60, - Segundos de Exaust
monsterAmount = 3 - quantidade de monstros para gerar
}
função onUse (cid, item, fromPosition, itemEx, toPosition)

- exaustão
playerPosition local = getThingPosition (cid)
if exhaustion.check (cid, config.exhaust_sto) então
doPlayerSendTextMessage (cid, 27, "Exaustão !! Aguarde" .. exhaustion.get (cid, config.exhaust_sto) .. "segundos.")
doSendMagicEffect (playerPosition, CONST_ME_POFF)
retorna falso
fim
exhaustion.set (cid, config.exhaust_sto, config.exhaust_time)

- verificação da zona de proteção
se getTileInfo (getThingPos (cid)). proteção, então
doPlayerSendCancel (cid, "Este item não pode ser usado em áreas seguras.")
doSendMagicEffect (playerPosition, CONST_ME_POFF)
retorno verdadeiro
fim

- verificação da cidade
verificação local, pos = areasThatItemCannotBeUsed, toPosition
para i = 1, #check fazer
impressão("-------")
print ("pos = (x =" .. pos.x .. ", y =" .. pos.y .. ", z =" .. pos.z .. ")")
print ("check1 = (x =" .. check [1] .x .. ", y =" .. check [1] .y .. ", z =" .. check [i ] [1] .z .. ")")
print ("check2 = (x =" .. check [2] .x .. ", y =" .. check [2] .y .. ", z =" .. check [i ] [2] .z .. ")")
se pos.x> = verifique [1] .x e pos.x <= verifique [2] .x e pos.y> = verifique [1] .y e pos.y < = check [2] .y e pos.z> = check [1] .z e pos.z <= check [2] .z então
print ("O item não pode ser usado nesta área!")
doPlayerSendCancel (cid, "Este item não pode ser usado dentro das cidades!")
doSendMagicEffect (playerPosition, CONST_ME_POFF)
retorno verdadeiro
fim
fim

- criar monstros
para i = 1, config.monsterAmount faça
doCreateMonster (KEY [math.random (#KEY)], playerPosition)
fim

- enviar efeito e remover item
doSendMagicEffect (playerPosition, CONST_ME_TELEPORT)
doRemoveItem (item.uid, 1)
retorno verdadeiro
fim [/ código]
 

Attachments

tfs 0.3.6
Post automatically merged:
Lua:
local areasThatItemCannotBeUsed = {
    --{fromPosition, toPosition}
    --{top_left_corner, bottom_right_corner}
    --{{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}} -- 0 is top, 15 is bottom floor
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}},
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}},
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}}
}

local KEY = {
    [1] = "Card Yokomon",
    [2] = "Card Koromon",
    [3] = "Card Sunmon",   
}
local config = {
    exhaust_sto = 5555, -- Storage que contabiliza o exaust
    exhaust_time = 60, -- Segundos de Exaust
    monsterAmount = 3 -- amount of monsters to spawn
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    
    -- exhaust
    local playerPosition = getThingPosition(cid)
    if exhaustion.check(cid, config.exhaust_sto) then
        doPlayerSendTextMessage(cid, 27, "Exhaustion!! Wait ".. exhaustion.get(cid, config.exhaust_sto) .." seconds.")
        doSendMagicEffect(playerPosition, CONST_ME_POFF)
        return false
    end
    exhaustion.set(cid, config.exhaust_sto, config.exhaust_time)
    
    -- protection zone check
    if getTileInfo(getThingPos(cid)).protection then
        doPlayerSendCancel(cid, "This item cannot be used in secure areas.")
        doSendMagicEffect(playerPosition, CONST_ME_POFF)
        return true
    end
    
    -- city check
    local check, pos = areasThatItemCannotBeUsed, playerPosition
    for i = 1, #check do
        if pos.x >= check[i][1].x and pos.x <= check[i][2].x and pos.y >= check[i][1].y and pos.y <= check[i][2].y and pos.z >= check[i][1].z and pos.z <= check[i][2].z then
            doPlayerSendCancel(cid, "This item cannot be used inside of towns!")
            doSendMagicEffect(playerPosition, CONST_ME_POFF)
            return true
        end
    end
    
    -- create monsters
    for i = 1, config.monsterAmount do
        doCreateMonster(KEY[math.random(#KEY)], playerPosition)
    end
    
    -- send effect and remove item
    doSendMagicEffect(playerPosition, CONST_ME_TELEPORT)
    doRemoveItem(item.uid, 1)
    return true
end
 
Solution
Lua:
local areasThatItemCannotBeUsed = {
    --{fromPosition, toPosition}
    --{top_left_corner, bottom_right_corner}
    --{{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}} -- 0 is top, 15 is bottom floor
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}},
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}},
    {{x = 900, y = 900, z = 0}, {x = 1100, y = 1100, z = 15}}
}

local KEY = {
    [1] = "Card Yokomon",
    [2] = "Card Koromon",
    [3] = "Card Sunmon",  
}
local config = {
    exhaust_sto = 5555, -- Storage que contabiliza o exaust
    exhaust_time = 60, -- Segundos de Exaust
    monsterAmount = 3 -- amount of monsters to spawn
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
   
    -- exhaust
    local playerPosition = getThingPosition(cid)
    if exhaustion.check(cid, config.exhaust_sto) then
        doPlayerSendTextMessage(cid, 27, "Exhaustion!! Wait ".. exhaustion.get(cid, config.exhaust_sto) .." seconds.")
        doSendMagicEffect(playerPosition, CONST_ME_POFF)
        return false
    end
    exhaustion.set(cid, config.exhaust_sto, config.exhaust_time)
   
    -- protection zone check
    if getTileInfo(getThingPos(cid)).protection then
        doPlayerSendCancel(cid, "This item cannot be used in secure areas.")
        doSendMagicEffect(playerPosition, CONST_ME_POFF)
        return true
    end
   
    -- city check
    local check, pos = areasThatItemCannotBeUsed, playerPosition
    for i = 1, #check do
        if pos.x >= check[i][1].x and pos.x <= check[i][2].x and pos.y >= check[i][1].y and pos.y <= check[i][2].y and pos.z >= check[i][1].z and pos.z <= check[i][2].z then
            doPlayerSendCancel(cid, "This item cannot be used inside of towns!")
            doSendMagicEffect(playerPosition, CONST_ME_POFF)
            return true
        end
    end
   
    -- create monsters
    for i = 1, config.monsterAmount do
        doCreateMonster(KEY[math.random(#KEY)], playerPosition)
    end
   
    -- send effect and remove item
    doSendMagicEffect(playerPosition, CONST_ME_TELEPORT)
    doRemoveItem(item.uid, 1)
    return true
end
It worked. thank you so much!
 
Back
Top