cannot cast undefined to bool: if(!range)
called from: loadPossave();
called from: self thread checksave();
called from: wait 0.01;
Code: Select all
watchMeleeKey() // for saving position
{
self endon("ufa_jump_threads");
for(;;)
{
if(self meleeButtonPressed() && self.sessionstate == "playing" && self isOnGround())
{
catch_next = false;
for(i=0; i<=0.25; i+=0.01) // allows 0.25 seconds for the next keypress
{
if(catch_next && self meleeButtonPressed())
{
self thread savePosition();
wait 2; // avoid overloading the server
break;
}
else if(!(self meleeButtonPressed()))
catch_next = true; // button was pressed/released once
wait 0.01;
}
}
wait 0.05;
}
}
watchMeleeKey_save() // for saving position
{
self endon("ufa_jump_threads");
for(;;)
{
if(self meleeButtonPressed() && self.sessionstate == "playing")
{
catch_next = false;
for(i=0; i<=0.25; i+=0.01) // allows 0.25 seconds for the next keypress
{
if(catch_next && self meleeButtonPressed())
{
self thread savePosition();
wait 1; // avoid overloading the server
break;
}
else if(!(self meleeButtonPressed()))
catch_next = true; // button was pressed/released once
wait 0.01;
}
}
wait 0.05;
}
}
watchUseKey() // for loading position
{
self endon("ufa_jump_threads");
for(;;)
{
if(self useButtonPressed())
{
catch_next = false;
for(i=0; i<=0.25; i+=0.01)
{
if(catch_next && self useButtonPressed())
{
self thread checksave();
wait 3.5;
break;
}
else if(!(self useButtonPressed()))
catch_next = true;
wait 0.01;
}
}
wait 0.05;
}
}
savePosition()
{
self.saved_origin = self.origin;
self.saved_angles = self.angles;
self iprintln("^2S^9ave ^2P^9osition^0: (^2" + (int)self.saved_origin[0] + "^0,^2" + (int)self.saved_origin[1] + "^0,^2" + (int)self.saved_origin[2] + "^0)");
}
checksave()
{
if (getcvar("ufa_jump"))
{
loadPossave();
}
else
{
loadPosition();
}
}
loadPosition()
{
thread positions();
if(!isDefined(self.saved_origin))
{
self iprintln("^1Error! ^3No Saved Position Available!");
return;
}
else
{
self setPlayerAngles(self.saved_angles); // angles need to come first
self setOrigin(self.saved_origin);
self iprintln("^5L^9oad ^5P^9osition^0: (^5" + (int)self.saved_origin[0] + "^0,^5" + (int)self.saved_origin[1] + "^0,^5" + (int)self.saved_origin[2] + "^0)");
}
}
loadPossave()
{
thread positions();
if(!isDefined(self.saved_origin))
{
self iprintln("^1Error! ^3No Saved Position Available!");
return;
}
else
if(self positions(70))
{
self iprintlnbold("A player is currently standing on that location!");
self iprintlnbold("Try again in a few sec.");
return;
}
else
{
self setPlayerAngles(self.saved_angles); // angles need to come first
self setOrigin(self.saved_origin);
self iprintln("^4L^9oad ^4P^9osition^0: (^4" + (int)self.saved_origin[0] + "^0,^4" + (int)self.saved_origin[1] + "^0,^4" + (int)self.saved_origin[2] + "^0)");
}
}
positions(range)
{
if (!range)
return true;
// Get all players and pick out the ones that are playing
allplayers = getentarray("player", "classname");
players = [];
for(i = 0; i < allplayers.size; i++)
{
if(allplayers[i].sessionstate == "playing")
players[players.size] = allplayers[i];
}
// Get the players that are in range
sortedplayers = sortByDist(players, self);
// Need at least 2 players (myself + one team mate)
if(sortedplayers.size<2)
return false;
// First player will be myself so check against second player
distance = distance(self.saved_origin, sortedplayers[1].origin);
if( distance <= range )
return true;
else
return false;
}
sortByDist(points, startpoint, maxdist, mindist)
{
if(!isdefined(points))
return undefined;
if(!isdefineD(startpoint))
return undefined;
if(!isdefined(mindist))
mindist = -1000000;
if(!isdefined(maxdist))
maxdist = 1000000; // almost 16 miles, should cover everything.
sortedpoints = [];
max = points.size-1;
for(i = 0; i < max; i++)
{
nextdist = 1000000;
next = undefined;
for(j = 0; j < points.size; j++)
{
thisdist = distance(startpoint.origin, points[j].origin);
if(thisdist <= nextdist && thisdist <= maxdist && thisdist >= mindist)
{
next = j;
nextdist = thisdist;
}
}
if(!isdefined(next))
break; // didn't find one that fit the range, stop trying
sortedpoints[i] = points[next];
// shorten the list, fewer compares
points[next] = points[points.size-1]; // replace the closest point with the end of the list
points[points.size-1] = undefined; // cut off the end of the list
}
sortedpoints[sortedpoints.size] = points[0]; // the last point in the list
return sortedpoints;
}
PlayerinRange(range)
{
if(!range)
return true;
// Get all players and pick out the ones that are playing
allplayers = getentarray("player", "classname");
players = [];
for(i = 0; i < allplayers.size; i++)
{
if(allplayers[i].sessionstate == "playing")
players[players.size] = allplayers[i];
}
// Get the players that are in range
sortedplayers = sortByDist(players, self);
// Need at least 2 players (myself + one team mate)
if(sortedplayers.size<2)
return false;
// First player will be myself so check against second player
distance = distance(self.origin, sortedplayers[1].origin);
if( distance <= range )
return true;
else
return false;
}