Welcome!

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!

Distance check for NPC

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
 
Junior Spellweaver
Joined
Apr 30, 2012
Messages
100
Reaction score
41
Look at the AbstractMapleMapObject class for position, AbstractLoadedMapleLife for footholds.
 
Upvote 0
Newbie Spellweaver
Joined
Nov 26, 2015
Messages
61
Reaction score
0
Look at the AbstractMapleMapObject class for position, AbstractLoadedMapleLife for footholds.

Sorry, i have no knowledge on this distance chk. can i know how does the command like? and where i should put in. i think npcconversation java is a must/
 
Upvote 0
Junior Spellweaver
Joined
Dec 21, 2013
Messages
140
Reaction score
3
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!
 
Upvote 0
Newbie Spellweaver
Joined
Nov 26, 2015
Messages
61
Reaction score
0
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!

Hey modify. yeah i need it for v83. well the X and Y distance where can i check it in my source? and i should insert the code below in my js? do i need to do any coding in npcconversationmanager?
if (cm.getPlayer().getPosition().x >= leftSide && cm.getPlayer().getPosition().x <= rightSide && cm.getPlayer().getPosition().y == yPosition)


the leftSide and rightSide (is the number of the map) right?
 
Upvote 0
Junior Spellweaver
Joined
Dec 21, 2013
Messages
140
Reaction score
3
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
 
Upvote 0
Newbie Spellweaver
Joined
Nov 26, 2015
Messages
61
Reaction score
0
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

I see! thank you very much for the help tho! imma try it now haha uhh, im sorry which position is the right side? there has CY / RX0 /R / RX1

and what do i need to put in the y Position? or leave it empty?

if (cm.getPlayer().getPosition().x >= 123 && cm.getPlayer().getPosition().x <= 123 && cm.getPlayer().getPosition().y == yPosition)

is it like this?


Oh im sorry, if im using the npc at different JQS map. with the same npc. will the position all get changed? Is there anyway to add like player must be in position range of 50 to click the npc.
 
Last edited:
Upvote 0
Skilled Illusionist
Joined
Jul 17, 2010
Messages
333
Reaction score
165
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;
}
 
Upvote 0
Newbie Spellweaver
Joined
Nov 26, 2015
Messages
61
Reaction score
0
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;
}


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
 
Upvote 0
Skilled Illusionist
Joined
Jul 17, 2010
Messages
333
Reaction score
165
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
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;
}
 
Upvote 0
Newbie Spellweaver
Joined
Nov 26, 2015
Messages
61
Reaction score
0
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;
}
 
Upvote 0
Skilled Illusionist
Joined
Jul 17, 2010
Messages
333
Reaction score
165
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.
 
Upvote 0
Newbie Spellweaver
Joined
Nov 26, 2015
Messages
61
Reaction score
0
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.

I doesnt have any getNPCById function in my MapleMap.java so can i have the function of it?

and for this
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 need to add this in my NPC scripts???


And also add this in NPcTalkHandler?
//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;
}


Sorry i might be asking many idiot question.. as im a newbie on this but i hope that you can guide me how to make it
 
Upvote 0
Back
Top