So somehow I got it working with a timer:
PHP Code:
bool ReadDataFile()
{
float vecs[3];
Handle kvNew = CreateKeyValues("Locations");
BuildPath(Path_SM, szDataFile, sizeof(szDataFile), "data/sm_vec/sm_vec_%s.nav", g_szMapName);
FileToKeyValues(kvNew, szDataFile);
ArrayList path = new ArrayList(3); // create a dynamic list, hold enough space for a float[3]
for (int i = 1; i <= 12; i++)
{
// read the vector from your config file...
Format(Position, sizeof(Position), "Position%i", i);
KvJumpToKey(kvNew, Position, true);
KvGetVector(kvNew, NULL_STRING, vecs);
if(i == 12)
{
// PrintToChatAll("Vector: %f : %f : %f", vecs[0], vecs[1], vecs[2]);
Handle h=CreateDataPack();
WritePackFloat(h, vecs[0]);
WritePackFloat(h, vecs[1]);
WritePackFloat(h, vecs[2]);
CreateTimer(0.01, CheckTurn, h, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
KvRewind(kvNew);
// push your path coords onto the array
path.PushArray(vecs);
}
SetConVarInt(g_hVecSetup, 0);
SetConVarInt(g_hVecOn, 1);
CloseHandle(kvNew);
// below is mostly copied from CreateAll() the other post, I'm going to assume it works
char trackname[32];
char prevtrackname[32];
// iterate backwards from the last path entry to the first and create the tracks
for (int i = path.Length; i-- > 0;)
{
path.GetArray(i, vecs);
FormatEx( trackname, sizeof( trackname ), "_track%i", i );
CreatePath( trackname, vecs, prevtrackname );
strcopy( prevtrackname, sizeof( prevtrackname ), trackname );
}
delete path; // this closes our ArrayList instance
// Create func_tracktrain
int tracktrain = CreateTrackTrain( "_train", "_track0", "200" );
// Create our "helicopter"
int prop = CreateTrainProp( "_prop" );
// Parent it to func_tracktrain
ParentToEntity( prop, tracktrain );
return true;
}
and in the timer:
PHP Code:
public Action CheckTurn(Handle timer,any h)
{
ResetPack(h);
float pos[3];
pos[0]=ReadPackFloat(h);
pos[1]=ReadPackFloat(h);
pos[2]=ReadPackFloat(h);
float vecs[3];
int ent = -1;
while ((ent = FindEntityByClassname(ent, "func_tracktrain")) != -1)
{
if (IsValidEntity(ent))
{
GetEntPropVector(ent, Prop_Send, "m_vecOrigin", vecs);
// PrintToChatAll("Vector: %f: %f: %f",vecs[0], vecs[1], vecs[2] );
float distance;
distance = GetVectorDistance(pos, vecs);
if (distance < 50)
{
AcceptEntityInput(ent, "Reverse");
}
}
}
}
maybe there is an easier method or better way someone knows here ?