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

OnMoveItem

goesraphael

Member
Joined
Apr 4, 2017
Messages
59
Solutions
1
Reaction score
9
Hello,
I need a script that if has X items in a sqm, if the players try to put another item in that same sqm, return that is not possible.

I have tried in many ways, my last attempt:
Code:
function onMoveItem(moveItem, frompos, position, cid)
    if(Tile(toPosition):getItemCount(cid) >= X and toPosition ~= nil) then -- X = Número de itens
        doPlayerSendCancel(cid, "Sorry, not possible.")
    else
        return true
    end
end

If someone can help me I'll be glad.
 
What is the value of X & toPosition? Where are they defined?

Lets say that toPosition is a table, well even an empty table is not equal to nil.
 
What is the value of X & toPosition? Where are they defined?

Lets say that toPosition is a table, well even an empty table is not equal to nil.

X = the value that I want to choose, For example, If i want that the sqm can fit only 10 items per sqm, I replace X per 10.


TFS 1.2 ? 0.4 ? o_O
OTX2
 
Last edited:
Code:
local maxItems = 10

function onMoveItem(moveItem, frompos, position, cid)
    local currItems = getTileInfo(position).items
    if currItems >= maxItems then
        doPlayerSendCancel(cid, 'Sorry, not possible.')
        return false
    end
    return true
end
no test!
 
Code:
local maxItems = 10

function onMoveItem(moveItem, frompos, position, cid)
    local currItems = getTileInfo(position).items
    if currItems >= maxItems then
        doPlayerSendCancel(cid, 'Sorry, not possible.')
        return false
    end
    return true
end
no test!
2wfitsl.png

2z67zmd.png


Didn't work
I can still put more than 10 itens in the same sqm.
 
Example:
Code:
<event type="moveitem" name="MoveItem" event="script" value="houseprotect.lua"/>
Login.lua
Code:
registerCreatureEvent(cid, "MoveItem")
 
Example:
Code:
<event type="moveitem" name="MoveItem" event="script" value="houseprotect.lua"/>
Login.lua
Code:
registerCreatureEvent(cid, "MoveItem")
Code:
local config = {
    loginMessage = getConfigValue('loginMessage'),
    useFragHandler = getBooleanFromString(getConfigValue('useFragHandler'))
}

function onLogin(cid)
    if(getBooleanFromString(getConfigValue('accountManager')) == false) then
        if (getCreatureName(cid) == "Account Manager") then
            return doRemoveCreature(cid, true)
        end
    end
   
    local loss = getConfigValue('deathLostPercent')
    if(loss ~= nil and getPlayerStorageValue(cid, "bless") ~= 5) then
        doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, loss * 10)
        doPlayerSetLossPercent(cid, PLAYERLOSS_ITEMS, 7)
    end

    if(getPlayerStorageValue(cid, "death_bless") == 1) then
        local t = {PLAYERLOSS_EXPERIENCE, PLAYERLOSS_SKILLS, PLAYERLOSS_ITEMS, PLAYERLOSS_CONTAINERS}
        for i = 1, #t do
            doPlayerSetLossPercent(cid, t[i], 100)
        end
        setPlayerStorageValue(cid, "death_bless", 0)
    end

    local accountManager = getPlayerAccountManager(cid)
    if(accountManager == MANAGER_NONE) then
        local lastLogin, str = getPlayerLastLoginSaved(cid), config.loginMessage
        if(lastLogin > 0) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
            str = "Your last visit was on " .. os.date("%a %b %d %X %Y", lastLogin) .. "."
        else
            str = str .. " Please choose your outfit."
            doPlayerSendOutfitWindow(cid)
        end

        doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
    elseif(accountManager == MANAGER_NAMELOCK) then
        addEvent(valid(doCreatureSay), 500, cid, "Hello, it appears that your character has been locked for name violating rules, what new name would you like to have?", TALKTYPE_PRIVATE_NP, true, cid)
    elseif(accountManager == MANAGER_ACCOUNT) then
        addEvent(valid(doCreatureSay), 500, cid, "Hello, type 'account' to manage your account. If you would like to start over, type 'cancel' anywhere.", TALKTYPE_PRIVATE, true, cid)
    else
        addEvent(valid(doCreatureSay), 500, cid, "Hello, type 'account' to create an account or 'recover' to recover an account.", TALKTYPE_PRIVATE, true, cid)
    end

    if(not isPlayerGhost(cid)) then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
    end

    registerCreatureEvent(cid, "Idle")
    registerCreatureEvent(cid, "Mail")
    registerCreatureEvent(cid, "PVPCreature")
    registerCreatureEvent(cid, "ReportBug")
    if(config.useFragHandler) then
        registerCreatureEvent(cid, "SkullCheck")
    end

    registerCreatureEvent(cid, "GuildEvents")
    registerCreatureEvent(cid, "AdvanceSave")
    registerCreatureEvent(cid, "FimVip")

    if (InitArenaScript ~= 0) then
    InitArenaScript = 1

        for i = 42300, 42309 do
            setGlobalStorageValue(i, 0)
            setGlobalStorageValue(i+100, 0)
        end
    end

    if getPlayerStorageValue(cid, 42309) < 1 then
        for i = 42300, 42309 do
            setPlayerStorageValue(cid, i, 0)
        end
    end

    if getPlayerStorageValue(cid, 42319) < 1 then
        for i = 42310, 42319 do
            setPlayerStorageValue(cid, i, 0)
        end
    end

    if getPlayerStorageValue(cid, 42329) < 1 then
        for i = 42320, 42329 do
            setPlayerStorageValue(cid, i, 0)
        end
    end
    if getPlayerStorageValue(cid, 42355) == -1 then
        setPlayerStorageValue(cid, 42355, 0)
    end
    setPlayerStorageValue(cid, 42350, 0)
    setPlayerStorageValue(cid, 42352, 0)
return true
end

This is my login.lua, where should I edit?
 
Code:
local config = {
    loginMessage = getConfigValue('loginMessage'),
    useFragHandler = getBooleanFromString(getConfigValue('useFragHandler'))
}

function onLogin(cid)
    if(getBooleanFromString(getConfigValue('accountManager')) == false) then
        if (getCreatureName(cid) == "Account Manager") then
            return doRemoveCreature(cid, true)
        end
    end
  
    local loss = getConfigValue('deathLostPercent')
    if(loss ~= nil and getPlayerStorageValue(cid, "bless") ~= 5) then
        doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, loss * 10)
        doPlayerSetLossPercent(cid, PLAYERLOSS_ITEMS, 7)
    end

    if(getPlayerStorageValue(cid, "death_bless") == 1) then
        local t = {PLAYERLOSS_EXPERIENCE, PLAYERLOSS_SKILLS, PLAYERLOSS_ITEMS, PLAYERLOSS_CONTAINERS}
        for i = 1, #t do
            doPlayerSetLossPercent(cid, t[i], 100)
        end
        setPlayerStorageValue(cid, "death_bless", 0)
    end

    local accountManager = getPlayerAccountManager(cid)
    if(accountManager == MANAGER_NONE) then
        local lastLogin, str = getPlayerLastLoginSaved(cid), config.loginMessage
        if(lastLogin > 0) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
            str = "Your last visit was on " .. os.date("%a %b %d %X %Y", lastLogin) .. "."
        else
            str = str .. " Please choose your outfit."
            doPlayerSendOutfitWindow(cid)
        end

        doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
    elseif(accountManager == MANAGER_NAMELOCK) then
        addEvent(valid(doCreatureSay), 500, cid, "Hello, it appears that your character has been locked for name violating rules, what new name would you like to have?", TALKTYPE_PRIVATE_NP, true, cid)
    elseif(accountManager == MANAGER_ACCOUNT) then
        addEvent(valid(doCreatureSay), 500, cid, "Hello, type 'account' to manage your account. If you would like to start over, type 'cancel' anywhere.", TALKTYPE_PRIVATE, true, cid)
    else
        addEvent(valid(doCreatureSay), 500, cid, "Hello, type 'account' to create an account or 'recover' to recover an account.", TALKTYPE_PRIVATE, true, cid)
    end

    if(not isPlayerGhost(cid)) then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
    end

    registerCreatureEvent(cid, "Idle")
    registerCreatureEvent(cid, "Mail")
    registerCreatureEvent(cid, "PVPCreature")
    registerCreatureEvent(cid, "ReportBug")
    if(config.useFragHandler) then
        registerCreatureEvent(cid, "SkullCheck")
    end

    registerCreatureEvent(cid, "GuildEvents")
    registerCreatureEvent(cid, "AdvanceSave")
    registerCreatureEvent(cid, "FimVip")

    if (InitArenaScript ~= 0) then
    InitArenaScript = 1

        for i = 42300, 42309 do
            setGlobalStorageValue(i, 0)
            setGlobalStorageValue(i+100, 0)
        end
    end

    if getPlayerStorageValue(cid, 42309) < 1 then
        for i = 42300, 42309 do
            setPlayerStorageValue(cid, i, 0)
        end
    end

    if getPlayerStorageValue(cid, 42319) < 1 then
        for i = 42310, 42319 do
            setPlayerStorageValue(cid, i, 0)
        end
    end

    if getPlayerStorageValue(cid, 42329) < 1 then
        for i = 42320, 42329 do
            setPlayerStorageValue(cid, i, 0)
        end
    end
    if getPlayerStorageValue(cid, 42355) == -1 then
        setPlayerStorageValue(cid, 42355, 0)
    end
    setPlayerStorageValue(cid, 42350, 0)
    setPlayerStorageValue(cid, 42352, 0)
return true
end

This is my login.lua, where should I edit?
onLogin is the interface, pretty much anything you would like to execute goes inside of it. If you look closely at the script you will see other registerCreatureEvent calls, since this is the case then common sense would suggest that you place registerCreatureEvent(cid, "MoveItem") under one of them.
 
Under registerCreatureEvent(cid, "SkullCheck") or registerCreatureEvent(cid, "FimVip")?
Also, I find out something VERY strange.
I'm running my server in a debian Linux, also I have the same server in my computer, that is windows.
When I run local, in my computer, this bug does not happen, only in my VPS that I compiled the server in linux.
 
Back
Top