Thread: NPC attacks when thieving stalls?[PI]

Results 1 to 2 of 2
  1. #1 NPC attacks when thieving stalls?[PI] 
    Registered Member
    Edd -'s Avatar
    Join Date
    Jul 2011
    Posts
    664
    Thanks given
    62
    Thanks received
    43
    Rep Power
    84
    how would i add this i want it so if a npc is 10 squares near player he will attack. when player is thieving.

    I just need a code for somthing like
    any help please?
    Code:
    npcsid == (x,y,h) {
    npcs[i].forceChat("What do you think you're doing?"); 
    npcs[i].underAttack = true;
    idk how i would ago about this..
    Reply With Quote  
     

  2. #2  
    Donator

    Robgob69's Avatar
    Join Date
    Oct 2010
    Age
    33
    Posts
    749
    Thanks given
    71
    Thanks received
    139
    Rep Power
    117
    first you would need to import the NPC class into the class your stalls method is in.
    Code:
    import server.model.npcs.NPC;
    then inside the stall method, where it has you fail the method
    Code:
    		if (Misc.random(10) == 8 && c.playerLevel[c.playerThieving] < 99) {
    			NPC n = c.getCloseRandomNpc(10);
    			if (n != null) {
    				n.killerId = c.playerId;
    				n.underAttack = true;
    				n.forceChat("Get your thieving hands out of my stalls!");
    				return;
    			}
    		}
    and add this method to your Player.java:
    Code:
    	public NPC getCloseRandomNpc(int distance) {
    		ArrayList<NPC> npcs = new ArrayList<NPC>();
    		for (int j = 0; j < Server.npcHandler.npcs.length; j++) {
    			if (Server.npcHandler.npcs[j] != null) {
    				NPC n = Server.npcHandler.npcs[j];
    				if (distanceToPoint(n.getX(), n.getY()) <= distance) {
    					if (!n.underAttack)
    						if (n.heightLevel == heightLevel)
    							npcs.add(n);
    				}
    			}	
    		}
    		if (npcs.size() > 0)
    			return npcs.get(Misc.random(npcs.size() -1));
    		else
    			return null; // No near npcs :C
    	}
    here is my method with it implemeted so you can see:
    Code:
    	public void stealFromStall(int id, int xp, int level) {
    		if (System.currentTimeMillis() - c.lastThieve < 2500)
    			return;
    		if (Misc.random(100) == 0) {
    			return;
    		}
    		if (Misc.random(6) == 5 && c.playerLevel[c.playerThieving] < 99) {
    			NPC n = c.getCloseRandomNpc(10);
    			if (n != null) {
    				n.killerId = c.playerId;
    				n.underAttack = true;
    				n.forceChat("Get your thieving hands out of my stalls!");
    				return;
    			}
    		}
    		if (c.playerLevel[c.playerThieving] >= level) {
    			if (c.getItems().addItem(id,1)) {
    				c.startAnimation(832);
    				c.getPA().addSkillXP(xp * Config.THIEVING_EXPERIENCE, c.playerThieving);
    				c.lastThieve = System.currentTimeMillis();
    				c.sendMessage("You steal a " + server.model.items.Item.getItemName(id) + ".");
    			}	
    		} else {
    			c.sendMessage("You must have a thieving level of " + level + " to steal from this stall.");
    		}
    	}
    if you dont have getX() and getY() in your NPC class, add them.
    Code:
    	public int getX() {
    		return absX;
    	}
    	
    	public int getY() {
    		return absY;
    	}

    this is just off the top of my head. you get the picture tho.. x3

    potatoes.
    Reply With Quote  
     

  3. Thankful user:



Thread Information
Users Browsing this Thread

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


User Tag List

Similar Threads

  1. PI Need help with Thieving stalls
    By rocky2k10 in forum Help
    Replies: 13
    Last Post: 06-09-2012, 06:41 PM
  2. Thieving Stalls
    By Haegely in forum Requests
    Replies: 2
    Last Post: 04-09-2012, 04:43 AM
  3. thieving stalls
    By redbunny in forum Help
    Replies: 1
    Last Post: 02-09-2012, 05:46 PM
  4. Thieving Stalls [PI]
    By dizzle in forum Help
    Replies: 3
    Last Post: 12-13-2011, 08:48 PM
  5. Replies: 28
    Last Post: 01-31-2010, 05:07 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •