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

Compiling doSendChannelDialog

Xagul

deathzot.net
Joined
Jun 30, 2008
Messages
1,294
Solutions
3
Reaction score
1,037
Hello, I am trying to get a function to send a fake channel dialog to a player. Basically the idea is to send a channel dialog with a list of custom named channels that can then be used as a sort of "option menu". I have managed to get the function to work when you open a channel, but I can't get all the default channels out of the list so that it looks clean.

I am using TFS 0.4 r.3884 for 8.6
Any help regarding this would be greatly appreciated!

A great example was posted some time ago by Summ, this screenshot will serve as a better example of the desired outcome than I can explain in words.

unbenanntss.png
 
Last edited:
Well if it open the channel dialog through function and you cant get the default channels then you have added the function wrong.
 
0.4 r.3884 for 8.6
Yup and you added the function yourself. When it open channeldialog is it empty? Then i mean normally by clicking on the client to open it. Then when you use the function to openchanneldialog is it empty?
 
Well if it open the channel dialog through function and you cant get the default channels then you have added the function wrong.
Yup and you added the function yourself. When it open channeldialog is it empty? Then i mean normally by clicking on the client to open it. Then when you use the function to openchanneldialog is it empty?

No my normal channel (ctrl+o) works fine, I am trying to open a custom channel list without the default channels so I can make it into a sort of menu for players to choose options from.
Example:
type "/test"
> opens channel dialog with options "hello", "goodbye"
> click channel "hello"
print("you just tested hello")
 
OFFTOPIC:
this could be easily made with the new tfs... with Modal table and onModalWindow creaturescript...

Code:
function onSay(cid, words, param)
    local player = Player(cid)
    local modal = Modal(1, "Modal Title", "Make your choice:")
    modal.addChoice(1, "I want to live")
    modal.addChoice(2, "Pft, I don't give a f*ck")
    modal.addChoice(3, "Please... NO!")
    modal.addChoice(4, "Be my guest.")
    modal:sendToPlayer(player) 
    return false
end

function onModalWindow(cid, modalWindowId, buttonId, choiceId)
    if modalWindowId == 1 then
        print("You've selected the choice #" .. choiceId)
    end
end
 
Last edited:
you need to source edit.i already have this function in my 0.3.7 r5963 8.6
it is in protocolgame.cpp and player.cpp SendDialog
if you can't do it send me your source and i will try to add it
 
I got everything working perfectly however for some reason when I open my custom channel list it still displays the NPCs channel. Also the channels are listed out of order and I can't seem to figure out what order it's trying to sort them by.

FFtdtkK.jpg


Here is the function:
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);
        lua_pushboolean(L, true);
        return 1;
    }

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

And here is my test script:
Code:
local clist = {
    [40001] = "First",
    [40002] = "Second",
    [40003] = "Third",
    [40004] = "Fourth"
}

function onSay(cid, words, param, channel)
    doPlayerSendChannels(cid, clist)
    return true
end


If anyone knows how to fix this, it would be awesome!
 
Last edited:
NPCs channel is client sided and not controlled by the server. That is why on Ascalon Fare hex edited the NPC channel name to space / empty string for example.

You should use a indexed table like {{4000, "First"}, {4001, "Second"}} that should keep the order.
 
NPCs channel is client sided and not controlled by the server. That is why on Ascalon Fare hex edited the NPC channel name to space / empty string for example.

You should use a indexed table like {{4000, "First"}, {4001, "Second"}} that should keep the order.

Yea I searched for a quite a while last night and I couldn't find anything related to the NPC channel so I assumed it was client side but I was hopeful I was mistaken haha.
At any rate, Tetra20 sent me TFS 0.3.7 r.5963 which already had this function so I just pulled it from there. Not really sure how to change it to use an indexed table as you are suggesting, if you have some spare time and could walk me through it that would be great. I'm slowly trying to learn C++ though this is all new to me.
 
bump

Anyone out there know how to change this function to work with this table format?
Code:
local clist = {
     {40001, "First"},
     {40002, "Second"}

}

Or any other way to make the function display channels in the proper order.
 
bump

Anyone out there know how to change this function to work with this table format?
Code:
local clist = {
     {40001, "First"},
     {40002, "Second"}

}

Or any other way to make the function display channels in the proper order.
Try This one:(Not Sure if it will work)
Code:
local clist = {{40001, "First"}, {40002, "Second"}, {40003, "Third"}, {40004, "Fourth"}}
 
Try This one:(Not Sure if it will work)
Code:
local clist = {{40001, "First"}, {40002, "Second"}, {40003, "Third"}, {40004, "Fourth"}}

I can't just change the table, the actual function in the source needs to be changed as well.

Here is the current function:
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);
        lua_pushboolean(L, true);
        return 1;
    }

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