![]() |
Hit Players and NPC's with ease.
1 Attachment(s)
Specify Width*Height to create a set of co-ordinates for a Hitbox in front of the player. Additionally specify x and y offsets if directly in front of the player isn't what your going for.
Usage. PHP Code:
PHP Code:
|
It will be better overall to use this function to pre-calculate the hit box's instead of calling it everytime. Like
PHP Code:
This way the function adds almost zero time to finding players in the box serverside. |
what does this "box" do?
|
The getHitBox() function now only requires you call it whenever you want to change
your hitbox size||position. This is a far better way to go than my first example. getHitBox( box, offset x, offset y) box is a 4 element array, { width, height, offset x, offset y} all these are re-oriented depending on the way the player is facing. ie, if you offset the hitbox so it always hits on the players right, it will always be on the players right, no matter how your facing. The function returns a 2d where hbox = {{x,y,w,h},{x,y,w,h},{x,y,w,h},{x,y,w,h}}; where each set of coordinates represents the 4 directions the player/npc is facing. This way instead of running the function whenever the player changes directions, it can just lookup the proper coordinates we stored here. For use with players, you will want to add offset x/y as 1.5,2 to account for the fact the players x and y are at his top left. You can also leave it blank, this is optional. If you use it with an npc you may want to adjust this to center the box on your npc. As for the speed of this script, I'd say it can't get much faster serverside. Certainly only running getHitBox() once isn't slowing things down at all. Only way to increase the speed of this script seems to be bringing the player/npc detection to the client. The way it is now might get laggy with 50 players or more pking constantly. Hard to say without some more experienced insights. PHP Code:
PHP Code:
Also, the "box" itself doesn't do anything except be a well placed, direction oriented box. This function just takes the need to do any calculating out of your hands, and generates the coordinates for a good hitbox for you. You could use the box for various random things, but it was initially intended for a fully custom melee dmg system. With various shaped hitbox's for different shaped/size melee weapons. Daggers, staves, swords, etc... punch. kick. Left handed daggers, right handed daggers, that not only look different, but hit differently. |
Personally I'd check if they were in the hit-box on the client-side then pass that list to the server, and do level/distance checks with a slight amount of leeway and hit them accordingly.
We had a system like this on Zodiac a year or two ago and our sword users would lag the server to hell because of the unoptimized script. |
Quote:
|
We've been using a system like this on Maloria for quite a while. We first do the box detection clientside, and if there's any eligble target(s), proceed to serverside where it will just make sure that said target(s) are still within the box and take action accordingly.
|
All times are GMT +2. The time now is 07:42 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.