Results 1 to 9 of 9
  1. #1
    supergovs's Avatar
    Join Date
    Sep 2011
    Gender
    male
    Posts
    26
    Reputation
    10
    Thanks
    0

    Red face Making a random script...

    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.
    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);
    }
    If i write /spam in chat it will say command not recognised even through i used "event.cancel()".

  2. #2
    Rebel01390's Avatar
    Join Date
    Mar 2014
    Gender
    male
    Posts
    12
    Reputation
    10
    Thanks
    2
    You cannot compare strings with ==, You must use <string>.equals(<string>) or <string>.equalsIgnoreCase(<string>).

  3. #3
    CrazyJani's Avatar
    Join Date
    Jan 2013
    Gender
    male
    Posts
    2,475
    Reputation
    170
    Thanks
    15,666
    You defined variable:
    Quote Originally Posted by supergovs View Post
    var ID_PLAYERTEXT = $.findPacketId("PLAYERTEXT");
    But used it with extra _:
    Quote Originally Posted by supergovs View Post
    case ID_PLAYER_TEXT:
    __________________________________________

    Quote Originally Posted by Rebel01390 View Post
    You cannot compare strings with ==, You must use <string>.equals(<string>) or <string>.equalsIgnoreCase(<string>).
    You can compare strings with == on realm relay script
    __________________________________________

    Also
    Quote Originally Posted by supergovs View Post
    function spam() {

    var textp = $.createPacket(ID_PLAYERTEXT);
    textp.text = spamt;
    $.sendToServer(textp);
    }
    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.

  4. #4
    JustAnoobROTMG's Avatar
    Join Date
    Aug 2012
    Gender
    male
    Posts
    1,916
    Reputation
    185
    Thanks
    18,230
    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;
    Not familiar with RR but.. If you are have a PLAYERTEXT packet, why not just change the text ? Why creating another PLAYERTEXT ?
    Due to a recent DMCA takedown attempt we had to remove Faintmako brain. Please do not paid attention to what he say or do.


  5. #5
    runekri3's Avatar
    Join Date
    Feb 2011
    Gender
    male
    Posts
    792
    Reputation
    9
    Thanks
    240
    My Mood
    Cheerful
    Quote Originally Posted by JustAnoobROTMG View Post
    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;
    Not familiar with RR but.. If you are have a PLAYERTEXT packet, why not just change the text ? Why creating another PLAYERTEXT ?
    You are correct, there's no need to cancel a packet only to create the same packet again.
    Both ways work but changing the existing packet makes more sense.
    Reputation-
    Vouches
    Respect-
    Nilly, Ultran00b, JustAnoobROTMG, Nano, karolelis9, fallenhacks(cake), jaythedev
    DisRespect-
    mandela96, spaghetti master, floxxe, drillick, brendoo

  6. #6
    Knorrex's Avatar
    Join Date
    Nov 2010
    Gender
    male
    Location
    ~
    Posts
    517
    Reputation
    15
    Thanks
    975
    My Mood
    Angelic
    Quote Originally Posted by CrazyJani View Post
    You can compare strings with == on realm relay script
    You should educate yourself on what the == operator does, it's a good programming habit to never use it for strings

  7. #7
    nilly's Avatar
    Join Date
    Aug 2012
    Gender
    male
    Posts
    2,652
    Reputation
    155
    Thanks
    13,983
    My Mood
    Angelic
    Quote Originally Posted by Knorrex View Post
    You should educate yourself on what the == operator does, it's a good programming habit to never use it for strings
    Depends on what language you use. I know AS3 "==" does what the user think it does with strings but java equates the actual object instead of the value of the string.
    Be careful, stray too far from the pack and you'll get lost.

  8. #8
    Knorrex's Avatar
    Join Date
    Nov 2010
    Gender
    male
    Location
    ~
    Posts
    517
    Reputation
    15
    Thanks
    975
    My Mood
    Angelic
    Quote Originally Posted by nilly View Post
    Depends on what language you use. I know AS3 "==" does what the user think it does with strings but java equates the actual object instead of the value of the string.
    Well , while the java == will check for memory address, js == does type coercion and value comparison, one might say there's a small chance of unexpected behaviour, but yeah, I'll keep using equals for good habit

  9. #9
    nilly's Avatar
    Join Date
    Aug 2012
    Gender
    male
    Posts
    2,652
    Reputation
    155
    Thanks
    13,983
    My Mood
    Angelic
    Quote Originally Posted by Knorrex View Post
    Well , while the java == will check for memory address, js == does type coercion and value comparison, one might say there's a small chance of unexpected behaviour, but yeah, I'll keep using equals for good habit
    There is no equals in AS3. Afaik, one has to use == to compare two strings. Of course AS3 is more of an exception than the rule.
    Be careful, stray too far from the pack and you'll get lost.

Similar Threads

  1. [Help] Making a randomizer...
    By papadoo in forum Visual Basic Programming
    Replies: 40
    Last Post: 11-28-2012, 06:02 PM
  2. [Tutorial] How you make a BunnyHop script ! VAC Undetected (CSS) [AUTOHOTKEY]
    By CFhackerfree in forum CounterStrike (CS) 1.6 Hacks / Counter Strike: Source (CSS) Hacks
    Replies: 8
    Last Post: 05-22-2012, 09:57 PM
  3. [Help Request] Help needed - how to find xyz coordinates and make some simple scripts
    By qq12345 in forum Dragon Nest Help
    Replies: 1
    Last Post: 05-07-2012, 01:24 PM
  4. [Request] Can someone here please help me make an upload script?
    By Deergab in forum Web Languages
    Replies: 2
    Last Post: 02-26-2012, 02:16 AM
  5. any one can make me this script ??.. i will pay
    By scorpenoz in forum Runescape Help
    Replies: 5
    Last Post: 06-19-2011, 03:55 PM