I'm interested in a function that allows instant link copying using a /discord command. When the command is executed, the link should be copied to the clipboard, enabling easy pasting onto a website.
Which discord library is used? Every library must have onDiscordCommand event.
here is a method using my recent remexec04rel32.dll plugin
//Usage:!cp (id/name) www.google.com
//eg.!cp adam vc-mp.com
function onDiscordCommand(cmd, text)
{
if(cmd=="cp")
{
local idx=[0]; //storing index for strtok command
assert(text!=null);//if text null, strtok fails
local plrid = strtok2(text,idx);//get playerid/name
local player = FindPlayer(IsNum(plrid)? plrid.tointeger():plrid);//find player using id or name
if(!player)return print("Invalid Player");//invalid id/name return
local link = strtok2(text, idx);//the link
RemoteExec(GetRemoteValue("System")().SetClipboardText(link), player)
//make sure you put store files properly
}
}
/*strtok2 modified from Zeex strtok function sa-mp,
Max result len: 512*/
function strtok2(string,array)
{
local index=array[0];
local length=string.len();
/* Skip the leading white space */
while(index<length && string[index]<=' ')
index++;
local result="";
local offset = index;
while( index < length && string[index] > ' ' && index-offset < 512-1)
{
result+=string.slice(index,index+1);
index++;
}
array[0]=index;
return result;
}
plugin: https://forum.vc-mp.org/index.php?topic=9276
If you have trouble installing remexec04rel32 plugin, You have to use streams.
Stream.WriteByte(100);
Stream.WriteString("www.google.com");
Stream.SendStream(player);
Are you using blank server?
//store/script/main.nut
function Server::ServerData(stream)
{
...
case 100: local link= stream.ReadString();
::System.SetClipboardText(link);
break;
}
Quote from: habi on Aug 03, 2023, 09:44 AMStream.WriteByte(100);
Stream.WriteString("www.google.com");
Stream.SendStream(player);
Are you using blank server?
//store/script/main.nut
function Server::ServerData(stream)
{
...
case 100: local link= stream.ReadString();
::System.SetClipboardText(link);
break;
}
that's exactly thing I was looking for, thanks man! I thought it was server-side, but turned to be client side, which I have zero knowledge for. Nevertheless, I'll be using this.