• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

asString() Function

Elgenady

Veteran OT User
Joined
Aug 5, 2011
Messages
1,683
Solutions
36
Reaction score
388
hello guys anyone can help in this
if(!(*it)->executeChannelRequest(player, asString(channelId), false, !player->hasSentChat()) && !deny)
deny = true;
}
and when compile give this error
game.cpp `asString' was not declared in this scope

im use tfs 0.4
 
that function doesn't exist in any tfs 0.4 i can find
post executeChannelRequest and post the function that's calling this chunk of code
do you know what asString is supposed to do?
 
that function doesn't exist in any tfs 0.4 i can find
post executeChannelRequest and post the function that's calling this chunk of code
do you know what asString is supposed to do?

Code:
uint32_t CreatureEvent::executeChannelRequest(Player* player, const std::string& channel, bool isPrivate, bool custom)
{
    //onChannelRequest(cid, channel, custom)
    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;
            if(!isPrivate)
                scriptstream << "local channel = " << atoi(channel.c_str()) << std::endl;
            else
                scriptstream << "local channel = " << channel << std::endl;

            scriptstream << "local custom = " << (custom ? "true" : "false") << std::endl;
            if(m_scriptData)
                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[35];
            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));
            if(!isPrivate)
                lua_pushnumber(L, atoi(channel.c_str()));
            else
                lua_pushstring(L, channel.c_str());

            lua_pushboolean(L, custom);
            bool result = m_interface->callFunction(3);
            m_interface->releaseEnv();
            return result;
        }
    }
    else
    {
        std::clog << "[Error - CreatureEvent::executeChannelRequest] Call stack overflow." << std::endl;
        return 0;
    }
}

Code:
bool Game::playerOpenChannel(uint32_t playerId, uint16_t channelId)
{
    Player* player = getPlayerByID(playerId);
    if(!player || player->isRemoved())
        return false;

    bool deny = false;
    CreatureEventList openEvents = player->getCreatureEvents(CREATURE_EVENT_CHANNEL_REQUEST);
    for(CreatureEventList::iterator it = openEvents.begin(); it != openEvents.end(); ++it)
    {
        if(!(*it)->executeChannelRequest(player, asString(channelId), false, !player->hasSentChat()) && !deny)
            deny = true;
    }

    player->setSentChat(false);
   
    if(deny)
        return false;

    ChatChannel* channel = g_chat.addUserToChannel(player, channelId);
    if(!channel)
    {
        #ifdef __DEBUG_CHAT__
        std::clog << "Game::playerOpenChannel - failed adding user to channel." << std::endl;
        #endif
        return false;
    }

    player->sendChannel(channel->getId(), channel->getName());
    return true;
}
 
C++:
    bool deny = false;
    CreatureEventList openEvents = player->getCreatureEvents(CREATURE_EVENT_CHANNEL_REQUEST);
    for(CreatureEventList::iterator it = openEvents.begin(); it != openEvents.end(); ++it)
    {
        ChatChannel* channel = g_chat.getChannelById(channelId);
        if (channel) {
            if(!(*it)->executeChannelRequest(player, channel->getName(), false, !player->hasSentChat()) && !deny)
                deny = true;
        }
    }
 
compile done but when enter game and try to use my script get debug
i try to use this system
CreatureEvent - Advanced Checkpoint System (based on my own request and the work of Cyko)
or maybe the problem here
Code:
int32_t LuaInterface::luaDoPlayerSendChannels(lua_State* L)
{
    //doPlayerSendChannels(cid[, list])
    ChannelsList channels;
    uint32_t params = lua_gettop(L);
    if(params > 1)
    {
        if(!lua_istable(L, -1))
        {
            errorEx("Channel list is not a table");
            lua_pushboolean(L, false);
            return 1;
        }

        lua_pushnil(L);
        while(lua_next(L, -2))
        {
            channels.push_back(std::make_pair((uint16_t)lua_tonumber(L, -2), lua_tostring(L, -1)));
            lua_pop(L, 1);
        }

        lua_pop(L, 1);
    }

    ScriptEnviroment* env = getEnv();
    if(Player* player = env->getPlayerByUID(popNumber(L)))
    {
        if(params < 2)
            channels = g_chat.getChannelList(player);

        player->sendChannelsDialog(channels);
        player->setSentChat(params < 2);
        lua_pushboolean(L, true);
        return 1;
    }

    errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
    lua_pushboolean(L, false);
    return 1;
}

when compile it get error
luascript.cpp `ChannelsList' was not declared in this scope
 
Last edited:
@Stigma , its possible bro, later i will post the code, i just trying to fix and testing.
i did everything oki but when open game player get list of teleport place but don't tp
like this
vsDNtqh.png
 
what does your checkpoint script look like
Code:
local CHECKPOINT_TELEPORT = {
    [10] = {pos = {x = 145, y = 387, z = 7 , stackpos = 1}},
    [11] = {pos = {x = 137, y = 374, z = 7 , stackpos = 1}},
    [12] = {pos = {x = 1000, y = 1000, z = 7 , stackpos = 1}}
 
}
function onChannelRequest(cid, channel, custom)
local checkpoint = CHECKPOINT_TELEPORT[channel]
    unregisterCreatureEvent(cid, "checkpoint")
    if(not custom or type(channel) ~= 'number') then
        doPlayerSendCancel(cid, "Invalid action.")
        return false
    end
    if(not doPlayerRemoveMoney(cid, checkpoint.price)) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need ".. checkpoint.price .." gold coins to use checkpoint.")
    else
        doTeleportThing(cid, checkpoint.pos, false, true)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
        doSendMagicEffect(checkpoint.pos, CONST_ME_TELEPORT)
    end
    return false
end

full system here
CreatureEvent - Advanced Checkpoint System (based on my own request and the work of Cyko)
 
Last edited:
add a print inside the function to test if it's being executed at all
for example put print(123) after onChannelRequest(cid, channel, custom)
 
the problem here
kr6yoGr.png


i removed unregisterCreatureEventType(cid, "channelrequest") and add print(123) get this error

WXhrQki.png
it shouldve been clear that he meant to put unregisterCreatureEvent instead, change it in the movement script
LUA:
local CHECKPOINT_TELEPORT = {
    [10] = {pos = {x = 145, y = 387, z = 7 , stackpos = 1}},
    [11] = {pos = {x = 137, y = 374, z = 7 , stackpos = 1}},
    [12] = {pos = {x = 1000, y = 1000, z = 7 , stackpos = 1}}

}
function onChannelRequest(cid, channel, custom)
    local checkpoint = CHECKPOINT_TELEPORT[channel]
    unregisterCreatureEvent(cid, "checkpoint")
    if(not custom or type(channel) ~= 'number') or not checkpoint then
        doPlayerSendCancel(cid, "Invalid action.")
        return false
    end
    if(not doPlayerRemoveMoney(cid, checkpoint.price)) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need ".. checkpoint.price .." gold coins to use checkpoint.")
    else
        doTeleportThing(cid, checkpoint.pos, false, true)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
        doSendMagicEffect(checkpoint.pos, CONST_ME_TELEPORT)
    end
    return false
end
 
it shouldve been clear that he meant to put unregisterCreatureEvent instead, change it in the movement script
LUA:
local CHECKPOINT_TELEPORT = {
    [10] = {pos = {x = 145, y = 387, z = 7 , stackpos = 1}},
    [11] = {pos = {x = 137, y = 374, z = 7 , stackpos = 1}},
    [12] = {pos = {x = 1000, y = 1000, z = 7 , stackpos = 1}}

}
function onChannelRequest(cid, channel, custom)
    local checkpoint = CHECKPOINT_TELEPORT[channel]
    unregisterCreatureEvent(cid, "checkpoint")
    if(not custom or type(channel) ~= 'number') or not checkpoint then
        doPlayerSendCancel(cid, "Invalid action.")
        return false
    end
    if(not doPlayerRemoveMoney(cid, checkpoint.price)) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need ".. checkpoint.price .." gold coins to use checkpoint.")
    else
        doTeleportThing(cid, checkpoint.pos, false, true)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
        doSendMagicEffect(checkpoint.pos, CONST_ME_TELEPORT)
    end
    return false
end

my full script
in movements
Code:
local CHECKPOINT_STORAGE = {
    [10001] = {10, "10 - Demon helmet Quest"},
    [10002] = {11, "11 - Demon Legs quest"},
    [10003] = {12, "12 - Mountain"}
}
function onStepIn(cid, item, position, fromPosition)
if not isPlayer(cid) then
    return true
end
unregisterCreatureEvent(cid, "checkpoint")
local CHECKPOINT_LIST = {}
    for k, v in pairs(CHECKPOINT_STORAGE) do
        if(isPlayer(cid) and getCreatureStorage(cid, k) > 0) then
            table.insert(CHECKPOINT_LIST, v[1], v[2])
        end
    end
  
    doPlayerSendChannels(cid, CHECKPOINT_LIST)
    registerCreatureEvent(cid, "checkpoint")
    return true
end
function onStepOut(cid, item, position, lastPosition)
    unregisterCreatureEvent(cid, "checkpoint")
    return true
end
and in creaturescript
Code:
local CHECKPOINT_TELEPORT = {
    [10] = {pos = {x = 145, y = 387, z = 7 , stackpos = 1}},
    [11] = {pos = {x = 137, y = 374, z = 7 , stackpos = 1}},
    [12] = {pos = {x = 1000, y = 1000, z = 7 , stackpos = 1}}
}
function onChannelRequest(cid, channel, custom)
    local checkpoint = CHECKPOINT_TELEPORT[channel]
    unregisterCreatureEvent(cid, "checkpoint")
    if(not custom or type(channel) ~= 'number') or not checkpoint then
        doPlayerSendCancel(cid, "Invalid action.")
        return false
    end
    if(not doPlayerRemoveMoney(cid, checkpoint.price)) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need ".. checkpoint.price .." gold coins to use checkpoint.")
    else
        doTeleportThing(cid, checkpoint.pos, false, true)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
        doSendMagicEffect(checkpoint.pos, CONST_ME_TELEPORT)
    end
    return false
end
 
i don't understand
did you ever test out the print? i told you to add it and you never anything about it or posted code with it afterwards
now you posted scripts with no context, is something wrong still? is there an error happening?
you're giving no information
 
i don't understand
did you ever test out the print? i told you to add it and you never anything about it or posted code with it afterwards
now you posted scripts with no context, is something wrong still? is there an error happening?
you're giving no information

look bro when i remove unregisterCreatureEventType from movement scripts and add print in creaturescript give me this error

WXhrQki.png


and when add unregisterCreatureEventType to movements scripts give me this error

kr6yoGr.png


i try to use unregisterCreatureEvent(cid, "checkpoint") in movement script but don't work that all

the problem here unregisterCreatureEventType need to edit source :S
 
no, i told you to change it to unregisterCreatureEvent
it should be pretty obvious since other scripts use that exact same function
then i gave you a script to test out to see if it fixes checkpoint nil value and apparently you're not using it
 
no, i told you to change it to unregisterCreatureEvent
it should be pretty obvious since other scripts use that exact same function
then i gave you a script to test out to see if it fixes checkpoint nil value and apparently you're not using it

no bro i tested your script and nothing :S scripts i use now :
creaturescript.xml
Code:
<event type="channelrequest" registerTo ="manual" name="checkpoint" event="script" value="checkpointteleport.lua"/>

lua
Code:
local CHECKPOINT_TELEPORT = {
    [10] = {pos = {x = 145, y = 387, z = 7 , stackpos = 1}},
    [11] = {pos = {x = 137, y = 374, z = 7 , stackpos = 1}},
    [12] = {pos = {x = 1000, y = 1000, z = 7 , stackpos = 1}}
}
function onChannelRequest(cid, channel, custom)
print(123)
    local checkpoint = CHECKPOINT_TELEPORT[channel]
    unregisterCreatureEvent(cid, "checkpoint")
    if(not custom or type(channel) ~= 'number') or not checkpoint then
        doPlayerSendCancel(cid, "Invalid action.")
        return false
    end
    if(not doPlayerRemoveMoney(cid, checkpoint.price)) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need ".. checkpoint.price .." gold coins to use checkpoint.")
    else
        doTeleportThing(cid, checkpoint.pos, false, true)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
        doSendMagicEffect(checkpoint.pos, CONST_ME_TELEPORT)
    end
    return false
end

movements script
Code:
local CHECKPOINT_STORAGE = {
    [10001] = {1, "10 - Demon helmet Quest"},
    [10002] = {2, "11 - Demon Legs quest"},
    [10003] = {3, "12 - Mountain"}
}
function onStepIn(cid, item, position, fromPosition)
print(123)
if not isPlayer(cid) then
    return true
end
unregisterCreatureEvent(cid, "checkpoint")
local CHECKPOINT_LIST = {}
    for k, v in pairs(CHECKPOINT_STORAGE) do
        if(isPlayer(cid) and getCreatureStorage(cid, k) > 0) then
            table.insert(CHECKPOINT_LIST, v[1], v[2])
        end
    end
  
    doPlayerSendChannels(cid, CHECKPOINT_LIST)
    registerCreatureEvent(cid, "checkpoint")
    return true
end
function onStepOut(cid, item, position, lastPosition)
    unregisterCreatureEvent(cid, "checkpoint")
    return true
end

and give me this
nFtLmjJ.png


but player still no teleport
 
Back
Top