Author Topic: Simple Script Help  (Read 2733 times)

Alright, I'm trying to refresh myself with Torque's functions and whatnot

And somehow I seem to run into a problem

Code: [Select]
if(!$JoinMessage::Binds)
{
$remapDivision[$remapCount]="Join Message";
$remapName[$remapCount]="Toggle On/Off";
$remapCmd[$remapCount]="toggleJoinMessage";
$remapCount++;
$JoinMessage::Binds=1;
}

function ClientCmd_ClientJoin(%client)
{
messageAll('',"Welcome, %client.");
}

function toggleJoinMessage(%a)
{
if(!%a)
return;
if($JoinMessage::On)
{
$JoinMessage::On = false;
clientcmdcenterPrint("\c6Join message disabled.", 2);
}
else
{
$JoinMessage::On = true;
clientcmdcenterPrint("\c6Join Message enabled.", 2);
}
}

I realize it's a JoinMessage, I'm not planning on using it, simply to learn a few things
« Last Edit: June 09, 2012, 11:05:55 AM by ¥ola »


Alright, I'm trying to refresh myself with Torque's functions and whatnot

And somehow I seem to run into a problem

Code: [Select]
if(!$JoinMessage::Binds)
{
$remapDivision[$remapCount]="Join Message";
$remapName[$remapCount]="Toggle On/Off";
$remapCmd[$remapCount]="toggleJoinMessage";
$remapCount++;
$JoinMessage::Binds=1;
}

function ClientCmd_ClientJoin(%client)
{
messageAll('',"Welcome, %client.");
}

function toggleJoinMessage(%a)
{
if(!%a)
return;
if($JoinMessage::On)
{
$JoinMessage::On = false;
clientcmdcenterPrint("\c6Join message disabled.", 2);
}
else
{
$JoinMessage::On = true;
clientcmdcenterPrint("\c6Join Message enabled.", 2);
}
}

I realize it's a JoinMessage, I'm not planning on using it, simply to learn a few things
Few things.
1. ClientCmd_ClientJoin is a non existant function.
2. messageAll is server sided.

Few things.
1. ClientCmd_ClientJoin is a non existant function.
2. messageAll is server sided.
What the function for when a player joins?

How would I sent a chat message to the entire server through my players chat?

Since this is clientsided, you don't have access to messageAll. If you want to display a message to everyone, you have to use chat. commandToServer('messageSent', "message");

Second, you have to package the ClientCmd_ClientJoin (if it were a function, because the way you're using it, i'm guessing you thought it already existed).

package duckoverlords
{
     function ClientCmd_ClientJoin(%client)
     {
          parent::ClientCmd_ClientJoin(%client);
          commandToServer('messageSent', "Welcome, %client.");
     }
};
activatePackage(duckoverlords);


But the above code still wouldn't work as intended.

When you want to append a non-string thing onto a string, you have to use things like @ and SPC. (There's also NL and TAB, but you don't need those here.)

package duckoverlords
{
     function ClientCmd_ClientJoin(%client)
     {
          parent::ClientCmd_ClientJoin(%client);
          commandToServer('messageSent', "Welcome," SPC %client);
     }
};
activatePackage(duckoverlords);


@ appends whatever with no space, SPC appends it with a space. (obviously)

Now, one last thing. You appear to want to be able to toggle this. So we have to actually factor in whether it's on or not to the actual function.

package duckoverlords
{
     function ClientCmd_ClientJoin(%client)
     {
          parent::ClientCmd_ClientJoin(%client);
          if($JoinMessage::On)
               commandToServer('messageSent', "Welcome," SPC %client);
     }
};
activatePackage(duckoverlords);


Now, given that ClientCmd_ClientJoin actually existed and did what you thought it would do and had the only argument as %client, which is a string containing the player's name, that would work. (unless i made an error)

Thanks man, I figured that function was incorrect

Also, when I set the keybind, and try to use it, it stays on JoinMessage Enbaled every time

Now I have

Code: [Select]
if(!$JoinMessage::Binds)
{
$remapDivision[$remapCount]="Join Message";
$remapName[$remapCount]="Toggle On/Off";
$remapCmd[$remapCount]="toggleJoinMessage";
$remapCount++;
$JoinMessage::Binds=1;
}

package JoinMessage
{
     function ClientCmd_ClientJoin(%client)
     {
          parent::ClientCmd_ClientJoin(%client);
          if($JoinMessage::On = true)
               commandToServer('messageSent', "Welcome," SPC %client);
     }
};
activatePackage(JoinMessage);

function toggleJoinMessage(%a)
{
if(!%a)
return;
if($JoinMessage::On)
{
$JoinMessage::On = false;
clientcmdcenterPrint("\c6Join message disabled.", 2);
}
else
{
$JoinMessage::On = true;
clientcmdcenterPrint("\c6Join Message enabled.", 2);
}
}

And it still doesn't work

use NewPlayerListGui::update(%this,%cl,%name,%blid,%a,%b,%c).

use NewPlayerListGui::update(%this,%cl,%name,%blid,%a,%b,%c).
Hum.
Where?
Lol.

use NewPlayerListGui::update(%this,%cl,%name,%blid,%a,%b,%c).

forget no.

secureClientCmd_clientJoin.

Hold it!
if($JoinMessage::On = true)

That will set $JoinMessage::On to true, and so it'll always go even if it's off.

Either use == 1 or remove that part completely and just do $JoinMessage::On.

forget no.

secureClientCmd_clientJoin.
Dear god you're so damn paranoid.

Use this then:
Code: [Select]
function onServerMessage(%Message)
{
if(%Message $= "")
return;
newChatHud_addLine(%message);
if(getWord(%Message, getWordCount(%Message)-1) $= "connected.") {
//do stuff
}
}

Lol
You guys are making me constantly redo stuff

Dear god you're so damn paranoid.

Use this then:
Code: [Select]
function onServerMessage(%Message)
{
if(%Message $= "")
return;
newChatHud_addLine(%message);
if(getWord(%Message, getWordCount(%Message)-1) $= "connected.") {
//do stuff
}
}

Paranoid? What?