You cannot compare strings with ==, You must use <string>.equals(<string>) or <string>.equalsIgnoreCase(<string>).
Hello... So i was making a completly useless script just to learn a bit, but it aint working and as it is written in javascript its reaaalllyyy hard to understand whats wrong.
If i write /spam in chat it will say command not recognised even through i used "event.cancel()".Code:var ID_PLAYERTEXT = $.findPacketId("PLAYERTEXT"); var ID_TEXT = $.findPacketId("TEXT"); var spamt = "NOT SET!"; function onClientPacket(event) { var packet = event.getPacket(); switch (packet.id()) { case ID_PLAYER_TEXT: { var text = packet.text.toLowerCase(); if (text == "/spam") { event.cancel(); var textp = $.createPacket(ID_PLAYERTEXT); textp.text = spamt; $.sendToServer(textp); } break; } } } function onServerPacket(event) { var packet = event.getPacket(); switch (packet.id()) { case ID_TEXT: { var text = packet.text; if (text.length > 0) { var spamt = text; } } } } function spam() { var textp = $.createPacket(ID_PLAYERTEXT); textp.text = spamt; $.sendToServer(textp); }
You cannot compare strings with ==, You must use <string>.equals(<string>) or <string>.equalsIgnoreCase(<string>).
You defined variable:
But used it with extra _:
__________________________________________
You can compare strings with == on realm relay script
__________________________________________
Also
is never called. Anyways the script doesn't make sense even if these mistakes were corrected
Last edited by CrazyJani; 04-11-2014 at 11:26 AM.
Not familiar with RR but.. If you are have a PLAYERTEXT packet, why not just change the text ? Why creating another PLAYERTEXT ?Code:case ID_PLAYER_TEXT: { var text = packet.text.toLowerCase(); if (text == "/spam") { event.cancel(); var textp = $.createPacket(ID_PLAYERTEXT); textp.text = spamt; $.sendToServer(textp); } break;
Due to a recent DMCA takedown attempt we had to remove Faintmako brain. Please do not paid attention to what he say or do.
Reputation-
Vouches
Respect-
Nilly, Ultran00b, JustAnoobROTMG, Nano, karolelis9, fallenhacks(cake), jaythedev
DisRespect-
mandela96, spaghetti master, floxxe, drillick, brendoo