Hey im trying to add an option into the mellotrianer that allows my player to press “enter”(keybind for JS=13) it will open this link in their native browser.
Here is my current code that i have. It creates a button and i realize that you have to actually click on it with a mouse. But im stuck on how to actually make it a keybind option.
<p class="traineroption" data-action=""><button onclick="myFunction()">CLICK THIS TO JOIN DISCORD</button></p>
<script>
function myFunction() {
window.open("https://discord.gg/yyNjqmc");
}
</script>
Nope. i have only found a way in game. BUt its very laggy and often never works.
Your solution works mate.
The first one
1 Like
Hello again, I found Solution.
Add this to your cl_player.lua
RegisterNUICallback("discord", function(data, cb)
local action = data.action
local newstate = data. newstate
drawNotification("~g~DISCORD_LINK") --optional!
TriggerServerEvent('executeDiscord')
end)
And this to your HTML
<p class="traineroption"data-action="discord">JOIN THE DISCORD</p>
Add this to your sv_config.lua
RegisterServerEvent('executeDiscord')
AddEventHandler('executeDiscord', function()
os.execute('start DISCORD_LINK')
end)
2 Likes
But this script only open link in server machine. Not local machine. How to open local machine? Any ideas.
Please can anyone share the resource file for the same above, In my case i am not able to open links when Enter key is pressed
Thank You
This solution will work for you, if you are a good server developer
Html:
<div id="discord">Our Discord</div>
Js with Jquery:
$("#discord").click(function() {
window.invokeNative("openUrl", 'https://discord.gg/invite/k2u53wtd9x');
})
I hope it helps for somebody.
2 Likes