Prawy

Untitled

Mar 4th, 2022 (edited)
16
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.84 KB | None
  1. getSpawnpoint_Random(spawnpoints)
  2. {
  3. // level endon("intermission");
  4.  
  5. // There are no valid spawnpoints in the map
  6. if(!isdefined(spawnpoints))
  7. return undefined;
  8.  
  9. for(i = 0; i < spawnpoints.size; i++)
  10. {
  11. j = randomInt(spawnpoints.size);
  12. spawnpoint = spawnpoints[i];
  13. spawnpoints[i] = spawnpoints[j];
  14. spawnpoints[j] = spawnpoint;
  15. }
  16.  
  17. // for(j = 0; j < spawnpoints.size; j++)
  18. // {
  19. // println("^6origin" , j, " is ", spawnpoints[j].origin);
  20. // }
  21.  
  22. for(i = 0; i < spawnpoints.size; i++)
  23. {
  24. spawnpoint = spawnpoints[i];
  25. if(!positionWouldTelefrag(spawnpoint.origin) && !would_telefrag(spawnpoint.origin)) {
  26. break;
  27. }
  28. }
  29.  
  30. return spawnpoint;
  31. }
  32.  
  33. // Picks a non-telefragging spawn point farthest from other players
  34. getSpawnpoint_Farthest(spawnpoints)
  35. {
  36. // level endon("intermission");
  37.  
  38. // There are no valid spawnpoints in the map
  39. if(!isdefined(spawnpoints))
  40. return undefined;
  41.  
  42. // TEMP DISABLED SPAWNING AWAY FROM PLAYERS
  43. /*
  44. // Make a list of fully connected, non-spectating, alive players
  45. players = getentarray("player", "classname");
  46. for(i = 0; i < players.size; i++)
  47. {
  48. player = players[i];
  49.  
  50. if(player.sessionstate == "spectator" || player.sessionstate == "dead" || player == self)
  51. {
  52. // println("### ", player.name, " not considered:");
  53. //
  54. // println(" player.sessionstate == ", player.sessionstate);
  55. //
  56. // if(player == self)
  57. // println(" player == self");
  58.  
  59. continue;
  60. }
  61.  
  62. positions = addorigin_to_array(positions, player);
  63. // println("*** ", player.name, " added to consider list");
  64. }
  65. */
  66. if(isdefined(level.deatharray))
  67. {
  68. if(!isdefined(positions))
  69. {
  70. positions[0] = level.deatharray[0];
  71.  
  72. for(i = 1; i < level.deatharray.size; i++)
  73. positions[positions.size] = level.deatharray[i];
  74. }
  75. else
  76. {
  77. for(i = 0; i < level.deatharray.size; i++)
  78. positions[positions.size] = level.deatharray[i];
  79. }
  80. }
  81.  
  82. // Spawn away from players if they exist, otherwise spawn at a random spawnpoint
  83. if(isdefined(positions))
  84. {
  85. // println("*** SPAWNING FARTHEST: ", self.name);
  86.  
  87. distsmallest = 33554432;
  88.  
  89. for(i = 0; i < spawnpoints.size; i++)
  90. {
  91. if(positionWouldTelefrag(spawnpoints[i].origin) || would_telefrag(spawnpoints[i].origin))
  92. continue;
  93.  
  94. dist = 0;
  95.  
  96. for(j = 0; j < positions.size; j++)
  97. {
  98. dist += 1.0 / (distance(spawnpoints[i].origin, positions[j]) + 1.0);
  99. }
  100.  
  101. if(dist < distsmallest)
  102. {
  103. distsmallest = dist;
  104. bestposition = spawnpoints[i];
  105. }
  106. }
  107.  
  108. spawnpoint = bestposition;
  109. }
  110. else
  111. {
  112. // println("*** SPAWNING RANDOM: ", self.name);
  113. spawnpoint = getSpawnpoint_Random(spawnpoints);
  114. }
  115.  
  116. return spawnpoint;
  117. }
  118.  
  119. getSpawnpoint_NearTeam(spawnpoints)
  120. {
  121. // level endon("intermission");
  122.  
  123. // There are no valid spawnpoints in the map
  124. if(!isdefined(spawnpoints))
  125. return undefined;
  126.  
  127. // Make a list of fully connected, non-spectating, alive players
  128. players = getentarray("player", "classname");
  129. for(i = 0; i < players.size; i++)
  130. {
  131. player = players[i];
  132.  
  133. if(player.sessionstate == "spectator" || player.sessionstate == "dead" || player == self)
  134. {
  135. continue;
  136. }
  137.  
  138. aliveplayers = add_to_array(aliveplayers, player);
  139. }
  140.  
  141. // Spawn away from players if they exist, otherwise spawn at a random spawnpoint
  142. if(isdefined(aliveplayers))
  143. {
  144.  
  145. distlargest = -33554432;
  146.  
  147. for(i = 0; i < spawnpoints.size; i++)
  148. {
  149. if(positionWouldTelefrag(spawnpoints[i].origin) || would_telefrag(spawnpoints[i].origin))
  150. continue;
  151.  
  152. dist = 0;
  153.  
  154. for(j = 0; j < aliveplayers.size; j++)
  155. {
  156. if(aliveplayers[j].pers["team"] == self.pers["team"])
  157. dist = dist - (distance(spawnpoints[i].origin, aliveplayers[j].origin) * 2);
  158. else
  159. dist = dist + distance(spawnpoints[i].origin, aliveplayers[j].origin);
  160. }
  161.  
  162. if(dist > distlargest)
  163. {
  164. distlargest = dist;
  165. bestposition = spawnpoints[i];
  166. }
  167. }
  168.  
  169. spawnpoint = bestposition;
  170. }
  171. else
  172. {
  173. spawnpoint = getSpawnpoint_Random(spawnpoints);
  174. }
  175.  
  176. return spawnpoint;
  177. }
  178.  
  179. // Returns the spawn point closest to the passed in position.
  180. NearestSpawnpoint(aeSpawnpoints, vPosition)
  181. {
  182. eNearestSpot = aeSpawnpoints[0];
  183. fNearestDist = distance(vPosition, aeSpawnpoints[0].origin);
  184. for(i = 1; i < aeSpawnpoints.size; i++)
  185. {
  186. fDist = distance(vPosition, aeSpawnpoints[i].origin);
  187. if(fDist < fNearestDist)
  188. {
  189. eNearestSpot = aeSpawnpoints[i];
  190. fNearestDist = fDist;
  191. }
  192. }
  193.  
  194. return eNearestSpot;
  195. }
  196.  
  197. getSpawnpoint_SemiRandom(spawnpoints)
  198. {
  199. // level endon("intermission");
  200.  
  201. // There are no valid spawnpoints in the map
  202. if(!isdefined(spawnpoints))
  203. return undefined;
  204.  
  205. // Make a list of fully connected, non-spectating, alive players
  206. players = getentarray("player", "classname");
  207. for(i = 0; i < players.size; i++)
  208. {
  209. player = players[i];
  210. if(player.sessionstate == "spectator" || player.sessionstate == "dead" || player == self)
  211. continue;
  212. aliveplayers = add_to_array(aliveplayers, player);
  213. }
  214.  
  215. // Spawn away from players if they exist, otherwise spawn at a random spawnpoint
  216. if(isdefined(aliveplayers))
  217. {
  218. for(i = 0; i < spawnpoints.size; i++)
  219. {
  220. if(positionWouldTelefrag(spawnpoints[i].origin) || would_telefrag(spawnpoints[i].origin) )
  221. continue;
  222.  
  223. for(j = 0; j < aliveplayers.size; j++)
  224. {
  225. if ( (aliveplayers[j].pers["team"] != self.pers["team"]) && (distance(spawnpoints[i].origin, aliveplayers[j].origin) > 2000) )
  226. {
  227. semirandomspawns = add_to_array(semirandomspawns, spawnpoints[i]);
  228. continue;
  229. }
  230. }
  231. }
  232. if (isdefined(semirandomspawns))
  233. {
  234. spawnpoint = getSpawnpoint_Random(semirandomspawns);
  235. }
  236. else
  237. {
  238. for(i = 0; i < spawnpoints.size; i++)
  239. {
  240. if(positionWouldTelefrag(spawnpoints[i].origin) || would_telefrag(spawnpoints[i].origin) )
  241. continue;
  242.  
  243. for(j = 0; j < aliveplayers.size; j++)
  244. {
  245. if ( (aliveplayers[j].pers["team"] != self.pers["team"]) && (distance(spawnpoints[i].origin, aliveplayers[j].origin) > 1000) )
  246. {
  247. semirandomspawns = add_to_array(semirandomspawns, spawnpoints[i]);
  248. continue;
  249. }
  250. }
  251. }
  252. if (isdefined(semirandomspawns))
  253. spawnpoint = getSpawnpoint_Random(semirandomspawns);
  254. else
  255. spawnpoint = getSpawnpoint_Random(spawnpoints);
  256. }
  257. }
  258. else
  259. {
  260. // println("*** SPAWNING RANDOM: ", self.name);
  261. spawnpoint = getSpawnpoint_Random(spawnpoints);
  262. }
  263.  
  264. return spawnpoint;
  265. }
  266.  
  267. getSpawnpoint_MiddleThird(spawnpoints)
  268. {
  269. //This scores spawnpoints based on where the enemy is and where people just died.
  270. //It then throws out the best 1/3 and worst 1/3 spawn points and spawns you at random
  271. //Using the middle 1/3 rated spawn points.
  272.  
  273. // level endon("intermission");
  274.  
  275. // There are no valid spawnpoints in the map
  276. if(!isdefined(spawnpoints))
  277. return undefined;
  278.  
  279. // Make an array "badspot" of axis players
  280. players = getentarray("player", "classname");
  281. axiscount = -1;
  282. for(i = 0; i < players.size; i++)
  283. {
  284. if(players[i].sessionstate == "spectator" || players[i].sessionstate == "dead" || players[i] == self)
  285. continue;
  286.  
  287. if (players[i].pers["team"] != self.pers["team"])
  288. {
  289. axiscount++;
  290. //badspot = add_to_array(badspot, (players[i].origin[0],players[i].origin[1],(players[i].origin[2] * 3)));
  291. badspot = add_to_array(badspot, (players[i].origin));
  292. }
  293. }
  294.  
  295. // Add the death array to the array "badspot"
  296. if ( (isdefined(level.deatharray)) && (isdefined(level.deatharray[0])) )
  297. {
  298. for (i=0;i<level.deatharray.size;i++)
  299. badspot = add_to_array(badspot, level.deatharray[i]);
  300. }
  301.  
  302. // Give each spawn point a rating
  303. // Their score is the distance to the closest badspot
  304. if ( (isdefined (badspot)) && (isdefined (badspot[0])) )
  305. {
  306. for (i=0;i<spawnpoints.size;i++)
  307. {
  308. closest = 1000000;
  309. if(positionWouldTelefrag(spawnpoints[i].origin) || would_telefrag(spawnpoints[i].origin) )
  310. {
  311. //println ("THIS SPAWNPOINT WILL TELEFRAG!!!");
  312. spawnpoints[i].spawnscore = (-1);
  313. continue;
  314. }
  315.  
  316. spawnpoints[i].spawnscore = 0;
  317.  
  318. for(j = 0; j < badspot.size; j++)
  319. {
  320. distancescore = distance((spawnpoints[i].origin[0],spawnpoints[i].origin[1],(spawnpoints[i].origin[2] * 5)), (badspot[j][0],badspot[j][1],(badspot[j][2] * 5)));
  321. if (j > axiscount) // THIS IS A DEATH BADSPOT - CAN BE WEIGHTED DIFFERENTLY
  322. distancescore = (distancescore * 4);
  323.  
  324. if (distancescore < closest)
  325. closest = distancescore;
  326. }
  327. spawnpoints[i].spawnscore = closest;
  328. }
  329.  
  330. // Every spawn point has a score now
  331.  
  332. // Sort them in order
  333. for(i = 0; i < spawnpoints.size; i++)
  334. {
  335. for(j = i; j < spawnpoints.size; j++)
  336. {
  337. if(spawnpoints[i].spawnscore > spawnpoints[j].spawnscore)
  338. {
  339. temp = spawnpoints[i];
  340. spawnpoints[i] = spawnpoints[j];
  341. spawnpoints[j] = temp;
  342. }
  343. }
  344. }
  345.  
  346. //TEMP - PRINT ALL SCORES
  347. //for(i = 0; i < spawnpoints.size; i++)
  348. // println ("spawnpoint[" + i + "]: " + spawnpoints[i].spawnscore);
  349.  
  350. // Spawn points are sorted by score now
  351. firsthalf = (spawnpoints.size / 2);
  352. lastsixth = (spawnpoints.size - (spawnpoints.size / 6));
  353.  
  354. //println ("Taking " + firsthalf + " - " + lastsixth);
  355.  
  356. for (i=firsthalf;i<lastsixth;i++)
  357. {
  358. if (!isdefined (GoodSpawnPoints))
  359. GoodSpawnPoints[0] = spawnpoints[i];
  360. else
  361. GoodSpawnPoints[GoodSpawnPoints.size] = spawnpoints[i];
  362. }
  363.  
  364. if (GoodSpawnPoints.size < 1)
  365. {
  366. spawnpoint = getSpawnpoint_Random(spawnpoints);
  367. return spawnpoint;
  368. }
  369. else
  370. {
  371. spawnpoint = getSpawnpoint_Random(GoodSpawnPoints);
  372. return spawnpoint;
  373. }
  374.  
  375. }
  376. else
  377. {
  378. spawnpoint = getSpawnpoint_Random(spawnpoints);
  379. return spawnpoint;
  380. }
  381. }
  382.  
  383. /////////////////////////////////////////////////////////////////////////
  384.  
  385. getSpawnpoint_DM(spawnpoints)
  386. {
  387. // level endon("intermission");
  388.  
  389. // There are no valid spawnpoints in the map
  390. if(!isdefined(spawnpoints))
  391. return undefined;
  392.  
  393. // Make a list of fully connected, non-spectating, alive players
  394. players = getentarray("player", "classname");
  395. for(i = 0; i < players.size; i++)
  396. {
  397. player = players[i];
  398.  
  399. if(player.sessionstate == "spectator" || player.sessionstate == "dead" || player == self)
  400. continue;
  401.  
  402. aliveplayers = add_to_array(aliveplayers, player);
  403. }
  404.  
  405. // Spawn away from players if they exist, otherwise spawn at a random spawnpoint
  406. if(isdefined(aliveplayers))
  407. {
  408. // println("====================================");
  409.  
  410. j = 0;
  411. for(i = 0; i < spawnpoints.size; i++)
  412. {
  413. // Throw out bad spots
  414. if(positionWouldTelefrag(spawnpoints[i].origin) || would_telefrag(spawnpoints[i].origin) )
  415. {
  416. // println("Throwing out WouldTelefrag ", spawnpoints[i].origin);
  417. continue;
  418. }
  419.  
  420. if(isdefined(self.lastspawnpoint) && self.lastspawnpoint == spawnpoints[i])
  421. {
  422. // println("Throwing out last spawnpoint ", spawnpoints[i].origin);
  423. // println("self.lastspawnpoint.origin: ", self.lastspawnpoint.origin);
  424. continue;
  425. }
  426.  
  427. filteredspawnpoints[j] = spawnpoints[i];
  428. j++;
  429. }
  430.  
  431. // if no good spawnpoint, need to failsafe
  432. if (!isdefined(filteredspawnpoints))
  433. return getSpawnpoint_Random(spawnpoints);
  434.  
  435. for(i = 0; i < filteredspawnpoints.size; i++)
  436. {
  437. shortest = 1000000;
  438. for(j = 0; j < aliveplayers.size; j++)
  439. {
  440. current = distance(filteredspawnpoints[i].origin, aliveplayers[j].origin);
  441. // println("Current distance ", current);
  442.  
  443. if (current < shortest)
  444. {
  445. // println("^4Old shortest: ", shortest, " ^4New shortest: ", current);
  446. shortest = current;
  447. }
  448. }
  449.  
  450. filteredspawnpoints[i].spawnscore = shortest + 1;
  451. // println("^2Spawnscore: ", filteredspawnpoints[i].spawnscore);
  452. }
  453.  
  454. // TODO: Throw out spawnpoints with negative scores
  455.  
  456. newsize = filteredspawnpoints.size / 3;
  457. if(newsize < 1)
  458. newsize = 1;
  459.  
  460. total = 0;
  461. bestscore = 0;
  462.  
  463. // Find the top 3rd
  464. for(i = 0; i < newsize; i++)
  465. {
  466. for(j = 0; j < filteredspawnpoints.size; j++)
  467. {
  468. current = filteredspawnpoints[j].spawnscore;
  469. // println("Current distance ", current);
  470.  
  471. if (current > bestscore)
  472. bestscore = current;
  473. }
  474.  
  475. for(j = 0; j < filteredspawnpoints.size; j++)
  476. {
  477. if(filteredspawnpoints[j].spawnscore == bestscore)
  478. {
  479. // println("^3Adding to newarray: ", bestscore);
  480. newarray[i]["spawnpoint"] = filteredspawnpoints[j];
  481. newarray[i]["spawnscore"] = filteredspawnpoints[j].spawnscore;
  482. filteredspawnpoints[j].spawnscore = 0;
  483. bestscore = 0;
  484.  
  485. // println("^6Old total: ", total, "^6 New total: ", (total + newarray[i]["spawnscore"]), "^6 Added: ", newarray[i]["spawnscore"]);
  486. total = total + newarray[i]["spawnscore"];
  487.  
  488. break;
  489. }
  490. }
  491. }
  492.  
  493. randnum = randomInt(total);
  494. // println("^3Random Number: ", randnum, " ^3Between 0 and ", total);
  495.  
  496. for(i = 0; i < newarray.size; i++)
  497. {
  498. randnum = randnum - newarray[i]["spawnscore"];
  499. spawnpoint = newarray[i]["spawnpoint"];
  500.  
  501. // println("^2Subtracted: ", newarray[i]["spawnscore"], "^2 Left: ", randnum);
  502.  
  503. if(randnum < 0)
  504. break;
  505. }
  506.  
  507. self.lastspawnpoint = spawnpoint;
  508. return spawnpoint;
  509. }
  510. else
  511. return getSpawnpoint_Random(spawnpoints);
  512. }
  513.  
  514. add_to_array(array, ent)
  515. {
  516. if(!isdefined(ent))
  517. return array;
  518.  
  519. if(!isdefined(array))
  520. array[0] = ent;
  521. else
  522. array[array.size] = ent;
  523.  
  524. return array;
  525. }
  526.  
  527. addorigin_to_array(array, ent)
  528. {
  529. if(!isdefined(ent))
  530. return array;
  531.  
  532. if(!isdefined(array))
  533. array[0] = ent.origin;
  534. else
  535. array[array.size] = ent.origin;
  536.  
  537. return array;
  538. }
  539.  
  540. distance2d(a, b)
  541. {
  542. return distance((a[0], a[1], 0), (b[0], b[1], 0));
  543. }
  544.  
  545. would_telefrag(org)
  546. {
  547. players = getEntArray("player", "classname");
  548.  
  549. for (i = 0; i < players.size; i++) {
  550. if (distance2d(players[i].origin, org) < 64)
  551. return true;
  552. }
  553.  
  554. return false;
  555. }
RAW Paste Data Copied