Thread: Cannon

Page 1 of 2 12 LastLast
Results 1 to 10 of 15
  1. #1 Cannon 
    Member
    Boomer's Avatar
    Join Date
    Sep 2006
    Posts
    1,282
    Thanks given
    309
    Thanks received
    795
    Rep Power
    1111
    This is from my Paragon winterlove server WAY WAY BACK MANY CENTURIES AGO. This is before I figured out object animations so this rotates the cannon around completely.. A video of this:

    [Only registered and activated users can see links. ]

    Code:
    public class Cannon {
    	public int getNPC() {
    		for (int i = 0; i < server.npcHandler.maxNPCs; i++) {
    			NPC npc = server.npcHandler.npcs[i];
    			if (npc != null && !npc.isDieing) {
    				int directionFacingF = directionFacing+1;
    				if (directionFacingF == 4) {
    					directionFacingF = 0;
    				}
    				if (directionFacingF == 0) { //West
    					if ((npc.absY == (y+1) || npc.absY == (y-1) || npc.absY == y) && npc.absX < x && c.GoodDistance(x, y, npc.absX, npc.absY, 8)) {
    						return i;
    					}
    				}
    				if (directionFacingF == 2) { //East
    					if ((npc.absY == (y+1) || npc.absY == (y-1) || npc.absY == y) && npc.absX > x && c.GoodDistance(x, y, npc.absX, npc.absY, 8)) {
    						return i;
    					}
    				}
    				if (directionFacingF == 1) { //North
    					if ((npc.absX == (x+1) || npc.absX == (x-1) || npc.absX == x) && npc.absY > y && c.GoodDistance(x, y, npc.absX, npc.absY, 8)) {
    						return i;
    					}
    				}
    				if (directionFacingF == 3) { //South
    					if ((npc.absX == (x+1) || npc.absX == (x-1) || npc.absX == x) && npc.absY < y && c.GoodDistance(x, y, npc.absX, npc.absY, 8)) {
    						return i;
    					}
    				}
    			}
    		}
    		return -1;
    	}
    	public long spinDelay = -1;
    	public void fireCannon(int x, int y) {
    		if (server.cannonX[c.playerId] != x || server.cannonY[c.playerId] != y) {
    			c.sendMessage("That is not your cannon!");
    			return;
    		}	
    		else if (spinDelay != -1) {
    			c.sendMessage("Your cannon is already firing!");
    			return;
    		}	
    		else if (cannonBalls == 0) {
    			c.sendMessage("Your cannon has no cannonballs in it!");
    			return;
    		}
    		else {
    			spinDelay = System.currentTimeMillis()+1*1250;
    		}
    	}
    	public void pickupCannon(int x, int y) {
    		if (server.cannonX[c.playerId] != x || server.cannonY[c.playerId] != y) {
    			c.sendMessage("That is not your cannon!");
    			return;
    		}
    		else if ((c.freeSlots() == 4 && cannonBalls != 0 && !c.playerHasItemAmount(2, 1)) || (c.freeSlots() < 4)) {
    			c.sendMessage("You don't have enough room to pickup your cannon!");
    			return;
    		}
    		else {
    			c.addItem(2, cannonBalls);
    			c.addItem(6, 1);
    			c.addItem(8, 1);
    			c.addItem(10, 1);
    			c.addItem(12, 1);
    			c.deleteGlobalObject(x, y);
    			c.sendMessage("You pickup your cannon!");
    			resetValues();
    		}
    	}
    	public void resetValues() {
    		server.cannonX[c.playerId] = 0;
    		server.cannonY[c.playerId] = 0;
    		x = 0;
    		y = 0;
    		spinDelay = -1;
    		cannonBalls = 0;
    	}
    		
    	public boolean cannonNear() {
    		for (int i = 0; i < server.playerHandler.maxPlayers; i++) {
    			if (c.GoodDistance(c.absX, c.absY, server.cannonX[i], server.cannonY[i], 3)) {
    				return true;
    			}
    		}
    		return false;
    	}
    	public void createCannon() {
    		if (server.cannonX[c.playerId] != 0 && server.cannonX[c.playerId] != -1) {
    			c.sendMessage("You already have a cannon out!");
    			return;
    		}
    		else if (cannonNear()) {
    			c.sendMessage("You cannot put your cannon here!");
    			return;
    		}
    		else {
    			x = c.absX;
    			y = c.absY;
    			c.addGlobalObject(6, x, y, 0);
    			server.cannonX[c.playerId] = x;
    			server.cannonY[c.playerId] = y;
    		}
    	}
    	public int x = -1;
    	public int y = -1;
    	public int directionFacing = 0;
    	public void spinCannon() {
    		if (directionFacing+1 == 4) {
    			directionFacing = 0;
    		}
    		else {
    			directionFacing += 1;
    		}
    		c.addGlobalObject(6, x, y, directionFacing);
    		spinDelay = System.currentTimeMillis()+1*1250;
    	}
    	public void fire() {
    		if (cannonBalls == 0) {
    			c.sendMessage("Your cannon has run out of ammo!");
    			spinDelay = -1;
    			return;
    		}
    		if (getNPC() == -1) {
    			return;
    		}
    		NPC npc = server.npcHandler.npcs[getNPC()];
    		if (npc == null) { 
    			return;
    		}
    		if (npc.NPCCombat.isDieing) {
    			return;
    		}
    		int offsetX = (server.cannonX[c.playerId] - npc.absX) * -1;
    		int offsetY = (server.cannonY[c.playerId] - npc.absY) * -1;
    		c.createProjectile(server.cannonY[c.playerId], server.cannonX[c.playerId], offsetX, offsetY, 50, 80, 194, 40, 31, npc.npcId+1);
    		attackOnPast = npc;
    		cannonBalls--;
    		hitDelay = System.currentTimeMillis()+1*1000;
    		if (cannonBalls == 0) {
    			c.sendMessage("Your cannon has run out of ammo!");
    			spinDelay = -1;
    			return;
    		}
    		
    	}
    	public NPC attackOnPast = null;
    	public long hitDelay = -1;
    	public void process() {
    		if (hitDelay != -1 && hitDelay <= System.currentTimeMillis()) {
    			if (attackOnPast != null && !attackOnPast.isDieing) {
    				int hit = misc.random(30);
    				attackOnPast.hit(hit);
    				c.addSkillXP(25*hit, 4);
    			}
    			attackOnPast = null;
    			hitDelay = -1;
    		}
    				
    				
    		if (spinDelay != -1) {
    			if (spinDelay <= System.currentTimeMillis()) {
    				spinCannon();
    				fire();
    			}
    		}
    	}
    	public void addBalls(int x, int y, int useID) {
    		if (useID != 2) {
    			return;
    		}
    		else if (server.cannonX[c.playerId] != x || server.cannonY[c.playerId] != y) {
    			c.sendMessage("This isn't your cannon!");
    			return;
    		}
    		else if (cannonBalls == 30) {
    			c.sendMessage("Your cannon is full!");
    			return;
    		}
    		else {
    			int ballsNeeded = 30-cannonBalls;
    			int ballsHave = c.GetXItemsInBag(2);
    			if (ballsHave >= ballsNeeded) {
    				c.deleteItem(2, c.GetItemSlot(2), ballsNeeded);
    				cannonBalls += ballsNeeded;
    				c.sendMessage("You add "+ballsNeeded+" cannonballs to your cannon");
    				return;
    			}
    			if (ballsHave < ballsNeeded) {
    				c.deleteItem(2, c.GetItemSlot(2), ballsHave);
    				cannonBalls += ballsHave;
    				c.sendMessage("You add "+ballsHave+" cannonballs to your cannon");
    				return;
    			}
    		}
    	}
    	public int cannonBalls = 0;
    	public Cannon(client c) {
    		this.c = c;
    	}
    	private client c;
    }
    Good luck


    [Only registered and activated users can see links. ] ||| FightScape | InnerFantasy | PkIsle | [Only registered and activated users can see links. ] | [Only registered and activated users can see links. ] | [Only registered and activated users can see links. ]
    Reply With Quote  
     

  2. #2  
    Registered Member AFGscape's Avatar
    Join Date
    May 2009
    Posts
    3,556
    Thanks given
    458
    Thanks received
    636
    Rep Power
    39
    needed this ty mate
    rep+
    Reply With Quote  
     

  3. #3  
    .supersyn

    myK-'s Avatar
    Join Date
    Aug 2008
    Posts
    1,778
    Thanks given
    18
    Thanks received
    39
    Rep Power
    399
    omgss Boomer for president!

    butt... i got these err0rz.

    Code:
    Cannon.java:5: cannot find symbol
    symbol  : variable isDieing
    location: class NPC
                            if (npc != null && !npc.isDieing) {
                                                   ^
    Cannon.java:36: array required, but int found
                    if (server.cannonX[c.playerId] != x || server.cannonY[c.playerId
    ] != y) {
                                      ^
    Cannon.java:36: array required, but int found
                    if (server.cannonX[c.playerId] != x || server.cannonY[c.playerId
    ] != y) {
                                                                         ^
    Cannon.java:53: array required, but int found
                    if (server.cannonX[c.playerId] != x || server.cannonY[c.playerId
    ] != y) {
                                      ^
    Cannon.java:53: array required, but int found
                    if (server.cannonX[c.playerId] != x || server.cannonY[c.playerId
    ] != y) {
                                                                         ^
    Cannon.java:67: cannot find symbol
    symbol  : method deleteGlobalObject(int,int)
    location: class client
                            c.deleteGlobalObject(x, y);
                             ^
    Cannon.java:73: array required, but int found
                    server.cannonX[c.playerId] = 0;
                                  ^
    Cannon.java:74: array required, but int found
                    server.cannonY[c.playerId] = 0;
                                  ^
    Cannon.java:83: array required, but int found
                            if (c.GoodDistance(c.absX, c.absY, server.cannonX[i], se
    rver.cannonY[i], 3)) {
                                                                             ^
    Cannon.java:83: array required, but int found
                            if (c.GoodDistance(c.absX, c.absY, server.cannonX[i], se
    rver.cannonY[i], 3)) {
    
                ^
    Cannon.java:90: array required, but int found
                    if (server.cannonX[c.playerId] != 0 && server.cannonX[c.playerId
    ] != -1) {
                                      ^
    Cannon.java:90: array required, but int found
                    if (server.cannonX[c.playerId] != 0 && server.cannonX[c.playerId
    ] != -1) {
                                                                         ^
    Cannon.java:101: cannot find symbol
    symbol  : method addGlobalObject(int,int,int,int)
    location: class client
                            c.addGlobalObject(6, x, y, 0);
                             ^
    Cannon.java:102: array required, but int found
                            server.cannonX[c.playerId] = x;
                                          ^
    Cannon.java:103: array required, but int found
                            server.cannonY[c.playerId] = y;
                                          ^
    Cannon.java:116: cannot find symbol
    symbol  : method addGlobalObject(int,int,int,int)
    location: class client
                    c.addGlobalObject(6, x, y, directionFacing);
                     ^
    Cannon.java:132: cannot find symbol
    symbol  : variable NPCCombat
    location: class NPC
                    if (npc.NPCCombat.isDieing) {
                           ^
    Cannon.java:135: array required, but int found
                    int offsetX = (server.cannonX[c.playerId] - npc.absX) * -1;
                                                 ^
    Cannon.java:136: array required, but int found
                    int offsetY = (server.cannonY[c.playerId] - npc.absY) * -1;
                                                 ^
    Cannon.java:137: array required, but int found
                    c.createProjectile(server.cannonY[c.playerId], server.cannonX[c.
    playerId], offsetX, offsetY, 50, 80, 194, 40, 31, npc.npcId+1);
                                                     ^
    Cannon.java:137: array required, but int found
                    c.createProjectile(server.cannonY[c.playerId], server.cannonX[c.
    playerId], offsetX, offsetY, 50, 80, 194, 40, 31, npc.npcId+1);
                                                                                 ^
    Cannon.java:152: cannot find symbol
    symbol  : variable isDieing
    location: class NPC
                            if (attackOnPast != null && !attackOnPast.isDieing) {
                                                                     ^
    Cannon.java:154: cannot find symbol
    symbol  : method hit(int)
    location: class NPC
                                    attackOnPast.hit(hit);
                                                ^
    Cannon.java:173: array required, but int found
                    else if (server.cannonX[c.playerId] != x || server.cannonY[c.pla
    yerId] != y) {
                                           ^
    Cannon.java:173: array required, but int found
                    else if (server.cannonX[c.playerId] != x || server.cannonY[c.pla
    yerId] != y) {
                                                                              ^
    Note: EconomyReset.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    25 errors
    Finished!
    Press any key to continue . . .
    Reply With Quote  
     

  4. #4  
    Registered Member
    ~Tazz~'s Avatar
    Join Date
    Mar 2009
    Posts
    620
    Thanks given
    0
    Thanks received
    2
    Rep Power
    267
    Jesus! pretty sweet dude, i will try make the cannon rotate better.
    Reply With Quote  
     

  5. #5  
    Member
    Boomer's Avatar
    Join Date
    Sep 2006
    Posts
    1,282
    Thanks given
    309
    Thanks received
    795
    Rep Power
    1111
    Quote Originally Posted by nullSenSe View Post
    omgss Boomer for president!

    butt... i got these err0rz.

    Code:
    Cannon.java:5: cannot find symbol
    symbol  : variable isDieing
    location: class NPC
                            if (npc != null && !npc.isDieing) {
                                                   ^
    Cannon.java:36: array required, but int found
                    if (server.cannonX[c.playerId] != x || server.cannonY[c.playerId
    ] != y) {
                                      ^
    Cannon.java:36: array required, but int found
                    if (server.cannonX[c.playerId] != x || server.cannonY[c.playerId
    ] != y) {
                                                                         ^
    Cannon.java:53: array required, but int found
                    if (server.cannonX[c.playerId] != x || server.cannonY[c.playerId
    ] != y) {
                                      ^
    Cannon.java:53: array required, but int found
                    if (server.cannonX[c.playerId] != x || server.cannonY[c.playerId
    ] != y) {
                                                                         ^
    Cannon.java:67: cannot find symbol
    symbol  : method deleteGlobalObject(int,int)
    location: class client
                            c.deleteGlobalObject(x, y);
                             ^
    Cannon.java:73: array required, but int found
                    server.cannonX[c.playerId] = 0;
                                  ^
    Cannon.java:74: array required, but int found
                    server.cannonY[c.playerId] = 0;
                                  ^
    Cannon.java:83: array required, but int found
                            if (c.GoodDistance(c.absX, c.absY, server.cannonX[i], se
    rver.cannonY[i], 3)) {
                                                                             ^
    Cannon.java:83: array required, but int found
                            if (c.GoodDistance(c.absX, c.absY, server.cannonX[i], se
    rver.cannonY[i], 3)) {
    
                ^
    Cannon.java:90: array required, but int found
                    if (server.cannonX[c.playerId] != 0 && server.cannonX[c.playerId
    ] != -1) {
                                      ^
    Cannon.java:90: array required, but int found
                    if (server.cannonX[c.playerId] != 0 && server.cannonX[c.playerId
    ] != -1) {
                                                                         ^
    Cannon.java:101: cannot find symbol
    symbol  : method addGlobalObject(int,int,int,int)
    location: class client
                            c.addGlobalObject(6, x, y, 0);
                             ^
    Cannon.java:102: array required, but int found
                            server.cannonX[c.playerId] = x;
                                          ^
    Cannon.java:103: array required, but int found
                            server.cannonY[c.playerId] = y;
                                          ^
    Cannon.java:116: cannot find symbol
    symbol  : method addGlobalObject(int,int,int,int)
    location: class client
                    c.addGlobalObject(6, x, y, directionFacing);
                     ^
    Cannon.java:132: cannot find symbol
    symbol  : variable NPCCombat
    location: class NPC
                    if (npc.NPCCombat.isDieing) {
                           ^
    Cannon.java:135: array required, but int found
                    int offsetX = (server.cannonX[c.playerId] - npc.absX) * -1;
                                                 ^
    Cannon.java:136: array required, but int found
                    int offsetY = (server.cannonY[c.playerId] - npc.absY) * -1;
                                                 ^
    Cannon.java:137: array required, but int found
                    c.createProjectile(server.cannonY[c.playerId], server.cannonX[c.
    playerId], offsetX, offsetY, 50, 80, 194, 40, 31, npc.npcId+1);
                                                     ^
    Cannon.java:137: array required, but int found
                    c.createProjectile(server.cannonY[c.playerId], server.cannonX[c.
    playerId], offsetX, offsetY, 50, 80, 194, 40, 31, npc.npcId+1);
                                                                                 ^
    Cannon.java:152: cannot find symbol
    symbol  : variable isDieing
    location: class NPC
                            if (attackOnPast != null && !attackOnPast.isDieing) {
                                                                     ^
    Cannon.java:154: cannot find symbol
    symbol  : method hit(int)
    location: class NPC
                                    attackOnPast.hit(hit);
                                                ^
    Cannon.java:173: array required, but int found
                    else if (server.cannonX[c.playerId] != x || server.cannonY[c.pla
    yerId] != y) {
                                           ^
    Cannon.java:173: array required, but int found
                    else if (server.cannonX[c.playerId] != x || server.cannonY[c.pla
    yerId] != y) {
                                                                              ^
    Note: EconomyReset.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    25 errors
    Finished!
    Press any key to continue . . .
    Oh yeah, you need to put an array into the server class that has all the cannon x and y's.. I'd probably make a List if i re-did it now.


    [Only registered and activated users can see links. ] ||| FightScape | InnerFantasy | PkIsle | [Only registered and activated users can see links. ] | [Only registered and activated users can see links. ] | [Only registered and activated users can see links. ]
    Reply With Quote  
     

  6. #6  
    SERGEANT OF THE MASTER SERGEANTS MOST IMPORTANT PERSON OF EXTREME SERGEANTS TO THE MAX!

    cube's Avatar
    Join Date
    Jun 2007
    Posts
    8,881
    Thanks given
    1,854
    Thanks received
    4,741
    Rep Power
    5000
    /win, could you post your following?



    Reply With Quote  
     

  7. #7  
    Banned

    Join Date
    Jul 2008
    Age
    26
    Posts
    5,826
    Thanks given
    1,301
    Thanks received
    197
    Rep Power
    0
    Quote Originally Posted by Boomer View Post
    This is from my Paragon winterlove server WAY WAY BACK MANY CENTURIES AGO. This is before I figured out object animations so this rotates the cannon around completely.. A video of this:

    [Only registered and activated users can see links. ]

    Code:
    public class Cannon {
    	public int getNPC() {
    		for (int i = 0; i < server.npcHandler.maxNPCs; i++) {
    			NPC npc = server.npcHandler.npcs[i];
    			if (npc != null && !npc.isDieing) {
    				int directionFacingF = directionFacing+1;
    				if (directionFacingF == 4) {
    					directionFacingF = 0;
    				}
    				if (directionFacingF == 0) { //West
    					if ((npc.absY == (y+1) || npc.absY == (y-1) || npc.absY == y) && npc.absX < x && c.GoodDistance(x, y, npc.absX, npc.absY, 8)) {
    						return i;
    					}
    				}
    				if (directionFacingF == 2) { //East
    					if ((npc.absY == (y+1) || npc.absY == (y-1) || npc.absY == y) && npc.absX > x && c.GoodDistance(x, y, npc.absX, npc.absY, 8)) {
    						return i;
    					}
    				}
    				if (directionFacingF == 1) { //North
    					if ((npc.absX == (x+1) || npc.absX == (x-1) || npc.absX == x) && npc.absY > y && c.GoodDistance(x, y, npc.absX, npc.absY, 8)) {
    						return i;
    					}
    				}
    				if (directionFacingF == 3) { //South
    					if ((npc.absX == (x+1) || npc.absX == (x-1) || npc.absX == x) && npc.absY < y && c.GoodDistance(x, y, npc.absX, npc.absY, 8)) {
    						return i;
    					}
    				}
    			}
    		}
    		return -1;
    	}
    	public long spinDelay = -1;
    	public void fireCannon(int x, int y) {
    		if (server.cannonX[c.playerId] != x || server.cannonY[c.playerId] != y) {
    			c.sendMessage("That is not your cannon!");
    			return;
    		}	
    		else if (spinDelay != -1) {
    			c.sendMessage("Your cannon is already firing!");
    			return;
    		}	
    		else if (cannonBalls == 0) {
    			c.sendMessage("Your cannon has no cannonballs in it!");
    			return;
    		}
    		else {
    			spinDelay = System.currentTimeMillis()+1*1250;
    		}
    	}
    	public void pickupCannon(int x, int y) {
    		if (server.cannonX[c.playerId] != x || server.cannonY[c.playerId] != y) {
    			c.sendMessage("That is not your cannon!");
    			return;
    		}
    		else if ((c.freeSlots() == 4 && cannonBalls != 0 && !c.playerHasItemAmount(2, 1)) || (c.freeSlots() < 4)) {
    			c.sendMessage("You don't have enough room to pickup your cannon!");
    			return;
    		}
    		else {
    			c.addItem(2, cannonBalls);
    			c.addItem(6, 1);
    			c.addItem(8, 1);
    			c.addItem(10, 1);
    			c.addItem(12, 1);
    			c.deleteGlobalObject(x, y);
    			c.sendMessage("You pickup your cannon!");
    			resetValues();
    		}
    	}
    	public void resetValues() {
    		server.cannonX[c.playerId] = 0;
    		server.cannonY[c.playerId] = 0;
    		x = 0;
    		y = 0;
    		spinDelay = -1;
    		cannonBalls = 0;
    	}
    		
    	public boolean cannonNear() {
    		for (int i = 0; i < server.playerHandler.maxPlayers; i++) {
    			if (c.GoodDistance(c.absX, c.absY, server.cannonX[i], server.cannonY[i], 3)) {
    				return true;
    			}
    		}
    		return false;
    	}
    	public void createCannon() {
    		if (server.cannonX[c.playerId] != 0 && server.cannonX[c.playerId] != -1) {
    			c.sendMessage("You already have a cannon out!");
    			return;
    		}
    		else if (cannonNear()) {
    			c.sendMessage("You cannot put your cannon here!");
    			return;
    		}
    		else {
    			x = c.absX;
    			y = c.absY;
    			c.addGlobalObject(6, x, y, 0);
    			server.cannonX[c.playerId] = x;
    			server.cannonY[c.playerId] = y;
    		}
    	}
    	public int x = -1;
    	public int y = -1;
    	public int directionFacing = 0;
    	public void spinCannon() {
    		if (directionFacing+1 == 4) {
    			directionFacing = 0;
    		}
    		else {
    			directionFacing += 1;
    		}
    		c.addGlobalObject(6, x, y, directionFacing);
    		spinDelay = System.currentTimeMillis()+1*1250;
    	}
    	public void fire() {
    		if (cannonBalls == 0) {
    			c.sendMessage("Your cannon has run out of ammo!");
    			spinDelay = -1;
    			return;
    		}
    		if (getNPC() == -1) {
    			return;
    		}
    		NPC npc = server.npcHandler.npcs[getNPC()];
    		if (npc == null) { 
    			return;
    		}
    		if (npc.NPCCombat.isDieing) {
    			return;
    		}
    		int offsetX = (server.cannonX[c.playerId] - npc.absX) * -1;
    		int offsetY = (server.cannonY[c.playerId] - npc.absY) * -1;
    		c.createProjectile(server.cannonY[c.playerId], server.cannonX[c.playerId], offsetX, offsetY, 50, 80, 194, 40, 31, npc.npcId+1);
    		attackOnPast = npc;
    		cannonBalls--;
    		hitDelay = System.currentTimeMillis()+1*1000;
    		if (cannonBalls == 0) {
    			c.sendMessage("Your cannon has run out of ammo!");
    			spinDelay = -1;
    			return;
    		}
    		
    	}
    	public NPC attackOnPast = null;
    	public long hitDelay = -1;
    	public void process() {
    		if (hitDelay != -1 && hitDelay <= System.currentTimeMillis()) {
    			if (attackOnPast != null && !attackOnPast.isDieing) {
    				int hit = misc.random(30);
    				attackOnPast.hit(hit);
    				c.addSkillXP(25*hit, 4);
    			}
    			attackOnPast = null;
    			hitDelay = -1;
    		}
    				
    				
    		if (spinDelay != -1) {
    			if (spinDelay <= System.currentTimeMillis()) {
    				spinCannon();
    				fire();
    			}
    		}
    	}
    	public void addBalls(int x, int y, int useID) {
    		if (useID != 2) {
    			return;
    		}
    		else if (server.cannonX[c.playerId] != x || server.cannonY[c.playerId] != y) {
    			c.sendMessage("This isn't your cannon!");
    			return;
    		}
    		else if (cannonBalls == 30) {
    			c.sendMessage("Your cannon is full!");
    			return;
    		}
    		else {
    			int ballsNeeded = 30-cannonBalls;
    			int ballsHave = c.GetXItemsInBag(2);
    			if (ballsHave >= ballsNeeded) {
    				c.deleteItem(2, c.GetItemSlot(2), ballsNeeded);
    				cannonBalls += ballsNeeded;
    				c.sendMessage("You add "+ballsNeeded+" cannonballs to your cannon");
    				return;
    			}
    			if (ballsHave < ballsNeeded) {
    				c.deleteItem(2, c.GetItemSlot(2), ballsHave);
    				cannonBalls += ballsHave;
    				c.sendMessage("You add "+ballsHave+" cannonballs to your cannon");
    				return;
    			}
    		}
    	}
    	public int cannonBalls = 0;
    	public Cannon(client c) {
    		this.c = c;
    	}
    	private client c;
    }
    Good luck
    Wrong gfx

    lol jk but cannon is easy if someone would release how to use the object animation packet
    Reply With Quote  
     

  8. #8  
    Maxdata
    Guest
    Quote Originally Posted by Boomer View Post
    Oh yeah, you need to put an array into the server class that has all the cannon x and y's.. I'd probably make a List if i re-did it now.
    Could you do that? 3
    Reply With Quote  
     

  9. #9  
    Registered Member
    dark bl00d23's Avatar
    Join Date
    Sep 2008
    Posts
    333
    Thanks given
    5
    Thanks received
    10
    Rep Power
    111
    Quote Originally Posted by Boomer View Post
    This is from my Paragon winterlove server WAY WAY BACK MANY CENTURIES AGO. This is before I figured out object animations so this rotates the cannon around completely.. A video of this:

    [Only registered and activated users can see links. ]

    Code:
    public class Cannon {
    	public int getNPC() {
    		for (int i = 0; i < server.npcHandler.maxNPCs; i++) {
    			NPC npc = server.npcHandler.npcs[i];
    			if (npc != null && !npc.isDieing) {
    				int directionFacingF = directionFacing+1;
    				if (directionFacingF == 4) {
    					directionFacingF = 0;
    				}
    				if (directionFacingF == 0) { //West
    					if ((npc.absY == (y+1) || npc.absY == (y-1) || npc.absY == y) && npc.absX < x && c.GoodDistance(x, y, npc.absX, npc.absY, 8)) {
    						return i;
    					}
    				}
    				if (directionFacingF == 2) { //East
    					if ((npc.absY == (y+1) || npc.absY == (y-1) || npc.absY == y) && npc.absX > x && c.GoodDistance(x, y, npc.absX, npc.absY, 8)) {
    						return i;
    					}
    				}
    				if (directionFacingF == 1) { //North
    					if ((npc.absX == (x+1) || npc.absX == (x-1) || npc.absX == x) && npc.absY > y && c.GoodDistance(x, y, npc.absX, npc.absY, 8)) {
    						return i;
    					}
    				}
    				if (directionFacingF == 3) { //South
    					if ((npc.absX == (x+1) || npc.absX == (x-1) || npc.absX == x) && npc.absY < y && c.GoodDistance(x, y, npc.absX, npc.absY, 8)) {
    						return i;
    					}
    				}
    			}
    		}
    		return -1;
    	}
    	public long spinDelay = -1;
    	public void fireCannon(int x, int y) {
    		if (server.cannonX[c.playerId] != x || server.cannonY[c.playerId] != y) {
    			c.sendMessage("That is not your cannon!");
    			return;
    		}	
    		else if (spinDelay != -1) {
    			c.sendMessage("Your cannon is already firing!");
    			return;
    		}	
    		else if (cannonBalls == 0) {
    			c.sendMessage("Your cannon has no cannonballs in it!");
    			return;
    		}
    		else {
    			spinDelay = System.currentTimeMillis()+1*1250;
    		}
    	}
    	public void pickupCannon(int x, int y) {
    		if (server.cannonX[c.playerId] != x || server.cannonY[c.playerId] != y) {
    			c.sendMessage("That is not your cannon!");
    			return;
    		}
    		else if ((c.freeSlots() == 4 && cannonBalls != 0 && !c.playerHasItemAmount(2, 1)) || (c.freeSlots() < 4)) {
    			c.sendMessage("You don't have enough room to pickup your cannon!");
    			return;
    		}
    		else {
    			c.addItem(2, cannonBalls);
    			c.addItem(6, 1);
    			c.addItem(8, 1);
    			c.addItem(10, 1);
    			c.addItem(12, 1);
    			c.deleteGlobalObject(x, y);
    			c.sendMessage("You pickup your cannon!");
    			resetValues();
    		}
    	}
    	public void resetValues() {
    		server.cannonX[c.playerId] = 0;
    		server.cannonY[c.playerId] = 0;
    		x = 0;
    		y = 0;
    		spinDelay = -1;
    		cannonBalls = 0;
    	}
    		
    	public boolean cannonNear() {
    		for (int i = 0; i < server.playerHandler.maxPlayers; i++) {
    			if (c.GoodDistance(c.absX, c.absY, server.cannonX[i], server.cannonY[i], 3)) {
    				return true;
    			}
    		}
    		return false;
    	}
    	public void createCannon() {
    		if (server.cannonX[c.playerId] != 0 && server.cannonX[c.playerId] != -1) {
    			c.sendMessage("You already have a cannon out!");
    			return;
    		}
    		else if (cannonNear()) {
    			c.sendMessage("You cannot put your cannon here!");
    			return;
    		}
    		else {
    			x = c.absX;
    			y = c.absY;
    			c.addGlobalObject(6, x, y, 0);
    			server.cannonX[c.playerId] = x;
    			server.cannonY[c.playerId] = y;
    		}
    	}
    	public int x = -1;
    	public int y = -1;
    	public int directionFacing = 0;
    	public void spinCannon() {
    		if (directionFacing+1 == 4) {
    			directionFacing = 0;
    		}
    		else {
    			directionFacing += 1;
    		}
    		c.addGlobalObject(6, x, y, directionFacing);
    		spinDelay = System.currentTimeMillis()+1*1250;
    	}
    	public void fire() {
    		if (cannonBalls == 0) {
    			c.sendMessage("Your cannon has run out of ammo!");
    			spinDelay = -1;
    			return;
    		}
    		if (getNPC() == -1) {
    			return;
    		}
    		NPC npc = server.npcHandler.npcs[getNPC()];
    		if (npc == null) { 
    			return;
    		}
    		if (npc.NPCCombat.isDieing) {
    			return;
    		}
    		int offsetX = (server.cannonX[c.playerId] - npc.absX) * -1;
    		int offsetY = (server.cannonY[c.playerId] - npc.absY) * -1;
    		c.createProjectile(server.cannonY[c.playerId], server.cannonX[c.playerId], offsetX, offsetY, 50, 80, 194, 40, 31, npc.npcId+1);
    		attackOnPast = npc;
    		cannonBalls--;
    		hitDelay = System.currentTimeMillis()+1*1000;
    		if (cannonBalls == 0) {
    			c.sendMessage("Your cannon has run out of ammo!");
    			spinDelay = -1;
    			return;
    		}
    		
    	}
    	public NPC attackOnPast = null;
    	public long hitDelay = -1;
    	public void process() {
    		if (hitDelay != -1 && hitDelay <= System.currentTimeMillis()) {
    			if (attackOnPast != null && !attackOnPast.isDieing) {
    				int hit = misc.random(30);
    				attackOnPast.hit(hit);
    				c.addSkillXP(25*hit, 4);
    			}
    			attackOnPast = null;
    			hitDelay = -1;
    		}
    				
    				
    		if (spinDelay != -1) {
    			if (spinDelay <= System.currentTimeMillis()) {
    				spinCannon();
    				fire();
    			}
    		}
    	}
    	public void addBalls(int x, int y, int useID) {
    		if (useID != 2) {
    			return;
    		}
    		else if (server.cannonX[c.playerId] != x || server.cannonY[c.playerId] != y) {
    			c.sendMessage("This isn't your cannon!");
    			return;
    		}
    		else if (cannonBalls == 30) {
    			c.sendMessage("Your cannon is full!");
    			return;
    		}
    		else {
    			int ballsNeeded = 30-cannonBalls;
    			int ballsHave = c.GetXItemsInBag(2);
    			if (ballsHave >= ballsNeeded) {
    				c.deleteItem(2, c.GetItemSlot(2), ballsNeeded);
    				cannonBalls += ballsNeeded;
    				c.sendMessage("You add "+ballsNeeded+" cannonballs to your cannon");
    				return;
    			}
    			if (ballsHave < ballsNeeded) {
    				c.deleteItem(2, c.GetItemSlot(2), ballsHave);
    				cannonBalls += ballsHave;
    				c.sendMessage("You add "+ballsHave+" cannonballs to your cannon");
    				return;
    			}
    		}
    	}
    	public int cannonBalls = 0;
    	public Cannon(client c) {
    		this.c = c;
    	}
    	private client c;
    }
    Good luck
    Good job, + now you can't remove!Muahahahahaha! Nah but this is REALLY nice, and it wouldn't take a brain sergeant to implement this in with the cannon rotating tutorial that's out there...Thanks!Rep for you
    Quote Originally Posted by Zee Best View Post
    Nah i like posting saying im better than everyone else, it turns me on and gets me arroused.
    Reply With Quote  
     

  10. #10  
    Respected Member


    Luke132's Avatar
    Join Date
    Dec 2007
    Age
    32
    Posts
    12,549
    Thanks given
    177
    Thanks received
    5,789
    Discord
    View profile
    Rep Power
    5000
    Good job Boomer.

    EDIT: @ The OP can delete the topic.

    Reply With Quote  
     

Page 1 of 2 12 LastLast

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
  •