mirror of
https://github.com/ineedbots/iw4_bot_warfare.git
synced 2025-04-22 05:55:42 +00:00
use filesystem func
This commit is contained in:
parent
26acc1c792
commit
a7cd272b90
@ -73,7 +73,7 @@ getRemoteVersion()
|
|||||||
request = httpGet( "https://raw.githubusercontent.com/ineedbots/iw4x_waypoints/master/version.txt" );
|
request = httpGet( "https://raw.githubusercontent.com/ineedbots/iw4x_waypoints/master/version.txt" );
|
||||||
|
|
||||||
if (!isDefined(request))
|
if (!isDefined(request))
|
||||||
return result;
|
return undefined;
|
||||||
|
|
||||||
request waittill( "done", success, data );
|
request waittill( "done", success, data );
|
||||||
|
|
||||||
|
@ -702,30 +702,61 @@ parseTokensIntoWaypoint(tokens)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Loads waypoints from tables (iw4x will insert csv's into the game's filesystem, no need for them to be in a ff)
|
Returns an array of each line
|
||||||
*/
|
*/
|
||||||
// https://github.com/leiizko/cod4x_lua_plugin/blob/master/LuaScripts/Rotu-R/waypoints.gsc
|
getWaypointLinesFromFile(filename)
|
||||||
wpsFromCSV(mapname)
|
|
||||||
{
|
{
|
||||||
fileName = "waypoints/"+ toLower(mapname) + "_wp.csv";
|
result = spawnStruct();
|
||||||
|
result.lines = [];
|
||||||
|
|
||||||
|
waypointStr = fileRead(filename);
|
||||||
|
|
||||||
|
if (!isDefined(waypointStr))
|
||||||
|
return result;
|
||||||
|
|
||||||
|
line = "";
|
||||||
|
for (i=0;i<waypointStr.size;i++)
|
||||||
|
{
|
||||||
|
c = waypointStr[i];
|
||||||
|
|
||||||
|
if (c == "\n")
|
||||||
|
{
|
||||||
|
result.lines[result.lines.size] = line;
|
||||||
|
|
||||||
|
line = "";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
line += c;
|
||||||
|
}
|
||||||
|
result.lines[result.lines.size] = line;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Loads waypoints from file
|
||||||
|
*/
|
||||||
|
readWpsFromFile(mapname)
|
||||||
|
{
|
||||||
waypoints = [];
|
waypoints = [];
|
||||||
|
filename = "waypoints/" + mapname + "_wp.csv";
|
||||||
|
|
||||||
waypointCount = int(tableLookupByRow(fileName, 0, 0));
|
if (!fileExists(filename))
|
||||||
|
|
||||||
if (waypointCount <= 0)
|
|
||||||
return waypoints;
|
return waypoints;
|
||||||
|
|
||||||
printLn( "Getting waypoints from csv: "+fileName );
|
res = getWaypointLinesFromFile(filename);
|
||||||
|
|
||||||
|
if (!res.lines.size)
|
||||||
|
return waypoints;
|
||||||
|
|
||||||
|
println("Attempting to read waypoints from " + filename);
|
||||||
|
|
||||||
|
waypointCount = int(res.lines[0]);
|
||||||
|
|
||||||
for (i = 1; i <= waypointCount; i++)
|
for (i = 1; i <= waypointCount; i++)
|
||||||
{
|
{
|
||||||
tokens = [];
|
tokens = tokenizeLine(res.lines[i], ",");
|
||||||
tokens[tokens.size] = tableLookupByRow(fileName, i, 0);
|
|
||||||
tokens[tokens.size] = tableLookupByRow(fileName, i, 1);
|
|
||||||
tokens[tokens.size] = tableLookupByRow(fileName, i, 2);
|
|
||||||
tokens[tokens.size] = tableLookupByRow(fileName, i, 3);
|
|
||||||
tokens[tokens.size] = tableLookupByRow(fileName, i, 4);
|
|
||||||
|
|
||||||
waypoint = parseTokensIntoWaypoint(tokens);
|
waypoint = parseTokensIntoWaypoint(tokens);
|
||||||
|
|
||||||
@ -745,7 +776,7 @@ load_waypoints()
|
|||||||
|
|
||||||
mapname = getDvar("mapname");
|
mapname = getDvar("mapname");
|
||||||
|
|
||||||
wps = wpsFromCSV(mapname);
|
wps = readWpsFromFile(mapname);
|
||||||
|
|
||||||
if (wps.size)
|
if (wps.size)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user