• 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 Destroy item on move

luccagomes

New Member
Joined
Jul 30, 2015
Messages
153
Reaction score
1
Im tryng use this function to delete item on move!
But dont work, when i start the server dont give me erros on console, when i move itens dont give erros on console
I think the problem is here:
Code:
if item.itemid == 2596 then

Or here:
Code:
doRemoveItem(item.uid, 1)




SCRIPTS \/




data/creaturescript/creaturescript.xml
Code:
<event type="moveitem" name="moveParcelRookgaard" event="script" value="moveParcelRookgaard.lua"/>

data/creaturescript/creaturescript.xml/
moveParcelRookgaard.lua
Code:
function onMoveItem(cid, item, count, toContainer, fromContainer, fromPos, toPos)
if getPlayerVocation(cid) == 0 then
if item.itemid == 2596 then
doRemoveItem(item.uid, 1)
return true
end
end
end


Sources CODE:
Code:
//Função add por luanluciano93uint32_tCreatureEvent::executeMoveItem(Player* player,Item* item,uint8_t count,constPosition& fromPos,constPosition& toPos,Item* toContainer,Item* fromContainer,int16_t fstack){//onMoveItem(cid, item, count, toContainer, fromContainer, fromPos, toPos)if(m_interface->reserveEnv()){ScriptEnviroment* env = m_interface->getEnv();if(m_scripted == EVENT_SCRIPT_BUFFER){
env->setRealPos(player->getPosition());
std::stringstream scriptstream;
scriptstream <<"local cid = "<< env->addThing(player)<< std::endl;

env->streamThing(scriptstream,"item", item, env->addThing(item));
scriptstream <<"local count = "<< count << std::endl;
env->streamThing(scriptstream,"toContainer", toContainer, env->addThing(toContainer));
env->streamThing(scriptstream,"fromContainer", fromContainer, env->addThing(fromContainer));
env->streamPosition(scriptstream,"fromPos", fromPos, fstack);
env->streamPosition(scriptstream,"toPos", toPos,0);


scriptstream << m_scriptData;bool result =true;if(m_interface->loadBuffer(scriptstream.str())){
lua_State* L = m_interface->getState();
result = m_interface->getGlobalBool(L,"_result",true);}

m_interface->releaseEnv();return result;}else{#ifdef __DEBUG_LUASCRIPTS__
char desc[30];
sprintf(desc,"%s", player->getName().c_str());
env->setEvent(desc);#endif

env->setScriptId(m_scriptId, m_interface);
env->setRealPos(player->getPosition());

lua_State* L = m_interface->getState();
m_interface->pushFunction(m_scriptId);

lua_pushnumber(L, env->addThing(player));

LuaInterface::pushThing(L, item, env->addThing(item));
lua_pushnumber(L, count);LuaInterface::pushThing(L, toContainer, env->addThing(toContainer));LuaInterface::pushThing(L, fromContainer, env->addThing(fromContainer));LuaInterface::pushPosition(L, fromPos, fstack);LuaInterface::pushPosition(L, toPos,0);

bool result = m_interface->callFunction(7);
m_interface->releaseEnv();return result;}}else{
std::clog <<"[Error - CreatureEvent::executeMoveItem] Call stack overflow."<< std::endl;return0;}}
 
Last edited:
Try this:
Code:
function onMoveItem(cid, item, count, toContainer, fromContainer, fromPos, toPos)
    if getPlayerVocation(cid) == 0 then
        doRemoveItem(item.uid, 1)
        return false
    end
end
In TFS 1.2 i used this:
Code:
    if item.itemid == 2223 then
        item:remove(-1)
        return false
    end
And it worked. You need to write remove item correctly.

Maybe this:
Code:
function onMoveItem(cid, item, count, toContainer, fromContainer, fromPos, toPos)
    if item.itemid == 2596 then
        if getPlayerVocation(cid) == 0 then
            doRemoveItem(item, 1)
            return false
        end
    end
end
 
Last edited:
Try this:
Code:
function onMoveItem(cid, item, count, toContainer, fromContainer, fromPos, toPos)
    if getPlayerVocation(cid) == 0 then
        doRemoveItem(item.uid, 1)
        return false
    end
end
In TFS 1.2 i used this:
Code:
    if item.itemid == 2223 then
        item:remove(-1)
        return false
    end
And it worked. You need to write remove item correctly.

Maybe this:
Code:
function onMoveItem(cid, item, count, toContainer, fromContainer, fromPos, toPos)
    if item.itemid == 2596 then
        if getPlayerVocation(cid) == 0 then
            doRemoveItem(item, 1)
            return false
        end
    end
end

Code:
function onMoveItem(cid, item, count, toContainer, fromContainer, fromPos, toPos)
    if getPlayerVocation(cid) == 0 then
        doRemoveItem(item.uid, 1)
        return false
    end
end
dont work, dont do nothing

i dont use 1.2, i use 0.4

Code:
function onMoveItem(cid, item, count, toContainer, fromContainer, fromPos, toPos)
    if getPlayerVocation(cid) == 0 then
        doRemoveItem(item.uid, 1)
        return false
    end
end

Code:
function onMoveItem(cid, item, count, toContainer, fromContainer, fromPos, toPos)
    if getPlayerVocation(cid) == 0 then
        doRemoveItem(item.uid, 1)
        return false
    end
end

dont work :(
 
Are you getting errors?
Returning false might screw it up as well.. Try return true for vocation 0..and return false for everyone else. or other way around. Sorry its 3am.Dx
 
Are you getting errors?
Returning false might screw it up as well.. Try return true for vocation 0..and return false for everyone else. or other way around. Sorry its 3am.Dx
lol

dont work :(
0.4? do you have function onMoveItem?? Where you put your script? If you don't have function you need to compile server and use this tutorial to add function.
https://otland.net/threads/creaturescript-onmoveitem-moveitem-frompos-position-cid.96742/

2 months ago i was hosting max 8.6 version, now when i use 10.77 and look at 8.6 engine i am like "wtf there is nothing, zero functions"
 
Last edited:
And no errors in console? thats all you can tell us?
If you have no errors that means you dont have this function or you put it in wrong file.
Say what files you using to run this script and show us full script.
Full paths to scripts from data/ to file.xml/.lua
Take a look on console when you trying to run script and when you reload scripts if there is any error.
Example: cannot load script moveitem.lua or anything that could help us to see the problem.

Answer like not working script is useless for us if you don't post errors.
 
And no errors in console? thats all you can tell us?
If you have no errors that means you dont have this function or you put it in wrong file.
Say what files you using to run this script and show us full script.
Full paths to scripts from data/ to file.xml/.lua
Take a look on console when you trying to run script and when you reload scripts if there is any error.
Example: cannot load script moveitem.lua or anything that could help us to see the problem.

Answer like not working script is useless for us if you don't post errors.

I'm edit the first post (on this topic)
 
Code:
function onMoveItem(cid, item, count, toContainer, fromContainer, fromPos, toPos)
print("Script started.")
    if getPlayerVocation(cid) == 0 then
        print("Vocation = 0. OK")
        if item.itemid == 2596 then
            print("item.itemid == 2596. OK")
            doRemoveItem(item.uid, 1)
            return true
        end
    end
    print("END script.")
end
Use this script then show us screen shot from your console after you try to move item.
 
Code:
function onMoveItem(cid, item, count, toContainer, fromContainer, fromPos, toPos)
print("Script started.")
    if getPlayerVocation(cid) == 0 then
        print("Vocation = 0. OK")
        if item.itemid == 2596 then
            print("item.itemid == 2596. OK")
            doRemoveItem(item.uid, 1)
            return true
        end
    end
    print("END script.")
end
Use this script then show us screen shot from your console after you try to move item.

Dont print nothing
I think I'm using this function the wrong way


looking at the code in source code, you can tell me the right way?

Code:
//Função add por luanluciano93uint32_tCreatureEvent::executeMoveItem(Player* player,Item* item,uint8_t count,constPosition& fromPos,constPosition& toPos,Item* toContainer,Item* fromContainer,int16_t fstack){//onMoveItem(cid, item, count, toContainer, fromContainer, fromPos, toPos)if(m_interface->reserveEnv()){ScriptEnviroment* env = m_interface->getEnv();if(m_scripted == EVENT_SCRIPT_BUFFER){
env->setRealPos(player->getPosition());
std::stringstream scriptstream;
scriptstream <<"local cid = "<< env->addThing(player)<< std::endl;

env->streamThing(scriptstream,"item", item, env->addThing(item));
scriptstream <<"local count = "<< count << std::endl;
env->streamThing(scriptstream,"toContainer", toContainer, env->addThing(toContainer));
env->streamThing(scriptstream,"fromContainer", fromContainer, env->addThing(fromContainer));
env->streamPosition(scriptstream,"fromPos", fromPos, fstack);
env->streamPosition(scriptstream,"toPos", toPos,0);


scriptstream << m_scriptData;bool result =true;if(m_interface->loadBuffer(scriptstream.str())){
lua_State* L = m_interface->getState();
result = m_interface->getGlobalBool(L,"_result",true);}

m_interface->releaseEnv();return result;}else{#ifdef __DEBUG_LUASCRIPTS__
char desc[30];
sprintf(desc,"%s", player->getName().c_str());
env->setEvent(desc);#endif

env->setScriptId(m_scriptId, m_interface);
env->setRealPos(player->getPosition());

lua_State* L = m_interface->getState();
m_interface->pushFunction(m_scriptId);

lua_pushnumber(L, env->addThing(player));

LuaInterface::pushThing(L, item, env->addThing(item));
lua_pushnumber(L, count);LuaInterface::pushThing(L, toContainer, env->addThing(toContainer));LuaInterface::pushThing(L, fromContainer, env->addThing(fromContainer));LuaInterface::pushPosition(L, fromPos, fstack);LuaInterface::pushPosition(L, toPos,0);

bool result = m_interface->callFunction(7);
m_interface->releaseEnv();return result;}}else{
std::clog <<"[Error - CreatureEvent::executeMoveItem] Call stack overflow."<< std::endl;return0;}}
 
Back
Top