Quote: |
case EVENT_PlayerMove:
{ Player *p = (Player*)event.p[0] //provided by catid. if (p->tile.x == # && p->tile.y == #) { /* they are on tile. */ } } |
Code: Show/Hide // functions go in the DLL "import" section bool closeto(Player *p, int x, int y, int tolerance) { return (abs((p->tile.x) - x) < tolerance) && (abs((p->tile.y) - y) < tolerance); } inline int abs(int n) { if (n < 0) return -n; else return n; } case EVENT_PlayerMove: { Player *p = (Player*)event.p[0]; int radius = 30; if (p->ship != SHIP_Spectator) if (closeto(p, 512, 512, radius)){ // do action here } |
Code: Show/Hide bool closeto(Player *p, int x, int y, int tolerance)
{ int deltax = p->tile.x - x; int deltay = p->tile.y - y; return (tolerance * tolerance >= deltax*deltax + deltay*deltay); } |
Underlord wrote: |
almost exactly from the tutorial |
50% Packetloss wrote: |
you could use the distance formula too, to measure the distance between a point and a player then see if they are within the distance you want |
Quote: |
Mr. Ekted - Every known C/C++ system has abs as a basic function/macro. There's no need to redefine it, especially when it requires the use of 2 returns. |
Code: Show/Hide int __cdecl abs(int); |
Underlord wrote: |
The Dr Brain version looks better anyways. |
Code: Show/Hide if(p->tile.x >= x1 && p->tile.y >= y1 && p->tile.x <=x2 && p->tile.y <=y2)
|
Code: Show/Hide #include <windows.h>
#define TOLERANCE 100 #define TIMER_TAG_INDEX 151561 #define X1 512 #define X2 520 #define Y1 512 #define Y2 520 #define WARPTO_X 450 #define WARPTO_Y 430 |
Code: Show/Hide if(p->tile.x >= X1 && p->tile.y >= Y1 && p->tile.x <=X2 && p->tile.y <=Y2) // Player is in region { int curTime = GetTickCount() / 10 ; int lastWarpTime = get_tag(p, TIMER_TAG_INDEX); if (curTime - lastWarpTime > TOLERANCE) // player wasn't just warped { sendPrivate(p,"*warpto" + (String)WARPTO_X + " " + (String)WARPTO_Y); set_tag(p, TIMER_TAG_INDEX, curTime); } } |
Code: Show/Hide #include <windows.h>
#define TOLERANCE 100 #define TIMER_TAG_INDEX 151561 |
Code: Show/Hide #include <vector>
using namespace std; struct WarpRect { int x1,x2,y1,y2,warpto_x,warpto_y; WarpRect(int _x1, int _x2, int _y1, int _y2, int _warpto_x, int _warpto_y) { x1 = _x1; x2 = _x2; y1 = _y1; y2 = _y2; warpto_x = _warpto_x; warpto_y = _warpto_y; } bool contains(Player *p) { bool rv = false; if(p->tile.x >= x1 && p->tile.y >= y1 && p->tile.x <= x2 && p->tile.y <= y2) // Player is in region { rv = true; } return rv; } }; |
Code: Show/Hide vector <WarpRect> warpRects;
botInfo(CALL_HANDLE given) { warpRects.push_back(WarpRect(512,600,512,600,400,400)); warpRects.push_back(WarpRect(200,250,200,250,100,100)); warpRects.push_back(WarpRect(10,20,10,20,1000,1000)); warpRects.push_back(WarpRect(600,650,12,20,80,900)); |
Code: Show/Hide case EVENT_PlayerMove:
{ Player *p = (Player*)event.p[0]; for (unsigned int x = 0; x < warpRects.size();++x) { if (warpRects[x].contains(p)) { int curTime = GetTickCount() / 10 ; int lastWarpTime = get_tag(p, TIMER_TAG_INDEX); if (curTime - lastWarpTime > TOLERANCE) // player wasn't just warped { sendPrivate(p,"*warpto" + (String)warpRects[x].warpto_x + " " + (String)warpRects[x].warpto_y); set_tag(p, TIMER_TAG_INDEX, curTime); } break; } } } |
Bak wrote: |
The only issue you might get is after the system is on 25 days where the integer variable will wrap around to negatives. Then new players may get warped more than once. I'll update the code to use centiseconds instead and it should solve this, as the value will always stay positive. Good catch Ekted. |
Code: Show/Hide if (time2 - time1 < tolerance && time1 - time2 > -tolerance) |