[Help] Occupation Skills

Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Account Upgraded | Title Enabled! TacoBell is offline
    MemberRank
    Aug 2011 Join Date
    518Posts

    angry [Help] Occupation Skills

    How would one save occupation skills into the database (MySQL)? It works when the player is changing channel or going into Cash Shop and all but once I relog it refreshes and becomes spammable because relogging can always reset it. I have the command:
    PHP Code:
    if (!c.getPlayer().getCheatTracker().SmegaSpam(150002)) {
                    if (
    c.getPlayer().haveItem(50720001truetrue)) {
                        
    c.getPlayer().getClient().getChannelServer().broadcastPacket(CWvsContext.serverNotice(3c.getChannel(), sb.toString()));
                        
    MapleInventoryManipulator.removeById(cMapleInventoryType.CASH50720001truetrue);
                    } else {
                        
    c.getPlayer().dropMessage("You do not have a megaphone to use this command.");
                    }
                } else {
                    
    c.getPlayer().dropMessage("You need to wait every 15 seconds before using this command again!");
                } 
    PHP Code:
    public synchronized boolean SmegaSpam(int limitint type) {
            if (
    type || lastTime.length type) {
                
    type 1// Default numbuh
            
    }
            if (
    System.currentTimeMillis() < limit lastTime[type]) {
                return 
    true;
            }
            
    lastTime[type] = System.currentTimeMillis();
            return 
    false;
        } 
    The SmegaSpam prevents them from spamming/using the command repeatedly even if they CC or enter cash shop. Once someone relogs they can use the command again like SmegaSpam doesn't exist.


  2. #2
    Wut. QuietCrystal is offline
    MemberRank
    Aug 2010 Join Date
    SingaporeLocation
    346Posts

    Re: [Help] Occupation Skills

    Quote Originally Posted by TacoBell View Post
    How would one save occupation skills into the database (MySQL)? It works when the player is changing channel or going into Cash Shop and all but once I relog it refreshes and becomes spammable because relogging can always reset it. I have the command:
    PHP Code:
    if (!c.getPlayer().getCheatTracker().SmegaSpam(150002)) {
                    if (
    c.getPlayer().haveItem(50720001truetrue)) {
                        
    c.getPlayer().getClient().getChannelServer().broadcastPacket(CWvsContext.serverNotice(3c.getChannel(), sb.toString()));
                        
    MapleInventoryManipulator.removeById(cMapleInventoryType.CASH50720001truetrue);
                    } else {
                        
    c.getPlayer().dropMessage("You do not have a megaphone to use this command.");
                    }
                } else {
                    
    c.getPlayer().dropMessage("You need to wait every 15 seconds before using this command again!");
                } 
    PHP Code:
    public synchronized boolean SmegaSpam(int limitint type) {
            if (
    type || lastTime.length type) {
                
    type 1// Default numbuh
            
    }
            if (
    System.currentTimeMillis() < limit lastTime[type]) {
                return 
    true;
            }
            
    lastTime[type] = System.currentTimeMillis();
            return 
    false;
        } 
    The SmegaSpam prevents them from spamming/using the command repeatedly even if they CC or enter cash shop. Once someone relogs they can use the command again like SmegaSpam doesn't exist.
    Search how cooldowns work for normal skills. Relogging doesn't reset those. Then come up with a custom skill ID for that specific command, and deal with it as a cooldown skill.

  3. #3
    Member Drum is offline
    MemberRank
    Jul 2013 Join Date
    80Posts

    Re: [Help] Occupation Skills

    Also, I dont see the need to synchronize SmegaSpam. If you use unique values for the int type parameter paired with unique time restricted tasks, there should never be a situation where concurrent threads create erroneous data in your lastTime array.

    Try remove it.

  4. #4
    Account Upgraded | Title Enabled! TacoBell is offline
    MemberRank
    Aug 2011 Join Date
    518Posts

    Re: [Help] Occupation Skills

    Quote Originally Posted by QuietCrystal View Post
    Search how cooldowns work for normal skills. Relogging doesn't reset those. Then come up with a custom skill ID for that specific command, and deal with it as a cooldown skill.
    How would something like that even look like? I have a system set-up and it doesn't work even though some of it was leeched (gasp) and made sure it was 100% coded properly. How does one come up with a custom skill ID for a command?

  5. #5
    Wut. QuietCrystal is offline
    MemberRank
    Aug 2010 Join Date
    SingaporeLocation
    346Posts

    [Help] Occupation Skills

    Just choose any ID that isn't already taken by a skill, then save a cooldown with that ID. after that, just load cooldowns using that ID.

    Edit: But look if your cooldown is going to be only 15 seconds, relogging to bypass the cooldown will take about that long too, and it'll be pointless to have something like this.

  6. #6
    Account Upgraded | Title Enabled! TacoBell is offline
    MemberRank
    Aug 2011 Join Date
    518Posts

    Re: [Help] Occupation Skills

    Quote Originally Posted by QuietCrystal View Post
    Just choose any ID that isn't already taken by a skill, then save a cooldown with that ID. after that, just load cooldowns using that ID.

    Edit: But look if your cooldown is going to be only 15 seconds, relogging to bypass the cooldown will take about that long too, and it'll be pointless to have something like this.
    I was just using 15 seconds as a test mode. It worked surprisingly easily (O_O) which concerns me because it felt a little too easy. It seemed to work flawlessly though, thanks for the help ^.^. Unrelated to topic but if I wanted to show a constant timer how would that look like? Like this?
    PHP Code:
    long remaining System.currentTimeMillis() - 20
    Deletes 1 second off a 20 second command timer and displays the 'real' time?

  7. #7
    desk.getCoffee().drink(); AngelSpirit is offline
    MemberRank
    Jul 2010 Join Date
    CanadaLocation
    318Posts

    Re: [Help] Occupation Skills

    Quote Originally Posted by TacoBell View Post
    I was just using 15 seconds as a test mode. It worked surprisingly easily (O_O) which concerns me because it felt a little too easy. It seemed to work flawlessly though, thanks for the help ^.^. Unrelated to topic but if I wanted to show a constant timer how would that look like? Like this?
    PHP Code:
    long remaining System.currentTimeMillis() - 20
    Deletes 1 second off a 20 second command timer and displays the 'real' time?
    Just a heads up -- you're working with System.currentTimeMillis(). Read that more closely -- millis. Milliseconds. If you subtract 20, you'll be subtracting 20 milliseconds, not 20 seconds.

  8. #8
    Account Upgraded | Title Enabled! TacoBell is offline
    MemberRank
    Aug 2011 Join Date
    518Posts

    Re: [Help] Occupation Skills

    Quote Originally Posted by AngelSpirit View Post
    Just a heads up -- you're working with System.currentTimeMillis(). Read that more closely -- millis. Milliseconds. If you subtract 20, you'll be subtracting 20 milliseconds, not 20 seconds.
    Meant 20000 milliseconds so that converts to 20 seconds I think? How would a constant deducting timer work though? I have seen a few examples like "i--;" where it shaves off 1 second constantly and etc... I can't seem to do it though.

  9. #9
    Wut. QuietCrystal is offline
    MemberRank
    Aug 2010 Join Date
    SingaporeLocation
    346Posts

    Re: [Help] Occupation Skills

    Quote Originally Posted by TacoBell View Post
    Meant 20000 milliseconds so that converts to 20 seconds I think? How would a constant deducting timer work though? I have seen a few examples like "i--;" where it shaves off 1 second constantly and etc... I can't seem to do it though.
    To make it a constant timer would require a sub to run every 1 second to minus 1 second from the timer. Multiply that by how many cooldowns and players you'll have, and you'll have a pretty RAM-consuming server. Don't forget timers would lag, and not be to-the-second accurate.

    On the other hand, if you want a cooldown, just set it like this:

    Long cooldownEnds = System.currentTimeMillis() + 15000; // (15 seconds)

    Then to check if it's finished,

    if (System.currentTimeMillis() >= cooldownEnds) {
    // Cooldown has ended
    }

    To check how much time left to cooldown ending (in milliseconds):
    cooldownEnds - System.currentTimeMillis()

  10. #10
    Account Upgraded | Title Enabled! TacoBell is offline
    MemberRank
    Aug 2011 Join Date
    518Posts

    Re: [Help] Occupation Skills

    Quote Originally Posted by QuietCrystal View Post
    To make it a constant timer would require a sub to run every 1 second to minus 1 second from the timer. Multiply that by how many cooldowns and players you'll have, and you'll have a pretty RAM-consuming server. Don't forget timers would lag, and not be to-the-second accurate.

    On the other hand, if you want a cooldown, just set it like this:

    Long cooldownEnds = System.currentTimeMillis() + 15000; // (15 seconds)

    Then to check if it's finished,

    if (System.currentTimeMillis() >= cooldownEnds) {
    // Cooldown has ended
    }

    To check how much time left to cooldown ending (in milliseconds):
    cooldownEnds - System.currentTimeMillis()
    I have that down already (or I hope it's at least right) but my method looks different from yours but hopefully it still functions as flawless as I thought.
    PHP Code:
    public static class Bomb extends CommandExecute {

               [
    MENTION=2000004426]Override[/MENTION]
            public 
    int execute(MapleClient cString[] splitted) {
                
    MapleCharacter chr c.getPlayer();
                if (
    chr.getOccupation() != OccupationConstants.NXWHORE) {
                    
    chr.dropMessage(5"You have to be an NX Whore to use this skill.");
                    return 
    0;
                }
                if (
    chr.skillisCooling(1337)) {
                    
    chr.tacoMessage("You have already used this command in the last 20 seconds.");
                    return 
    0;
                }
                
    chr.getMap().spawnMonsterOnGroundBelow(MapleLifeFactory.getMonster(9300166), chr.getPosition());
                
    chr.getClient().getSession().write(CField.skillCooldown(133720));
                
    chr.addCooldown(1337System.currentTimeMillis(), 20000);
                
    chr.tacoMessage("You must now wait 10.0 seconds before using this command again.");
                return 
    1;
            }
        } 
    My question is how can I put a timer that if the command has been used already? Like @bomb and if it's been used in the last 20 seconds it says ("You have used this command in the last 20 seconds please wait " + remaining + " seconds. And the remaining variable shows the 20 seconds counting down.
    Last edited by TacoBell; 28-02-14 at 09:41 PM.

  11. #11
    Wut. QuietCrystal is offline
    MemberRank
    Aug 2010 Join Date
    SingaporeLocation
    346Posts

    Re: [Help] Occupation Skills

    Quote Originally Posted by TacoBell View Post
    I have that down already (or I hope it's at least right) but my method looks different from yours but hopefully it still functions as flawless as I thought.
    PHP Code:
    public static class Bomb extends CommandExecute {

              [
    MENTION=2000004426]Override[/MENTION]
            public 
    int execute(MapleClient cString[] splitted) {
                
    MapleCharacter chr c.getPlayer();
                if (
    chr.getOccupation() != OccupationConstants.NXWHORE) {
                    
    chr.dropMessage(5"You have to be an NX Whore to use this skill.");
                    return 
    0;
                }
                if (
    chr.skillisCooling(1337)) {
                    
    chr.tacoMessage("You have already used this command in the last 20 seconds.");
                    return 
    0;
                }
                
    chr.getMap().spawnMonsterOnGroundBelow(MapleLifeFactory.getMonster(9300166), chr.getPosition());
                
    chr.getClient().getSession().write(CField.skillCooldown(133720));
                
    chr.addCooldown(1337System.currentTimeMillis(), 20000);
                
    chr.tacoMessage("You must now wait 10.0 seconds before using this command again.");
                return 
    1;
            }
        } 
    My question is how can I put a timer that if the command has been used already? Like @bomb and if it's been used in the last 20 seconds it says ("You have used this command in the last 20 seconds please wait " + remaining + " seconds. And the remaining variable shows the 20 seconds counting down.
    Show me your skillIsCooling function. In camp at the moment with no access to any sources :P

  12. #12
    Account Upgraded | Title Enabled! TacoBell is offline
    MemberRank
    Aug 2011 Join Date
    518Posts

    Re: [Help] Occupation Skills

    Quote Originally Posted by QuietCrystal View Post
    Show me your skillIsCooling function. In camp at the moment with no access to any sources :P
    Lmao.
    PHP Code:
    public boolean skillisCooling(int skillId) {
            return 
    coolDowns.containsKey(Integer.valueOf(skillId));
        } 
    Adding a variable like "int remaining = 20" and adding "remaining--;" under "if (chr.skillisCooling(1337)) {" shaves off 1 second but it isn't constant and doesn't keep shaving off seconds, it just stays at 19 seconds lol.

  13. #13
    Wut. QuietCrystal is offline
    MemberRank
    Aug 2010 Join Date
    SingaporeLocation
    346Posts

    Re: [Help] Occupation Skills

    Quote Originally Posted by TacoBell View Post
    Lmao.
    PHP Code:
    public boolean skillisCooling(int skillId) {
            return 
    coolDowns.containsKey(Integer.valueOf(skillId));
        } 
    Adding a variable like "int remaining = 20" and adding "remaining--;" under "if (chr.skillisCooling(1337)) {" shaves off 1 second but it isn't constant and doesn't keep shaving off seconds, it just stays at 19 seconds lol.
    Add to MapleCharacter.java:
    PHP Code:
        public long skillCoolTimeLeft(int skillId) {
            if (!
    this.coolDowns.containsKey(Integer.valueOf(skillId))) {
                return -
    1L;
            }
            
    MapleCoolDownValueHolder cd this.coolDowns.get(skillId);
            return 
    System.currentTimeMillis() - cd.startTime cd.length;
        } 
    Use this to get the time left till cooldown ends in milliseconds.

  14. #14
    Account Upgraded | Title Enabled! TacoBell is offline
    MemberRank
    Aug 2011 Join Date
    518Posts

    Re: [Help] Occupation Skills

    Quote Originally Posted by QuietCrystal View Post
    Add to MapleCharacter.java:
    PHP Code:
        public long skillCoolTimeLeft(int skillId) {
            if (!
    this.coolDowns.containsKey(Integer.valueOf(skillId))) {
                return -
    1L;
            }
            
    MapleCoolDownValueHolder cd this.coolDowns.get(skillId);
            return 
    System.currentTimeMillis() - cd.startTime cd.length;
        } 
    Use this to get the time left till cooldown ends in milliseconds.
    It kinda worked. It counted with the "-" sign and went from negative to positive. http://imgur.com/axLRnhj,BvKZZCj,iSwdhIv,HII6H3G
    I tried fixing it but failed horribly and messed up the timer so I went back to default. It goes from negative to positive and then let's me use the command which works but why does it do that? Why doesn't it start from 20000/19000 and starts deducting there?

  15. #15
    Wut. QuietCrystal is offline
    MemberRank
    Aug 2010 Join Date
    SingaporeLocation
    346Posts

    Re: [Help] Occupation Skills

    Whoops try "return (long) Math.max(cd.length - (System.currentTimeMillis() - cd.startTime));"



Page 1 of 2 12 LastLast

Advertisement