Thread: [PI] Yell Timer

Results 1 to 6 of 6
  1. #1 [PI] Yell Timer 
    Registered Member
    Join Date
    Dec 2011
    Posts
    454
    Thanks given
    17
    Thanks received
    37
    Rep Power
    61
    I'm trying to add a timer to this yell command so non-premium players can yell only every 20 seconds to avoid spammers, right now the 20 seconds applies to everyone. Any clue on the way to place it so it would only work for non-premium players and not affect anyone else.




    Code:
    if (playerCommand.startsWith("yell")) {
    				if(System.currentTimeMillis() - c.yellTimer > 20000) {
    				c.yellTimer = System.currentTimeMillis();
    				for (int j = 0; j < Server.playerHandler.players.length; j++) {
    					if (Server.playerHandler.players[j] != null) {
    						Client c2 = (Client)Server.playerHandler.players[j];
    						
    							
    							if (c.isDonator == 1 && (c.playerRights < 1 || c.playerRights > 3)){
    								c2.sendMessage("<shad=6081134>[Donator]</col><img=0>"+ Misc.optimizeText(c.playerName) +": "
    												+ Misc.optimizeText(playerCommand.substring(5)) +"");
    							}else if (c.playerRights == 0){
    								c2.sendMessage("[Player]"+ Misc.optimizeText(c.playerName) +": "
    												+ Misc.optimizeText(playerCommand.substring(5)) +"");
    							}else if (c.playerRights == 1){
    								c2.sendMessage("<col=255>[Mod]</col><img=1>"+ Misc.optimizeText(c.playerName) +": "
    												+ Misc.optimizeText(playerCommand.substring(5)) +"");
    							}else if (c.playerRights == 2){
    								c2.sendMessage("<col=255>[Admin]</col><img=2>"+ Misc.optimizeText(c.playerName) +": "
    												+ Misc.optimizeText(playerCommand.substring(5)) +"");
    							}else if (c.playerRights == 3){
    								c2.sendMessage("<shad=15695415>[Owner]</col><img=2>"+ Misc.optimizeText(c.playerName) +": "
    												+ Misc.optimizeText(playerCommand.substring(5)) +"");
    							 
    							 
    							 
    							 
    							 }else{
            c.sendMessage("Sorry, You must wait 20 seconds");
    									
    							}
    							
    						}
    					}
    				}
    			}
    Your help is appreciated.
    Reply With Quote  
     

  2. #2  
    Registered Member Treq's Avatar
    Join Date
    Aug 2010
    Posts
    463
    Thanks given
    71
    Thanks received
    65
    Rep Power
    22
    Code:
    if(System.currentTimeMillis() - c.yellTimer > 20000) {
    Change that line to

    Code:
    if(System.currentTimeMillis() - c.yellTimer > 20000 || c.playerRights >= 1) {
    Should solve your problem.
    ~Treq~ (Previously Spetsnaz)
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Dec 2011
    Posts
    454
    Thanks given
    17
    Thanks received
    37
    Rep Power
    61
    Quote Originally Posted by Spetsnaz View Post
    Code:
    if(System.currentTimeMillis() - c.yellTimer > 20000) {
    Change that line to

    Code:
    if(System.currentTimeMillis() - c.yellTimer > 20000 || c.playerRights >= 1) {
    Should solve your problem.
    Thank you, repped, but the else statement is not showing up for people.
    Reply With Quote  
     

  4. #4  
    Respected Member


    Join Date
    Jan 2009
    Posts
    5,743
    Thanks given
    1,162
    Thanks received
    3,603
    Rep Power
    5000
    Code:
    if (playerCommand.startsWith("yell")) {
        if((System.currentTimeMillis() - c.yellTimer < 20000) && !c.isDonator && c.playerRights == 0) {
            c.sendMessage("Sorry, You must wait 20 seconds");
            return;
        }
        c.yellTimer = System.currentTimeMillis();
        String yell = "";
        switch(c.playerRights) {
            case 0:
                if(c.isDonator) {
                    yell = "[Player]"+ Misc.optimizeText(c.playerName) +": " + Misc.optimizeText(playerCommand.substring(5));
                } else {
                    yell =  "<shad=6081134>[Donator]</col><img=0>"+ Misc.optimizeText(c.playerName) +": "  + Misc.optimizeText(playerCommand.substring(5));
                }
                break;
            case 1:
            case 2:
                yell = "<col=255>[" + (c.playerRights == 1 ? "Mod" : "Admin") + "]</col><img=2>"+ Misc.optimizeText(c.playerName) +": " + Misc.optimizeText(playerCommand.substring(5))
                break;
            case 3:
                yell = "<shad=15695415>[Owner]</col><img=2>"+ Misc.optimizeText(c.playerName) +": " + Misc.optimizeText(playerCommand.substring(5));
                break;
        }
        for (int j = 0; j < Server.playerHandler.players.length; j++)
            if (Server.playerHandler.players[j] != null)
                ((Client)Server.playerHandler.players[j]).sendMessage(yell);
    }
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Dec 2011
    Posts
    454
    Thanks given
    17
    Thanks received
    37
    Rep Power
    61
    Quote Originally Posted by 5tuart View Post
    Code:
    if (playerCommand.startsWith("yell")) {
        if((System.currentTimeMillis() - c.yellTimer < 20000) && !c.isDonator && c.playerRights == 0) {
            c.sendMessage("Sorry, You must wait 20 seconds");
            return;
        }
        c.yellTimer = System.currentTimeMillis();
        String yell = "";
        switch(c.playerRights) {
            case 0:
                if(c.isDonator) {
                    yell = "[Player]"+ Misc.optimizeText(c.playerName) +": " + Misc.optimizeText(playerCommand.substring(5));
                } else {
                    yell =  "<shad=6081134>[Donator]</col><img=0>"+ Misc.optimizeText(c.playerName) +": "  + Misc.optimizeText(playerCommand.substring(5));
                }
                break;
            case 1:
            case 2:
                yell = "<col=255>[" + (c.playerRights == 1 ? "Mod" : "Admin") + "]</col><img=2>"+ Misc.optimizeText(c.playerName) +": " + Misc.optimizeText(playerCommand.substring(5))
                break;
            case 3:
                yell = "<shad=15695415>[Owner]</col><img=2>"+ Misc.optimizeText(c.playerName) +": " + Misc.optimizeText(playerCommand.substring(5));
                break;
        }
        for (int j = 0; j < Server.playerHandler.players.length; j++)
            if (Server.playerHandler.players[j] != null)
                ((Client)Server.playerHandler.players[j]).sendMessage(yell);
    }
    Code:
    src\server\model\players\packets\Commands.java:274: operator ! cannot be applied
     to int
        if((System.currentTimeMillis() - c.yellTimer < 20000) && !c.isDonator && c.p
    layerRights == 0) {
                                                                 ^
    src\server\model\players\packets\Commands.java:282: incompatible types
    found   : int
    required: boolean
                if(c.isDonator) {
                    ^
    Note: Some input files use unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    2 errors
    Press any key to continue . . .
    Do you mean c.ifDonator == 1 or c.ifDonator == 0 since this is a boolean.

    I made it like:
    Code:
    if (playerCommand.startsWith("yell")) {
        if((System.currentTimeMillis() - c.yellTimer < 20000) && c.isDonator == 0 && c.playerRights == 0) {
            c.sendMessage("Sorry, You must wait 20 seconds");
            return;
        }
        c.yellTimer = System.currentTimeMillis();
        String yell = "";
        switch(c.playerRights) {
            case 0:
                if(c.isDonator == 1) {
                    yell = "[Player]"+ Misc.optimizeText(c.playerName) +": " + Misc.optimizeText(playerCommand.substring(5));
                } else {
                    yell =  "<shad=6081134>[Donator]</col><img=0>"+ Misc.optimizeText(c.playerName) +": "  + Misc.optimizeText(playerCommand.substring(5));
                }
                break;
            case 1:
            case 2:
                yell = "<col=255>[" + (c.playerRights == 1 ? "Mod" : "Admin") + "]</col><img=2>"+ Misc.optimizeText(c.playerName) +": " + Misc.optimizeText(playerCommand.substring(5));
                break;
            case 3:
                yell = "<shad=15695415>[Owner]</col><img=2>"+ Misc.optimizeText(c.playerName) +": " + Misc.optimizeText(playerCommand.substring(5));
                break;
        }
        for (int j = 0; j < Server.playerHandler.players.length; j++)
            if (Server.playerHandler.players[j] != null)
                ((Client)Server.playerHandler.players[j]).sendMessage(yell);
    }
    With no errors, but I am not sure if this is what your going at.
    Reply With Quote  
     

  6. #6  
    Respected Member


    Join Date
    Jan 2009
    Posts
    5,743
    Thanks given
    1,162
    Thanks received
    3,603
    Rep Power
    5000
    Quote Originally Posted by omgitsbob123 View Post
    Code:
    src\server\model\players\packets\Commands.java:274: operator ! cannot be applied
     to int
        if((System.currentTimeMillis() - c.yellTimer < 20000) && !c.isDonator && c.p
    layerRights == 0) {
                                                                 ^
    src\server\model\players\packets\Commands.java:282: incompatible types
    found   : int
    required: boolean
                if(c.isDonator) {
                    ^
    Note: Some input files use unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    2 errors
    Press any key to continue . . .
    Do you mean c.ifDonator == 1 or c.ifDonator == 0 since this is a boolean.

    I made it like:
    Code:
    if (playerCommand.startsWith("yell")) {
        if((System.currentTimeMillis() - c.yellTimer < 20000) && c.isDonator == 0 && c.playerRights == 0) {
            c.sendMessage("Sorry, You must wait 20 seconds");
            return;
        }
        c.yellTimer = System.currentTimeMillis();
        String yell = "";
        switch(c.playerRights) {
            case 0:
                if(c.isDonator == 1) {
                    yell = "[Player]"+ Misc.optimizeText(c.playerName) +": " + Misc.optimizeText(playerCommand.substring(5));
                } else {
                    yell =  "<shad=6081134>[Donator]</col><img=0>"+ Misc.optimizeText(c.playerName) +": "  + Misc.optimizeText(playerCommand.substring(5));
                }
                break;
            case 1:
            case 2:
                yell = "<col=255>[" + (c.playerRights == 1 ? "Mod" : "Admin") + "]</col><img=2>"+ Misc.optimizeText(c.playerName) +": " + Misc.optimizeText(playerCommand.substring(5));
                break;
            case 3:
                yell = "<shad=15695415>[Owner]</col><img=2>"+ Misc.optimizeText(c.playerName) +": " + Misc.optimizeText(playerCommand.substring(5));
                break;
        }
        for (int j = 0; j < Server.playerHandler.players.length; j++)
            if (Server.playerHandler.players[j] != null)
                ((Client)Server.playerHandler.players[j]).sendMessage(yell);
    }
    With no errors, but I am not sure if this is what your going at.
    Second one should be == 0 and sorry, didn't realise it wasn't a boolean... It should be....
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 11
    Last Post: 12-23-2011, 02:10 AM
  2. [PI] Yell timer [PI]
    By Sillhouette in forum Help
    Replies: 27
    Last Post: 06-28-2011, 11:12 AM
  3. Yell Timer
    By Segadora in forum Configuration
    Replies: 2
    Last Post: 07-07-2008, 11:13 PM
  4. very easy yell timer can yell once in 5 secs
    By lord jahva in forum Tutorials
    Replies: 13
    Last Post: 07-06-2008, 10:57 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •