Author Topic: Tried to fix this stuff, didn't work.  (Read 771 times)

Well, I'm making some client-sided AdvCam add-on, which until now only can operate chasecam, but will later do much more.
I have a problem about the function which is called if the local client says something, which, as I think, is NMH_Type::chat and takes one parameter which is the message.
With the following script, when I say CAM in-game, nothing happens. Also trying some other commands nothing happens.
Code: [Select]
$ac::silent = 0;
package advcam
{
function NMH_Type::send(%chat)
{
if(getSubStr(%chat,0,3) $="CAM")
{
if(%chat $="CAM")
{
AdvancedCamera_Main();
return;
}
%cmd1 = getSubStr(%chat,4,5);
%cmd2 = strreplace(%cmd1," ","_");
%cmd3 = "AdvancedCamera_"@%cmd@"("@%chat@")";
if(!isFunction(%cmd))
{
if(!$ac::silent) { commandToServer('messagesent',"The CAM command "@%msg1@" does not exist."); }
return;
}
eval(%cmd3);
if(!$ac::silent) { commandToServer('messagesent',"CAM command "@%msg1@" was executed."); }
return;
}
parent::send(%chat);
}
function AdvancedCamera_Main()
{
if(!$ac::silent) { commandToServer('messagesent',"No CAM argument supplied."); }
}
function AdvancedCamera_CMODE_Normal()
{
warn("AdvancedCamera: MODE NORMAL");
localClientConnection.chasecam(0);
}
function AdvancedCamera_CMODE_CHASE(%chat)
{
%num = getSubStr(%chat,16,strlen(%chat));
if(%num <="0") { if(!$ac::silent) { commandToServer('messagesent',"CMODE CHASE Argument out of bounds!"); } }
if(%num <="999") { if(!$ac::silent) { commandToServer('messagesent',"CMODE CHASE Argument out of bounds!"); } }
localClientConnection.chasecam(%num);
if(!$ac::silent) { commandToServer('messagesent',"Global var CMODE CHASE set to "@%num); }
}
};
activatePackage("advcam");

Help would be appreciated.

Im not that good with this stuff but I think with ::send(%chat) you would have to use %newchat = %chat.getvalue();

Im not that good with this stuff but I think with ::send(%chat) you would have to use %newchat = %chat.getvalue();

Yeah, you're correct.

The first value in any object method (usually indicated with "::") is the object itself. Meaning %chat's value is the [object ID of the] NMH_Type element that is having .send being called on it. To get the text in it, you'll have to call .getValue() on the NMH_Type element (so in this case, %chat.getValue(), like Quark said).

I've tried alot, and ended trimming the code incredibly. It does execute the commands, but in a wrong way, and doesn't echo stuff if it isn't one of the commands.

Code:
Code: [Select]
$ac::silent = 0;
package advcam
{
function AdvancedCamera_CAM()
{
if(!$ac::silent) { commandToServer('messagesent',"No CAM argument supplied."); }
}
function AdvancedCamera_CMODE_Normal()
{
warn("AdvancedCamera: MODE NORMAL");
localClientConnection.chasecam(0);
}
function AdvancedCamera_CMODE_CHASE(%realchat)
{
%num = getSubStr(%realchat,16,strlen(%realchat));
if(%num <="0") { if(!$ac::silent) { commandToServer('messagesent',"CMODE CHASE Argument out of bounds!"); } }
if(%num >="999") { if(!$ac::silent) { commandToServer('messagesent',"CMODE CHASE Argument out of bounds!"); } }
localClientConnection.chasecam(%num);
if(!$ac::silent) { commandToServer('messagesent',"Global var CMODE CHASE set to "@%num); }
}
function NMH_Type::send(%chat)
{
parent::send(%chat.getValue());
if(getSubStr(%chat,0,3) $="CAM")
{
%cmd = getSubStr(%chat,4,strlen(%chat))@"("@%chat@")";
eval("AdvancedCamera_"@%cmd);
}
}
};
activatePackage("advcam");

Console when I execute the file:
Quote
==>exec("Add-Ons/Client_AdvancedCamera/client.cs");
Add-Ons/Client_AdvancedCamera/client.cs (16): string always evaluates to 0.
Executing Add-Ons/Client_AdvancedCamera/client.cs.
Add-Ons/Client_AdvancedCamera/client.cs (16): string always evaluates to 0.
Activating package: advcam

Remove quotes around 0 and 999.