Author Topic: Client Sided Calculator Problems.  (Read 1605 times)

Alright, so I decided to make a client sided calculator. Long story short, Slick fixed all the idiot mistakes I made, then we proceeded to try and make it work, we couldn't. This is the script:



package calculator
{
 function NMH_Type::send(%this)
 {
  %msg=%this.getValue();
  Parent::send(%this);
  if(getWord(%msg,0)$="+calc")
  {
   %str=getWords(%msg,1);
   for(%i=0;%i<getWordCount(%str);%i+=2)
    %mathproblem = %mathproblem@getWord(%str,%i)@getWord(%str,%i+1);
   eval($clientMath::Problem=%mathproblem);
   commandToServer('MessageSent',$clientMath::Problem);
  }
 }
};
activatepackage(calculator);




([ tt ] > [ code ])

Well it DOES react, but not in the way I wanted it to, all it did was say (for example) 1+1 if I said +calc 1+1.

I think I have to access the console (sort of) using commandtoclient or something.

Any help would be very much appreciated, thank you.



What if %this.getValue(); is quit();

And what the hell dude.

Code: [Select]
    function clientCMDChatMessage(%a,%b,%c,%d,%e,%name,%f,%msg)
« Last Edit: September 02, 2009, 09:28:19 PM by Kalphiter »

Parent the script, outside the if() statement.  Personally there is no need for protection unless you do something stupid.

Parent the script, outside the if() statement.
Parent::send(%this);

I couldn't find it at first, either.

What if %this.getValue(); is quit();
Someone else had a chatbot calculator, and I did Calculate $Pref::Server::Adminpassword. It actually worked.

Someone else had a chatbot calculator, and I did Calculate $Pref::Server::Adminpassword. It actually worked.
lol'd

Alright I thought of a good way of doing it.

But how would you tell the game that something ISN'T part of a message, like rather than "1+1" it would be 1+1.

Complications. D:



Guys, It's not a chatbot calculator, it's just for me and me only.
« Last Edit: September 03, 2009, 01:51:39 AM by Gamefandan »

Guys, It's not a chatbot calculator, it's just for me and me only.

So why does it have to send the answer to the entire server?

So why does it have to send the answer to the entire server?

So it will send the answer as a chat message. I didn't literally mean for me, all I meant was that it's not effected by other clients saying +calc.

Now can let's turn down the interrogation lights people, an ideas on how I can fix this?

So essentially it's just so you can go into a server and do something like this:

Gamefandan joined
Gamefandan: Hi guys! I have a calculator!
Gamefandan: +calc 5+5
Gamefandan: 10
Everyone: shut the forget up, script kiddie
Gamefandan: but but, the calculator!
Gamefandan: +calc 10*2
Gamefandan: 20
Gamefandan was permanently banned.


I bet this echoes "Syntax error in input" a lot

eval("$clientMath::Problem =" SPC %mathproblem @ ";"); might work better.

eval("$clientMath::Problem =" SPC %mathproblem @ ";"); might work better.

I love you.

You stopped me from doing this:



package calculator
{
 function NMH_Type::send(%this)
 {
  %msg=%this.getValue();
  Parent::send(%this);
  if(getWord(%msg,0)$="+calc")
  {
   %str=getWords(%msg,1);
   for(%i=0;%i<getWordCount(%str);%i+=2)
    %mathproblem = %mathproblem.getWord(%str,%i).getWord(%str,%i+1);
   $clientMath::Problem=%mathproblem;
   $Num1=getWord(%msg,1);
   $Num2=getWord(%msg,3);
   $Sign=getword(%msg,2).getvalue;

   if(getWord(%msg,2)$="+") 
    Commandtoserver('messagesent',$clientMath::Problem SPC "=" SPC $Num1 + $Num2);

   else if(getword(%msg,2)$="-")
    Commandtoserver('messagesent',$clientMath::Problem SPC "=" SPC $Num1 - $Num2);

   else if(getword(%msg,2)$="*")
    Commandtoserver('messagesent',$clientMath::Problem SPC "=" SPC $Num1 * $Num2);

   else if(getword(%msg,2)$="/")
    Commandtoserver('messagesent',$clientMath::Problem SPC "=" SPC $Num1 / $Num2);
  }
 }
};
activatepackage(calculator);




Sooo ugly. D:



Ephi, even though you try to bring me down and slap me back into real life.

I wuvz you. <3



Thanks again M, you were a big help.

Also, I will not lock this topic because I consider locking coding help topics a bad practice, you can continue discussing if you want. :D