Thread: 667 Model Offset issue

Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1 667 Model Offset issue 
    Registered Member
    Ebp90's Avatar
    Join Date
    Apr 2018
    Posts
    238
    Thanks given
    18
    Thanks received
    158
    Rep Power
    878
    I have an issue where NPC models aren't actually in the game tile that the game thinks they are in. I noticed it while trying to code Nex.





    The coordinates for the objectspawns were correct, and nex did not move as she was set to can't move in combat. I have noticed it with other NPCS, as they can attack from tiles they shouldn't be able to.

    Thanks for reading, any help would be appreciated.
    Reply With Quote  
     

  2. #2  
    Registered Member

    Join Date
    May 2013
    Age
    27
    Posts
    414
    Thanks given
    215
    Thanks received
    200
    Rep Power
    137
    It might be a npc size issue not model offset, afaik npcs don't have a model offset definition.
    Reply With Quote  
     

  3. #3  
    Registered Member
    Ebp90's Avatar
    Join Date
    Apr 2018
    Posts
    238
    Thanks given
    18
    Thanks received
    158
    Rep Power
    878
    Quote Originally Posted by ReverendDread View Post
    It might be a npc size issue not model offset, afaik npcs don't have a model offset definition.
    Would I need to change the npc size in the cache?
    Reply With Quote  
     

  4. #4  
    EXALTED

    Join Date
    Nov 2012
    Posts
    393
    Thanks given
    35
    Thanks received
    33
    Rep Power
    5
    Depends on what the size of Nex is in the cache. Check for us, I'm curious.
    Reply With Quote  
     

  5. #5  
    Registered Member
    Ebp90's Avatar
    Join Date
    Apr 2018
    Posts
    238
    Thanks given
    18
    Thanks received
    158
    Rep Power
    878
    Quote Originally Posted by databomb View Post
    Depends on what the size of Nex is in the cache. Check for us, I'm curious.
    They are all size 3. I am also having the same issue with General Graardor, he is able to attack an extra square farther with melee than he should be able to, and he is not on special. He is size 4.
    Reply With Quote  
     

  6. #6  
    EXALTED

    Join Date
    Nov 2012
    Posts
    393
    Thanks given
    35
    Thanks received
    33
    Rep Power
    5
    3 is the right size, so I'm thinking that there is something very wrong with your withinDistance(...) method. Snoop around in your NPC.java or whatever it might be called in your case, and look at the canAttack() or NPC processing methods to find the method that determines whether or not an NPC is within distance to perform an attack, post it here when you find it.

    I could be wrong but this seems like the only probable cause.
    Reply With Quote  
     

  7. #7  
    Registered Member
    Ebp90's Avatar
    Join Date
    Apr 2018
    Posts
    238
    Thanks given
    18
    Thanks received
    158
    Rep Power
    878
    Quote Originally Posted by databomb View Post
    3 is the right size, so I'm thinking that there is something very wrong with your withinDistance(...) method. Snoop around in your NPC.java or whatever it might be called in your case, and look at the canAttack() or NPC processing methods to find the method that determines whether or not an NPC is within distance to perform an attack, post it here when you find it.

    I could be wrong but this seems like the only probable cause.
    Code:
    	public static boolean colides(int x1, int y1, int size1, int x2, int y2, int size2) {
    		int distanceX = x1 - x2;
    		int distanceY = y1 - y2;
    		return distanceX < size2 && distanceX > -size1 && distanceY < size2 && distanceY > -size1;
    	}
    
    	public static boolean isOnRange(int x1, int y1, int size1, int x2, int y2, int size2, int maxDistance) {
    		int distanceX = x1 - x2;
    		int distanceY = y1 - y2;
    		if (distanceX > size2 + maxDistance || distanceX < -size1 - maxDistance || distanceY > size2 + maxDistance || distanceY < -size1 - maxDistance)
    			return false;
    		return true;
    	}
    Reply With Quote  
     

  8. #8  
    EXALTED

    Join Date
    Nov 2012
    Posts
    393
    Thanks given
    35
    Thanks received
    33
    Rep Power
    5
    How is max distance determined?
    Reply With Quote  
     

  9. #9  
    Registered Member
    Ebp90's Avatar
    Join Date
    Apr 2018
    Posts
    238
    Thanks given
    18
    Thanks received
    158
    Rep Power
    878
    Quote Originally Posted by databomb View Post
    How is max distance determined?
    Here, just look at my NPCcombat

    Code:
    package com.rs.game.npc.combat;
    
    import com.rs.game.Animation;
    import com.rs.game.Entity;
    import com.rs.game.ForceMovement;
    import com.rs.game.World;
    import com.rs.game.WorldTile;
    import com.rs.game.npc.NPC;
    import com.rs.game.npc.familiar.Familiar;
    import com.rs.game.npc.godwars.GodWarMinion;
    import com.rs.game.npc.godwars.armadyl.KreeArra;
    import com.rs.game.npc.godwars.bandos.GeneralGraardor;
    import com.rs.game.npc.godwars.saradomin.CommanderZilyana;
    import com.rs.game.npc.godwars.zammorak.KrilTstsaroth;
    import com.rs.game.npc.godwars.zaros.Nex;
    import com.rs.game.player.Player;
    import com.rs.game.player.actions.BandosGodwars;
    import com.rs.game.player.content.Combat;
    import com.rs.utils.MapAreas;
    import com.rs.utils.Utils;
    
    public final class NPCCombat {
    
    	private NPC npc;
    	private int combatDelay;
    	private Entity target;
    
    	public NPCCombat(NPC npc) {
    		this.npc = npc;
    	}
    
    	public int getCombatDelay() {
    		return combatDelay;
    	}
    
    	/*
    	 * returns if under combat
    	 */
    	public boolean process() {
    		if (combatDelay > 0)
    			combatDelay--;
    		if (target != null) {
    		
    			if (!checkAll()) {
    				removeTarget();
    				return false;
    			
    			}
    			if (combatDelay <= 0)
    				combatDelay = combatAttack();
    			return true;
    		
    		}
    		return false;
    	}
    	
    	/*
    	 * return combatDelay
    	 */
    	private int combatAttack() {
    		Entity target = this.target; // prevents multithread issues
    		if (target == null)
    			return 0;
    		// if hes frooze not gonna attack
    		if (npc.getFreezeDelay() >= Utils.currentTimeMillis())
    			return 0;
    		
    		// check if close to target, if not let it just walk and dont attack
    		// this gameticket
    		NPCCombatDefinitions defs = npc.getCombatDefinitions();
    		int attackStyle = defs.getAttackStyle();
    		if (target instanceof Familiar && Utils.random(3) == 0) {
    			Familiar familiar = (Familiar) target;
    			Player player = familiar.getOwner();
    			if (player != null) {
    				target = player;
    				npc.setTarget(target);
    			}
    
    		}
    		// MAGE_FOLLOW and RANGE_FOLLOW follow close but can attack far unlike
    		// melee
    		int maxDistance = attackStyle == NPCCombatDefinitions.MELEE ? 0 : /*npc instanceof HarAkenTentacle ? 16 : */7;
    		if ((!(npc instanceof Nex))
    				&& !npc.clipedProjectile(target, maxDistance == 0))
    			return 0;
    		
    		if (npc.hasWalkSteps())
    			maxDistance += npc.getRun() ? 2 : 1;
    		int size = npc.getSize() ;
    		int targetSize = target.getSize();
    		if (!Utils.isOnRange(npc.getX(), npc.getY(), size, target.getX(), target.getY(), targetSize, maxDistance))
    			return 0;
    		if (Utils.colides(npc.getX(), npc.getY(), size, target.getX(), target.getY(), targetSize))
    			return 0;
    		addAttackedByDelay(target);
    		return CombatScriptsHandler.specialAttack(npc, target);
    	}
    
    	protected void doDefenceEmote(Entity target) {
    		/*
    		 * if (target.getNextAnimation() != null) // if has att emote already return;
    		 */
    		target.setNextAnimationNoPriority(new Animation(Combat.getDefenceEmote(target)));
    	}
    
    	public Entity getTarget() {
    		return target;
    	}
    
    	public void addAttackedByDelay(Entity target) { // prevents multithread
    		// issues
    
    		target.setAttackedBy(npc);
    		target.setAttackedByDelay(Utils.currentTimeMillis() + npc.getCombatDefinitions().getAttackDelay() * 600 + 600); // 8seconds
    	}
    
    	public void setTarget(Entity target) {
    		this.target = target;
    		npc.setNextFaceEntity(target);
    		if (!checkAll()) {
    			removeTarget();
    			return;
    		}
    		
    	}
    
    	public boolean checkAll() {
    		Entity target = this.target; // prevents multithread issues
    		if (target == null)
    			return false;
    		if (npc instanceof GeneralGraardor  && target.hasTeleported())
    			return false;
    		if (npc instanceof KreeArra  && target.hasTeleported())
    			return false;
    		if (npc instanceof CommanderZilyana && target.hasTeleported())
    			return false;
    		if (npc instanceof KrilTstsaroth && target.hasTeleported())
    			return false;
    		if (npc instanceof GodWarMinion && target.hasTeleported())
    			return false;
    		if (npc.isDead() || npc.hasFinished() || npc.isForceWalking() || target.isDead() || target.hasFinished() || npc.getPlane() != target.getPlane() ||(target.getX() == 2863 && target.getX() == 5354) )
    			return false;
    		if (npc.getFreezeDelay() >= Utils.currentTimeMillis())
    			return true; // if freeze cant move ofc
    		int distanceX = npc.getX() - npc.getRespawnTile().getX();
    		int distanceY = npc.getY() - npc.getRespawnTile().getY();
    		int size = npc.getSize();
    		int maxDistance;
    		int agroRatio = npc.getCombatDefinitions().getAgroRatio();
    		if (!npc.isNoDistanceCheck() && !npc.isCantFollowUnderCombat()) {
    			maxDistance = agroRatio > 32 ? agroRatio : 32;
    			if (!(npc instanceof Familiar)) {
    
    				if (npc.getMapAreaNameHash() != -1) {
    					// if out his area
    					if (!MapAreas.isAtArea(npc.getMapAreaNameHash(), npc) || (!npc.canBeAttackFromOutOfArea() && !MapAreas.isAtArea(npc.getMapAreaNameHash(), target))) {
    						npc.forceWalkRespawnTile();
    						return false;
    					}
    				} else if (distanceX > size + maxDistance || distanceX < -1 - maxDistance || distanceY > size + maxDistance || distanceY < -1 - maxDistance) {
    					// if more than 32 distance from respawn place	
    					npc.forceWalkRespawnTile();
    					return false;
    				}
    			}
    			maxDistance = agroRatio > 16 ? agroRatio : 16;
    			distanceX = target.getX() - npc.getX();
    			distanceY = target.getY() - npc.getY();
    			if (distanceX > size + maxDistance || distanceX < -1 - maxDistance || distanceY > size + maxDistance || distanceY < -1 - maxDistance) {
    				return false; // if target distance higher 16
    			}
    		} else {
    			distanceX = target.getX() - npc.getX();
    			distanceY = target.getY() - npc.getY();
    		}
    		// checks for no multi area :)
    		if (npc instanceof Familiar) {
    			Familiar familiar = (Familiar) npc;
    			if (!familiar.canAttack(target))
    				return false;
    		} else {
    			if (!npc.isForceMultiAttacked()) {
    				if (!target.isAtMultiArea() || !npc.isAtMultiArea()) {
    					if (npc.getAttackedBy() != target && npc.getAttackedByDelay() > Utils.currentTimeMillis())
    						return false;
    					if (target.getAttackedBy() != npc && target.getAttackedByDelay() > Utils.currentTimeMillis())
    						return false;
    				}
    			}
    		}
    		if (!npc.isCantFollowUnderCombat()) {
    			// if is under
    			int targetSize = target.getSize();
    			
    			 if (distanceX < size && distanceX > -targetSize && distanceY < size && distanceY > -targetSize && !target.hasWalkSteps())
    			
    			
    			if ( Utils.colides(npc.getX(), npc.getY(), size, target.getX(), target.getY(), targetSize)) {
    				npc.resetWalkSteps();
    				if (!npc.addWalkSteps(target.getX() + targetSize, npc.getY())) {
    					npc.resetWalkSteps();
    					if (!npc.addWalkSteps(target.getX() - size, npc.getY())) {
    						npc.resetWalkSteps();
    						if (!npc.addWalkSteps(npc.getX(), target.getY() + targetSize)) {
    							npc.resetWalkSteps();
    							if (!npc.addWalkSteps(npc.getX(), target.getY() - size)) {
    								return true;
    							}
    						}
    					}
    				}
    				return true;
    			}
    			if (npc.getCombatDefinitions().getAttackStyle() == NPCCombatDefinitions.MELEE && targetSize == 1 && size == 1 && Math.abs(npc.getX() - target.getX()) == 1 && Math.abs(npc.getY() - target.getY()) == 1 && !target.hasWalkSteps()) {
    				if (!npc.addWalkSteps(target.getX(), npc.getY(), 1))
    					npc.addWalkSteps(npc.getX(), target.getY(), 1);
    				return true;
    			}
    			int attackStyle = npc.getCombatDefinitions().getAttackStyle();
    			
    			
    			if (npc instanceof Nex) {
    				Nex nex = (Nex) npc;
    				maxDistance = nex.isFollowTarget() ? 0 : 7;
    				if (nex.getFlyTime() == 0
    						&& (distanceX > size + maxDistance
    								|| distanceX < -1 - maxDistance
    								|| distanceY > size + maxDistance || distanceY < -1
    								- maxDistance)) {
    					npc.resetWalkSteps();
    					npc.addWalkStepsInteract(target.getX(), target.getY(), 2,
    							size, true);
    					if (!npc.hasWalkSteps()) {
    						int[][] dirs = Utils.getCoordOffsetsNear(size);
    						for (int dir = 0; dir < dirs[0].length; dir++) {
    							final WorldTile tile = new WorldTile(new WorldTile(
    									target.getX() + dirs[0][dir], target.getY()
    											+ dirs[1][dir], target.getPlane()));
    							if (World.canMoveNPC(tile.getPlane(), tile.getX(),
    									tile.getY(), size)) { // if found done
    								nex.setFlyTime(4);
    								npc.setNextForceMovement(new ForceMovement(
    										new WorldTile(npc), 0, tile, 1, Utils
    												.getMoveDirection(
    														tile.getX()
    																- npc.getX(),
    														tile.getY()
    																- npc.getY())));
    								npc.setNextAnimation(new Animation(6985));
    								npc.setNextWorldTile(tile);
    								return true;
    							}
    						}
    					}
    					return true;
    				} else
    					// if doesnt need to move more stop moving
    					npc.resetWalkSteps();
    			} else {
    				maxDistance = npc.isForceFollowClose() ? 0
    						: (attackStyle == NPCCombatDefinitions.MELEE || attackStyle == NPCCombatDefinitions.SPECIAL2) ? 0
    								: 7;
    				// is far from target, moves to it till can attack
    				if ((!npc.clipedProjectile(target, maxDistance == 0))
    						|| distanceX > size + maxDistance
    						|| distanceX < -1 - maxDistance
    						|| distanceY > size + maxDistance
    						|| distanceY < -1 - maxDistance) {
    					
    						
    					npc.resetWalkSteps();
    					npc.addWalkStepsInteract(target.getX(), target.getY(), 2,
    							size, true);
    					return true;
    				} else
    					// if doesnt need to move more stop moving
    					npc.resetWalkSteps();
    			
    				// if under target, moves
    			
    			}
    		}
    		return true;
    	}
    	public void addCombatDelay(int delay) {
    		combatDelay += delay;
    	}
    
    	public void setCombatDelay(int delay) {
    		combatDelay = delay;
    	}
    
    	public boolean underCombat() {
    		return target != null;
    	}
    
    	public void removeTarget() {
    		this.target = null;
    		npc.setNextFaceEntity(null);
    	}
    
    	public void reset() {
    		combatDelay = 0;
    		target = null; 
    		
    	}
    
    }
    Their agroRatios are 16
    Reply With Quote  
     

  10. #10  
    EXALTED

    Join Date
    Nov 2012
    Posts
    393
    Thanks given
    35
    Thanks received
    33
    Rep Power
    5
    EDIT:
    I have an issue where NPC models aren't actually in the game tile that the game thinks they are in.
    Forgive me, I didn't read this part. The distance to attack theory wouldn't apply to this. Not sure what would cause that, sorry!
    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

Similar Threads

  1. 634-667 Models
    By abdul100 in forum Requests
    Replies: 1
    Last Post: 10-16-2011, 11:52 PM
  2. [REQ]667 Models
    By BullETH in forum Models
    Replies: 9
    Last Post: 10-12-2011, 04:07 AM
  3. [PI] [NICK's] Model offset
    By Jeffrey in forum Help
    Replies: 7
    Last Post: 03-07-2011, 11:00 AM
  4. [#474 SSC] Model Loading Issue(Maps)
    By NICKname in forum Help
    Replies: 3
    Last Post: 05-13-2010, 08:20 PM
  5. Model loading issue.
    By Jon in forum Help
    Replies: 0
    Last Post: 11-12-2009, 03:24 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
  •