1 decade ago by Nico
Hey guys so I'm trying to dynamically check whether or not the player is clicking on an NPC by looping through the array of EntityNpc's. If an entity is clicked on something should happen but the players weapon shouldn't fire.
It's super easy to just check whether ig.game.getEntitiesByType( EntityNpc )[0] is inFocus and then not fire if it is. But that doesn't scale at all...I feel like I'm on the right track but could use a push in the right direction.
Currently when I'm in a map with NPC's and I use the code as is, all the NPC's are affected by my click, no matter where I click on the screen.
Any help is greatly appreciated !
It's super easy to just check whether ig.game.getEntitiesByType( EntityNpc )[0] is inFocus and then not fire if it is. But that doesn't scale at all...I feel like I'm on the right track but could use a push in the right direction.
Currently when I'm in a map with NPC's and I use the code as is, all the NPC's are affected by my click, no matter where I click on the screen.
this.npcList = ig.game.getEntitiesByType( EntityNpc );
if(this.npcList.length > 0){
for( e in this.npcList ){
this.npc = ig.game.getEntitiesByType( EntityNpc )[e];
if(ig.input.pressed('click') && this.npc.inFocus ){
this.npc.vel.y = -150;
}else if(ig.input.pressed('click') && !this.npc.inFocus ){
this.shootSwitch();
}
}
}else if(this.npcList.length <= 0 && ig.input.pressed('click')){
this.shootSwitch();
}
Any help is greatly appreciated !
