Author Topic: messageAll('',%string);  (Read 1133 times)

First things first...

1) If you messageAll('',"%client.player.getDatablock()");, you'll get a chat message saying the underlined. This I know.
2) If you messageAll('',%client.player.getDatablock()); instead, you'll get a chat message saying the value of the underlined. This I also know.

Now with this script...

Code: [Select]
package ExeChat {
function serverCmdMessageSent(%client,%msg) {
if(getSubStr(%msg, 0, 3) $= "#=#") {
%msg = strReplace(%msg,"#=#","");
messageAll('',%client.name @ ": " @ %msg);
}
else {
Parent::serverCmdMessageSent(%client,%msg);
}
}
};
activatePackage(ExeChat);

...I'd like it to display the value of %msg, not %msg itself, when you type "#=#" first.
Since it's a string entered by the user, I have no idea what to do.

To clarify:

Right now the script works as this:
- *Player types in "#=#findclientbyname(Truce).bl_id"*
- A chat message appears saying "Truce: findclientbyname(Truce).bl_id"

What it should be doing:
- *Player types in "#=#findclientbyname(Truce).bl_id"*
- A chat message appears saying "Truce: 3808"

Does anyone know a way to solve this?
Thanks in advance.

You would have to use eval(); to evaluate whatever the command the user sent is, then assign it to a variable to send it back to them.

You would have to use eval(); to evaluate whatever the command the user sent is, then assign it to a variable to send it back to them.

NiXiLL had tried explaining eval(); to me, but I didn't get the syntax.
This is what I had tried before, but obviously I'm doing it wrong.

Code: [Select]
messageAll('',%client.name @ ": " @ eval(%msg));

Code: [Select]
eval("%var = " @ %msg);
messageAll('',"\c3" @ %client.name @ "\c7:" SPC %var);

Note that this is very insecure and could be used to e.g. crash servers.

Code: [Select]
eval("%var = " @ %msg);
messageAll('',"\c3" @ %client.name @ "\c7:" SPC %var);

Note that this is very insecure and could be used to e.g. crash servers.

Thanks, and don't worry, I already have a lot of if tests going on to prevent that.