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

OTClient Yes/No Dialog Window

zxmatzx

Advanced OT User
Joined
Dec 1, 2010
Messages
312
Solutions
27
Reaction score
155
Location
Brazil
GitHub
Mateuso8
Hello,
I need a yes / no dialog window for OTC. I do not know if there is already a model ready, searched a lot and found nothing related. I know the logic behind this code, I believe it works like TFS Events (onMoveItem, onLook, onTurn) which will expect a return true to actually do the action, but I don't know how to implement it in OTC.
It would be possible to be called by both client and server.

Ex:
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if itemEx.itemId == 2160 then --if target item == 2161 (crystal coin)
        local dialog = showYesNoDialog() --Show Yes/No Dialog Window
        if dialog == true then --If dialogResult == Yes(true)
            item:remove() --Remove Item
            return true --Finish with true
        else --If dialogResult == No(false)
            return false --Finish with false
        end
    end
    return false --Finish with false by default
end


Yes/No Dialog Exemple:
14.png



How can I do this?
Any help will be welcome! Thanks.
 
 
Thanks. I already use this, but how can i make the code "wait" for the dialog result? Later i will change all my systems that works with modal Windows to OTC Modules for better visual, because this i dont did this YES/NO dialog window with modals.
 
Thanks. I already use this, but how can i make the code "wait" for the dialog result? Later i will change all my systems that works with modal Windows to OTC Modules for better visual, because this i dont did this YES/NO dialog window with modals.
Lua can't handle that. You would have to use events and multiple functions. Show dialog in one, do whatever you need based on user input in another.
 
Lua can't handle that. You would have to use events and multiple functions. Show dialog in one, do whatever you need based on user input in another.
Thanks.
Yeah, therefore i want to do through OTC Modules. Instead i use in Lua onUse function, i can use in OTC Function that call Use or MoveItem to check if player realy want to throw item in dustbin or water. Or as in the example I showed, if the player wants to perform a very important action.
 
Thanks.
Yeah, therefore i want to do through OTC Modules. Instead i use in Lua onUse function, i can use in OTC Function that call Use or MoveItem to check if player realy want to throw item in dustbin or water. Or as in the example I showed, if the player wants to perform a very important action.
These are server-side things, in OTC you can create new window with 2 buttons, but all the logic should be on the server-side.
 
You split the code into multiple functions, and in the correct callback (etc the "Yes" callback), you execute the rest of the code? (/or call the function to the rest of the code)
 
You split the code into multiple functions, and in the correct callback (etc the "Yes" callback), you execute the rest of the code? (/or call the function to the rest of the code)
In OTC Modules too? I think in onMoveItem functions will be more easier to do, but in onUse itens don't... Maybe onUse call a YesNoWindowTemplate with some ID referencing to specific function like:
All in diferent scripts:
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    --using item with actionId 1000
    showYesNoDialog(1)
    return true
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    --using itemId 5000 in itemId 3000
    if itemEx.itemId == 3000 then
        showYesNoDialog(2)
    end
    return true
end

function showYesNoDialog(dialogId)
    --Interface with YES / NO Buttons
    
    if dialogId == 1 then
        --code for using item with actionId 1000
        return true
    elseif dialogId == 2 then
        --code for using itemId 5000 in itemId 3000
        return true
    else
        return false
    end
end
 
In OTC Modules too? I think in onMoveItem functions will be more easier to do, but in onUse itens don't... Maybe onUse call a YesNoWindowTemplate with some ID referencing to specific function like:
All in diferent scripts:
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    --using item with actionId 1000
    showYesNoDialog(1)
    return true
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    --using itemId 5000 in itemId 3000
    if itemEx.itemId == 3000 then
        showYesNoDialog(2)
    end
    return true
end

function showYesNoDialog(dialogId)
    --Interface with YES / NO Buttons

    if dialogId == 1 then
        --code for using item with actionId 1000
        return true
    elseif dialogId == 2 then
        --code for using itemId 5000 in itemId 3000
        return true
    else
        return false
    end
end
This is TFS code. If you want to show custom GUI on your client this way then you have to write new network packets.
When player moves an item, check if toPosition contain a bin, if so then save that item and the player somewhere for future reference, send dialog packet to the player then return false to prevent moving that item.
Now you wait for the player to press Yes/No button . When that happens send another packet but this time to the server, with a response (which button was pressed).
If the response was No then just ignore it, you already did prevent that item from being moved.
If it's Yes then you can just simply remove that item from the game, there is no need to move it again to the bin.

About onUse I'm not sure if you can force using an item on a player (but I don't think so).
 
This is TFS code. If you want to show custom GUI on your client this way then you have to write new network packets.
When player moves an item, check if toPosition contain a bin, if so then save that item and the player somewhere for future reference, send dialog packet to the player then return false to prevent moving that item.
Now you wait for the player to press Yes/No button . When that happens send another packet but this time to the server, with a response (which button was pressed).
If the response was No then just ignore it, you already did prevent that item from being moved.
If it's Yes then you can just simply remove that item from the game, there is no need to move it again to the bin.

About onUse I'm not sure if you can force using an item on a player (but I don't think so).
I have some ideas, when i get home Will try develop, i'll send the code here later.
Thanks to all
 
Back
Top