Thread: My Skull handling..

Results 1 to 10 of 10
  1. #1 My Skull handling.. 
    Registered Member

    Join Date
    Jun 2009
    Posts
    1,071
    Thanks given
    304
    Thanks received
    381
    Rep Power
    348
    Yeah I don't even know if it's good but here, ha.

    Updated the snippet to save by the Player's username, because it was saving the entire other player's character file to yours.

    Code:
    private Map<String, Long> attackedFirst;
    Make sure to call this somewhere, somewhere where it is only going to be called once.
    Code:
    		if(attackedFirst == null)
    			attackedFirst = new HashMap<String, Long>();
    Code:
    	public boolean attackedFirst(Player player, Player victim) {
    		if(!victim.getAttackedFirst().containsKey(player.getUsername()))
    			player.getAttackedFirst().put(victim.getUsername(), System.currentTimeMillis());
    		refreshAttacked(player);
    		if(player.getAttackedFirst().containsKey(victim.getUsername()))
    			return true;
    
    		return false;
    	}
    	private void refreshAttacked(Player player) {
    		for(Map.Entry<String, Long> entry : player.getAttackedFirst().entrySet()) {
    			if(entry.getKey() != null) {
    				if(System.currentTimeMillis() - entry.getValue() > 600000)
    					player.getAttackedFirst().remove(entry.getKey());
    			}
    		}
    	}
    	public Map<String, Long> getAttackedFirst() {
    		return attackedFirst;
    	}
    	public void clearAttacked() {
    		attackedFirst.clear();
    	}
    Call the clearAttacked method on death, and the attackedFirst(Player, Victim) boolean in your attack method, and if it returns true set skull. It should work, I think...

    After 10 minutes when you go to attack someone, before the method attackedFirst(Player, Victim) is returned it checks for any players you attacked over 10 minutes ago, and removes them. Therefore if 10 minutes passes (Without you continuing to attack them) they can then skull on you.

    Untested - It works.
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Oct 2009
    Posts
    94
    Thanks given
    0
    Thanks received
    2
    Rep Power
    1
    gj & first
    Reply With Quote  
     

  3. #3  
    Registered Member
    ƅʅ1ƭȥȥ ツ's Avatar
    Join Date
    May 2008
    Age
    27
    Posts
    1,132
    Thanks given
    10
    Thanks received
    8
    Rep Power
    330
    nice, I think I would try this because the method I have now it failzor
    Reply With Quote  
     

  4. #4  
    Respected Member


    Luke132's Avatar
    Join Date
    Dec 2007
    Age
    32
    Posts
    12,549
    Thanks given
    177
    Thanks received
    5,784
    Discord
    View profile
    Rep Power
    5000
    Why don't you use brackets for 1 line if statements? it may be your preference but that could get really confusing for someone else..

    You don't need a Map for this either, a single Object is fine.

    EDIT : Which means the whole thing is a bit pointless.

    Reply With Quote  
     

  5. #5  
    Hi.

    'Mystic Flow's Avatar
    Join Date
    Nov 2007
    Posts
    7,141
    Thanks given
    256
    Thanks received
    1,247
    Rep Power
    3636
    Good job, i see that you improved your programming skills (c).

    [Only registered and activated users can see links. ]

    Reply With Quote  
     

  6. #6  
    Registered Member
    G Force's Avatar
    Join Date
    Aug 2009
    Age
    25
    Posts
    315
    Thanks given
    8
    Thanks received
    1
    Rep Power
    356
    Quote Originally Posted by 'Mystic Flow View Post
    Good job, i see that you improved your programming skills (c).
    The 525s PvN was terrible same with pvp, but the 554s was great and PvN was amazing to be honest.

    And good job Peril, good luck with your 554 too.
    Signature - Cming Soon
    Reply With Quote  
     

  7. #7  
    Registered Member

    Join Date
    Jun 2009
    Posts
    1,071
    Thanks given
    304
    Thanks received
    381
    Rep Power
    348
    Quote Originally Posted by 'Mystic Flow View Post
    Good job, i see that you improved your programming skills (c).
    Thanks mate, ha.

    Quote Originally Posted by Luke132 View Post
    Why don't you use brackets for 1 line if statements? it may be your preference but that could get really confusing for someone else..

    You don't need a Map for this either, a single Object is fine.

    EDIT : Which means the whole thing is a bit pointless.
    Its my preference, my bad...

    I made a Map because I am familiar with the local classes variables, for looping entrySets and things like that.

    Read over the code, it is not pointless.

    Thanks anyways.. :\
    Reply With Quote  
     

  8. #8  
    Respected Member


    Luke132's Avatar
    Join Date
    Dec 2007
    Age
    32
    Posts
    12,549
    Thanks given
    177
    Thanks received
    5,784
    Discord
    View profile
    Rep Power
    5000
    Quote Originally Posted by Peril View Post
    Thanks mate, ha.



    Its my preference, my bad...

    I made a Map because I am familiar with the local classes variables, for looping entrySets and things like that.

    Read over the code, it is not pointless.

    Thanks anyways.. :\
    By pointless i meant if you just used an Object instead of a Map, the other methods would need to be changed to, perhaps pointless was the wrong word, i didn't mean anything by it .

    Reply With Quote  
     

  9. #9  
    Registered Member

    Join Date
    Jun 2009
    Posts
    1,071
    Thanks given
    304
    Thanks received
    381
    Rep Power
    348
    Quote Originally Posted by Luke132 View Post
    By pointless i meant if you just used an Object instead of a Map, the other methods would need to be changed to, perhaps pointless was the wrong word, i didn't mean anything by it .
    Ha alrighty,
    I just thought a map would be good in my case, and it works quite well so hey.
    Reply With Quote  
     

  10. #10  
    Registered Member

    Join Date
    Mar 2009
    Age
    28
    Posts
    1,008
    Thanks given
    32
    Thanks received
    7
    Rep Power
    111
    Kewl, stuff
    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

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •