public OnPlayerClosestNodeIDChange(playerid,old_NodeID,new_NodeID){ new strr[128]; format(strr,128,"Old %d New %d",old_NodeID,new_NodeID); SendClientMessageToAll(-1,strr); return true; }
print("1"); new car = GetPlayerVehicleID(playerid); node++; new Float:x,Float:y,Float:z; print("2"); GetVehiclePos(car,x,y,z); print("3"); AddNode(x,y,z,1, 1); new str[256]; format(str,256,"node %d",node); print("4"); CreateDynamic3DTextLabel(str, 0xFF0000FF, x, y, z+5,50); print("5");
//example for RebuildGraph
#include <a_samp>
#include <RouteConnector>
#define MY_NODES (5)
new Float:ArrayWithPositions[MY_NODES][3] =
{
{0.0,0.0,0.0},
{1.0,1.0,1.0},
{2.0,2.0,2.0},
{3.0,3.0,3.0},
{4.0,4.0,4.0}
};
new SavedNodeIDS[MY_NODES];
new Errors[2] = {0,0};
public OnFilterScriptInit()
{
//create nodes
for(new index = 0; index < MY_NODES; ++index)
{
SavedNodeIDS[index] = AddNode(ArrayWithPositions[index][0],ArrayWithPositions[index][1],ArrayWithPositions[index][2]);
if(SavedNodeIDS[index] == (-1))
{
++Errors[0];
}
}
//connect nodes
for(new index = 1; index < MY_NODES; ++index)
{
if(SavedNodeIDS[index-1] != (-1) && SavedNodeIDS[index] != (-1))
{
if(ConnectNodes(SavedNodeIDS[index-1],SavedNodeIDS[index]) < 0)
{
++Errors[1];
}
}
}
//rebuild graph
if(RebuildGraph())//server freezes until graph is rebuild, should take a few miliseconds
{
if(Errors[0] || Errors[1])
{
printf("Graph rebuilded succesfully but failed adding %d nodes and failed to create %d connections.",Errors[0],Errors[1]);
}
else
{
printf("Graph rebuilded succesfully without errors.");
}
}
else
{
if(Errors[0] || Errors[1])
{
printf("Graph rebuild FAILED, %d nodes could not be added and creating %d connections failed.",Errors[0],Errors[1]);
}
else
{
printf("Graph rebuild FAILED but all nodes were added succesfully.");
}
}
return 1;
}
new File:f = fopen("Nodes.txt",io_read); print("2"); new str[256]; new indexx; while(fread(f,str)){ new Float:x,Float:y,Float:z; sscanf(str, "p<|>fff", x, y, z); //sscanf plugin :) // printf("%f %f %f",x, y, z); SavedNodeIDS[indexx] = AddNode(x, y, z); if(SavedNodeIDS[indexx] == (-1)) { print("ERROR"); ++Errors[0]; } indexx++; } fclose(f); print("4"); //connect nodes for(new index = 1; index < MY_NODES; ++index) { if(SavedNodeIDS[index-1] != (-1) && SavedNodeIDS[index] != (-1)) { if(ConnectNodes(SavedNodeIDS[index-1],SavedNodeIDS[index]) < 0) { print("ERROR 2"); ++Errors[1]; } } } print("creating graph !!!!!!!!!!!"); //rebuild graph if(RebuildGraph())//server freezes until graph is rebuild, should take a few miliseconds { if(Errors[0] || Errors[1]) { printf("Graph rebuilded succesfully but failed adding %d nodes and failed to create %d connections.",Errors[0],Errors[1]); } else { printf("Graph rebuilded succesfully without errors."); } } else { if(Errors[0] || Errors[1]) { printf("Graph rebuild FAILED, %d nodes could not be added and creating %d connections failed.",Errors[0],Errors[1]); } else { printf("Graph rebuild FAILED but all nodes were added succesfully."); } }
-892.458129|1273.021728|35.418518 -896.376647|1263.579833|34.825996 -893.042053|1248.275878|34.745880 -887.429809|1233.633300|35.088066 -883.389709|1216.690673|33.656955 -884.337829|1196.213745|31.959152 -890.417846|1175.161621|30.537527 -886.196411|1151.811767|28.928644 -879.719177|1127.689697|27.161552
I have this
Code:
new File:f = fopen("Nodes.txt",io_read); print("2"); new str[256]; new indexx; while(fread(f,str)){ new Float:x,Float:y,Float:z; sscanf(str, "p<|>fff", x, y, z); //sscanf plugin :) // printf("%f %f %f",x, y, z); SavedNodeIDS[indexx] = AddNode(x, y, z); if(SavedNodeIDS[indexx] == (-1)) { print("ERROR"); ++Errors[0]; } indexx++; } fclose(f); print("4"); //connect nodes for(new index = 1; index < MY_NODES; ++index) { if(SavedNodeIDS[index-1] != (-1) && SavedNodeIDS[index] != (-1)) { if(ConnectNodes(SavedNodeIDS[index-1],SavedNodeIDS[index]) < 0) { print("ERROR 2"); ++Errors[1]; } } } print("creating graph !!!!!!!!!!!"); //rebuild graph if(RebuildGraph())//server freezes until graph is rebuild, should take a few miliseconds { if(Errors[0] || Errors[1]) { printf("Graph rebuilded succesfully but failed adding %d nodes and failed to create %d connections.",Errors[0],Errors[1]); } else { printf("Graph rebuilded succesfully without errors."); } } else { if(Errors[0] || Errors[1]) { printf("Graph rebuild FAILED, %d nodes could not be added and creating %d connections failed.",Errors[0],Errors[1]); } else { printf("Graph rebuild FAILED but all nodes were added succesfully."); } } In Nodes.txt i have Code:
-892.458129|1273.021728|35.418518 -896.376647|1263.579833|34.825996 -893.042053|1248.275878|34.745880 -887.429809|1233.633300|35.088066 -883.389709|1216.690673|33.656955 -884.337829|1196.213745|31.959152 -890.417846|1175.161621|30.537527 -886.196411|1151.811767|28.928644 -879.719177|1127.689697|27.161552 |
if(!strcmp("/3",cmdtext)){ new nodeID = NearestPlayerNode(playerid); new nodeID2 = NearestNodeFromPoint(0,0,5); print("CalculatePath"); CalculatePath(nodeID,nodeID2,playerid, .GrabNodePositions = true); return 1; }