You possibly added it in the wrong place, try adding it right under
Code:public class ***** {
|
I am looking at this error...
and I am confused... I can't use int variables?
Show more code
It was under the process function inside the NPCHandler class. All I did was make a function return an int and in the process function I made it store it into a variable. Seems right to me.
Here is the whole process method:
Code:public void process() { for (int i = 0; i < maxNPCs; i++) { if (npcs[i] == null) continue; npcs[i].clearUpdateFlags(); } for (int i = 0; i < maxNPCs; i++) { if (npcs[i] != null) { NPC n = npcs[i]; if (npcs[i].splashDelay > 0) npcs[i].splashDelay--; if (npcs[i].splashDelay == 4) { corpSplash(n); for (int p = 1; p < Server.playerHandler.players.length; p++) { c2 = allPlayers(p); if (c2 != null) { if (c2.getX() == npcs[i].splashCoord[0][0] && c2.getY() == npcs[i].splashCoord[0][1]) int duckIsHere; duckIsHere = c2.dealDamage(10); //c2.dealDamage(10); //Duck - Adjusted to make damage appear correctly. Read Player > dealDamage } } } else if (npcs[i].splashDelay == 0) { for (int p = 1; p < Server.playerHandler.players.length; p++) { c2 = allPlayers(p); for (int coords = 1; coords < npcs[i].splashCoord.length; coords++) { if (c2 != null) { if (c2.getX() == npcs[i].splashCoord[coords][0] && c2.getY() == npcs[i].splashCoord[coords][1]) int duckIsHere; duckIsHere = c2.dealDamage(10); //c2.dealDamage(10); //Duck - Adjusted to make damage appear correctly. Read Player > dealDamage c2.getPA().stillGfx(1808, npcs[i].splashCoord[coords][0], npcs[i].splashCoord[coords][1], 0, 0); } } } npcs[i].splashDelay = -1; } if (npcs[i].summonedFor > 0 && !npcs[i].isDead) summoningFollow(i, npcs[i].summonedFor); if (npcs[i].actionTimer > 0) { npcs[i].actionTimer--; } if (npcs[i].freezeTimer > 0) { npcs[i].freezeTimer--; } if (npcs[i].hitDelayTimer > 0) { npcs[i].hitDelayTimer--; } if (npcs[i].hitDelayTimer == 1) { npcs[i].hitDelayTimer = 0; applyDamage(i); } if(npcs[i].attackTimer > 0) { npcs[i].attackTimer--; } if(npcs[i].spawnedBy > 0) { if(Server.playerHandler.players[npcs[i].spawnedBy] == null || Server.playerHandler.players[npcs[i].spawnedBy].heightLevel != npcs[i].heightLevel || Server.playerHandler.players[npcs[i].spawnedBy].respawnTimer > 0 || !Server.playerHandler.players[npcs[i].spawnedBy].goodDistance(npcs[i].getX(), npcs[i].getY(), Server.playerHandler.players[npcs[i].spawnedBy].getX(), Server.playerHandler.players[npcs[i].spawnedBy].getY(), 20)) { if(Server.playerHandler.players[npcs[i].spawnedBy] != null) { for(int o = 0; o < Server.playerHandler.players[npcs[i].spawnedBy].barrowsNpcs.length; o++){ if(npcs[i].npcType == Server.playerHandler.players[npcs[i].spawnedBy].barrowsNpcs[o][0]) { if (Server.playerHandler.players[npcs[i].spawnedBy].barrowsNpcs[o][1] == 1) Server.playerHandler.players[npcs[i].spawnedBy].barrowsNpcs[o][1] = 0; } } } npcs[i] = null; } } if (npcs[i] == null) continue; /** * Attacking player **/ if (isAggressive(i) && !npcs[i].underAttack && !npcs[i].isDead && !switchesAttackers(i)) { npcs[i].killerId = getCloseRandomPlayer(i); } else if (isAggressive(i) && !npcs[i].underAttack && !npcs[i].isDead && switchesAttackers(i)) { npcs[i].killerId = getCloseRandomPlayer(i); } if (System.currentTimeMillis() - npcs[i].lastDamageTaken > 5000) npcs[i].underAttackBy = 0; if((npcs[i].killerId > 0 || npcs[i].underAttack) && !npcs[i].walkingHome && retaliates(npcs[i].npcType)) { if(!npcs[i].isDead) { int p = npcs[i].killerId; if(Server.playerHandler.players[p] != null) { Client c = (Client) Server.playerHandler.players[p]; followPlayer(i, c.playerId); if (npcs[i] == null) continue; if(npcs[i].attackTimer == 0) { if(c != null) { attackPlayer(c, i); } 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); } } } /** * Random walking and walking home **/ if (npcs[i] == null) continue; if((!npcs[i].underAttack || npcs[i].walkingHome) && npcs[i].randomWalk && !npcs[i].isDead) { npcs[i].facePlayer(0); npcs[i].killerId = 0; if(npcs[i].spawnedBy == 0) { if((npcs[i].absX > npcs[i].makeX + Config.NPC_RANDOM_WALK_DISTANCE) || (npcs[i].absX < npcs[i].makeX - Config.NPC_RANDOM_WALK_DISTANCE) || (npcs[i].absY > npcs[i].makeY + Config.NPC_RANDOM_WALK_DISTANCE) || (npcs[i].absY < npcs[i].makeY - Config.NPC_RANDOM_WALK_DISTANCE)) { npcs[i].walkingHome = true; } } if (npcs[i].walkingHome && npcs[i].absX == npcs[i].makeX && npcs[i].absY == npcs[i].makeY) { npcs[i].walkingHome = false; } else if(npcs[i].walkingHome) { npcs[i].moveX = GetMove(npcs[i].absX, npcs[i].makeX); npcs[i].moveY = GetMove(npcs[i].absY, npcs[i].makeY); npcs[i].getNextNPCMovement(i); npcs[i].updateRequired = true; } if(npcs[i].walkingType == 1) { if(Misc.random(3)== 1 && !npcs[i].walkingHome) { int MoveX = 0; int MoveY = 0; int Rnd = Misc.random(9); if (Rnd == 1) { MoveX = 1; MoveY = 1; } else if (Rnd == 2) { MoveX = -1; } else if (Rnd == 3) { MoveY = -1; } else if (Rnd == 4) { MoveX = 1; } else if (Rnd == 5) { MoveY = 1; } else if (Rnd == 6) { MoveX = -1; MoveY = -1; } else if (Rnd == 7) { MoveX = -1; MoveY = 1; } else if (Rnd == 8) { MoveX = 1; MoveY = -1; } if (MoveX == 1) { if (npcs[i].absX + MoveX < npcs[i].makeX + 1) { npcs[i].moveX = MoveX; } else { npcs[i].moveX = 0; } } if (MoveX == -1) { if (npcs[i].absX - MoveX > npcs[i].makeX - 1) { npcs[i].moveX = MoveX; } else { npcs[i].moveX = 0; } } if(MoveY == 1) { if(npcs[i].absY + MoveY < npcs[i].makeY + 1) { npcs[i].moveY = MoveY; } else { npcs[i].moveY = 0; } } if(MoveY == -1) { if(npcs[i].absY - MoveY > npcs[i].makeY - 1) { npcs[i].moveY = MoveY; } else { npcs[i].moveY = 0; } } int x = (npcs[i].absX + npcs[i].moveX); int y = (npcs[i].absY + npcs[i].moveY); if (VirtualWorld.I(npcs[i].heightLevel, npcs[i].absX, npcs[i].absY, x, y, 0)) npcs[i].getNextNPCMovement(i); else { npcs[i].moveX = 0; npcs[i].moveY = 0; } npcs[i].updateRequired = true; } } } if (npcs[i].isDead) { if (npcs[i].actionTimer == 0 && npcs[i].applyDead == false && npcs[i].needRespawn == false) { npcs[i].updateRequired = true; npcs[i].facePlayer(0); npcs[i].killedBy = getNpcKillerId(i); npcs[i].animNumber = getCombatEmote(i, "Death"); // dead emote npcs[i].animUpdateRequired = true; npcs[i].freezeTimer = 0; npcs[i].applyDead = true; npcs[i].splashDelay = -1; killedBarrow(i); if (isFightCaveNpc(i)) killedTzhaar(i); if (isBarbNpc(i)) killedBarb(i); npcs[i].actionTimer = 4; // delete time resetPlayersInCombat(i); } else if (npcs[i].actionTimer == 0 && npcs[i].applyDead == true && npcs[i].needRespawn == false) { npcs[i].needRespawn = true; npcs[i].actionTimer = getRespawnTime(i); // respawn time if (!npcs[i].inBarbDef()) dropItems(i); appendSlayerExperience(i); appendKillCount(i); npcs[i].absX = npcs[i].makeX; npcs[i].absY = npcs[i].makeY; npcs[i].HP = npcs[i].MaxHP; npcs[i].animNumber = 0x328; npcs[i].updateRequired = true; npcs[i].animUpdateRequired = true; if (npcs[i].npcType >= 2440 && npcs[i].npcType <= 2446) { Server.objectManager.removeObject(npcs[i].absX, npcs[i].absY); } if (npcs[i].npcType == 2745) { handleJadDeath(i); } } else if (npcs[i].actionTimer == 0 && npcs[i].needRespawn == true) { if(npcs[i].spawnedBy > 0 || npcs[i].summonedFor > 0) { npcs[i] = null; } else { int old1 = npcs[i].npcType; int old2 = npcs[i].makeX; int old3 = npcs[i].makeY; int old4 = npcs[i].heightLevel; int old5 = npcs[i].walkingType; int old6 = npcs[i].MaxHP; int old7 = npcs[i].maxHit/10; int old8 = npcs[i].attack; int old9 = npcs[i].defence; npcs[i] = null; newNPC(old1, old2, old3, old4, old5, old6, old7, old8, old9); } } } } } }
you are using an if-statement for the variable only since you didnt put any brasket....
try thisCode:public void process() { for (int i = 0; i < maxNPCs; i++) { if (npcs[i] == null) continue; npcs[i].clearUpdateFlags(); } int duckIsHere = 0; for (int i = 0; i < maxNPCs; i++) { if (npcs[i] != null) { NPC n = npcs[i]; if (npcs[i].splashDelay > 0) npcs[i].splashDelay--; if (npcs[i].splashDelay == 4) { corpSplash(n); for (int p = 1; p < Server.playerHandler.players.length; p++) { c2 = allPlayers(p); if (c2 != null) { if (c2.getX() == npcs[i].splashCoord[0][0] && c2.getY() == npcs[i].splashCoord[0][1]) duckIsHere = c2.dealDamage(10); //c2.dealDamage(10); //Duck - Adjusted to make damage appear correctly. Read Player > dealDamage } } } else if (npcs[i].splashDelay == 0) { for (int p = 1; p < Server.playerHandler.players.length; p++) { c2 = allPlayers(p); for (int coords = 1; coords < npcs[i].splashCoord.length; coords++) { if (c2 != null) { if (c2.getX() == npcs[i].splashCoord[coords][0] && c2.getY() == npcs[i].splashCoord[coords][1]) // int duckIsHere; duckIsHere = c2.dealDamage(10); //c2.dealDamage(10); //Duck - Adjusted to make damage appear correctly. Read Player > dealDamage c2.getPA().stillGfx(1808, npcs[i].splashCoord[coords][0], npcs[i].splashCoord[coords][1], 0, 0); } } } npcs[i].splashDelay = -1; } if (npcs[i].summonedFor > 0 && !npcs[i].isDead) summoningFollow(i, npcs[i].summonedFor); if (npcs[i].actionTimer > 0) { npcs[i].actionTimer--; } if (npcs[i].freezeTimer > 0) { npcs[i].freezeTimer--; } if (npcs[i].hitDelayTimer > 0) { npcs[i].hitDelayTimer--; } if (npcs[i].hitDelayTimer == 1) { npcs[i].hitDelayTimer = 0; applyDamage(i); } if(npcs[i].attackTimer > 0) { npcs[i].attackTimer--; } if(npcs[i].spawnedBy > 0) { if(Server.playerHandler.players[npcs[i].spawnedBy] == null || Server.playerHandler.players[npcs[i].spawnedBy].heightLevel != npcs[i].heightLevel || Server.playerHandler.players[npcs[i].spawnedBy].respawnTimer > 0 || !Server.playerHandler.players[npcs[i].spawnedBy].goodDistance(npcs[i].getX(), npcs[i].getY(), Server.playerHandler.players[npcs[i].spawnedBy].getX(), Server.playerHandler.players[npcs[i].spawnedBy].getY(), 20)) { if(Server.playerHandler.players[npcs[i].spawnedBy] != null) { for(int o = 0; o < Server.playerHandler.players[npcs[i].spawnedBy].barrowsNpcs.length; o++){ if(npcs[i].npcType == Server.playerHandler.players[npcs[i].spawnedBy].barrowsNpcs[o][0]) { if (Server.playerHandler.players[npcs[i].spawnedBy].barrowsNpcs[o][1] == 1) Server.playerHandler.players[npcs[i].spawnedBy].barrowsNpcs[o][1] = 0; } } } npcs[i] = null; } } if (npcs[i] == null) continue; /** * Attacking player **/ if (isAggressive(i) && !npcs[i].underAttack && !npcs[i].isDead && !switchesAttackers(i)) { npcs[i].killerId = getCloseRandomPlayer(i); } else if (isAggressive(i) && !npcs[i].underAttack && !npcs[i].isDead && switchesAttackers(i)) { npcs[i].killerId = getCloseRandomPlayer(i); } if (System.currentTimeMillis() - npcs[i].lastDamageTaken > 5000) npcs[i].underAttackBy = 0; if((npcs[i].killerId > 0 || npcs[i].underAttack) && !npcs[i].walkingHome && retaliates(npcs[i].npcType)) { if(!npcs[i].isDead) { int p = npcs[i].killerId; if(Server.playerHandler.players[p] != null) { Client c = (Client) Server.playerHandler.players[p]; followPlayer(i, c.playerId); if (npcs[i] == null) continue; if(npcs[i].attackTimer == 0) { if(c != null) { attackPlayer(c, i); } 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); } } } /** * Random walking and walking home **/ if (npcs[i] == null) continue; if((!npcs[i].underAttack || npcs[i].walkingHome) && npcs[i].randomWalk && !npcs[i].isDead) { npcs[i].facePlayer(0); npcs[i].killerId = 0; if(npcs[i].spawnedBy == 0) { if((npcs[i].absX > npcs[i].makeX + Config.NPC_RANDOM_WALK_DISTANCE) || (npcs[i].absX < npcs[i].makeX - Config.NPC_RANDOM_WALK_DISTANCE) || (npcs[i].absY > npcs[i].makeY + Config.NPC_RANDOM_WALK_DISTANCE) || (npcs[i].absY < npcs[i].makeY - Config.NPC_RANDOM_WALK_DISTANCE)) { npcs[i].walkingHome = true; } } if (npcs[i].walkingHome && npcs[i].absX == npcs[i].makeX && npcs[i].absY == npcs[i].makeY) { npcs[i].walkingHome = false; } else if(npcs[i].walkingHome) { npcs[i].moveX = GetMove(npcs[i].absX, npcs[i].makeX); npcs[i].moveY = GetMove(npcs[i].absY, npcs[i].makeY); npcs[i].getNextNPCMovement(i); npcs[i].updateRequired = true; } if(npcs[i].walkingType == 1) { if(Misc.random(3)== 1 && !npcs[i].walkingHome) { int MoveX = 0; int MoveY = 0; int Rnd = Misc.random(9); if (Rnd == 1) { MoveX = 1; MoveY = 1; } else if (Rnd == 2) { MoveX = -1; } else if (Rnd == 3) { MoveY = -1; } else if (Rnd == 4) { MoveX = 1; } else if (Rnd == 5) { MoveY = 1; } else if (Rnd == 6) { MoveX = -1; MoveY = -1; } else if (Rnd == 7) { MoveX = -1; MoveY = 1; } else if (Rnd == 8) { MoveX = 1; MoveY = -1; } if (MoveX == 1) { if (npcs[i].absX + MoveX < npcs[i].makeX + 1) { npcs[i].moveX = MoveX; } else { npcs[i].moveX = 0; } } if (MoveX == -1) { if (npcs[i].absX - MoveX > npcs[i].makeX - 1) { npcs[i].moveX = MoveX; } else { npcs[i].moveX = 0; } } if(MoveY == 1) { if(npcs[i].absY + MoveY < npcs[i].makeY + 1) { npcs[i].moveY = MoveY; } else { npcs[i].moveY = 0; } } if(MoveY == -1) { if(npcs[i].absY - MoveY > npcs[i].makeY - 1) { npcs[i].moveY = MoveY; } else { npcs[i].moveY = 0; } } int x = (npcs[i].absX + npcs[i].moveX); int y = (npcs[i].absY + npcs[i].moveY); if (VirtualWorld.I(npcs[i].heightLevel, npcs[i].absX, npcs[i].absY, x, y, 0)) npcs[i].getNextNPCMovement(i); else { npcs[i].moveX = 0; npcs[i].moveY = 0; } npcs[i].updateRequired = true; } } } if (npcs[i].isDead) { if (npcs[i].actionTimer == 0 && npcs[i].applyDead == false && npcs[i].needRespawn == false) { npcs[i].updateRequired = true; npcs[i].facePlayer(0); npcs[i].killedBy = getNpcKillerId(i); npcs[i].animNumber = getCombatEmote(i, "Death"); // dead emote npcs[i].animUpdateRequired = true; npcs[i].freezeTimer = 0; npcs[i].applyDead = true; npcs[i].splashDelay = -1; killedBarrow(i); if (isFightCaveNpc(i)) killedTzhaar(i); if (isBarbNpc(i)) killedBarb(i); npcs[i].actionTimer = 4; // delete time resetPlayersInCombat(i); } else if (npcs[i].actionTimer == 0 && npcs[i].applyDead == true && npcs[i].needRespawn == false) { npcs[i].needRespawn = true; npcs[i].actionTimer = getRespawnTime(i); // respawn time if (!npcs[i].inBarbDef()) dropItems(i); appendSlayerExperience(i); appendKillCount(i); npcs[i].absX = npcs[i].makeX; npcs[i].absY = npcs[i].makeY; npcs[i].HP = npcs[i].MaxHP; npcs[i].animNumber = 0x328; npcs[i].updateRequired = true; npcs[i].animUpdateRequired = true; if (npcs[i].npcType >= 2440 && npcs[i].npcType <= 2446) { Server.objectManager.removeObject(npcs[i].absX, npcs[i].absY); } if (npcs[i].npcType == 2745) { handleJadDeath(i); } } else if (npcs[i].actionTimer == 0 && npcs[i].needRespawn == true) { if(npcs[i].spawnedBy > 0 || npcs[i].summonedFor > 0) { npcs[i] = null; } else { int old1 = npcs[i].npcType; int old2 = npcs[i].makeX; int old3 = npcs[i].makeY; int old4 = npcs[i].heightLevel; int old5 = npcs[i].walkingType; int old6 = npcs[i].MaxHP; int old7 = npcs[i].maxHit/10; int old8 = npcs[i].attack; int old9 = npcs[i].defence; npcs[i] = null; newNPC(old1, old2, old3, old4, old5, old6, old7, old8, old9); } } } } } }
What changes did you make?
i placed the variable outside of the if/for-statements + there is no need to declare the same variable twice
That can not be the problem. I declared the same variable twice because it a local variable, not a global, so it is required.
If I set it like this:
I get this error:Code:if (c2.getX() == npcs[i].splashCoord[0][0] && c2.getY() == npcs[i].splashCoord[0][1]) int duckIsHere = c2.dealDamage(10);
If I set it like this:
I do not get an error...Code:if (c2.getX() == npcs[i].splashCoord[0][0] && c2.getY() == npcs[i].splashCoord[0][1]){ int duckIsHere; duckIsHere = c2.dealDamage(10); //c2.dealDamage(10); }
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |