Newbie Spellweaver
- Joined
- Nov 26, 2015
- Messages
- 61
- Reaction score
- 0
anyone know how to add distance check for npc? make player must be in the same platform as the npc to click
Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!
Join Today!Look at the AbstractMapleMapObject class for position, AbstractLoadedMapleLife for footholds.
cm.getPlayer().getPosition().x for X position
cm.getPlayer().getPosition().y for Y position
if (cm.getPlayer().getPosition().x >= leftSide && cm.getPlayer().getPosition().x <= rightSide && cm.getPlayer().getPosition().y == yPosition)
Code:cm.getPlayer().getPosition().x for X position cm.getPlayer().getPosition().y for Y position
So if you wanted to check if someone is on a certain platform
Code:if (cm.getPlayer().getPosition().x >= leftSide && cm.getPlayer().getPosition().x <= rightSide && cm.getPlayer().getPosition().y == yPosition)
How do you check for your position? Take a look at your source to see how to find your position
This is only in reference to v0.83 sources, I don't know how other sources do it
Good luck!
If your base is v0.83, you should have the command !mynpcpos, it'll show you X position and Y position. No coding is needed for NPCConversationManager. leftSide and rightSide are numbers you can find with !mynpcpos
//readInt for NPC's object ID
~~
short xpos = slea.readShort();
short ypos = slea.readShort();
if (Math.abs(npc.getPosition().x - xpos) > 1200 || Math.abs(npc.getPosition().y - ypos) > 800) {//change the distance as you wish
return;
}
Uhh, you're talking about SelectNpc (NPCTalkHandler), right?
There should be an int to check player's position
Code://readInt for NPC's object ID ~~ short xpos = slea.readShort(); short ypos = slea.readShort(); if (Math.abs(npc.getPosition().x - xpos) > 1200 || Math.abs(npc.getPosition().y - ypos) > 800) {//change the distance as you wish return; }
That's for NPCTalkHandler.Yeah Yuuroido. Can i know where should i add it in? Hmm. Yeah i summon an npc on the map like JQ and i want them must be on the platform to click the npc
var npc = cm.getPlayer().getMap().getNPCById(npcid here);
var npcPos = npc.getPosition();
var playerPos = cm.getPlayer().getPosition();
if (Math.sqrt(Math.pow(npcPos.x - playerPos.x, 2) + Math.pow(npcPos.y - playerPos.y, 2)) > 50) {//whatever
return;
}
That's for NPCTalkHandler.
1. Create GameConstants.getNPCClickableRange(int npcId) or something that return distance you can click the npc.
or
2. Create MapleMap#getNPCById to get the npc in a map and call from npc script.
Code:var npc = cm.getPlayer().getMap().getNPCById(npcid here); var npcPos = npc.getPosition(); var playerPos = cm.getPlayer().getPosition(); if (Math.sqrt(Math.pow(npcPos.x - playerPos.x, 2) + Math.pow(npcPos.y - playerPos.y, 2)) > 50) {//whatever return; }
Thanks for helping. So if im doing the second optoin. This is what i had to do? i need to paste this is anywhere inside MapleMap? What you mean by create MapleMap#getNPCByID? do u mean i need to create this getnpcbyid function in MapleMap.java to call from npc script? so after i insert this into the maplemap.java do i still need to add anything in my NPC Scripts?
var npc = cm.getPlayer().getMap().getNPCById(9000030);
var npcPos = npc.getPosition();
var playerPos = cm.getPlayer().getPosition();
if (Math.sqrt(Math.pow(npcPos.x - playerPos.x, 2) + Math.pow(npcPos.y - playerPos.y, 2)) > 50) {//whatever
return;
}
I mean, If you don't have getNPCById in MapleMap.java then create it. (search on google or look MapleMap carefully and think what you should add)
Also, that code should be in your NPC script.