Advertisement
Prawy

Untitled

Mar 2nd, 2022
21
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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) && !playerIsTooClose(spawnpoint.origin) )
  26. break;
  27. }
  28.  
  29. return spawnpoint;
  30. }
  31.  
  32. // Picks a non-telefragging spawn point farthest from other players
  33. getSpawnpoint_Farthest(spawnpoints)
  34. {
  35. // level endon("intermission");
  36.  
  37. // There are no valid spawnpoints in the map
  38. if(!isdefined(spawnpoints))
  39. return undefined;
  40.  
  41. // TEMP DISABLED SPAWNING AWAY FROM PLAYERS
  42. /*
  43. // Make a list of fully connected, non-spectating, alive players
  44. players = getentarray("player", "classname");
  45. for(i = 0; i < players.size; i++)
  46. {
  47. player = players[i];
  48.  
  49. if(player.sessionstate == "spectator" || player.sessionstate == "dead" || player == self)
  50. {
  51. // println("### ", player.name, " not considered:");
  52. //
  53. // println(" player.sessionstate == ", player.sessionstate);
  54. //
  55. // if(player == self)
  56. // println(" player == self");
  57.  
  58. continue;
  59. }
  60.  
  61. positions = addorigin_to_array(positions, player);
  62. // println("*** ", player.name, " added to consider list");
  63. }
  64. */
  65. if(isdefined(level.deatharray))
  66. {
  67. if(!isdefined(positions))
  68. {
  69. positions[0] = level.deatharray[0];
  70.  
  71. for(i = 1; i < level.deatharray.size; i++)
  72. positions[positions.size] = level.deatharray[i];
  73. }
  74. else
  75. {
  76. for(i = 0; i < level.deatharray.size; i++)
  77. positions[positions.size] = level.deatharray[i];
  78. }
  79. }
  80.  
  81. // Spawn away from players if they exist, otherwise spawn at a random spawnpoint
  82. if(isdefined(positions))
  83. {
  84. // println("*** SPAWNING FARTHEST: ", self.name);
  85.  
  86. distsmallest = 33554432;
  87.  
  88. for(i = 0; i < spawnpoints.size; i++)
  89. {
  90. if(positionWouldTelefrag(spawnpoints[i].origin) && playerIsTooClose(spawnpoints[i].origin) )
  91. continue;
  92.  
  93. dist = 0;
  94.  
  95. for(j = 0; j < positions.size; j++)
  96. {
  97. dist += 1.0 / (distance(spawnpoints[i].origin, positions[j]) + 1.0);
  98. }
  99.  
  100. if(dist < distsmallest)
  101. {
  102. distsmallest = dist;
  103. bestposition = spawnpoints[i];
  104. }
  105. }
  106.  
  107. spawnpoint = bestposition;
  108. }
  109. else
  110. {
  111. // println("*** SPAWNING RANDOM: ", self.name);
  112. spawnpoint = getSpawnpoint_Random(spawnpoints);
  113. }
  114.  
  115. return spawnpoint;
  116. }
  117.  
  118. getSpawnpoint_NearTeam(spawnpoints)
  119. {
  120. // level endon("intermission");
  121.  
  122. // There are no valid spawnpoints in the map
  123. if(!isdefined(spawnpoints))
  124. return undefined;
  125.  
  126. // Make a list of fully connected, non-spectating, alive players
  127. players = getentarray("player", "classname");
  128. for(i = 0; i < players.size; i++)
  129. {
  130. player = players[i];
  131.  
  132. if(player.sessionstate == "spectator" || player.sessionstate == "dead" || player == self)
  133. {
  134. // println("### ", player.name, " not considered:");
  135. //
  136. // println(" player.sessionstate == ", player.sessionstate);
  137. //
  138. // if(player == self)
  139. // println(" player == self");
  140.  
  141. continue;
  142. }
  143.  
  144. aliveplayers = add_to_array(aliveplayers, player);
  145. // println("*** ", player.name, " on team ", player.pers["team"], " added to consider list");
  146. }
  147.  
  148. // Spawn away from players if they exist, otherwise spawn at a random spawnpoint
  149. if(isdefined(aliveplayers))
  150. {
  151. // println("*** SPAWNING FARTHEST: ", self.name);
  152.  
  153. distlargest = -33554432;
  154.  
  155. for(i = 0; i < spawnpoints.size; i++)
  156. {
  157. if(positionWouldTelefrag(spawnpoints[i].origin) && playerIsTooClose(spawnpoints[i].origin) )
  158. continue;
  159.  
  160. dist = 0;
  161.  
  162. for(j = 0; j < aliveplayers.size; j++)
  163. {
  164. if(aliveplayers[j].pers["team"] == self.pers["team"])
  165. dist = dist - (distance(spawnpoints[i].origin, aliveplayers[j].origin) * 2);
  166. else
  167. dist = dist + distance(spawnpoints[i].origin, aliveplayers[j].origin);
  168. }
  169.  
  170. if(dist > distlargest)
  171. {
  172. distlargest = dist;
  173. bestposition = spawnpoints[i];
  174. }
  175. }
  176.  
  177. spawnpoint = bestposition;
  178. }
  179. else
  180. {
  181. // println("*** SPAWNING RANDOM: ", self.name);
  182. spawnpoint = getSpawnpoint_Random(spawnpoints);
  183. }
  184.  
  185. return spawnpoint;
  186. }
  187.  
  188. // Returns the spawn point closest to the passed in position.
  189. NearestSpawnpoint(aeSpawnpoints, vPosition)
  190. {
  191. eNearestSpot = aeSpawnpoints[0];
  192. fNearestDist = distance(vPosition, aeSpawnpoints[0].origin);
  193. for(i = 1; i < aeSpawnpoints.size; i++)
  194. {
  195. fDist = distance(vPosition, aeSpawnpoints[i].origin);
  196. if(fDist < fNearestDist)
  197. {
  198. eNearestSpot = aeSpawnpoints[i];
  199. fNearestDist = fDist;
  200. }
  201. }
  202.  
  203. return eNearestSpot;
  204. }
  205.  
  206. getSpawnpoint_SemiRandom(spawnpoints)
  207. {
  208. // level endon("intermission");
  209.  
  210. // There are no valid spawnpoints in the map
  211. if(!isdefined(spawnpoints))
  212. return undefined;
  213.  
  214. // Make a list of fully connected, non-spectating, alive players
  215. players = getentarray("player", "classname");
  216. for(i = 0; i < players.size; i++)
  217. {
  218. player = players[i];
  219. if(player.sessionstate == "spectator" || player.sessionstate == "dead" || player == self)
  220. continue;
  221. aliveplayers = add_to_array(aliveplayers, player);
  222. }
  223.  
  224. // Spawn away from players if they exist, otherwise spawn at a random spawnpoint
  225. if(isdefined(aliveplayers))
  226. {
  227. for(i = 0; i < spawnpoints.size; i++)
  228. {
  229. if(positionWouldTelefrag(spawnpoints[i].origin) && playerIsTooClose(spawnpoints[i].origin) )
  230. continue;
  231.  
  232. for(j = 0; j < aliveplayers.size; j++)
  233. {
  234. if ( (aliveplayers[j].pers["team"] != self.pers["team"]) && (distance(spawnpoints[i].origin, aliveplayers[j].origin) > 2000) )
  235. {
  236. semirandomspawns = add_to_array(semirandomspawns, spawnpoints[i]);
  237. continue;
  238. }
  239. }
  240. }
  241. if (isdefined(semirandomspawns))
  242. {
  243. spawnpoint = getSpawnpoint_Random(semirandomspawns);
  244. }
  245. else
  246. {
  247. for(i = 0; i < spawnpoints.size; i++)
  248. {
  249. if(positionWouldTelefrag(spawnpoints[i].origin) && playerIsTooClose(spawnpoints[i].origin) )
  250. continue;
  251.  
  252. for(j = 0; j < aliveplayers.size; j++)
  253. {
  254. if ( (aliveplayers[j].pers["team"] != self.pers["team"]) && (distance(spawnpoints[i].origin, aliveplayers[j].origin) > 1000) )
  255. {
  256. semirandomspawns = add_to_array(semirandomspawns, spawnpoints[i]);
  257. continue;
  258. }
  259. }
  260. }
  261. if (isdefined(semirandomspawns))
  262. spawnpoint = getSpawnpoint_Random(semirandomspawns);
  263. else
  264. spawnpoint = getSpawnpoint_Random(spawnpoints);
  265. }
  266. }
  267. else
  268. {
  269. // println("*** SPAWNING RANDOM: ", self.name);
  270. spawnpoint = getSpawnpoint_Random(spawnpoints);
  271. }
  272.  
  273. return spawnpoint;
  274. }
  275.  
  276. getSpawnpoint_MiddleThird(spawnpoints)
  277. {
  278. //This scores spawnpoints based on where the enemy is and where people just died.
  279. //It then throws out the best 1/3 and worst 1/3 spawn points and spawns you at random
  280. //Using the middle 1/3 rated spawn points.
  281.  
  282. // There are no valid spawnpoints in the map
  283. if(!isdefined(spawnpoints))
  284. return undefined;
  285.  
  286. // Make an array "badspot" of axis players
  287. players = getentarray("player", "classname");
  288. axiscount = -1;
  289. for(i = 0; i < players.size; i++)
  290. {
  291. if(players[i].sessionstate == "spectator" || players[i].sessionstate == "dead" || players[i] == self)
  292. continue;
  293.  
  294. if (players[i].pers["team"] != self.pers["team"])
  295. {
  296. axiscount++;
  297. badspot = add_to_array(badspot, (players[i].origin));
  298. }
  299. }
  300.  
  301. // Add the death array to the array "badspot"
  302. if ( (isdefined(level.deatharray)) && (isdefined(level.deatharray[0])) )
  303. {
  304. for (i=0;i<level.deatharray.size;i++)
  305. badspot = add_to_array(badspot, level.deatharray[i]);
  306. }
  307.  
  308. // Give each spawn point a rating
  309. // Their score is the distance to the closest badspot
  310. if ( (isdefined (badspot)) && (isdefined (badspot[0])) )
  311. {
  312. for (i=0;i<spawnpoints.size;i++)
  313. {
  314. closest = 1000000;
  315. if(positionWouldTelefrag(spawnpoints[i].origin) && playerIsTooClose(spawnpoints[i].origin) )
  316. {
  317. spawnpoints[i].spawnscore = (-1);
  318. continue;
  319. }
  320.  
  321. spawnpoints[i].spawnscore = 0;
  322.  
  323. for(j = 0; j < badspot.size; j++)
  324. {
  325. 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)));
  326. if (j > axiscount) // THIS IS A DEATH BADSPOT - CAN BE WEIGHTED DIFFERENTLY
  327. distancescore = (distancescore * 4);
  328.  
  329. if (distancescore < closest)
  330. closest = distancescore;
  331. }
  332. spawnpoints[i].spawnscore = closest;
  333. }
  334.  
  335. // Every spawn point has a score now
  336.  
  337. // Sort them in order
  338. for(i = 0; i < spawnpoints.size; i++)
  339. {
  340. for(j = i; j < spawnpoints.size; j++)
  341. {
  342. if(spawnpoints[i].spawnscore > spawnpoints[j].spawnscore)
  343. {
  344. temp = spawnpoints[i];
  345. spawnpoints[i] = spawnpoints[j];
  346. spawnpoints[j] = temp;
  347. }
  348. }
  349. }
  350.  
  351. // Spawn points are sorted by score now
  352. firsthalf = (spawnpoints.size / 2);
  353. lastsixth = (spawnpoints.size - (spawnpoints.size / 6));
  354.  
  355. for (i=firsthalf;i<lastsixth;i++)
  356. {
  357. if (!isdefined (GoodSpawnPoints))
  358. GoodSpawnPoints[0] = spawnpoints[i];
  359. else
  360. GoodSpawnPoints[GoodSpawnPoints.size] = spawnpoints[i];
  361. }
  362.  
  363. if (GoodSpawnPoints.size < 1)
  364. {
  365. spawnpoint = getSpawnpoint_Random(spawnpoints);
  366. return spawnpoint;
  367. }
  368. else
  369. {
  370. spawnpoint = getSpawnpoint_Random(GoodSpawnPoints);
  371. return spawnpoint;
  372. }
  373.  
  374. }
  375. else
  376. {
  377. spawnpoint = getSpawnpoint_Random(spawnpoints);
  378. return spawnpoint;
  379. }
  380. }
  381.  
  382. /////////////////////////////////////////////////////////////////////////
  383.  
  384. getSpawnpoint_DM(spawnpoints)
  385. {
  386. // level endon("intermission");
  387.  
  388. // There are no valid spawnpoints in the map
  389. if(!isdefined(spawnpoints))
  390. return undefined;
  391.  
  392. // Make a list of fully connected, non-spectating, alive players
  393. players = getentarray("player", "classname");
  394. for(i = 0; i < players.size; i++)
  395. {
  396. player = players[i];
  397.  
  398. if(player.sessionstate == "spectator" || player.sessionstate == "dead" || player == self)
  399. continue;
  400.  
  401. aliveplayers = add_to_array(aliveplayers, player);
  402. }
  403.  
  404. // Spawn away from players if they exist, otherwise spawn at a random spawnpoint
  405. if(isdefined(aliveplayers))
  406. {
  407. // println("====================================");
  408.  
  409. j = 0;
  410. for(i = 0; i < spawnpoints.size; i++)
  411. {
  412. // Throw out bad spots
  413. if(positionWouldTelefrag(spawnpoints[i].origin) && playerIsTooClose(spawnpoints[i].origin) )
  414. {
  415. // println("Throwing out WouldTelefrag ", spawnpoints[i].origin);
  416. continue;
  417. }
  418.  
  419. if(isdefined(self.lastspawnpoint) && self.lastspawnpoint == spawnpoints[i])
  420. {
  421. // println("Throwing out last spawnpoint ", spawnpoints[i].origin);
  422. // println("self.lastspawnpoint.origin: ", self.lastspawnpoint.origin);
  423. continue;
  424. }
  425.  
  426. filteredspawnpoints[j] = spawnpoints[i];
  427. j++;
  428. }
  429.  
  430. // if no good spawnpoint, need to failsafe
  431. if (!isdefined(filteredspawnpoints))
  432. return getSpawnpoint_Random(spawnpoints);
  433.  
  434. for(i = 0; i < filteredspawnpoints.size; i++)
  435. {
  436. shortest = 1000000;
  437. for(j = 0; j < aliveplayers.size; j++)
  438. {
  439. current = distance(filteredspawnpoints[i].origin, aliveplayers[j].origin);
  440. // println("Current distance ", current);
  441.  
  442. if (current < shortest)
  443. {
  444. // println("^4Old shortest: ", shortest, " ^4New shortest: ", current);
  445. shortest = current;
  446. }
  447. }
  448.  
  449. filteredspawnpoints[i].spawnscore = shortest + 1;
  450. // println("^2Spawnscore: ", filteredspawnpoints[i].spawnscore);
  451. }
  452.  
  453. // TODO: Throw out spawnpoints with negative scores
  454.  
  455. newsize = filteredspawnpoints.size / 3;
  456. if(newsize < 1)
  457. newsize = 1;
  458.  
  459. total = 0;
  460. bestscore = 0;
  461.  
  462. // Find the top 3rd
  463. for(i = 0; i < newsize; i++)
  464. {
  465. for(j = 0; j < filteredspawnpoints.size; j++)
  466. {
  467. current = filteredspawnpoints[j].spawnscore;
  468. // println("Current distance ", current);
  469.  
  470. if (current > bestscore)
  471. bestscore = current;
  472. }
  473.  
  474. for(j = 0; j < filteredspawnpoints.size; j++)
  475. {
  476. if(filteredspawnpoints[j].spawnscore == bestscore)
  477. {
  478. // println("^3Adding to newarray: ", bestscore);
  479. newarray[i]["spawnpoint"] = filteredspawnpoints[j];
  480. newarray[i]["spawnscore"] = filteredspawnpoints[j].spawnscore;
  481. filteredspawnpoints[j].spawnscore = 0;
  482. bestscore = 0;
  483.  
  484. // println("^6Old total: ", total, "^6 New total: ", (total + newarray[i]["spawnscore"]), "^6 Added: ", newarray[i]["spawnscore"]);
  485. total = total + newarray[i]["spawnscore"];
  486.  
  487. break;
  488. }
  489. }
  490. }
  491.  
  492. randnum = randomInt(total);
  493. // println("^3Random Number: ", randnum, " ^3Between 0 and ", total);
  494.  
  495. for(i = 0; i < newarray.size; i++)
  496. {
  497. randnum = randnum - newarray[i]["spawnscore"];
  498. spawnpoint = newarray[i]["spawnpoint"];
  499.  
  500. // println("^2Subtracted: ", newarray[i]["spawnscore"], "^2 Left: ", randnum);
  501.  
  502. if(randnum < 0)
  503. break;
  504. }
  505.  
  506. self.lastspawnpoint = spawnpoint;
  507. return spawnpoint;
  508. }
  509. else
  510. return getSpawnpoint_Random(spawnpoints);
  511. }
  512.  
  513. add_to_array(array, ent)
  514. {
  515. if(!isdefined(ent))
  516. return array;
  517.  
  518. if(!isdefined(array))
  519. array[0] = ent;
  520. else
  521. array[array.size] = ent;
  522.  
  523. return array;
  524. }
  525.  
  526. addorigin_to_array(array, ent)
  527. {
  528. if(!isdefined(ent))
  529. return array;
  530.  
  531. if(!isdefined(array))
  532. array[0] = ent.origin;
  533. else
  534. array[array.size] = ent.origin;
  535.  
  536. return array;
  537. }
  538.  
  539. getSpawnpoint_NearTeam_AwayfromRadios(spawnpoints)
  540. {
  541. // There are no valid spawnpoints in the map
  542. if(!isdefined(spawnpoints))
  543. return undefined;
  544.  
  545. // Make a list of fully connected, non-spectating, alive players
  546. aliveplayers = [];
  547. teammates = 0;
  548. players = getentarray("player", "classname");
  549. for(i = 0; i < players.size; i++)
  550. {
  551. if(isdefined (players[i].pers["team"]))
  552. teammates++;
  553. if(players[i].sessionstate == "spectator" || players[i].sessionstate == "dead" || players[i] == self)
  554. continue;
  555. aliveplayers[aliveplayers.size] = players[i];
  556. }
  557.  
  558. // Spawn away from players if they exist, otherwise spawn at a random spawnpoint
  559. if(isdefined(aliveplayers))
  560. {
  561. for(i = 0; i < spawnpoints.size; i++)
  562. {
  563. if(positionWouldTelefrag(spawnpoints[i].origin) && playerIsTooClose(spawnpoints[i].origin) )
  564. {
  565. spawnpoints[i].spawnscore = -37483274;
  566. continue;
  567. }
  568.  
  569. spawnpoints[i].spawnscore = 0;
  570.  
  571. // Measuse the distance to all alive players and modify the spawnpoints score
  572. for(j = 0; j < aliveplayers.size; j++)
  573. {
  574. dist = (distance(spawnpoints[i].origin, aliveplayers[j].origin));
  575.  
  576. if(aliveplayers[j].pers["team"] == self.pers["team"])
  577. {
  578. // If this team is controlling a radio
  579. if (level.captured_radios[self.pers["team"]] > 0)
  580. bias = (0.5);
  581. else // This team doesn't have a radio to increase the bias
  582. bias = (1.6);
  583.  
  584. // IF THE PLAYER JUST SPAWNED IN A WAVE MAKE THIS PLAYER VERY VERY VALUEABLE
  585. if (isdefined (aliveplayers[j].wavespawner))
  586. bias = (100);
  587.  
  588. spawnpoints[i].spawnscore -= ( dist * bias );
  589. }
  590. else
  591. {
  592. if (dist <= 850) // If there is an enemy within 850 units dont spawn a player here
  593. {
  594. spawnpoints[i].spawnscore = -37483274;
  595. continue;
  596. }
  597. else
  598. spawnpoints[i].spawnscore += ( dist * 0.8 );
  599. }
  600. }
  601.  
  602. // Measure the distance to all the shown radios and modify the spawnpoints score
  603. for(j = 0; j < level.radio.size; j++)
  604. {
  605. if ( (level.radio[j].hidden == true) || (level.radio[j].team == "none") )
  606. continue;
  607.  
  608. // If the radio is within 700 units of an attacker, the attacker should not spawn there
  609. if (level.radio[j].team != self.pers["team"])
  610. {
  611. dist = (distance(spawnpoints[i].origin, level.radio[j].origin));
  612. if (dist <= 700)
  613. {
  614. spawnpoints[i].spawnscore = -37483274;
  615. continue;
  616. }
  617. }
  618. }
  619. }
  620.  
  621. // Every spawn point has a score now
  622.  
  623. // Sort them in order
  624. for(i = 0; i < spawnpoints.size; i++)
  625. {
  626. for(j = i; j < spawnpoints.size; j++)
  627. {
  628. if(spawnpoints[i].spawnscore < spawnpoints[j].spawnscore)
  629. {
  630. temp = spawnpoints[i];
  631. spawnpoints[i] = spawnpoints[j];
  632. spawnpoints[j] = temp;
  633. }
  634. }
  635. }
  636.  
  637. // Spawn points are sorted by score now. Index 0 has highest score
  638. // A Higher Score is Better
  639. for(i = 0; i < spawnpoints.size; i++)
  640. {
  641. if(positionWouldTelefrag(spawnpoints[i].origin) && playerIsTooClose(spawnpoints[i].origin) )
  642. continue;
  643. if (spawnpoints[i].spawnscore == -37483274)
  644. continue;
  645. return spawnpoints[i];
  646. }
  647.  
  648. spawnpoint = getSpawnpoint_MiddleThird(spawnpoints);
  649. }
  650. else
  651. {
  652. spawnpoint = getSpawnpoint_MiddleThird(spawnpoints);
  653. }
  654.  
  655. return spawnpoint;
  656. }
  657.  
  658. playerIsTooClose(spawnpointOrigin){
  659.  
  660. player = getEntArray( "player", "classname" );
  661. for( i = 0; i < player.size; i++ ){
  662. if(distanceSquared(spawnpointOrigin, player[i].origin) <= 1000 )
  663. return true;
  664. }
  665. return false;
  666.  
Advertisement
RAW Paste Data Copied
Advertisement