Skip to content

Commit 51351d3

Browse files
author
Kristo Isberg
committed
added GetPathNodeIndex (#1)
1 parent 324c548 commit 51351d3

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

GPS.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ native bool:IsValidPath(Path:pathid);
4141
native GetPathSize(Path:pathid, &size);
4242
native GetPathLength(Path:pathid, &Float:length);
4343
native GetPathNode(Path:pathid, index, &MapNode:nodeid);
44+
native GetPathNodeIndex(Path:pathid, MapNode:nodeid, &index);
4445
native DestroyPath(Path:pathid);
4546

4647

src/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ AMX_NATIVE_INFO PluginNatives[] = {
5757
{"GetPathSize", Natives::GetPathSize},
5858
{"GetPathLength", Natives::GetPathLength},
5959
{"GetPathNode", Natives::GetPathNode},
60+
{"GetPathNodeIndex", Natives::GetPathNodeIndex},
6061
{"DestroyPath", Natives::DestroyPath},
6162

6263
{0, 0}

src/natives.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,39 @@ namespace Natives {
364364
}
365365

366366

367+
cell AMX_NATIVE_CALL GetPathNodeIndex(AMX* amx, cell* params) {
368+
CHECK_PARAMS(3);
369+
370+
int id = static_cast<int>(params[1]);
371+
Path* path = Pathfinder::GetPathByID(id);
372+
373+
if (path == nullptr) {
374+
return GPS_ERROR_INVALID_PATH;
375+
}
376+
377+
int nodeid = static_cast<int>(params[2]);
378+
Node* node = Pathfinder::GetNodeByID(nodeid);
379+
380+
if (node == nullptr) {
381+
return GPS_ERROR_INVALID_NODE;
382+
}
383+
384+
std::deque<Node*> nodes = path->getNodes();
385+
386+
for (unsigned int i = 0; i < nodes.size(); i++) {
387+
if (nodes.at(i) == node) {
388+
cell* addr = NULL;
389+
amx_GetAddr(amx, params[3], &addr);
390+
*addr = i;
391+
392+
return GPS_ERROR_NONE;
393+
}
394+
}
395+
396+
return GPS_ERROR_INVALID_NODE;
397+
}
398+
399+
367400
cell AMX_NATIVE_CALL DestroyPath(AMX* amx, cell* params) {
368401
CHECK_PARAMS(1);
369402

src/natives.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@ namespace Natives {
4040
cell AMX_NATIVE_CALL GetPathSize(AMX* amx, cell* params);
4141
cell AMX_NATIVE_CALL GetPathLength(AMX* amx, cell* params);
4242
cell AMX_NATIVE_CALL GetPathNode(AMX* amx, cell* params);
43+
cell AMX_NATIVE_CALL GetPathNodeIndex(AMX* amx, cell* params);
4344
cell AMX_NATIVE_CALL DestroyPath(AMX* amx, cell* params);
4445
}

test.pwn

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,17 @@ Test(MapNode:start, MapNode:target) {
8282

8383

8484
Test2(Path:path) {
85-
new Float:x, Float:y, Float:z, size, Float:length, MapNode:node;
85+
new Float:x, Float:y, Float:z, size, Float:length, MapNode:node, index;
8686
GetPathSize(path, size);
8787
GetPathLength(path, length);
8888

8989
printf("Valid: %s | Distance: %fm | Amount of nodes: %i", IsValidPath(path) ? ("Yes") : ("No"), length, size);
9090

9191
for (new i; i < size; i++) {
9292
GetPathNode(path, i, node);
93+
GetPathNodeIndex(path, node, index);
9394
GetMapNodePos(node, x, y, z);
94-
printf("%i: %f %f %f", i + 1, x, y, z);
95+
printf("%i: %f %f %f %i %s", i + 1, x, y, z, index + 1, (i == index) ? ("YES") : ("NO"));
9596
}
9697

9798
DestroyPath(path);

0 commit comments

Comments
 (0)