Ehh...not really.
There are essentially two different ways you script: on serverside, or on clientside. If a script is serverside, it means that the NPC-server interprets and performs the code. The advantage to this is that you know the code can't be tamperered with. If the code is clientside, it means that it is ran on the computer of the player. This has the advantage of being faster and not requiring communication with the server, but has the disadvantage of being less secure.
Since serverside is not performed for a specific player it cannot display interface graphics (HUDs, etc). It also can't handle player chat events, among others.
To communicate between the server and the client you use something called a trigger. In the past this was accomplished with the
triggerAction function, but now it's standard practice to use
triggerServer and
triggerClient. Simply enough,
triggerServer is used to send a "trigger", or a message, from clientside (a player's computer) to the NPC-server. Similarly,
triggerClient is used to send a "trigger" from the NPC-server to a player's computer.
The simplest trigger from clientside to server would work like so:
PHP Code:
function onActionServerSide() {
echo("Ping received!");
}
//#CLIENTSIDE
function onCreated() {
triggerServer("gui", this.name, null);
}
In your case you would want to send the player's chat serverside. The
onPlayerChats event is called on clientside whenever the player chats.
PHP Code:
//#CLIENTSIDE
function onPlayerChats() {
// code
}
You can then check if the player's chat starts with "/copy" by using the string function
str.starts(str). This would be "true" if the string starts with the parameter given.
PHP Code:
//#CLIENTSIDE
function onPlayerChats() {
if (player.chat.starts("/copy")) {
// code
}
}
Now, you need to send a trigger to the server with the
triggerServer command.
triggerServer and
triggerClient both have three parameters (two on the latest beta of Graal or for
triggerClient): script type, script name, param1[, param2...].]
The script types that you can trigger are "gui" or "weapon", which both trigger a weapon script. Scripters have their own personal preference on which to use, but it doesn't really matter. The other script type is "npc", which triggers a database NPC. If you don't know what that is, don't worry about it yet.
Adding the trigger code would look like so:
PHP Code:
//#CLIENTSIDE
function onPlayerChats() {
if (player.chat.starts("/copy")) {
triggerServer("gui", this.name, null);
}
}
this.name is simply referring to the current name of the weapon. It's generally preferred to use this instead of typing the weapon name in case the name were to change.
Then, you would need to "tokenize" the player's chat. This is the same as the
explode function found in PHP and other languages. It splits the string into different parts at the "delimiter". You can specify a custom delimiter for
str.tokenize(str delimiter), but in this case there is no need to.
PHP Code:
//#CLIENTSIDE
function onPlayerChats() {
if (player.chat.starts("/copy")) {
temp.tokens = player.chat.tokenize();
triggerServer("gui", this.name, tokens);
}
}
Now you just need to build the serverside portion of the script. This part of the script will need to identify the command given, identify the player wanted, and the property to copy. You would start by adding the
onActionServerSide() event. This is always called when using
triggerServer. The parameter you specified in the trigger ("tokens") will be in the first parameter for that function.
PHP Code:
function onActionServerSide(tokens) {
// code
}
//#CLIENTSIDE
function onPlayerChats() {
if (player.chat.starts("/copy")) {
temp.tokens = player.chat.tokenize();
triggerServer("gui", this.name, tokens);
}
}
You can then check for the command and find the player
PHP Code:
function onActionServerSide(tokens) {
if (tokens[0] == "/copy") {
temp.pl = findPlayerByCommunityName(tokens[1]);
}
}
//#CLIENTSIDE
function onPlayerChats() {
if (player.chat.starts("/copy")) {
temp.tokens = player.chat.tokenize();
triggerServer("gui", this.name, tokens);
}
}
Now all you need to do is identify the property which is to be copied.
PHP Code:
function onActionServerSide(tokens) {
if (tokens[0] == "/copy") {
temp.pl = findPlayerByCommunityName(tokens[1]);
if (tokens[2] == "body") {
player.body = pl.body;
}
}
}
//#CLIENTSIDE
function onPlayerChats() {
if (player.chat.starts("/copy")) {
temp.tokens = player.chat.tokenize();
triggerServer("gui", this.name, tokens);
}
}
There's a better way to do that involving dynamic variables but I feel like I've already thoroughly confused you with this post. As I said before, it seems like you're jumping in too fast and you're just going to get lost. Focus on the basics first.