Advertisement
Guest User

Untitled

a guest
Sep 29th, 2010
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.92 KB | None | 0 0
  1. #include maps\mp\_utility;
  2. #include maps\mp\gametypes\_hud_util;
  3. #include common_scripts\utility;
  4.  
  5. init()
  6. {
  7. if ( !isDefined( game["gamestarted"] ) )
  8. {
  9. //setMatchDataDef( "mp/matchdata_" + level.gametype + ".def" );
  10. setMatchDataDef( "mp/matchdata.def" );
  11. setMatchData( "map", level.script );
  12. setMatchData( "gametype", level.gametype );
  13. setMatchData( "buildVersion", getBuildVersion() );
  14. setMatchData( "buildNumber", getBuildNumber() );
  15. setMatchData( "dateTime", getSystemTime() );
  16. }
  17.  
  18. level.MaxLives = 250; // must match MaxKills in matchdata definition
  19. level.MaxNameLength = 21; // must match Player xuid size in clientmatchdata definition
  20. level.MaxEvents = 150;
  21. level.MaxKillstreaks = 125;
  22. level.MaxLogClients = 128;
  23.  
  24. level thread gameEndListener();
  25. }
  26.  
  27.  
  28. logKillstreakEvent( event, position )
  29. {
  30. assertEx( isPlayer( self ), "self is not a player: " + self.code_classname );
  31.  
  32. if ( !matchMakingGame() || !canLogClient( self ) || !canLogKillstreak() )
  33. return;
  34.  
  35. eventId = getMatchData( "killstreakCount" );
  36. setMatchData( "killstreakCount", eventId+1 );
  37.  
  38. setMatchData( "killstreaks", eventId, "eventType", event );
  39. setMatchData( "killstreaks", eventId, "player", self.clientid );
  40. setMatchData( "killstreaks", eventId, "eventTime", getTime() );
  41. setMatchData( "killstreaks", eventId, "eventPos", 0, int( position[0] ) );
  42. setMatchData( "killstreaks", eventId, "eventPos", 1, int( position[1] ) );
  43. setMatchData( "killstreaks", eventId, "eventPos", 2, int( position[2] ) );
  44. }
  45.  
  46.  
  47. logGameEvent( event, position )
  48. {
  49. assertEx( isPlayer( self ), "self is not a player: " + self.code_classname );
  50.  
  51. if ( !matchMakingGame() || !canLogClient( self ) || !canLogEvent() )
  52. return;
  53.  
  54. eventId = getMatchData( "eventCount" );
  55. setMatchData( "eventCount", eventId+1 );
  56.  
  57. setMatchData( "events", eventId, "eventType", event );
  58. setMatchData( "events", eventId, "player", self.clientid );
  59. setMatchData( "events", eventId, "eventTime", getTime() );
  60. setMatchData( "events", eventId, "eventPos", 0, int( position[0] ) );
  61. setMatchData( "events", eventId, "eventPos", 1, int( position[1] ) );
  62. setMatchData( "events", eventId, "eventPos", 2, int( position[2] ) );
  63. }
  64.  
  65.  
  66. logKillEvent( lifeId, eventRef )
  67. {
  68. if ( !matchMakingGame() || !canLogLife( lifeId ) )
  69. return;
  70.  
  71. setMatchData( "lives", lifeId, "modifiers", eventRef, true );
  72. }
  73.  
  74.  
  75. logMultiKill( lifeId, multikillCount )
  76. {
  77. if ( !matchMakingGame() || !canLogLife( lifeId ) )
  78. return;
  79.  
  80. setMatchData( "lives", lifeId, "multikill", multikillCount );
  81. }
  82.  
  83.  
  84. logPlayerLife( lifeId )
  85. {
  86. if ( !matchMakingGame() || !canLogClient( self ) || !canLogLife( lifeId ) )
  87. return;
  88.  
  89. setMatchData( "lives", lifeId, "player", self.clientid );
  90. setMatchData( "lives", lifeId, "spawnPos", 0, int( self.spawnPos[0] ) );
  91. setMatchData( "lives", lifeId, "spawnPos", 1, int( self.spawnPos[1] ) );
  92. setMatchData( "lives", lifeId, "spawnPos", 2, int( self.spawnPos[2] ) );
  93. setMatchData( "lives", lifeId, "wasTacticalInsertion", self.wasTI );
  94. setMatchData( "lives", lifeId, "team", self.team );
  95. setMatchData( "lives", lifeId, "spawnTime", self.spawnTime );
  96. setMatchData( "lives", lifeId, "duration", getTime() - self.spawnTime );
  97.  
  98. self logLoadout( lifeId );
  99. }
  100.  
  101.  
  102. logLoadout( lifeId )
  103. {
  104. if ( !matchMakingGame() || !canLogClient( self ) || !canLogLife( lifeId ) )
  105. return;
  106.  
  107. class = self.curClass;
  108.  
  109. if ( class == "copycat" )
  110. {
  111. clonedLoadout = self.pers["copyCatLoadout"];
  112.  
  113. loadoutPrimary = clonedLoadout["loadoutPrimary"];
  114. loadoutPrimaryAttachment = clonedLoadout["loadoutPrimaryAttachment"];
  115. loadoutPrimaryAttachment2 = clonedLoadout["loadoutPrimaryAttachment2"] ;
  116. loadoutPrimaryCamo = clonedLoadout["loadoutPrimaryCamo"];
  117. loadoutSecondary = clonedLoadout["loadoutSecondary"];
  118. loadoutSecondaryAttachment = clonedLoadout["loadoutSecondaryAttachment"];
  119. loadoutSecondaryAttachment2 = clonedLoadout["loadoutSecondaryAttachment2"];
  120. loadoutSecondaryCamo = clonedLoadout["loadoutSecondaryCamo"];
  121. loadoutEquipment = clonedLoadout["loadoutEquipment"];
  122. loadoutPerk1 = clonedLoadout["loadoutPerk1"];
  123. loadoutPerk2 = clonedLoadout["loadoutPerk2"];
  124. loadoutPerk3 = clonedLoadout["loadoutPerk3"];
  125. loadoutOffhand = clonedLoadout["loadoutOffhand"];
  126. loadoutDeathStreak = "specialty_copycat";
  127. }
  128. else if( isSubstr( class, "custom" ) )
  129. {
  130. class_num = maps\mp\gametypes\_class::getClassIndex( class );
  131.  
  132. loadoutPrimary = maps\mp\gametypes\_class::cac_getWeapon( class_num, 0 );
  133. loadoutPrimaryAttachment = maps\mp\gametypes\_class::cac_getWeaponAttachment( class_num, 0 );
  134. loadoutPrimaryAttachment2 = maps\mp\gametypes\_class::cac_getWeaponAttachmentTwo( class_num, 0 );
  135.  
  136. loadoutSecondary = maps\mp\gametypes\_class::cac_getWeapon( class_num, 1 );
  137. loadoutSecondaryAttachment = maps\mp\gametypes\_class::cac_getWeaponAttachment( class_num, 1 );
  138. loadoutSecondaryAttachment2 = maps\mp\gametypes\_class::cac_getWeaponAttachmentTwo( class_num, 1 );
  139.  
  140. loadoutOffhand = maps\mp\gametypes\_class::cac_getOffhand( class_num );
  141.  
  142. loadoutEquipment = maps\mp\gametypes\_class::cac_getPerk( class_num, 0 );
  143. loadoutPerk1 = maps\mp\gametypes\_class::cac_getPerk( class_num, 1 );
  144. loadoutPerk2 = maps\mp\gametypes\_class::cac_getPerk( class_num, 2 );
  145. loadoutPerk3 = maps\mp\gametypes\_class::cac_getPerk( class_num, 3 );
  146. }
  147. else
  148. {
  149. class_num = maps\mp\gametypes\_class::getClassIndex( class );
  150.  
  151. loadoutPrimary = maps\mp\gametypes\_class::table_getWeapon( level.classTableName, class_num, 0 );
  152. loadoutPrimaryAttachment = maps\mp\gametypes\_class::table_getWeaponAttachment( level.classTableName, class_num, 0 , 0);
  153. loadoutPrimaryAttachment2 = maps\mp\gametypes\_class::table_getWeaponAttachment( level.classTableName, class_num, 0, 1 );
  154.  
  155. loadoutSecondary = maps\mp\gametypes\_class::table_getWeapon( level.classTableName, class_num, 1 );
  156. loadoutSecondaryAttachment = maps\mp\gametypes\_class::table_getWeaponAttachment( level.classTableName, class_num, 1 , 0);
  157. loadoutSecondaryAttachment2 = maps\mp\gametypes\_class::table_getWeaponAttachment( level.classTableName, class_num, 1, 1 );;
  158.  
  159. loadoutOffhand = maps\mp\gametypes\_class::table_getOffhand( level.classTableName, class_num );
  160.  
  161. loadoutEquipment = maps\mp\gametypes\_class::table_getEquipment( level.classTableName, class_num, 0 );
  162. loadoutPerk1 = maps\mp\gametypes\_class::table_getPerk( level.classTableName, class_num, 1 );
  163. loadoutPerk2 = maps\mp\gametypes\_class::table_getPerk( level.classTableName, class_num, 2 );
  164. loadoutPerk3 = maps\mp\gametypes\_class::table_getPerk( level.classTableName, class_num, 3 );
  165. }
  166.  
  167. setMatchData( "lives", lifeId, "primaryWeapon", loadoutPrimary );
  168. setMatchData( "lives", lifeId, "primaryAttachments", 0, loadoutPrimaryAttachment );
  169. setMatchData( "lives", lifeId, "primaryAttachments", 1, loadoutPrimaryAttachment2 );
  170.  
  171. setMatchData( "lives", lifeId, "secondaryWeapon", loadoutSecondary );
  172. setMatchData( "lives", lifeId, "secondaryAttachments", 0, loadoutSecondaryAttachment );
  173. setMatchData( "lives", lifeId, "secondaryAttachments", 1, loadoutSecondaryAttachment );
  174.  
  175. setMatchData( "lives", lifeId, "offhandWeapon", loadoutOffhand );
  176.  
  177. setMatchData( "lives", lifeId, "equipment", loadoutEquipment );
  178. setMatchData( "lives", lifeId, "perks", 0, loadoutPerk1 );
  179. setMatchData( "lives", lifeId, "perks", 1, loadoutPerk2 );
  180. setMatchData( "lives", lifeId, "perks", 2, loadoutPerk3 );
  181. }
  182.  
  183.  
  184. logPlayerDeath( lifeId, attacker, iDamage, sMeansOfDeath, sWeapon, sPrimaryWeapon, sHitLoc )
  185. {
  186. if ( !matchMakingGame() || !canLogClient( self ) || ( isPlayer( attacker ) && !canLogClient( attacker ) ) || !canLogLife( lifeId ) )
  187. return;
  188.  
  189. if ( lifeId >= level.MaxLives )
  190. return;
  191.  
  192. if ( sWeapon == "none" )
  193. {
  194. sWeaponType = "none";
  195. sWeaponClass = "none";
  196. }
  197. else
  198. {
  199. sWeaponType = weaponInventoryType( sWeapon );
  200. sWeaponClass = weaponClass( sWeapon );
  201. }
  202.  
  203. if ( isDefined( sWeaponType ) && (sWeaponType == "primary" || sWeaponType == "altmode") && (sWeaponClass == "pistol" || sWeaponClass == "smg" || sWeaponClass == "rifle" || sWeaponClass == "spread" || sWeaponClass == "mg" || sWeaponClass == "grenade" || sWeaponClass == "rocketlauncher" || sWeaponClass == "sniper") )
  204. {
  205. sWeaponOriginal = undefined;
  206.  
  207. if ( sWeaponType == "altmode" )
  208. {
  209. sWeaponOriginal = sWeapon;
  210. sWeapon = sPrimaryWeapon;
  211.  
  212. setMatchData( "lives", lifeId, "altMode", true );
  213. }
  214.  
  215. weaponTokens = strTok( sWeapon, "_" );
  216.  
  217. /#
  218. if ( !(weaponTokens.size > 1 && weaponTokens.size <= 4) )
  219. {
  220. PrintLn( "attacker: ", attacker );
  221. PrintLn( "iDamage: ", iDamage );
  222. PrintLn( "sMeansOfDeath: ", sMeansOfDeath );
  223.  
  224. if ( isDefined( sWeaponOriginal ) )
  225. PrintLn( "sWeaponOriginal: ", sWeaponOriginal );
  226.  
  227. PrintLn( "sWeapon: ", sWeapon );
  228. PrintLn( "sPrimaryWeapon: ", sPrimaryWeapon );
  229. PrintLn( "--------------------------------" );
  230. PrintLn( "sWeaponType: ", sWeaponType );
  231. PrintLn( "sWeaponClass: ", sWeaponClass );
  232. PrintLn( "--------------------------------" );
  233. PrintLn( "weaponTokens.size: ", weaponTokens.size );
  234.  
  235. tokenCount = 0;
  236. foreach ( token in weaponTokens )
  237. {
  238. PrintLn( "weaponTokens[", tokenCount, "]: ", weaponTokens[tokenCount] );
  239. tokenCount++;
  240. }
  241. }
  242. #/
  243. assert( weaponTokens.size > 1 && weaponTokens.size <= 4 );
  244.  
  245. assertEx( weaponTokens[weaponTokens.size - 1] == "mp", "weaponTokens[weaponTokens.size - 1]: " + weaponTokens[weaponTokens.size - 1] );
  246. weaponTokens[weaponTokens.size - 1] = undefined; // remove the trailing "mp"
  247.  
  248. setMatchData( "lives", lifeId, "weapon", weaponTokens[0] );
  249.  
  250. if ( isDefined( weaponTokens[1] ) )
  251. setMatchData( "lives", lifeId, "attachments", 0, weaponTokens[1] );
  252.  
  253. if ( isDefined( weaponTokens[2] ) )
  254. setMatchData( "lives", lifeId, "attachments", 1, weaponTokens[2] );
  255. }
  256. else if ( sWeaponType == "item" || sWeaponType == "offhand" )
  257. {
  258. weaponName = strip_suffix( sWeapon, "_mp" );
  259. setMatchData( "lives", lifeId, "weapon", weaponName );
  260. }
  261. else
  262. {
  263. setMatchData( "lives", lifeId, "weapon", sWeapon );
  264. }
  265.  
  266. if ( isKillstreakWeapon( sWeapon ) )
  267. setMatchData( "lives", lifeId, "modifiers", "killstreak", true );
  268.  
  269. setMatchData( "lives", lifeId, "mod", sMeansOfDeath );
  270. if ( isPlayer( attacker ) )
  271. {
  272. setMatchData( "lives", lifeId, "attacker", attacker.clientid );
  273. setMatchData( "lives", lifeId, "attackerPos", 0, int( attacker.origin[0] ) );
  274. setMatchData( "lives", lifeId, "attackerPos", 1, int( attacker.origin[1] ) );
  275. setMatchData( "lives", lifeId, "attackerPos", 2, int( attacker.origin[2] ) );
  276.  
  277. victimForward = anglesToForward( (0,self.angles[1],0) );
  278. attackDirection = (self.origin - attacker.origin);
  279. attackDirection = VectorNormalize( (attackDirection[0], attackDirection[1], 0) );
  280. setMatchData( "lives", lifeId, "dotOfDeath", VectorDot( victimForward, attackDirection ) );
  281. }
  282. else
  283. {
  284. // 255 is world
  285. setMatchData( "lives", lifeId, "attacker", 255 );
  286. setMatchData( "lives", lifeId, "attackerPos", 0, int( self.origin[0] ) );
  287. setMatchData( "lives", lifeId, "attackerPos", 1, int( self.origin[1] ) );
  288. setMatchData( "lives", lifeId, "attackerPos", 2, int( self.origin[2] ) );
  289. }
  290.  
  291. setMatchData( "lives", lifeId, "player", self.clientid );
  292. setMatchData( "lives", lifeId, "deathPos", 0, int( self.origin[0] ) );
  293. setMatchData( "lives", lifeId, "deathPos", 1, int( self.origin[1] ) );
  294. setMatchData( "lives", lifeId, "deathPos", 2, int( self.origin[2] ) );
  295.  
  296. setMatchData( "lives", lifeId, "deathAngles", 0, int( self.angles[0] ) );
  297. setMatchData( "lives", lifeId, "deathAngles", 1, int( self.angles[1] ) );
  298. setMatchData( "lives", lifeId, "deathAngles", 2, int( self.angles[2] ) );
  299. }
  300.  
  301.  
  302. logPlayerData()
  303. {
  304. if ( !matchMakingGame() || !canLogClient( self ) )
  305. return;
  306.  
  307. setMatchData( "players", self.clientid, "score", self getPersStat( "score" ) );
  308. setMatchData( "players", self.clientid, "assists", self getPersStat( "assists" ) );
  309. setMatchData( "players", self.clientid, "longestStreak", self getPersStat( "longestStreak" ) );
  310. }
  311.  
  312.  
  313. // log the lives of players who are still alive at match end.
  314. gameEndListener()
  315. {
  316. if ( !matchMakingGame() )
  317. return;
  318.  
  319. level waittill ( "game_ended" );
  320.  
  321. setMatchData( "gameLength", int( getTimePassed() ) );
  322.  
  323. foreach ( player in level.players )
  324. {
  325. if ( player.team != "allies" && player.team != "axis" )
  326. continue;
  327.  
  328. player logPlayerData();
  329.  
  330. if ( !isAlive( player ) )
  331. continue;
  332.  
  333. lifeId = getNextLifeId();
  334. player logPlayerLife( lifeId );
  335. }
  336. }
  337.  
  338.  
  339.  
  340. canLogClient( client )
  341. {
  342. assertEx( isPlayer( client ) , "Client is not a player: " + client.code_classname );
  343. return ( client.clientid < level.MaxLogClients );
  344. }
  345.  
  346. canLogEvent()
  347. {
  348. return ( getMatchData( "eventCount" ) < level.MaxEvents );
  349. }
  350.  
  351. canLogKillstreak()
  352. {
  353. return ( getMatchData( "killstreakCount" ) < level.MaxKillstreaks );
  354. }
  355.  
  356. canLogLife( lifeId )
  357. {
  358. return ( getMatchData( "lifeCount" ) < level.MaxLives );
  359. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement