Thread: Why won't my Npc vs Npc Work? :'( Theres A little base for Skilled coders here!

Results 1 to 2 of 2
  1. #1 Why won't my Npc vs Npc Work? :'( Theres A little base for Skilled coders here! 
    Registered Member
    Pride's Avatar
    Join Date
    Mar 2008
    Posts
    727
    Thanks given
    0
    Thanks received
    1
    Rep Power
    121
    Okay, Here's what I have:
    Code:
    	if (npcs[i] != null) {
    						
    				/*		if(npcs[i].npcType == 19) {
    							npcs[i].againstMonsters = true;
    							npcs[i].againstMonsterID = 178;
    							}*/
    						try {
    						NPC b = npcs[i]
    												.getNearestFreeNPCByID(npcs[i].againstMonsterID);
    						
    						if (npcs[i].againstMonsters
    								&& !npcs[i].walkingHome) {
    
    							if (!npcs[i].isDead) {
    								if (b != null) {
    									npcs[i].faceNPC(npcs[i].npcId);
    									followNPC(i, b);
    									if (npcs[i] == null)
    										continue;
    
    									if (npcs[i].attackTimer == 0) {
    
    										if (npcs[i] != null) {
    
    											attackNPC(b, b.npcId);
    											
    										} else {
    											npcs[i].killerId = 0;
    											npcs[i].underAttack = false;
    											npcs[i].facePlayer(0);
    										}
    									}
    								} else {
    									npcs[i].killerId = 0;
    									npcs[i].underAttack = false;
    									npcs[i].facePlayer(0);
    								}
    							}
    						}
    						} catch(Exception e) {
    							e.printStackTrace();
    						}
    					}
    Thats in my NPCHandler Process, Now before you scream: "AAAHH PROCESS NERD", I want to get it working before I Convert it, If I even can
    Code:
    public void attackNPC(NPC c,int i) {
    		if (npcs[i] != null) {
    			if (goodDistance(npcs[i].getX(), npcs[i].getY(), c.getX(),
    					c.getY(), distanceRequired(i))) {
    				if (!c.isDead) {
    					c.killerId = npcs[i].npcId;
    					npcs[i].facePlayer(c.npcId);
    					npcs[i].attackTimer = getNpcDelay(i);
    					npcs[i].hitDelayTimer = getHitDelay(i);
    					npcs[i].attackType = 0;
    					loadSpell(i);
    					startAnimation(getAttackEmote(i), i);
    				}
    			}
    		}
    	}
    Code:
    	public void followNPC(int i, NPC Freenpc) {
    		if (Freenpc == null) {
    			return;
    		}
    		if (!Freenpc.isDead) {
    			npcs[i].faceNPC(i);
    			npcs[i].randomWalk = true;
    			npcs[i].underAttackNPC = false;
    			return;
    		}
    
    		int otherX = Freenpc.absX;
    		int otherY = Freenpc.absY;
    		npcs[i].randomWalk = false;
    		boolean canwalk = true;
    		if ((npcs[i].spawnedBy > 0)
    				|| ((npcs[i].absX < npcs[i].makeX + Config.NPC_FOLLOW_DISTANCE)
    						&& (npcs[i].absX > npcs[i].makeX
    								- Config.NPC_FOLLOW_DISTANCE)
    						&& (npcs[i].absY < npcs[i].makeY
    								+ Config.NPC_FOLLOW_DISTANCE) && (npcs[i].absY > npcs[i].makeY
    						- Config.NPC_FOLLOW_DISTANCE))) {
    			if (npcs[i].heightLevel == Freenpc.heightLevel) {
    				if (Freenpc != null
    						&& npcs[i] != null) {
    					if (otherY < npcs[i].absY) {
    						npcs[i].moveX = GetMove(npcs[i].absX, otherX);
    						npcs[i].moveY = GetMove(npcs[i].absY, otherY + 1);
    						if (WorldMap.isWalkAble(npcs[i].heightLevel,
    								npcs[i].absX, npcs[i].absY, npcs[i].absX,
    								npcs[i].absY + npcs[i].moveY) == false)
    							canwalk = false;
    					} else if (otherY > npcs[i].absY) {
    						npcs[i].moveX = GetMove(npcs[i].absX, otherX);
    						npcs[i].moveY = GetMove(npcs[i].absY, otherY - 1);
    						if (WorldMap.isWalkAble(npcs[i].heightLevel,
    								npcs[i].absX, npcs[i].absY, npcs[i].absX,
    								npcs[i].absY - npcs[i].moveY) == false)
    							canwalk = false;
    					} else if (otherX < npcs[i].absX) {
    						npcs[i].moveX = GetMove(npcs[i].absX, otherX + 1);
    						npcs[i].moveY = GetMove(npcs[i].absY, otherY);
    						if (WorldMap.isWalkAble(npcs[i].heightLevel,
    								npcs[i].absX, npcs[i].absY, npcs[i].absX
    										+ npcs[i].moveX, npcs[i].absY) == false)
    							canwalk = false;
    					} else if (otherX > npcs[i].absX) {
    						npcs[i].moveX = GetMove(npcs[i].absX, otherX - 1);
    						npcs[i].moveY = GetMove(npcs[i].absY, otherY);
    						if (WorldMap.isWalkAble(npcs[i].heightLevel,
    								npcs[i].absX, npcs[i].absY, npcs[i].absX
    										- npcs[i].moveX, npcs[i].absY) == false)
    							canwalk = false;
    					} else if (otherX == npcs[i].absX
    							|| otherY == npcs[i].absY) {
    						int o = Misc.random(3);
    						switch (o) {
    						case 0:
    							npcs[i].moveX = GetMove(npcs[i].absX, otherX);
    							npcs[i].moveY = GetMove(npcs[i].absY, otherY + 1);
    							if (WorldMap.isWalkAble(npcs[i].heightLevel,
    									npcs[i].absX, npcs[i].absY, npcs[i].absX,
    									npcs[i].absY + npcs[i].moveY) == false)
    								canwalk = false;
    							break;
    
    						case 1:
    							npcs[i].moveX = GetMove(npcs[i].absX, otherX);
    							npcs[i].moveY = GetMove(npcs[i].absY, otherY - 1);
    							if (WorldMap.isWalkAble(npcs[i].heightLevel,
    									npcs[i].absX, npcs[i].absY, npcs[i].absX,
    									npcs[i].absY + npcs[i].moveY) == false)
    								canwalk = false;
    							break;
    
    						case 2:
    							npcs[i].moveX = GetMove(npcs[i].absX, otherX + 1);
    							npcs[i].moveY = GetMove(npcs[i].absY, otherY);
    							if (WorldMap.isWalkAble(npcs[i].heightLevel,
    									npcs[i].absX, npcs[i].absY, npcs[i].absX
    											+ npcs[i].moveX, npcs[i].absY) == false)
    								canwalk = false;
    							break;
    
    						case 3:
    							npcs[i].moveX = GetMove(npcs[i].absX, otherX - 1);
    							npcs[i].moveY = GetMove(npcs[i].absY, otherY);
    							if (WorldMap.isWalkAble(npcs[i].heightLevel,
    									npcs[i].absX, npcs[i].absY, npcs[i].absX
    											- npcs[i].moveX, npcs[i].absY) == false)
    								canwalk = false;
    							break;
    						}
    					}
    					if (canwalk == true) {
    						npcs[i].getNextNPCMovement(i);
    						npcs[i].updateRequired = true;
    					}
    				}
    			}
    		} else {
    			npcs[i].facePlayer(0);
    			npcs[i].randomWalk = true;
    			npcs[i].underAttack = false;
    		}
    	}
    Code:
    	public void faceNPC(int npc) {
    		face = npc + 32768;
    		dirUpdateRequired = true;
    		updateRequired = true;
    	}
    Explaining what happens:
    Well If you look at the top of the code, You should see

    /* if(npcs[i].npcType == 19) {
    npcs[i].againstMonsters = true;
    npcs[i].againstMonsterID = 178;
    }*/
    Anyways, Thats White knights Versus Black knights, When I de-null this,
    The black knight keeps doing his emote, theres no Splats, no Movement from the White knight....
    Whats going wrong?

    PS:
    I know, I haven't supplied you with "getNearestFreeNPCByID(npcs[i].againstMonsterID)"
    But thats to stop noobs from stealing the code!

    PLEASE HELP GUYS!
     

  2. #2  
    Registered Member

    Join Date
    Jun 2008
    Posts
    225
    Thanks given
    0
    Thanks received
    0
    Rep Power
    137
    I don't think the aggressive part is working.
     


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
  •