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

If player is in certain area then give storage

Lucas Durais

New Member
Joined
Jan 13, 2017
Messages
40
Reaction score
1
Hello guys!

I am trying to make my script gives a x if I use a certain item in a square area. But I only managed to do it in a straight line.

My script is :

Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)

        if item.itemid == x    then
        if  player:getStorage(x.x.x) == 1 then
        if isInRange(player:getPosition(), Position(x, y, z), Position(x, y, z)) and  player:getStorage(x.x.x) < 8 and  player:getStorage(x.x.x) < 1 then
        player:setStorageValue(x.x.x,  player:getStorage(x.x.x) + 1)
        player:setStorageValue(x.x.x, 1)
        player:say('x', TALKTYPE_MONSTER_SAY)
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        elseif isInRange(player:getPosition(), Position(x, y, z), Position(x, y, z)) and  player:getStorage(x.x.x) < 8 and  player:getStorage(x.x.x) < 1 then
        player:setStorageValue(x.x.x,  player:getStorage(x.x.x) + 1)
        player:setStorageValue(x.x.x, 1)
        player:say('x', TALKTYPE_MONSTER_SAY)
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        elseif isInRange(player:getPosition(), Position(x, y, z), Position(x, y, z)) and  player:getStorage(x.x.x) < 8 and  player:getStorage(x.x.x) < 1 then
        player:setStorageValue(x.x.x,  player:getStorage(x.x.x) + 1)
        player:setStorageValue(x.x.x, 1)
        player:say('x', TALKTYPE_MONSTER_SAY)
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        elseif isInRange(player:getPosition(), Position(x, y, z), Position(x, y, z)) and  player:getStorage(x.x.x) < 8 and  player:getStorage(x.x.x) < 1 then
        player:setStorageValue(x.x.x,  player:getStorage(x.x.x) + 1)
        player:setStorageValue(x.x.x, 1)
        player:say('x', TALKTYPE_MONSTER_SAY)
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        elseif isInRange(player:getPosition(), Position(x, y, z), Position(x, y, z)) and  player:getStorage(x.x.x) < 8 and  player:getStorage(x.x.x) < 1 then
        player:setStorageValue(x.x.x,  player:getStorage(x.x.x) + 1)
        player:setStorageValue(x.x.x, 1)
        player:say('x', TALKTYPE_MONSTER_SAY)
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        elseif isInRange(player:getPosition(), Position(x, y, z), Position(x, y, z)) and  player:getStorage(x.x.x) < 8 and  player:getStorage(x.x.x) < 1 then
        player:setStorageValue(x.x.x,  player:getStorage(x.x.x) + 1)
        player:setStorageValue(x.x.x, 1)
        player:say('x', TALKTYPE_MONSTER_SAY)
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        elseif isInRange(player:getPosition(), Position(x, y, z), Position(x, y, z)) and  player:getStorage(x.x.x) < 8 and  player:getStorage(x.x.x) < 1 then
        player:setStorageValue(x.x.x,  player:getStorage(x.x.x) + 1)
        player:setStorageValue(x.x.x, 1)
        player:say('x.', TALKTYPE_MONSTER_SAY)
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        elseif isInRange(player:getPosition(), Position(x, y, z), Position(x, y, z)) and  player:getStorage(x.x.x) < 8 and  player:getStorage(x.x.x) < 1 then
        player:setStorageValue(x.x.x,  player:getStorage(x.x.x) + 1)
        player:setStorageValue(x.x.x, 1)
        player:say('x', TALKTYPE_MONSTER_SAY)
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
       
        end
    end
end
        return true     
    end
 
Last edited:
Solution
Do you want to check if player is in a certain square?

Code:
local f = Pos() --top left
local t = Pos() --bottom right
local p = player:getPosition()

if ((p.x >= f.x and p.y >= f.y and p.z == f.z) and (p.x <= t.x and p.y <= t.y and p.z == t.z)) and ... then
Do you want to check if player is in a certain square?

Code:
local f = Pos() --top left
local t = Pos() --bottom right
local p = player:getPosition()

if ((p.x >= f.x and p.y >= f.y and p.z == f.z) and (p.x <= t.x and p.y <= t.y and p.z == t.z)) and ... then
 
Solution
I got the following error:

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/quests/x.lua:onUse
...ctions/scripts/quests/x.lua:3: attempt to call global 'Pos' (a nil value)
stack traceback:
        [C]: in function 'Pos'
        ...ctions/scripts/quests/x.lua:3: in function <...ctions/scripts/quests/x.lua:1>

----EDITED----

I changed "Pos" to "Position" and it worked!

Thanks man
 
Last edited:
Back
Top