Page 1 of 2 12 LastLast
Results 1 to 20 of 23

Thread: Help with code

  1. #1
    universal is offline Member
    Join Date
    Apr 2011
    Posts
    10
    Rep Power
    0

    Default Help with code

    Java Code:
    public void handleDeath(Player p) {
    		if(isGameLocked())
    			return;
    	   		
    	    if(blueTeam.contains(p)){
    	    	sendCTFAnnouncement("@blu@Blue Team Scores!");
    	    	sendCTFMessage("@blu@" + p.getUsername() + " @whi@scored 1 point for the @blu@Blue Team");
    	    	p.updateWornItems(BLUE_CARRIER_ITEM.getWieldableDef().getWieldPos(), p.getPlayerAppearance().getSprite(BLUE_CARRIER_ITEM.getWieldableDef().getWieldPos()));
    	    	world.registerGameObject(new GameObject(RED_FLAG, RED_FLAG_ID, 0, 0));
    	    	blueFlagCarrier = null;
    	    	blueScore++;
    	    }
    	    else if(redTeam.contains(p)) {
    	    	sendCTFAnnouncement("@red@Red Team Scores!");
    	    	sendCTFMessage("@red@" + p.getUsername() + " @whi@scored 1 point for the @red@Red Team");
    			p.updateWornItems(RED_CARRIER_ITEM.getWieldableDef().getWieldPos(), p.getPlayerAppearance().getSprite(RED_CARRIER_ITEM.getWieldableDef().getWieldPos()));
    			world.registerGameObject(new GameObject(BLUE_FLAG, BLUE_FLAG_ID, 0, 0));
    			redFlagCarrier = null;
    			redScore++;
    	    }
    	    updateScores();
    		
    	    if (blueScore == SCORE_TO_WIN || redScore == SCORE_TO_WIN){
    			for (Player pl : blueTeam) 
    				pl.teleport(220, 455, false);
    			for (Player pl : redTeam) 
    				pl.teleport(220, 455, false);
    			doGates(false);
    			
    			world.getDelayedEventHandler().add(new MiniEvent(null, 4000) {
    			    public void action() {
    					if (blueScore >= SCORE_TO_WIN) {
    						sendCTFAnnouncement("@blu@Blue Team Wins!");
    					 }
    					else {
    						sendCTFAnnouncement("@red@Red Team Wins!");
    						
    					}
    					world.getDelayedEventHandler().add(new MiniEvent(null, 7500) {
    						    public void action() {
    						    	endCTF();
    						    }
    						});
    			    	}
    				});
    		    } 
    	    else {
    			world.getDelayedEventHandler().add(new MiniEvent(null, 3000) {
    			    public void action() {
    				setGameLocked(false);
    			    }
    			});
    	    }
    	}
    any 1 can help me with this code ? i need to change this then player die other team gets scored :( plz help me :( and (no flag ) just if player (blue team ) kill player (red team ) blue get score ++ ...... any help plz ?
    Last edited by universal; 04-10-2011 at 06:29 AM. Reason: code tags added

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Hello, and welcome to the forum. I hope you don't mind, but I've taken the liberty to edit your code and added code tags which should help make your posted code retain its formatting and be more readable.

    To do this yourself, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.

    Another way to do this is to manually place the tags into your code by placing the tag [code] above your pasted code and the tag [/code] below your pasted code like so:

    Java Code:
    [code]
      // your code goes here
      // notice how the top and bottom tags are different
    [/code]
    Best of luck, and again, welcome!

  3. #3
    universal is offline Member
    Join Date
    Apr 2011
    Posts
    10
    Rep Power
    0

    Default

    Fubarable sry i did it :)

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by universal View Post
    Fubarable sry i did it :)
    No need to apologize. My post was for future reference. :)

    Regarding your question, what class to blueTeam and redTeam belong to? Does this class have a method that allows you to increment or decrement its score? Can you show us the method signature?

  5. #5
    universal is offline Member
    Join Date
    Apr 2011
    Posts
    10
    Rep Power
    0

    Default

    ummmm i just try to post all code then ... it is from game runescape classic.
    Java Code:
    
    
    package rsca.gs.model.minigames;
    
    import java.util.ArrayList;
    
    import rsca.config.Constants;
    import rsca.gs.builders.RSCPacketBuilder;
    import rsca.gs.event.MiniEvent;
    import rsca.gs.model.GameObject;
    import rsca.gs.model.InvItem;
    import rsca.gs.model.MenuHandler;
    import rsca.gs.model.Player;
    import rsca.gs.model.Point;
    import rsca.gs.model.World;
    import rsca.gs.util.Logger;
    
    public class CTF {
    	/**
    	 * World instnace
    	 */
    	private static final World world = World.getWorld();
    	/**
    	 * Players in the red team are refrenced here
    	 */
    	private ArrayList<Player> redTeam = new ArrayList<Player>();
    	/**
    	 * Player name array list, used to determine if player was in a team when he logged out/in
    	 */
    	private ArrayList<String> redTeamPlayernames = new ArrayList<String>();
    	/**
    	 * Players in the blue team are refrenced here
    	 */
    	private ArrayList<Player> blueTeam = new ArrayList<Player>();
    	/**
    	 * Player name array list, used to determine if player was in a team when he logged out/in
    	 */
    	private ArrayList<String> blueTeamPlayernames = new ArrayList<String>();
    	/**
    	 * Determines if the CTF is enabled or not
    	 */
    	private boolean matchRunning = false;
    	
    	private boolean warmupRunning = false;
    	
    	public boolean isEventRunning = false;
    	
    	private Player redFlagCarrier = null;
    	
    	private Player blueFlagCarrier = null;
    	
    	private int blueScore = 0;
    	
    	private int redScore = 0;
    	
    	public static final int SCORE_TO_WIN = 1;
        public static final int RED_FLAG_ID = 1170;
        public static final int BLUE_FLAG_ID = 1169;
        public static final Point RED_SPAWN = Point.location(71, 18);
        public static final Point BLUE_SPAWN = Point.location(27, 18);
        public static final InvItem RED_GEAR_CHEST = new InvItem(702);
        public static final InvItem RED_GEAR_LEG = new InvItem(703);
        public static final InvItem BLUE_GEAR_CHEST = new InvItem(184);
        public static final InvItem BLUE_GEAR_LEG = new InvItem(187);
        public static final InvItem BLUE_CARRIER_ITEM = new InvItem(183);
        public static final InvItem RED_CARRIER_ITEM = new InvItem(229);
        public static final int[] FREE_ITEMS = { 221, 222, 223, 224, 367, 188, 11, 31, 32, 33, 34, 35, 38, 41 };
        public static final int[] DISALLOWED_ITEMS = { 40, 42, 
        	183, 
        	209, 229, 
        	370, 373, 
        	474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 
        	500, 511, 512, 513, 514, 546, 551, 553, 555, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 592, 
        	619, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, 655, 656, 657, 676, 
        	723, 750, 751, 796, 
        	825, 
        	1213, 1214, 1215, 1216, 1217, 1218, 1288};
        public static Point RED_FLAG = Point.location(69, 18);
        public static Point BLUE_FLAG = Point.location(30, 18);
        public static int currentLevelRank = 0;
        public static final Point RED_GATES1 = Point.location(65, 17);
        public static final Point RED_GATES2 = Point.location(65, 19);
        public static final Point BLUE_GATES1 = Point.location(23, 18);
        public static final int GATE_ID = 1033;
        public static final Point RED_CHEST = Point.location(69, 18);
        public static final Point BLUE_CHEST = Point.location(17, 22);
        public static final int CHEST_ID = 1005;
        private String oldMOTD = "";
        public int redDeaths = 0;
        public int blueDeaths = 0;
        public int redKills = 0;
        public int blueKills = 0;
        public boolean firstblood = true;
        public static final int DEATHS_FOR_HUMULIATION = 5;
        public static final int RAMPAGE_KILLS = 5;
        public static final int UNSTOPPABLE_KILLS = 10;
        public int PLAYERS_NEEDED = 1;
        private static final Point MIN_RADIUS = Point.location(12, 4);
        private static final Point MAX_RADIUS = Point.location(91, 33);
        public static final int WILDERNESS_LEVEL = 150;
        
    	public void startWarmup(int lvlrank) {
    		if(matchRunning || warmupRunning || isEventRunning || World.getWar().isRunning()) 
    			return;
    		/**
    		 * Initlizie
    		 */
    		
    		blueTeam = new ArrayList<Player>();
    		redTeam = new ArrayList<Player>();
    		blueTeamPlayernames = new ArrayList<String>();
    		redTeamPlayernames = new ArrayList<String>();
    		
    		blueScore = 0;
    		redScore = 0;
    		
    		redFlagCarrier = null;
    		blueFlagCarrier = null;
    		
    		/**
    		 * Settings
    		 */
    		isEventRunning = true;
    		warmupRunning = true;
    		currentLevelRank = lvlrank;
    	    doGates(false); 
    	   // doFlags(); 
    	    doChests(true);
    	    world.sendBroadcastMessage("@yel@Server@whi@", "@gre@Capture the Flag@whi@ is about to begin! (Levels " + getLevelString(currentLevelRank) + ")");
    	    world.sendBroadcastMessage("@yel@Server@whi@", "type @yel@::ctf@whi@ to join the event!");
    	    oldMOTD = Constants.GameServer.MOTD;
    	    Constants.GameServer.MOTD = "@gre@Capture the Flag is Live.@whi@ (Levels " + getLevelString(currentLevelRank) + ") Type ::ctf to join is elgible.";
    	}
    	public void startMatchCTF() {
    			if(!warmupRunning || matchRunning || World.getWar().isRunning()) {
    				return;
    			}
    			matchRunning = true;
    			warmupRunning = false;
    			firstblood = true;
    			world.getDelayedEventHandler().add(new MiniEvent(null, 5000)
    			
    			
    			
    			
    			{
    			    public void action() {
    				    
    			    	sendCTFAnnouncement("@whi@Round starts in 25 Seconds");
    			    	sendCTFMessage("Get ready");
    			    }
    		});
    			world.getDelayedEventHandler().add(new MiniEvent(null, 15000) {
    			    public void action() {
    			    	sendCTFAnnouncement("@whi@Round starts in 15 seconds!");
    			    	world.getDelayedEventHandler().add(new MiniEvent(null, 14670) {
    					    public void action() {
    						doGates(true); 
    					    }
    					});
    				world.getDelayedEventHandler().add(new MiniEvent(null, 12000) {
    				    public void action() {
    						sendCTFAnnouncement("@gre@3..");
    						world.getDelayedEventHandler().add(new MiniEvent(null, 1000) {
    						    public void action() {
    						    	sendCTFAnnouncement("@yel@        2..");
    								world.getDelayedEventHandler().add(new MiniEvent(null, 1000) {
    								    public void action() {
    								    	sendCTFAnnouncement("@ran@                  1..");
    										world.getDelayedEventHandler().add(new MiniEvent(null, 1000) {
    										    public void action() {
    										    	sendCTFAnnouncement("@red@                           F I G H T !");
    										    	}
    											});
    								    	}
    									});
    						    	}
    							});
    				    	}
    					});
    			    }
    		});
    	}
    	public void endCTF() {
    		try {
    		world.sendWorldMessage("Capture The Flag is over!");
    		matchRunning = false;
    		warmupRunning = false;
    		isEventRunning = false;
    		setGameLocked(false);
    		
    	    Constants.GameServer.MOTD = oldMOTD;
    	    GameObject object = world.getTile(RED_FLAG).getGameObject();
    	    if (object != null)
    	    	world.unregisterGameObject(object);
    	    object = world.getTile(BLUE_FLAG).getGameObject();
    	    if (object != null)
    	    	world.unregisterGameObject(object);
    
    	    doGates(false);
    	    doChests(false);
    
    		for(Player p : redTeam) {
    			handleDeath(p, false);
    		}
    		for(Player p : blueTeam) {
    			handleDeath(p, false);
    		}	
    		redTeam = new ArrayList<Player>();
    		blueTeam = new ArrayList<Player>();
    		}
    		catch(Exception e) {
    			e.printStackTrace();
    		}
    		
    	}
    	public void doGates(boolean open) {
    		GameObject object;
    		if (open) {
    			object = world.getTile(RED_GATES1).getGameObject();
    			if (object != null)
    				world.unregisterGameObject(object);
    			
    			object = world.getTile(BLUE_GATES1).getGameObject();
    			if (object != null)
    				world.unregisterGameObject(object);
    			
    			object = world.getTile(RED_GATES2).getGameObject();
    			if (object != null)
    				world.unregisterGameObject(object);
    		}
    		else {
    			world.registerGameObject(new GameObject(BLUE_GATES1, GATE_ID, 0, 0));
    			world.registerGameObject(new GameObject(RED_GATES2, GATE_ID, 0, 0));
    			world.registerGameObject(new GameObject(RED_GATES1, GATE_ID, 0, 0));
    		}
    	}
    
    	
    	public void doChests(boolean spawn) {
    		if (spawn) {
        	    world.registerGameObject(new GameObject(BLUE_CHEST, CHEST_ID, 0, 0));
        	    world.registerGameObject(new GameObject(RED_CHEST, CHEST_ID, 0, 0));
        	} 
    		else {
        	    GameObject object = world.getTile(BLUE_CHEST).getGameObject();
        	    if (object != null)
        		world.unregisterGameObject(object);
        	    object = world.getTile(RED_CHEST).getGameObject();
        	    if (object != null)
        		world.unregisterGameObject(object);
        		}
            }
    	public static String getLevelString(int lvlrank) {
    		if (lvlrank == 0)
    			return "ALL LEVELS!";
    		if (lvlrank == 1)
    			return "3-34";
    		if (lvlrank == 2)
    			return "35-64";
    		if (lvlrank == 3)
    			return "65-94";
    		if (lvlrank == 4)
    			return "95-123";
    		return "error? fail";
    	}
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	public void handleDeath(Player p) {
    		if(isGameLocked())
    			return;
    	   		
    	    if(blueTeam.contains(p)){
    	    	sendCTFAnnouncement("@blu@Blue Team Scores!");
    	    	sendCTFMessage("@blu@" + p.getUsername() + " @whi@scored 1 point for the @blu@Blue Team");
    	    	p.updateWornItems(BLUE_CARRIER_ITEM.getWieldableDef().getWieldPos(), p.getPlayerAppearance().getSprite(BLUE_CARRIER_ITEM.getWieldableDef().getWieldPos()));
    	    	world.registerGameObject(new GameObject(RED_FLAG, RED_FLAG_ID, 0, 0));
    	    	blueFlagCarrier = null;
    	    	blueScore++;
    	    }
    	    else if(redTeam.contains(p)) {
    	    	sendCTFAnnouncement("@red@Red Team Scores!");
    	    	sendCTFMessage("@red@" + p.getUsername() + " @whi@scored 1 point for the @red@Red Team");
    			p.updateWornItems(RED_CARRIER_ITEM.getWieldableDef().getWieldPos(), p.getPlayerAppearance().getSprite(RED_CARRIER_ITEM.getWieldableDef().getWieldPos()));
    			world.registerGameObject(new GameObject(BLUE_FLAG, BLUE_FLAG_ID, 0, 0));
    			redFlagCarrier = null;
    			redScore++;
    	    }
    	    updateScores();
    		
    	    if (blueScore == SCORE_TO_WIN || redScore == SCORE_TO_WIN){
    			for (Player pl : blueTeam) 
    				pl.teleport(220, 455, false);
    			for (Player pl : redTeam) 
    				pl.teleport(220, 455, false);
    			doGates(false);
    			
    			world.getDelayedEventHandler().add(new MiniEvent(null, 4000) {
    			    public void action() {
    					if (blueScore >= SCORE_TO_WIN) {
    						sendCTFAnnouncement("@blu@Blue Team Wins!");
    					 }
    					else {
    						sendCTFAnnouncement("@red@Red Team Wins!");
    						
    					}
    					world.getDelayedEventHandler().add(new MiniEvent(null, 7500) {
    						    public void action() {
    						    	endCTF();
    						    }
    						});
    			    	}
    				});
    		    } 
    	    else {
    			world.getDelayedEventHandler().add(new MiniEvent(null, 3000) {
    			    public void action() {
    				setGameLocked(false);
    			    }
    			});
    	    }
    	} 
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    		
    	public void handlePlayerJoin(Player p) {
    		if(!isEventRunning){
    			p.getActionSender().sendMessage("Sorry, CaptureTheFlag isn't running at the moment!");
    			return;
    		}
    		if(p.isMod() || p.isPMod()) {
    			p.getActionSender().sendMessage("Please use a regular account to join the CTF");
    			return;
    		}
    		if(redTeam.contains(p) || blueTeam.contains(p)) { 
    			p.getActionSender().sendMessage("You are already apart of a team!");
    			return;
    		}
    		if(!isLevelValid(p.getCombatLevel())) {
    			p.getActionSender().sendMessage("Sorry, you are not in the correct level rank for CaptureTheFlag");
    			p.getActionSender().sendMessage("Currently levels " + getLevelString(currentLevelRank) + " are allowed");
    			return;
    		}
    	    boolean cont = true;
    	    for (InvItem i : p.getInventory().getItems()) {
    			for (int in = 0; in < FREE_ITEMS.length; in++) {
    			    if (i.getID() == FREE_ITEMS[in]) {
    			    	p.getActionSender().sendMessage("You may not bring " + i.getDef().name + " to CaptureTheFlag");
    			    	cont = false;
    			    }
    			}
    			for (int in = 0; in < DISALLOWED_ITEMS.length; in++) {
    			    if (i.getID() == DISALLOWED_ITEMS[in]) {
    			    	p.getActionSender().sendMessage("You may not bring " + i.getDef().name + " to CaptureTheFlag");
    			    	cont = false;
    			    }
    			}
    	    }
    	    if (!cont)
    	    	return;
    		if(redTeam.size() > blueTeam.size()) {
    			blueTeam.add(p);
    			blueTeamPlayernames.add(p.getUsername());
    			p.getActionSender().sendMessage("@blu@You have joined the blue team!");
    			p.teleportCTF(BLUE_SPAWN.getX(), BLUE_SPAWN.getY(), false);
    		}
    		else {
    			redTeam.add(p);
    			redTeamPlayernames.add(p.getUsername());
    			p.getActionSender().sendMessage("You have joined the red team!");
    			p.teleportCTF(RED_SPAWN.getX(), RED_SPAWN.getY(), false);
    		}
    		handlePlayerClothing(p);
    	    if (!checkAndStart())
    			world.getDelayedEventHandler().add(new MiniEvent(p, 4000) {
    			    public void action() {
    				if (!matchRunning)
    				    owner.getActionSender().sendMessage("&CaptureTheFlag Will start when Both teams have " + PLAYERS_NEEDED + " players ready");
    			    }
    			});
    
    	    p.getActionSender().sendMessage("Use ::leave when you want to leave.");
    		p.getActionSender().sendMessage("Use ::leave when you want to leave.");
    		updateScores();
    	}
        public boolean checkAndStart() {
        	if (redTeam.size() >= PLAYERS_NEEDED && blueTeam.size() >= PLAYERS_NEEDED) {
        		if(warmupRunning && !matchRunning) {
        			startMatchCTF();
        		}
        		return true;
        		}
        	return false;
            }
    		  
    	    public void handleDeath(Player p, boolean remove) {
    		if(!inCTF(p))
    			return;
    		
    		p.teleportCTF(100, 500, false);
    		
    		
    		for (int i : FREE_ITEMS) {
    			int count = p.getInventory().countId(i);
    			InvItem item = new InvItem(i, count);
    			if (count > 0) {
    			    if (item.getDef().stackable) {
    			    	p.getInventory().remove(item.getID(), item.getAmount());
    			    } 
    			    else {
    			    	for (int in = 0; in < count; in++) {
    			    		p.getInventory().remove(item.getID(), 1);
    			    	}
    			    }
    			}
    		}
    		
    		p.getActionSender().sendInventory();
    		p.getActionSender().sendMessage("All your free items have been removed, thanks for playing");
    
    		for (InvItem i : p.getInventory().getItems()) {
    			if (i.isWielded())
    				p.updateWornItems(i.getWieldableDef().getWieldPos(), i.getWieldableDef().getSprite());
    			}
    		
    		redTeamPlayernames.remove(p.getUsername());
    		blueTeamPlayernames.remove(p.getUsername());
    
    		
    		
    		} 
    		
    		public void handlePlayerLeave(Player p, boolean remove) {
    		if(!inCTF(p))
    			return;
    		
    				
    		p.teleportCTF(100, 500, false);
    			
    		}
    		
    		
    		
    	public void handlePlayerLogin(Player p) {
    		if(!isEventRunning) {
    			if(!redTeamPlayernames.contains(p.getUsername()) && !blueTeamPlayernames.contains(p.getUsername())) {
    				handleDeath(p, true);
    				return;
    			}
    			if(isInCaptureTheFlagBoundary(p.getX(), p.getY())) {
    				handleDeath(p, true);
    				return;
    			}
    			return;
    		}
    		if(!redTeamPlayernames.contains(p.getUsername()) && !blueTeamPlayernames.contains(p.getUsername()) && isInCaptureTheFlagBoundary(p.getX(), p.getY())) {
    			handleDeath(p, true);
    			return;
    		}
    		if(!CTF.isInCaptureTheFlagBoundary(p.getX(), p.getY())) {
    			handleDeath(p,true);
    			return;
    		}
    		if(redTeamPlayernames.contains(p.getUsername())) {
    			redTeam.add(p);
    			p.getActionSender().sendMessage("Don't run off during a match! If you want to leave type ::leave");
    		}
    		else if(blueTeamPlayernames.contains(p.getUsername())) {
    			blueTeam.add(p);
    			p.getActionSender().sendMessage("Don't run off during a match! If you want to leave type ::leave");
    		}
    		handlePlayerClothing(p);
    	}
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	 public void handleDeath(Player p) {
    		if(!isEventRunning)
    			return;		
    		p.teleportCTF(100, 500, false);	
    		
    		
    		for (int i : FREE_ITEMS) {
    			int count = p.getInventory().countId(i);
    			InvItem item = new InvItem(i, count);
    			if (count > 0) {
    			    if (item.getDef().stackable) {
    			    	p.getInventory().remove(item.getID(), item.getAmount());
    			    } 
    			    else {
    			    	for (int in = 0; in < count; in++) {
    			    		p.getInventory().remove(item.getID(), 1);
    			    	}
    			    }
    			}
    		}		
    		
    		
    		
    		
    		for (int i : FREE_ITEMS) {
    			int count = p.getInventory().countId(i);
    			InvItem item = new InvItem(i, count);
    			if (count > 0) {
    			    if (item.getDef().stackable) {
    			    	p.getInventory().remove(item.getID(), item.getAmount());
    			    } 
    			    else {
    			    	for (int in = 0; in < count; in++) {
    			    		p.getInventory().remove(item.getID(), 1);
    			    	}
    			    }
    			}
    		}
    
              if (redTeam.contains(p)) {
    			p.updateWornItems(RED_GEAR_CHEST.getWieldableDef().getWieldPos(), p.getPlayerAppearance().getSprite(RED_GEAR_CHEST.getWieldableDef().getWieldPos()));
    			p.updateWornItems(RED_GEAR_LEG.getWieldableDef().getWieldPos(), p.getPlayerAppearance().getSprite(RED_GEAR_LEG.getWieldableDef().getWieldPos()));
    			redTeam.remove(p);
    		} 
    		else {
    			p.updateWornItems(BLUE_GEAR_CHEST.getWieldableDef().getWieldPos(), p.getPlayerAppearance().getSprite(BLUE_GEAR_CHEST.getWieldableDef().getWieldPos()));
    			p.updateWornItems(BLUE_GEAR_LEG.getWieldableDef().getWieldPos(), p.getPlayerAppearance().getSprite(BLUE_GEAR_LEG.getWieldableDef().getWieldPos()));
    			blueTeam.remove(p);
    		}
    
    		for (int i : FREE_ITEMS) {
    			int count = p.getInventory().countId(i);
    			InvItem item = new InvItem(i, count);
    			if (count > 0) {
    			    if (item.getDef().stackable) {
    			    	p.getInventory().remove(item.getID(), item.getAmount());
    			    } 
    			    else {
    			    	for (int in = 0; in < count; in++) {
    			    		p.getInventory().remove(item.getID(), 1);
    			    	}
    			    }
    			}
    		}
    		
    		p.getActionSender().sendInventory();
    		p.getActionSender().sendMessage("All your free items have been removed, thanks for playing");
    
    		for (InvItem i : p.getInventory().getItems()) {
    			if (i.isWielded())
    				p.updateWornItems(i.getWieldableDef().getWieldPos(), i.getWieldableDef().getSprite());
    			}
    		
    		redTeamPlayernames.remove(p.getUsername());
    		blueTeamPlayernames.remove(p.getUsername());
    	} 
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	public void handlePlayerClothing(Player p) {
    		if(!isEventRunning) 
    			return;
    		if(blueTeamPlayernames.contains(p.getUsername())) {
    			p.updateWornItems(BLUE_GEAR_LEG.getWieldableDef().getWieldPos(), BLUE_GEAR_LEG.getWieldableDef().getSprite());
    			p.updateWornItems(BLUE_GEAR_CHEST.getWieldableDef().getWieldPos(), BLUE_GEAR_CHEST.getWieldableDef().getSprite());
    		}
    		else if(redTeamPlayernames.contains(p.getUsername())) {
    			p.updateWornItems(RED_GEAR_LEG.getWieldableDef().getWieldPos(), RED_GEAR_LEG.getWieldableDef().getSprite());
    			p.updateWornItems(RED_GEAR_CHEST.getWieldableDef().getWieldPos(), RED_GEAR_CHEST.getWieldableDef().getSprite());
    		}
    	}
    	private boolean gameLocked = false;
    	/**
    	 * Determines if the game is locked or not (someone captures the flag and everyone should be returned)
    	 * @return
    	 */
    	public boolean isGameLocked() {
    		return gameLocked;
    	}
    	/**
    	 * gameLocked setter
    	 * @param gameLocked
    	 */
        public void setGameLocked(boolean gameLocked) {
        	this.gameLocked = gameLocked;
        }
        public void sendSound(Player p, String soundfile) {
       	    RSCPacketBuilder pb = new RSCPacketBuilder();
       	    pb.setID(22);
       	    pb.addBytes(soundfile.getBytes());
       	    p.getIoSession().write(pb.toPacket());
            }
        public void sendSound(String soundfile) {
       	    for(Player p : redTeam) {
       	    	sendSound(p, soundfile);
       	    	}
       	    for(Player p : blueTeam) {
       	    	sendSound(p, soundfile);
       	    	}
            }
        public void sendCTFMessage(String message) {
       	    for(Player p : redTeam) {
       	    	p.getActionSender().sendMessage(message);
       	    	}
       	    for(Player p : blueTeam) {
       	    	p.getActionSender().sendMessage(message);
       	    	}
            }
        public void sendCTFAnnouncement(String message) {
       	    for(Player p : redTeam) {
       	    	p.getActionSender().sendMessage("&"+ message);
       	    	}
       	    for(Player p : blueTeam) {
       	    	p.getActionSender().sendMessage("&"+ message);
       	    	}
            } 
        public void updateScores() {
        	for (Player p : redTeam)
        		updateScore(p);
        	for (Player p : blueTeam)
        		updateScore(p);   	
        }
        public void updateScore(Player p) {
            RSCPacketBuilder pkt = new RSCPacketBuilder();
            pkt.setID(1);
            pkt.addByte((byte)blueScore);
            pkt.addByte((byte)redScore);
            p.getIoSession().write(pkt.toPacket());
        }
    	    
       
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	public boolean inCTF(Player p) {
    		return redTeam.contains(p) || blueTeam.contains(p) || isInCaptureTheFlagBoundary(p.getX(), p.getY());
    	}
    	public boolean isRedTeam(Player p) {
    		return redTeam.contains(p);
    	}
    	public boolean isBlueTeam(Player p) {
    		return blueTeam.contains(p);
    	}
    	public boolean isSameTeam(Player p1, Player p2) {
    		return (redTeam.contains(p1) && redTeam.contains(p2)) || (blueTeam.contains(p1) && blueTeam.contains(p2));
    	}
        public static boolean isInCaptureTheFlagBoundary(int x, int y) {
        	return (x > MIN_RADIUS.getX() && y > MIN_RADIUS.getY()) && (x < MAX_RADIUS.getX() && y < MAX_RADIUS.getY());
        }
        public void handleOpenChest(Player p, GameObject obj) {
        	if (redTeam.contains(p) && (obj.getX() == BLUE_CHEST.getX() && obj.getY() == BLUE_CHEST.getY())) {
        	    p.getActionSender().sendMessage("You can not open the other teams chest");
        	    return;
        	} 
        	else if (blueTeam.contains(p) && (obj.getX() == RED_CHEST.getX() && obj.getY() == RED_CHEST.getY())) {
        	    p.getActionSender().sendMessage("You can not open the other teams chest");
        	    return;
        	}
        	if (p.isFlagCarrier()) {
        	    p.getActionSender().sendMessage("You have the flag, you are not allowed to use this");
        	    return;
        	}
        	p.getActionSender().sendMessage("Use free stuff from chest");
        	String[] options = new String[] { "Strength Potion", "Food", "Archery Supplies", "Magic Supplies" };
        	p.setMenuHandler(new MenuHandler(options) {
        	    public void handleReply(final int option, final String reply) {
        		if (!CTF.isInCaptureTheFlagBoundary(owner.getX(), owner.getY())) {
        		    owner.getActionSender().sendMessage("Nice try..");
        		    Logger.print(owner.getUsername() + " tried to exploit a nasty CaptureTheFlag (fixed) exploit");
        		    return;
        		}
        		if (option == 0) {
        		    owner.getInventory().add(new InvItem(221));
        		} else if (option == 1) {
        		    while (!owner.getInventory().full()) {
        			owner.getInventory().add(new InvItem(367));
        		    }
        		} else if (option == 2) {
        		    owner.getInventory().add(new InvItem(188));
        		    owner.getInventory().add(new InvItem(11, 300));
        		} else if (option == 3) {
        		    owner.getInventory().add(new InvItem(31, 3000));
        		    owner.getInventory().add(new InvItem(32, 3000));
        		    owner.getInventory().add(new InvItem(33, 3000));
        		    owner.getInventory().add(new InvItem(34, 3000));
        		    owner.getInventory().add(new InvItem(35, 3000));
        		    owner.getInventory().add(new InvItem(38, 300));
        		    owner.getInventory().add(new InvItem(41, 300));
        		}
        		owner.getActionSender().sendInventory();
        	    }
        	});
        	p.getActionSender().sendMenu(options);
        }
        public boolean isLevelValid(int combat) {
        	if (currentLevelRank == 0)
        	    return true;
        	if (currentLevelRank == 1 && combat > 2 && combat < 35)
        	    return true;
        	if (currentLevelRank == 2 && combat > 34 && combat < 65)
        	    return true;
        	if (currentLevelRank == 3 && combat > 64 && combat < 96)
        	    return true;
        	if (currentLevelRank == 4 && combat > 94 && combat < 124)
        	    return true;
        	return false;
            }
    }

  6. #6
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Hahaha Fubarable, I think this is where SSCCE applies :P

    @OP
    This is all extremely complicated. The average person looking at this thread wouldn't look through the entire code. Try condensing it, taking out unnecessary parts, and explaining exactly what the situation is.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by ra4king View Post
    Hahaha Fubarable, I think this is where SSCCE applies :P
    especially the "short" part. Til then, tl;dr

  8. #8
    universal is offline Member
    Join Date
    Apr 2011
    Posts
    10
    Rep Power
    0

    Default

    sry guys but i just look in forums it is says "new to java" did i must leave this forum ? :(

  9. #9
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    No it's just you have posted too much code and we don't understand what exactly is your problem.

  10. #10
    universal is offline Member
    Join Date
    Apr 2011
    Posts
    10
    Rep Power
    0

    Default

    in first topic with code i need change from flag to player die = get score. So just asking help. That must be like if red team kills blue team , red team gets score +1 and if score = score to win (like 5 points) that team wins...

  11. #11
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You don't have to leave, just, as fubar said, many people are going to look at this, recognize it's a few hundred lines of code and just skip it. We are here to help you out, bit you are responsible for giving us small snippets and explaining problems. We will try to tell you what's wrong, but ultimately a lot of the work is going to be done by you.

  12. #12
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    It looks like you've already got all that in the code....?
    if blueTeam contains p, +1 to blueScore
    else if redTeam contains p, +1 to redScore

  13. #13
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    That logic sounds fairly good. Do you know the java basics? Flow control structures are good for situations like this(if else clauses).

  14. #14
    universal is offline Member
    Join Date
    Apr 2011
    Posts
    10
    Rep Power
    0

    Default

    i need just do when player red kill blue red get SCORE but how to do ( if SCORE = SCORE TO WIN ) that team SCORE TO WIN wins.... no i did no know java ( looking for some learn now :( sry but when i asking for some help in rsc forums thay say "u are retard " :( same here :(

  15. #15
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    We aren't saying you are retarded.

    The problem is you need to actually understand java to be able to properly code that. I highly suggest you look up the oracle java tutorials and start at the beginning. This probably won't be possible without decent java knowledge or exceptional knowledge in a similar language.

  16. #16
    universal is offline Member
    Join Date
    Apr 2011
    Posts
    10
    Rep Power
    0

    Default

    thats is the point i cant understand what is that :(Lesson:

  17. #17
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    @universal
    Oh now I understand what you want.
    If you want to know if a specific team won, you just do

    Java Code:
    if(blueScore == SCORE_TO_WIN) {
        //Code when Blue Team won
    }
    else if(redScore == SCORE_TO_WIN) {
        //Code when Red Team won
    }

  18. #18
    universal is offline Member
    Join Date
    Apr 2011
    Posts
    10
    Rep Power
    0

    Default

    ok but how to add point for that team witch is still live ? :( like red kill blue how to do if blue die and add point to red ? :(
    ra4king tx

    it is must to be in this code or this code going somewhere out ?
    Java Code:
    public void handleDeath(Player p) {      // if player die
    		if(isGameLocked())
    			return;
    	   		
    	    if(blueTeam.contains(p)){
    	    	sendCTFAnnouncement("@blu@Blue Team Scores!");                                       //send message to blue team
    	    	sendCTFMessage("@blu@" + p.getUsername() + " @whi@scored 1 point for the @blu@Blue Team");                  // send message to all game players
    	    	p.updateWornItems(BLUE_CARRIER_ITEM.getWieldableDef().getWieldPos(),              // updating items ... ( i thing after die ? )                   p.getPlayerAppearance().getSprite(BLUE_CARRIER_ITEM.getWieldableDef().getWieldPos()));  // update items
    	    	world.registerGameObject(new GameObject(RED_FLAG, RED_FLAG_ID, 0, 0));          // put back flag to place 
    	    	blueFlagCarrier = null;   //player who hawe before flag gos to non carrier
    	    	blueScore++;                          //this giving score
    	    }
    	    else if(redTeam.contains(p)) {
    	    	sendCTFAnnouncement("@red@Red Team Scores!");
    	    	sendCTFMessage("@red@" + p.getUsername() + " @whi@scored 1 point for the @red@Red Team");
    			p.updateWornItems(RED_CARRIER_ITEM.getWieldableDef().getWieldPos(), p.getPlayerAppearance().getSprite(RED_CARRIER_ITEM.getWieldableDef().getWieldPos()));
    			world.registerGameObject(new GameObject(BLUE_FLAG, BLUE_FLAG_ID, 0, 0));
    			redFlagCarrier = null;
    			redScore++;
    	    }
    	    updateScores();
    		
    	    if (blueScore == SCORE_TO_WIN || redScore == SCORE_TO_WIN){
    			for (Player pl : blueTeam) 
    				pl.teleport(220, 455, false);
    			for (Player pl : redTeam) 
    				pl.teleport(220, 455, false);
    			doGates(false);
    			
    			world.getDelayedEventHandler().add(new MiniEvent(null, 4000) {
    			    public void action() {
    					if (blueScore >= SCORE_TO_WIN) {
    						sendCTFAnnouncement("@blu@Blue Team Wins!");
    					 }
    					else {
    						sendCTFAnnouncement("@red@Red Team Wins!");
    						
    					}
    					world.getDelayedEventHandler().add(new MiniEvent(null, 7500) {
    						    public void action() {
    						    	endCTF();
    						    }
    						});
    			    	}
    				});
    		    } 
    	    else {
    			world.getDelayedEventHandler().add(new MiniEvent(null, 3000) {
    			    public void action() {
    				setGameLocked(false);
    			    }
    			});
    	    }
    	}
    i can explain what arrow what means ... but i do not know what i need change to do it for get score ....


    and this is when player die is go out of game ..... teleporting somewhere ....



    Java Code:
     public void handleDeath(Player p) {
    		if(!isEventRunning)
    			return;		
    		p.teleportCTF(100, 500, false);	
    		
    		
    		for (int i : FREE_ITEMS) {
    			int count = p.getInventory().countId(i);
    			InvItem item = new InvItem(i, count);
    			if (count > 0) {
    			    if (item.getDef().stackable) {
    			    	p.getInventory().remove(item.getID(), item.getAmount());
    			    } 
    			    else {
    			    	for (int in = 0; in < count; in++) {
    			    		p.getInventory().remove(item.getID(), 1);
    			    	}
    			    }
    			}
    		}		
    		
    		
    		
    		
    		for (int i : FREE_ITEMS) {
    			int count = p.getInventory().countId(i);
    			InvItem item = new InvItem(i, count);
    			if (count > 0) {
    			    if (item.getDef().stackable) {
    			    	p.getInventory().remove(item.getID(), item.getAmount());
    			    } 
    			    else {
    			    	for (int in = 0; in < count; in++) {
    			    		p.getInventory().remove(item.getID(), 1);
    			    	}
    			    }
    			}
    		}
    
              if (redTeam.contains(p)) {
    			p.updateWornItems(RED_GEAR_CHEST.getWieldableDef().getWieldPos(), p.getPlayerAppearance().getSprite(RED_GEAR_CHEST.getWieldableDef().getWieldPos()));
    			p.updateWornItems(RED_GEAR_LEG.getWieldableDef().getWieldPos(), p.getPlayerAppearance().getSprite(RED_GEAR_LEG.getWieldableDef().getWieldPos()));
    			redTeam.remove(p);
    		} 
    		else {
    			p.updateWornItems(BLUE_GEAR_CHEST.getWieldableDef().getWieldPos(), p.getPlayerAppearance().getSprite(BLUE_GEAR_CHEST.getWieldableDef().getWieldPos()));
    			p.updateWornItems(BLUE_GEAR_LEG.getWieldableDef().getWieldPos(), p.getPlayerAppearance().getSprite(BLUE_GEAR_LEG.getWieldableDef().getWieldPos()));
    			blueTeam.remove(p);
    		}
    
    		for (int i : FREE_ITEMS) {
    			int count = p.getInventory().countId(i);
    			InvItem item = new InvItem(i, count);
    			if (count > 0) {
    			    if (item.getDef().stackable) {
    			    	p.getInventory().remove(item.getID(), item.getAmount());
    			    } 
    			    else {
    			    	for (int in = 0; in < count; in++) {
    			    		p.getInventory().remove(item.getID(), 1);
    			    	}
    			    }
    			}
    		}
    		
    		p.getActionSender().sendInventory();
    		p.getActionSender().sendMessage("All your free items have been removed, thanks for playing");
    
    		for (InvItem i : p.getInventory().getItems()) {
    			if (i.isWielded())
    				p.updateWornItems(i.getWieldableDef().getWieldPos(), i.getWieldableDef().getSprite());
    			}
    		
    		redTeamPlayernames.remove(p.getUsername());
    		blueTeamPlayernames.remove(p.getUsername());
    	}

    and the last one it is counting just kills but did not show them ..... so i thing i need mix them but if i do my self i get loads loads error and after is no working if i fix errors ...
    Java Code:
     public void handleDeath(Player opponent) {
        	boolean red = redTeam.contains(opponent);
        	if (red) {
        	    blueKills++;
        	    redDeaths++;
        	    blueDeaths = 0;
        	} else {
        	    redKills++;
        	    redDeaths = 0;
        	    blueDeaths++;
        	}
        	if (!firstblood) {
        		firstblood = false;
        	    sendSound("firstblood");
        	    if (red)
        	    	sendCTFMessage("@red@" + opponent.getUsername() + " @whi@from the @red@Red@whi@ team draws FIRST BLOOD");
        	    if (!red)
        	    	sendCTFMessage("@blu@" + opponent.getUsername() + " @whi@from the @blu@Blue@whi@ team draws FIRST BLOOD");
        	}
        	if (blueDeaths == DEATHS_FOR_HUMULIATION || blueDeaths == DEATHS_FOR_HUMULIATION * 2) {
    
        	    sendSound("humuliation");
        	    sendCTFMessage("@blu@Blue@whi@ has had " + blueDeaths + " deaths without a kill");
        	    sendCTFAnnouncement("     Blue Fails!");
        	    if (blueDeaths != DEATHS_FOR_HUMULIATION)
        		blueDeaths = 0;
        	}
        	if (redDeaths == DEATHS_FOR_HUMULIATION || redDeaths == DEATHS_FOR_HUMULIATION * 2) {
    
        	    sendSound("humuliation");
        	    sendCTFMessage("@red@Red@whi@ has had " + redDeaths + " deaths without a kill");
        	    sendCTFAnnouncement("     Red Fails!");
        	    if (redDeaths != DEATHS_FOR_HUMULIATION)
        		redDeaths = 0;
        		}
            }
    Last edited by universal; 04-10-2011 at 09:10 AM.

  19. #19
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    The very beginning tutorials start much simpler than that 2d tutorial, start with those and see how much you can understand.

  20. #20
    universal is offline Member
    Join Date
    Apr 2011
    Posts
    10
    Rep Power
    0

    Default

    @sunde
    i am just looking for tut witch is can explain
    if
    else
    boolen
    string
    publick void
    int
    final int
    etc....

    so i just need understand what they do and i thing i can try to do my self then ...

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 0
    Last Post: 02-21-2011, 11:50 AM
  2. Replies: 1
    Last Post: 03-04-2010, 11:19 AM
  3. Convert java code to midlet code
    By coldvoice05 in forum New To Java
    Replies: 1
    Last Post: 08-12-2009, 11:14 AM
  4. Convert java code to midlet code
    By coldvoice05 in forum Advanced Java
    Replies: 1
    Last Post: 08-09-2009, 01:21 PM
  5. Replies: 1
    Last Post: 04-26-2007, 03:52 PM

Posting Permissions

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