y_classes.inc 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372
  1. /**--------------------------------------------------------------------------**\
  2. ======================================
  3. y_classes - Advanced class selection
  4. ======================================
  5. Description:
  6. Allows greater control over classes so not everyone has every class. Uses
  7. a form of compression for locations.
  8. Legal:
  9. Version: MPL 1.1
  10. The contents of this file are subject to the Mozilla Public License Version
  11. 1.1 (the "License"); you may not use this file except in compliance with
  12. the License. You may obtain a copy of the License at
  13. http://www.mozilla.org/MPL/
  14. Software distributed under the License is distributed on an "AS IS" basis,
  15. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  16. for the specific language governing rights and limitations under the
  17. License.
  18. The Original Code is the YSI classes include.
  19. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  20. Portions created by the Initial Developer are Copyright (C) 2011
  21. the Initial Developer. All Rights Reserved.
  22. Contributors:
  23. ZeeX, koolk, JoeBullet/Google63, g_aSlice/Slice
  24. Thanks:
  25. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  26. ZeeX - Very productive conversations.
  27. koolk - IsPlayerinAreaEx code.
  28. TheAlpha - Danish translation.
  29. breadfish - German translation.
  30. Fireburn - Dutch translation.
  31. yom - French translation.
  32. 50p - Polish translation.
  33. Zamaroht - Spanish translation.
  34. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
  35. for me to strive to better.
  36. Pixels^ - Running XScripters where the idea was born.
  37. Matite - Pestering me to release it and using it.
  38. Very special thanks to:
  39. Thiadmer - PAWN, whose limits continue to amaze me!
  40. Kye/Kalcor - SA:MP.
  41. SA:MP Team past, present and future - SA:MP.
  42. Version:
  43. 0.1
  44. Changelog:
  45. 14/04/12:
  46. Readded OnRequestSpawn logic.
  47. Fixed Class_AddWithGroupSet.
  48. Improved GM/FS interaction.
  49. 02/01/08:
  50. First '08 edit - Fixed minus numbers in spawn points.
  51. 18/11/07:
  52. Improved location compression to allow larger areas.
  53. Moved position code to Class_OnPlayerSpawn to reduce overhead.
  54. 10/10/07:
  55. Fixed spawn data problem.
  56. 31/08/07:
  57. Added cheap master system - YSI_SLAVE_CLASSs can't be master.
  58. 05/08/07:
  59. Fixed a few bugs with repeated selection.
  60. 04/08/07:
  61. First version.
  62. Functions:
  63. Public:
  64. Class_AddRemote - Adds a class to the remote master.
  65. Class_Remote - Updates settings remotely.
  66. Core:
  67. Class_Class - Sets up the system.
  68. Class_OnPlayerRequestSpawn - Called when a player requests a spawn.
  69. Class_OnPlayerRequestClass - Called when a player requests a class.
  70. Class_OnPlayerConnect - Called when a player connects.
  71. Stock:
  72. Class_Delete - Removes a class.
  73. Class_SetPlayer - Sets whether or not a player can use a class.
  74. Class_Disable - Disables a class.
  75. Class_Enable - Enables a disabled class.
  76. Class_AddForGroup - Adds a class to the system for only one group.
  77. Class_Add - Adds a class to the system.
  78. Class_AddEx - Adds a class to the system with group selection and setting.
  79. Class_AddWithGroupSet - Adds a class and sets their group on selection.
  80. Class_AllowReselection - Allows or disallows people to return to reselect a class.
  81. Class_RequireSpawnLogin - Require people to login before spawning.
  82. Class_RequireSelectionLogin - Require people to login before selecting.
  83. Class_RequireSelectionReg - Require people to register before selecting.
  84. Class_RequireSpawnReg - Require people to register before spawning.
  85. Static:
  86. Class_AddClass - Adds a class, wrapped by API and remote functions.
  87. Inline:
  88. Class_IsActive - Checks a class is active.
  89. Class_Enabled - Checks a class is enabled.
  90. Class_IsValid - Checks a class is valid.
  91. Class_X - Gets a classes x position.
  92. Class_Y - Gets a classes y position.
  93. Class_Z - Gets a classes z position.
  94. Class_A - Gets a classes angle.
  95. Class_Skin - Gets a classes skin.
  96. API:
  97. -
  98. Callbacks:
  99. -
  100. Definitions:
  101. MAX_CLASSES - Maximum number of classes storeable by the system.
  102. CLASS_LEFT - Flag for last internal class viewed.
  103. CLASS_MIDDLE - Flag for last internal class viewed.
  104. CLASS_RIGHT - Flag for last internal class viewed.
  105. Enums:
  106. e_CLASS_FLAGS - Small data for individual classes.
  107. E_CLASS - Class data structure.
  108. Macros:
  109. -
  110. Tags:
  111. -
  112. Variables:
  113. Global:
  114. -
  115. Static:
  116. YSI_g_sClasses - Data for classes.
  117. YSI_g_sPlayerClass - Player's current classes.
  118. YSI_g_sLeft - Handle for the first internal class.
  119. YSI_g_sMiddle - Handle for the second internal class.
  120. YSI_g_sRight - Handle for the third internal class.
  121. YSI_g_sClassCount - Number of classes stored.
  122. Commands:
  123. -
  124. Compile options:
  125. -
  126. Operators:
  127. -
  128. </remarks>
  129. \**--------------------------------------------------------------------------**/
  130. #include "internal\y_version"
  131. #include "y_bit"
  132. #include "y_debug"
  133. #define YSIM_U_DISABLE
  134. #include "y_master"
  135. #include "y_iterate"
  136. #include "y_hooks"
  137. #include "internal\y_natives"
  138. #if !defined MAX_CLASSES
  139. #define MAX_CLASSES (256)
  140. #endif
  141. #if !defined MAX_CLASS_SPAWN_WEAPONS
  142. #define MAX_CLASS_SPAWN_WEAPONS (13)
  143. #endif
  144. #if !defined WEAPON_ARMOUR
  145. #define WEAPON_ARMOUR (100)
  146. #endif
  147. //#define OnPlayerRequestClassEx(%0) OnPlayerRequestClassEx_(%0)if(!YSI_gOPRCE)return 0;else
  148. //#define OnPlayerRequestSpawnEx(%0) OnPlayerRequestSpawnEx_(%0)if(!YSI_gOPRCE)return 0;else
  149. //forward OnPlayerRequestClassEx_(playerid, classid);
  150. //forward OnPlayerRequestSpawnEx_(playerid, classid);
  151. forward _Class_OnPlayerRequestClass(playerid, classid);
  152. forward _Class_OnPlayerRequestSpawn(playerid);
  153. forward _Class_OtherRequestClass(playerid, classid);
  154. forward _Class_OtherRequestSpawn(playerid);
  155. #define INFINATE_ARMOUR (0x00800000)
  156. #define _CLASS_WEAPON_CODE if((n-w)&0x01)while(w!=n&&s<MAX_CLASS_SPAWN_WEAPONS){cw=getarg(w++);if(cw==WEAPON_ARMOUR)weapons[MAX_CLASS_SPAWN_WEAPONS]=WEAPON_ARMOUR|(100<<8);else if(w==n)P:E(": Insufficient class weapon data.");else weapons[s++]=(cw&0xFF)|(getarg(w++)<<8);}else while(w!=n&&s<MAX_CLASS_SPAWN_WEAPONS){cw=getarg(w++);if(cw==WEAPON_ARMOUR)weapons[MAX_CLASS_SPAWN_WEAPONS]=WEAPON_ARMOUR|(getarg(w++)<<8);else weapons[s++]=(cw&0xFF)|(getarg(w++)<<8);}
  157. #define _GROUP_MAKE_NAME_CLASSES<%0...%1> %0Class%1
  158. #define _GROUP_MAKE_LIMIT_CLASSES MAX_CLASSES
  159. forward Class_ResolveGroups(class, Group:forgroup, bool:cp);
  160. #include "y_groups"
  161. #include "y_playerarray"
  162. #include "y_iterate"
  163. enum e_CLASS_FLAGS (<<= 1)
  164. {
  165. e_CLASS_FLAGS_SKIN = 0x0000FFFF,
  166. e_CLASS_FLAGS_ENABLED = 0x00010000,
  167. e_CLASS_FLAGS_ACTIVE
  168. }
  169. enum E_CLASS
  170. {
  171. e_CLASS_FLAGS:E_CLASS_FLAGS,
  172. Float:E_CLASS_X,
  173. Float:E_CLASS_Y,
  174. Float:E_CLASS_Z,
  175. Float:E_CLASS_A,
  176. E_CLASS_WEAPONS[MAX_CLASS_SPAWN_WEAPONS + 1],
  177. Group:E_CLASS_GROUP,
  178. PlayerArray:E_CLASS_PLAYERS<MAX_PLAYERS>
  179. }
  180. enum e_PLAYER_CLASS (<<= 1)
  181. {
  182. e_PLAYER_CLASS_NONE = 0,
  183. e_PLAYER_CLASS_SKIN = 0x000FFFFF,
  184. e_PLAYER_CLASS_PRESS = 0x00700000,
  185. e_PLAYER_CLASS_RIGHT = 0x00100000,
  186. e_PLAYER_CLASS_MIDDLE,
  187. e_PLAYER_CLASS_LEFT,
  188. // Control flags.
  189. e_PLAYER_CLASS_RETURNED, // Back in class selection.
  190. e_PLAYER_CLASS_SPAWNSINCE, // Spawned after class selection.
  191. e_PLAYER_CLASS_DISABLED, // Class selection disabled.
  192. e_PLAYER_CLASS_HADFIRST, // Spawned ever.
  193. e_PLAYER_CLASS_INSTANT, // Sent straight to class selection.
  194. e_PLAYER_CLASS_INSELECT, // In class selection.
  195. e_PLAYER_CLASS_IGNORE_ONCE
  196. }
  197. enum e_CLASS_SETTINGS (<<= 1)
  198. {
  199. e_CLASS_SETTING_NORE = 1,
  200. e_CLASS_SETTING_OPRCE,
  201. e_CLASS_SETTING_OPRSE
  202. }
  203. #define CLASS_MOVE_LEFT (-1)
  204. #define CLASS_MOVE_RIGHT (1)
  205. #define CLASS_MOVE_NONE (0)
  206. static stock
  207. YSI_g_sClasses[MAX_CLASSES][E_CLASS],
  208. e_PLAYER_CLASS:YSI_g_sPlayerClass[MAX_PLAYERS],
  209. YSI_g_sTimer[MAX_PLAYERS],
  210. YSI_g_sLeft,
  211. YSI_g_sMiddle,
  212. YSI_g_sRight,
  213. e_CLASS_SETTINGS:YSI_g_sSettings,
  214. YSI_g_sClassCount,
  215. YSI_g_sHookC,
  216. YSI_g_sHookS,
  217. YSI_g_sLastRefuse[MAX_PLAYERS];
  218. stock
  219. bool:YSI_gOPRCE = true;
  220. stock Class_ResolveGroups(class, Group:forgroup, bool:cp) <YSI_has_groups : n>
  221. {
  222. #pragma unused forgroup
  223. P:2("Class_ResolveGroups<n>: call Resolve %d %d %d", class, _:forgroup, cp);
  224. if (!cp) PA_Init(YSI_g_sClasses[class][E_CLASS_PLAYERS], true);
  225. //else if (forgroup) {}
  226. //Bit_SetAll(YSI_g_sClasses[class][E_CLASS_PLAYERS], true, bits<MAX_PLAYERS>);
  227. }
  228. stock Class_ResolveGroups(class, Group:forgroup, bool:cp) <>
  229. {
  230. #pragma unused forgroup
  231. P:2("Class_ResolveGroups<>: call Resolve %d %d %d", class, _:forgroup, cp);
  232. if (!cp) PA_Init(YSI_g_sClasses[class][E_CLASS_PLAYERS], true);
  233. //else if (forgroup) {}
  234. //Bit_SetAll(YSI_g_sClasses[class][E_CLASS_PLAYERS], true, bits<MAX_PLAYERS>);
  235. }
  236. /**--------------------------------------------------------------------------**\
  237. <summary>Class_IsValid</summary>
  238. <param name="classid">Class to check if valid.</param>
  239. <returns>
  240. -
  241. </returns>
  242. <remarks>
  243. -
  244. </remarks>
  245. \**--------------------------------------------------------------------------**/
  246. #define Class_IsValid(%1) (0<=(%1)<MAX_CLASSES&&Class_IsActive(%1))
  247. /**--------------------------------------------------------------------------**\
  248. <summary>Class_IsValid</summary>
  249. <param name="classid">Class to check if active.</param>
  250. <returns>
  251. -
  252. </returns>
  253. <remarks>
  254. -
  255. </remarks>
  256. \**--------------------------------------------------------------------------**/
  257. #define Class_IsActive(%1) (YSI_g_sClasses[(%1)][E_CLASS_FLAGS]&e_CLASS_FLAGS_ACTIVE)
  258. /**--------------------------------------------------------------------------**\
  259. <summary>Class_Enabled</summary>
  260. <param name="classid">Class to check.</param>
  261. <returns>
  262. -
  263. </returns>
  264. <remarks>
  265. -
  266. </remarks>
  267. \**--------------------------------------------------------------------------**/
  268. #define Class_Enabled(%1) (YSI_g_sClasses[(%1)][E_CLASS_FLAGS]&e_CLASS_FLAGS_ENABLED)
  269. /**--------------------------------------------------------------------------**\
  270. <summary>Class_X</summary>
  271. <param name="classid">Class to get X location for.</param>
  272. <returns>
  273. -
  274. </returns>
  275. <remarks>
  276. -
  277. </remarks>
  278. \**--------------------------------------------------------------------------**/
  279. #define Class_X(%1) YSI_g_sClasses[(%1)][E_CLASS_X]
  280. /**--------------------------------------------------------------------------**\
  281. <summary>Class_Y</summary>
  282. <param name="classid">Class to get Y location for.</param>
  283. <returns>
  284. -
  285. </returns>
  286. <remarks>
  287. -
  288. </remarks>
  289. \**--------------------------------------------------------------------------**/
  290. #define Class_Y(%1) YSI_g_sClasses[(%1)][E_CLASS_Y]
  291. /**--------------------------------------------------------------------------**\
  292. <summary>Class_Z</summary>
  293. <param name="classid">Class to get Z location for.</param>
  294. <returns>
  295. -
  296. </returns>
  297. <remarks>
  298. -
  299. </remarks>
  300. \**--------------------------------------------------------------------------**/
  301. #define Class_Z(%1) YSI_g_sClasses[(%1)][E_CLASS_Z]
  302. /**--------------------------------------------------------------------------**\
  303. <summary>Class_A</summary>
  304. <param name="classid">Class to get angle for.</param>
  305. <returns>
  306. -
  307. </returns>
  308. <remarks>
  309. -
  310. </remarks>
  311. \**--------------------------------------------------------------------------**/
  312. #define Class_A(%1) YSI_g_sClasses[(%1)][E_CLASS_A]
  313. /**--------------------------------------------------------------------------**\
  314. <summary>Class_Skin</summary>
  315. <param name="classid">Class to get skin for.</param>
  316. <returns>
  317. -
  318. </returns>
  319. <remarks>
  320. -
  321. </remarks>
  322. \**--------------------------------------------------------------------------**/
  323. #define Class_Skin(%1) (YSI_g_sClasses[(%1)][E_CLASS_FLAGS]&e_CLASS_FLAGS_SKIN)
  324. /**--------------------------------------------------------------------------**\
  325. <summary>Class_Class</summary>
  326. <returns>
  327. -
  328. </returns>
  329. <remarks>
  330. Creates three real player classes so you can scroll correctly with the
  331. direction being detected.
  332. </remarks>
  333. \**--------------------------------------------------------------------------**/
  334. hook OnScriptInit()
  335. {
  336. #if !_YSIM_IS_CLIENT
  337. if (!YSI_FILTERSCRIPT)
  338. {
  339. // This code placement is not generic.
  340. YSI_g_sLeft = AddPlayerClass(0, 1958.0, 1343.0, 15.0, 269.0, 0, 0, 0, 0, 0, 0);
  341. YSI_g_sMiddle = AddPlayerClass(0, 1958.0, 1343.0, 15.0, 269.0, 0, 0, 0, 0, 0, 0);
  342. YSI_g_sRight = AddPlayerClass(0, 1958.0, 1343.0, 15.0, 269.0, 0, 0, 0, 0, 0, 0);
  343. //printf("==========================");
  344. //printf("%d %d %d", YSI_g_sLeft, YSI_g_sMiddle, YSI_g_sRight);
  345. //printf("==========================");
  346. YSI_g_sSettings = ((funcidx("OnPlayerRequestClassEx_") == -1) ? (e_CLASS_SETTINGS:0) : (e_CLASS_SETTING_OPRCE)) | ((funcidx("OnPlayerRequestSpawnEx_") == -1) ? (e_CLASS_SETTINGS:0) : (e_CLASS_SETTING_OPRSE));
  347. #if !defined YSI_NO_MASTER
  348. // Steal the master system.
  349. _Master_Get(#_YCM, true);
  350. #if _YSIM_IS_CLOUD
  351. // Set to uninitialised.
  352. state _YCM:u;
  353. //_YCM = _YCM@u;
  354. _YCM@ = _E_YCM@u;
  355. #endif
  356. CallRemoteFunction(#_YCM, "");
  357. #if _YSIM_IS_CLOUD
  358. // Fully master.
  359. state _YCM:y;
  360. //_YCM = _YCM@y;
  361. _YCM@ = _E_YCM@y;
  362. #endif
  363. #endif
  364. }
  365. #endif
  366. //Hooks_RedirectPublic("OnPlayerRequestClass", "_Class_OnPlayerRequestClass");
  367. //Hooks_RedirectPublic("OnPlayerRequestSpawn", "_Class_OnPlayerRequestSpawn");
  368. YSI_g_sHookC = Hooks_RedirectPublic("OnPlayerRequestClass", "_Class_OnPlayerRequestClass");
  369. YSI_g_sHookS = Hooks_RedirectPublic("OnPlayerRequestSpawn", "_Class_OnPlayerRequestSpawn");
  370. return 1;
  371. }
  372. /**--------------------------------------------------------------------------**\
  373. <summary>Class_OnPlayerRequestClass</summary>
  374. <param name="playerid">Player who requested a class.</param>
  375. <param name="class">Class they requested.</param>
  376. <returns>
  377. -
  378. </returns>
  379. <remarks>
  380. The input is one of the three real classes used to detect selected
  381. direction of alteration. Scans for a class the player is allowed to use
  382. and hot swaps it out. Uses SetPlayerSkin AND SetSpawnInfo to combat bugs
  383. with calling this from OnPlayerRequestSpawn (e.g. the example team script).
  384. Calls OnPlayerRequestClassEx with the current internal class not the real
  385. one.
  386. </remarks>
  387. \**--------------------------------------------------------------------------**/
  388. static stock Class_FindNew(playerid, playerclass, dir)
  389. {
  390. P:4("Class_FindNew called: %i, %i, %i", playerid, playerclass, dir);
  391. // Handles the special case where "dir" = 0 very nicely with no extra code
  392. // slowing down the common case (as it should be)! This is simply because
  393. // "playerclass != old" will fail on the first loop with "+ 0";
  394. new
  395. old = playerclass % YSI_g_sClassCount;
  396. do
  397. {
  398. playerclass = (playerclass + dir) % YSI_g_sClassCount;
  399. P:4("Class_FindNew: %d %d", playerclass, playerid);
  400. }
  401. while (playerclass != old && (!Class_Enabled(playerclass) || !PA_Get(YSI_g_sClasses[playerclass][E_CLASS_PLAYERS], playerid)));
  402. return playerclass;
  403. }
  404. public _Class_OtherRequestClass(playerid, classid)
  405. {
  406. if (YSI_g_sHookC)
  407. {
  408. #emit PUSH.S classid
  409. #emit PUSH.S playerid
  410. #emit PUSH.C 8
  411. #emit LCTRL 6
  412. #emit ADD.C 28
  413. #emit PUSH.pri
  414. #emit LOAD.pri YSI_g_sHookC
  415. #emit SCTRL 6
  416. #emit RETN
  417. }
  418. }
  419. #if !defined YSI_NO_MASTER && _YSIM_IS_CLIENT
  420. public _Class_OnPlayerRequestClass(playerid, classid)
  421. {
  422. return 1;
  423. }
  424. #else
  425. #if !defined YSI_NO_MASTER && _YSIM_IS_CLOUD
  426. //mhook OnPlayerRequestClass(playerid, classid)
  427. public _Class_OnPlayerRequestClass(playerid, classid) <>
  428. {
  429. return 1;
  430. }
  431. //mhook OnPlayerRequestClass(playerid, classid)
  432. public _Class_OnPlayerRequestClass(playerid, classid) <_YCM:y>
  433. {
  434. #else
  435. //mhook OnPlayerRequestClass(playerid, classid)
  436. public _Class_OnPlayerRequestClass(playerid, classid)
  437. {
  438. #endif
  439. if (YSI_g_sPlayerClass[playerid] & (e_PLAYER_CLASS_IGNORE_ONCE))
  440. {
  441. SetTimerEx("_Class_SpawnPlayer3", 10, 0, "i", playerid);
  442. return 1;
  443. }
  444. P:1("_Class_OnPlayerRequestClass called: %d %d", playerid, classid);
  445. Class_TK(playerid);
  446. new
  447. dir = CLASS_MOVE_RIGHT;
  448. // Spawned from returning to class selection but not meant to.
  449. //P:5("Class_OnPlayerRequestClass(): Spawn check %d %d", playerclass, playerclass); //(playerclass & e_PLAYER_CLASS_SPAWN_CHECK), e_PLAYER_CLASS_SPAWN_CHECK);
  450. // Find which direction they pressed.
  451. switch (YSI_g_sPlayerClass[playerid] & e_PLAYER_CLASS_PRESS)
  452. {
  453. case e_PLAYER_CLASS_RIGHT:
  454. {
  455. if (classid == YSI_g_sMiddle)
  456. {
  457. // Went from the right to the middle - that's a move left.
  458. dir = CLASS_MOVE_LEFT;
  459. }
  460. else if (classid != YSI_g_sLeft)
  461. {
  462. dir = CLASS_MOVE_NONE;
  463. }
  464. }
  465. case e_PLAYER_CLASS_MIDDLE:
  466. {
  467. if (classid == YSI_g_sLeft)
  468. {
  469. // Went from the middle to the left - that's a move left.
  470. dir = CLASS_MOVE_LEFT;
  471. }
  472. else if (classid != YSI_g_sRight)
  473. {
  474. dir = CLASS_MOVE_NONE;
  475. }
  476. }
  477. default:
  478. {
  479. if (classid == YSI_g_sRight)
  480. {
  481. // Went from the left to the right - that's a wrap move left.
  482. dir = CLASS_MOVE_LEFT;
  483. }
  484. else if (classid != YSI_g_sMiddle)
  485. {
  486. dir = CLASS_MOVE_NONE;
  487. }
  488. }
  489. }
  490. // Store which class they are now on.
  491. //printf("%d %d %d %d", classid, YSI_g_sMiddle, YSI_g_sLeft, YSI_g_sRight);
  492. if (classid == YSI_g_sMiddle)
  493. {
  494. YSI_g_sPlayerClass[playerid] = (YSI_g_sPlayerClass[playerid] & ~e_PLAYER_CLASS_PRESS) | e_PLAYER_CLASS_MIDDLE | e_PLAYER_CLASS_INSELECT;
  495. }
  496. else if (classid == YSI_g_sLeft)
  497. {
  498. YSI_g_sPlayerClass[playerid] = (YSI_g_sPlayerClass[playerid] & ~e_PLAYER_CLASS_PRESS) | e_PLAYER_CLASS_LEFT | e_PLAYER_CLASS_INSELECT;
  499. }
  500. else if (classid == YSI_g_sRight)
  501. {
  502. YSI_g_sPlayerClass[playerid] = (YSI_g_sPlayerClass[playerid] & ~e_PLAYER_CLASS_PRESS) | e_PLAYER_CLASS_RIGHT | e_PLAYER_CLASS_INSELECT;
  503. }
  504. P:C(else {P:E("y_classes unidentified classid.");YSI_g_sPlayerClass[playerid] |= e_PLAYER_CLASS_INSELECT;});
  505. classid = (YSI_g_sPlayerClass[playerid] & e_PLAYER_CLASS_SKIN);
  506. if (YSI_g_sClassCount)
  507. {
  508. // Find the next available skin for this player. I'm still not sure how
  509. // this handles the case where you can't use any skin. I'll have to
  510. // look in to that.
  511. // Don't want to get stuck constantly adding "0".
  512. classid = Class_FindNew(playerid, classid, dir);
  513. P:5("Class_OnPlayerRequestClass() selected: %d", classid);
  514. Class_Goto(playerid, _:classid);
  515. }
  516. else
  517. {
  518. SetSpawnInfo(playerid, NO_TEAM, 0, 1958.0, 1343.0, 15.0, 269.0, 0, 0, 0, 0, 0, 0);
  519. SetPlayerSkin(playerid, 0);
  520. P:E("No YSI classes found");
  521. classid = -1;
  522. }
  523. // Now sort out if they actually should be spawned.
  524. /*if (YSI_g_sPlayerClass[playerid] & (e_PLAYER_CLASS_IGNORE_ONCE))
  525. {
  526. YSI_g_sPlayerClass[playerid] &= ~(e_PLAYER_CLASS_IGNORE_ONCE);
  527. return 1;
  528. }
  529. else*/
  530. if (YSI_g_sPlayerClass[playerid] & (e_PLAYER_CLASS_RETURNED | e_PLAYER_CLASS_SPAWNSINCE) == (e_PLAYER_CLASS_RETURNED | e_PLAYER_CLASS_SPAWNSINCE))
  531. {
  532. YSI_g_sPlayerClass[playerid] &= ~(e_PLAYER_CLASS_RETURNED | e_PLAYER_CLASS_SPAWNSINCE);
  533. Class_Spectate(playerid);
  534. //SpawnPlayer(playerid);
  535. //printf("0");
  536. SetTimerEx("_Class_SpawnPlayer2", 10, 0, "i", playerid);
  537. YSI_g_sTimer[playerid] = SetTimerEx("_Class_SpawnPlayer4", 50, 0, "i", playerid);
  538. /*if (YSI_g_sHookC)
  539. {
  540. #emit PUSH.C 0xFFFFFFFF
  541. #emit PUSH.S playerid
  542. #emit PUSH.C 8
  543. #emit LCTRL 6
  544. #emit ADD.C 28
  545. #emit PUSH.pri
  546. #emit LOAD.pri YSI_g_sHookC
  547. #emit SCTRL 6
  548. //#emit RETN
  549. }*/
  550. CallRemoteFunction("_Class_OtherRequestClass", "ii", playerid, -1);
  551. }
  552. else if (YSI_g_sPlayerClass[playerid] & (e_PLAYER_CLASS_RETURNED | e_PLAYER_CLASS_DISABLED | e_PLAYER_CLASS_HADFIRST) == (e_PLAYER_CLASS_DISABLED | e_PLAYER_CLASS_HADFIRST))
  553. {
  554. // If class selection is disabled for this player, they have already selected
  555. // a class and we haven't manually sent them back to the menu.
  556. //YSI_g_sPlayerClass[playerid] &= ~(e_PLAYER_CLASS_RETURNED | e_PLAYER_CLASS_SPAWNSINCE);
  557. Class_Spectate(playerid);
  558. //SpawnPlayer(playerid);
  559. //printf("1");
  560. SetTimerEx("_Class_SpawnPlayer1", 10, 0, "i", playerid);
  561. /*if (YSI_g_sHookC)
  562. {
  563. #emit PUSH.C 0xFFFFFFFF
  564. #emit PUSH.S playerid
  565. #emit PUSH.C 8
  566. #emit LCTRL 6
  567. #emit ADD.C 28
  568. #emit PUSH.pri
  569. #emit LOAD.pri YSI_g_sHookC
  570. #emit SCTRL 6
  571. //#emit RETN
  572. }*/
  573. CallRemoteFunction("_Class_OtherRequestClass", "ii", playerid, -1);
  574. }
  575. else
  576. {
  577. /*if (YSI_g_sHookC)
  578. {
  579. #emit PUSH.S classid
  580. #emit PUSH.S playerid
  581. #emit PUSH.C 8
  582. #emit LCTRL 6
  583. #emit ADD.C 28
  584. #emit PUSH.pri
  585. #emit LOAD.pri YSI_g_sHookC
  586. #emit SCTRL 6
  587. //#emit RETN
  588. }*/
  589. CallRemoteFunction("_Class_OtherRequestClass", "ii", playerid, classid);
  590. }
  591. return 1;
  592. }
  593. #endif
  594. foreign void:Class_Goto(playerid, playerclass);
  595. global void:Class_Goto(playerid, playerclass)
  596. {
  597. P:2("Class_Goto called: %i, %i", playerid, playerclass);
  598. // This now sets the REAL spawn information, including spawn location.
  599. SetSpawnInfo(playerid, NO_TEAM, Class_Skin(e_PLAYER_CLASS:playerclass), Class_X(e_PLAYER_CLASS:playerclass), Class_Y(e_PLAYER_CLASS:playerclass), Class_Z(e_PLAYER_CLASS:playerclass), Class_A(e_PLAYER_CLASS:playerclass), 0, 0, 0, 0, 0, 0);
  600. SetPlayerSkin(playerid, Class_Skin(e_PLAYER_CLASS:playerclass));
  601. YSI_g_sPlayerClass[playerid] = (YSI_g_sPlayerClass[playerid] & ~(e_PLAYER_CLASS_SKIN)) | (e_PLAYER_CLASS:playerclass);
  602. // Save the last viewed class so that we know which direction the person
  603. // went next time OnPlayerRequestClass is called.
  604. P:2("Class_Goto() end %08h %08h %d", YSI_g_sSettings, _:e_CLASS_SETTING_OPRCE, playerclass);
  605. //return 1;
  606. }
  607. /**--------------------------------------------------------------------------**\
  608. <summary>Class_OnPlayerRequestSpawn</summary>
  609. <param name="playerid">Player who selected a spawn.</param>
  610. <returns>
  611. -
  612. </returns>
  613. <remarks>
  614. Has inbuilt protection for a bug where selections aren't correctly
  615. debounced so you can press shift twice at once which can mess up some
  616. scripts (e.g. the example team selection script). Calls
  617. OnPlayerRequestSpawnEx with an additional class parameter.
  618. </remarks>
  619. \**--------------------------------------------------------------------------**/
  620. public _Class_OtherRequestSpawn(playerid)
  621. {
  622. if (YSI_g_sHookS)
  623. {
  624. #emit PUSH.S playerid
  625. #emit PUSH.C 4
  626. #emit LCTRL 6
  627. #emit ADD.C 28
  628. #emit PUSH.pri
  629. #emit LOAD.pri YSI_g_sHookS
  630. #emit SCTRL 6
  631. #emit RETN
  632. }
  633. }
  634. //mhook OnPlayerRequestSpawn(playerid)
  635. #if !defined YSI_NO_MASTER && (_YSIM_IS_CLIENT || _YSIM_IS_STUB)
  636. public _Class_OnPlayerRequestSpawn(playerid)
  637. {
  638. return 1;
  639. }
  640. #else
  641. #if !defined YSI_NO_MASTER && _YSIM_IS_CLOUD
  642. //mhook OnPlayerRequestClass(playerid, classid)
  643. public _Class_OnPlayerRequestSpawn(playerid) <>
  644. {
  645. return 1;
  646. }
  647. //mhook OnPlayerRequestClass(playerid, classid)
  648. public _Class_OnPlayerRequestSpawn(playerid) <_YCM:y>
  649. {
  650. #else
  651. //mhook OnPlayerRequestClass(playerid, classid)
  652. public _Class_OnPlayerRequestSpawn(playerid)
  653. {
  654. #endif
  655. P:2("hook Class_OnPlayerRequestSpawn called: %d", playerid);
  656. new
  657. time = GetTickCount();
  658. if ((time - YSI_g_sLastRefuse[playerid]) >= 1000)
  659. {
  660. //YSI_gOPRSE = false;
  661. //new
  662. // ret = 1;
  663. //if (YSI_g_sClassOptions & e_CLASS_OPTION_HAS_RS_CALLBACK)
  664. //{
  665. // YSI_gOPRSE = true;
  666. // ret = CallLocalFunction("OnPlayerRequestSpawnEx_", "ii", playerid, playerclass);
  667. //}
  668. new
  669. ret = CallRemoteFunction("_Class_OtherRequestSpawn", "i", playerid);
  670. P:4("Class_OnPlayerRequestSpawn() return: %d", ret);
  671. if (ret)
  672. {
  673. //#if defined _YSI_SYSTEM_GROUPS
  674. new
  675. Group:newgroup = YSI_g_sClasses[(YSI_g_sPlayerClass[playerid] & e_PLAYER_CLASS_SKIN)][E_CLASS_GROUP];
  676. P:4("Class_OnPlayerRequestSpawn() newgroup: %d", _:newgroup);
  677. if (newgroup != Group:-1) Class_ResolveGroups(playerid, newgroup, true); //Group_AddPlayer(newgroup, playerid);
  678. //#endif
  679. if (ret == -1)
  680. {
  681. YSI_g_sPlayerClass[playerid] |= e_PLAYER_CLASS_SKIN;
  682. // The order is VERY important here - this will actually
  683. // call the function further down (directly below in fact).
  684. //OnPlayerRequestClass(playerid, YSI_g_sLeft);
  685. //Class_DoOnPlayerRequestClass(playerid, YSI_g_sLeft);
  686. switch (YSI_g_sPlayerClass[playerid] & e_PLAYER_CLASS_PRESS)
  687. {
  688. case e_PLAYER_CLASS_RIGHT:
  689. {
  690. _Class_OnPlayerRequestClass(playerid, YSI_g_sLeft);
  691. }
  692. case e_PLAYER_CLASS_MIDDLE:
  693. {
  694. _Class_OnPlayerRequestClass(playerid, YSI_g_sRight);
  695. }
  696. case e_PLAYER_CLASS_LEFT:
  697. {
  698. _Class_OnPlayerRequestClass(playerid, YSI_g_sMiddle);
  699. }
  700. }
  701. }
  702. else
  703. {
  704. return 1;
  705. }
  706. }
  707. }
  708. YSI_g_sLastRefuse[playerid] = time;
  709. //Class_ResumeRefresh(playerid);
  710. P:5("Class_OnPlayerRequestSpawn: Return 0");
  711. return 0;
  712. }
  713. #endif
  714. /**--------------------------------------------------------------------------**\
  715. <summary>Class_OnPlayerSpawn</summary>
  716. <param name="playerid">Player who spawned.</param>
  717. <returns>
  718. -
  719. </returns>
  720. <remarks>
  721. Sets a player's position based on skin.
  722. </remarks>
  723. \**--------------------------------------------------------------------------**/
  724. mhook OnPlayerSpawn(playerid)
  725. {
  726. P:2("Class_OnPlayerSpawn called: %d", playerid);
  727. Class_TK(playerid);
  728. new
  729. playerclass = _:(YSI_g_sPlayerClass[playerid] & e_PLAYER_CLASS_SKIN),
  730. weapon;
  731. //YSI_g_sPlayerClass[playerid] = (YSI_g_sPlayerClass[playerid] & ~(e_PLAYER_CLASS_NOT_FIRST | e_PLAYER_CLASS_ALLOW_ONE)) | e_PLAYER_CLASS_HAS_EVER_SPAWNED | e_PLAYER_CLASS_IS_SPAWNED;
  732. for (new i = 0; i != MAX_CLASS_SPAWN_WEAPONS; ++i)
  733. {
  734. weapon = YSI_g_sClasses[playerclass][E_CLASS_WEAPONS][i];
  735. //if (weapon == WEAPON_ARMOUR) SetPlayerArmour(playerid, 100.0);
  736. if (weapon)
  737. {
  738. GivePlayerWeapon(playerid, weapon & 0xFF, weapon >>> 8);
  739. }
  740. else
  741. {
  742. break;
  743. }
  744. }
  745. weapon = YSI_g_sClasses[playerclass][E_CLASS_WEAPONS][MAX_CLASS_SPAWN_WEAPONS];
  746. P:5("Class_OnPlayerSpawn: Armour %d %d %d", weapon, weapon & 0xFF, WEAPON_ARMOUR);
  747. if ((weapon & 0xFF) == WEAPON_ARMOUR)
  748. {
  749. weapon >>>= 8;
  750. if (weapon == 0x00800000)
  751. {
  752. // INFINITY
  753. SetPlayerArmour(playerid, Float:0x7F800000);
  754. }
  755. else
  756. {
  757. SetPlayerArmour(playerid, weapon);
  758. }
  759. }
  760. // Now update reselection variables.
  761. YSI_g_sPlayerClass[playerid] = (YSI_g_sPlayerClass[playerid] & ~(e_PLAYER_CLASS_INSELECT | e_PLAYER_CLASS_IGNORE_ONCE)) | (e_PLAYER_CLASS_HADFIRST);
  762. if (YSI_g_sPlayerClass[playerid] & (e_PLAYER_CLASS_RETURNED))
  763. {
  764. if (YSI_g_sPlayerClass[playerid] & (e_PLAYER_CLASS_INSTANT))
  765. {
  766. YSI_g_sPlayerClass[playerid] |= (e_PLAYER_CLASS_SPAWNSINCE);
  767. }
  768. else
  769. {
  770. YSI_g_sPlayerClass[playerid] &= ~(e_PLAYER_CLASS_RETURNED);
  771. }
  772. }
  773. //if (YSI_g_sPlayerClass[playerid] & (e_PLAYER_CLASS_DISABLED))
  774. //{
  775. // I know it may seem odd to force class selection when it is explicitly
  776. // disabled, but this will disable the "F4" message too.
  777. //ForceClassSelection(playerid);
  778. //}
  779. return 1;
  780. }
  781. forward _Class_SpawnPlayer1(playerid);
  782. public _Class_SpawnPlayer1(playerid)
  783. {
  784. P:1("_Class_SpawnPlayer1 called: %d", playerid);
  785. //SpawnPlayer(playerid);
  786. YSI_g_sPlayerClass[playerid] |= (e_PLAYER_CLASS_IGNORE_ONCE);
  787. TogglePlayerSpectating(playerid, false);
  788. //SpawnPlayer(playerid);
  789. //YSI_g_sTimer[playerid] = SetTimerEx("_Class_SpawnPlayer3", 20, 0, "i", playerid);
  790. //Class_TK(playerid);
  791. }
  792. forward _Class_SpawnPlayer2(playerid);
  793. public _Class_SpawnPlayer2(playerid)
  794. {
  795. P:1("_Class_SpawnPlayer2 called: %d", playerid);
  796. //SpawnPlayer(playerid);
  797. //YSI_g_sPlayerClass[playerid] |= (e_PLAYER_CLASS_IGNORE_ONCE);
  798. TogglePlayerSpectating(playerid, false);
  799. //Class_TK(playerid);
  800. }
  801. forward _Class_SpawnPlayer3(playerid);
  802. public _Class_SpawnPlayer3(playerid)
  803. {
  804. P:1("_Class_SpawnPlayer3 called: %d", playerid);
  805. SpawnPlayer(playerid);
  806. //Class_TK(playerid);
  807. //YSI_g_sPlayerClass[playerid] |= (e_PLAYER_CLASS_IGNORE_ONCE);
  808. //TogglePlayerSpectating(playerid, false);
  809. //Class_TK(playerid);
  810. }
  811. forward _Class_SpawnPlayer4(playerid);
  812. public _Class_SpawnPlayer4(playerid)
  813. {
  814. P:1("_Class_SpawnPlayer4 called: %d", playerid);
  815. //SpawnPlayer(playerid);
  816. Class_Spectate(playerid);
  817. if (YSI_g_sPlayerClass[playerid] & (e_PLAYER_CLASS_DISABLED))
  818. {
  819. YSI_g_sTimer[playerid] = SetTimerEx("_Class_SpawnPlayer1", 10, 0, "i", playerid);
  820. }
  821. else
  822. {
  823. YSI_g_sTimer[playerid] = SetTimerEx("_Class_SpawnPlayer2", 10, 0, "i", playerid);
  824. }
  825. //Class_TK(playerid);
  826. //YSI_g_sPlayerClass[playerid] |= (e_PLAYER_CLASS_IGNORE_ONCE);
  827. //TogglePlayerSpectating(playerid, false);
  828. //Class_TK(playerid);
  829. }
  830. forward _Class_Return(playerid);
  831. public _Class_Return(playerid)
  832. {
  833. P:1("_Class_Return called: %d", playerid);
  834. Class_ReturnToSelection(playerid);
  835. //Class_TK(playerid);
  836. //YSI_g_sTimer[playerid] = SetTimerEx("_Class_NotSpawned", 500, 0, "i", playerid);
  837. }
  838. forward _Class_NotSpawned(playerid);
  839. public _Class_NotSpawned(playerid)
  840. {
  841. P:1("_Class_NotSpawned called: %d", playerid);
  842. // Called if they don't connect properly.
  843. Class_DisableSelection(playerid);
  844. //SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  845. //SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  846. SetTimerEx("_Class_Return", 10, 0, "i", playerid);
  847. YSI_g_sPlayerClass[playerid] |= (e_PLAYER_CLASS_RETURNED | e_PLAYER_CLASS_INSTANT);
  848. }
  849. static stock Class_TK(playerid)
  850. {
  851. // "Timer Kill".
  852. if (YSI_g_sTimer[playerid])
  853. {
  854. KillTimer(YSI_g_sTimer[playerid]);
  855. YSI_g_sTimer[playerid] = 0;
  856. }
  857. }
  858. mhook OnPlayerConnect(playerid)
  859. {
  860. //printf("OnPlayerConnect %d", playerid);
  861. YSI_g_sPlayerClass[playerid] = (e_PLAYER_CLASS_NONE);
  862. YSI_g_sTimer[playerid] = SetTimerEx("_Class_NotSpawned", 500, 0, "i", playerid);
  863. NO_GROUPS()
  864. {
  865. new
  866. slot = Bit_Slot(playerid) + 1,
  867. Bit:mask = Bit_Mask(playerid); //Bit:(1 << (playerid & (cellbits - 1)));
  868. for (new i = 0; i != MAX_CLASSES; ++i)
  869. {
  870. YSI_g_sClasses[i][E_CLASS_PLAYERS][slot] |= mask;
  871. }
  872. }
  873. return 1;
  874. }
  875. /*mhook OnPlayerDeath(playerid, killerid, reason)
  876. {
  877. }
  878. mhook OnPlayerRequestSpawn(playerid)
  879. {
  880. }
  881. mhook OnPlayerDisconnect(playerid, reason)
  882. {
  883. }*/
  884. /**--------------------------------------------------------------------------**\
  885. <summary>Class_Add</summary>
  886. <param name="skin">Skin of the class.</param>
  887. <param name="Float:x">X spawn location.</param>
  888. <param name="Float:y">Y spawn location.</param>
  889. <param name="Float:z">Z spawn location.</param>
  890. <param name="Float:a">A spawn location.</param>
  891. <param name="...">Spawn weapons and ammo (weapon then ammo)</param>
  892. <returns>
  893. -
  894. </returns>
  895. <remarks>
  896. Pretty much AddPlayerClass but allows greater control over the classes.
  897. Now has infinate (MAX_CLASS_SPAWN_WEAPONS) spawn weapons. This is one of
  898. the few API functions which is not entirely remote. This is because it has
  899. variable parameters which is need to collect in to a single array to pass to
  900. the remote function.
  901. </remarks>
  902. \**--------------------------------------------------------------------------**/
  903. stock Class_Add(skin, Float:x, Float:y, Float:z, Float:a, ...)
  904. {
  905. //printf("Class_Add called: %i, %f, %f, %f, %f, (+%i)", skin, x, y, z, a, numargs() - 5);
  906. P:3("Class_Add called: %i, %f, %f, %f, %f, (+%i)", skin, x, y, z, a, numargs() - 5);
  907. new
  908. n = numargs(),
  909. w = 5,
  910. s,
  911. weapons[MAX_CLASS_SPAWN_WEAPONS + 1],
  912. cw;
  913. _CLASS_WEAPON_CODE
  914. return Class_AddClass(skin, x, y, z, a, weapons, MAX_CLASS_SPAWN_WEAPONS + 1, Group:-1, Group:-1);
  915. }
  916. /**--------------------------------------------------------------------------**\
  917. <summary>Class_AddEx</summary>
  918. <param name="forgroup">Group that can use the skin.</param>
  919. <param name="setgroup">Group to add the player to on selection.</param>
  920. <param name="skin">Skin of the class.</param>
  921. <param name="Float:x">X spawn location.</param>
  922. <param name="Float:y">Y spawn location.</param>
  923. <param name="Float:z">Z spawn location.</param>
  924. <param name="Float:a">A spawn location.</param>
  925. <param name="...">Spawn weapons and ammo (weapon then ammo)</param>
  926. <returns>
  927. -
  928. </returns>
  929. <remarks>
  930. Pretty much AddPlayerClass but allows greater control over the classes.
  931. Now has infinate (MAX_CLASS_SPAWN_WEAPONS) spawn weapons.
  932. </remarks>
  933. \**--------------------------------------------------------------------------**/
  934. stock Class_AddEx(Group:forgroup, Group:setgroup, skin, Float:x, Float:y, Float:z, Float:a, ...)
  935. {
  936. P:3("Class_AddEx called: %i, %i, %i, %f, %f, %f, %f (+%i)", _:forgroup, _:setgroup, skin, x, y, z, a, numargs() - 7);
  937. new
  938. n = numargs(),
  939. w = 7,
  940. s,
  941. weapons[MAX_CLASS_SPAWN_WEAPONS + 1],
  942. cw;
  943. _CLASS_WEAPON_CODE
  944. return Class_AddClass(skin, x, y, z, a, weapons, MAX_CLASS_SPAWN_WEAPONS + 1, forgroup, setgroup);
  945. }
  946. /**--------------------------------------------------------------------------**\
  947. <summary>Class_AddForGroup</summary>
  948. <param name="group">Group to allow to use the class.</param>
  949. <param name="skin">Skin of the class.</param>
  950. <param name="Float:x">X spawn location.</param>
  951. <param name="Float:y">Y spawn location.</param>
  952. <param name="Float:z">Z spawn location.</param>
  953. <param name="Float:a">A spawn location.</param>
  954. <param name="...">Weapon data.</param>
  955. <returns>
  956. -
  957. </returns>
  958. <remarks>
  959. Adds a class only people in the specified group can use.
  960. </remarks>
  961. \**--------------------------------------------------------------------------**/
  962. stock Class_AddForGroup(Group:group, skin, Float:x, Float:y, Float:z, Float:a, ...)
  963. {
  964. P:3("Class_AddForGroup called: %i, %i, %f, %f, %f, %f (+%i)", _:group, skin, x, y, z, a, numargs() - 6);
  965. new
  966. n = numargs(),
  967. w = 6,
  968. s,
  969. weapons[MAX_CLASS_SPAWN_WEAPONS + 1],
  970. cw;
  971. _CLASS_WEAPON_CODE
  972. return Class_AddClass(skin, x, y, z, a, weapons, MAX_CLASS_SPAWN_WEAPONS + 1, group, Group:-1);
  973. }
  974. /**--------------------------------------------------------------------------**\
  975. <summary>Class_AddWithGroupSet</summary>
  976. <param name="group">Group to make players who use this group.</param>
  977. <param name="skin">Skin of the class.</param>
  978. <param name="Float:x">X spawn location.</param>
  979. <param name="Float:y">Y spawn location.</param>
  980. <param name="Float:z">Z spawn location.</param>
  981. <param name="Float:a">A spawn location.</param>
  982. <param name="...">Spawn weapons.</param>
  983. <returns>
  984. -
  985. </returns>
  986. <remarks>
  987. Adds a class which puts you in the specified group when selected.
  988. </remarks>
  989. \**--------------------------------------------------------------------------**/
  990. stock Class_AddWithGroupSet(Group:group, skin, Float:x, Float:y, Float:z, Float:a, ...)
  991. {
  992. P:3("Class_AddWithGroupSet called: %i, %i, %f, %f, %f, %f (+%i)", _:group, skin, x, y, z, a, numargs() - 6);
  993. new
  994. n = numargs(),
  995. w = 6,
  996. s,
  997. weapons[MAX_CLASS_SPAWN_WEAPONS + 1],
  998. cw;
  999. _CLASS_WEAPON_CODE
  1000. return Class_AddClass(skin, x, y, z, a, weapons, MAX_CLASS_SPAWN_WEAPONS + 1, Group:-1, group);
  1001. }
  1002. /**--------------------------------------------------------------------------**\
  1003. <summary>Class_AddClass</summary>
  1004. <param name="skin">Skin of the class.</param>
  1005. <param name="Float:x">X spawn location.</param>
  1006. <param name="Float:y">Y spawn location.</param>
  1007. <param name="Float:z">Z spawn location.</param>
  1008. <param name="Float:a">A spawn location.</param>
  1009. <param name="weapons[]">Array of spawn weapon data.</param>
  1010. <param name="count">Number of weapons added.</param>
  1011. <param name="forgroup">Group that can use the class.</param>
  1012. <param name="asgroup">Group to assign people to with this class.</param>
  1013. <returns>
  1014. -
  1015. </returns>
  1016. <remarks>
  1017. Does the hard work. This took a long time to get working correctly with the
  1018. new master system, infact getting just this one function to compile took a
  1019. major re-working of the macros to reduce the length of intermediate stages.
  1020. </remarks>
  1021. \**--------------------------------------------------------------------------**/
  1022. foreign Class_AddClass(s,Float:x,Float:y,Float:z,Float:a,w[],c,Group:f,Group:g);
  1023. global Class_AddClass(s,Float:x,Float:y,Float:z,Float:a,w[],c,Group:f,Group:g)
  1024. {
  1025. //printf("Class_AddClass called: %i, %f, %f, %f, %f, %s, %i, %i, %i", s, x, y, z, a, Debug_PrintArray(w, c), c, _:f, _:g);
  1026. P:2("Class_AddClass called: %i, %f, %f, %f, %f, %s, %i, %i, %i", s, x, y, z, a, Debug_PrintArray(w, c), c, _:f, _:g);
  1027. new
  1028. i;
  1029. while (i < MAX_CLASSES)
  1030. {
  1031. if (!Class_IsActive(i)) break;
  1032. i++;
  1033. }
  1034. if (i == MAX_CLASSES) return -1;
  1035. YSI_g_sClasses[i][E_CLASS_FLAGS] = e_CLASS_FLAGS_ACTIVE | e_CLASS_FLAGS_ENABLED | e_CLASS_FLAGS:s;
  1036. YSI_g_sClasses[i][E_CLASS_X] = x;
  1037. YSI_g_sClasses[i][E_CLASS_Y] = y;
  1038. YSI_g_sClasses[i][E_CLASS_Z] = z;
  1039. YSI_g_sClasses[i][E_CLASS_A] = a;
  1040. new
  1041. j;
  1042. // This may be better with a memcpy.
  1043. while (j < c)
  1044. {
  1045. P:5("Class_AddClass: weapon %d %d %d", j, c, w[j]);
  1046. YSI_g_sClasses[i][E_CLASS_WEAPONS][j] = w[j];
  1047. ++j;
  1048. }
  1049. //printf("Class_AddClass: weapon %d %d %d", j, c, i);
  1050. PA_FastInit(YSI_g_sClasses[i][E_CLASS_PLAYERS]);
  1051. //printf("Class_AddClass: weapon %d %d %d", j, c, f);
  1052. Class_ResolveGroups(i, f, false);
  1053. //printf("Class_AddClass: weapon %d %d %d", j, c, g);
  1054. YSI_g_sClasses[i][E_CLASS_GROUP] = g;
  1055. YSI_g_sClassCount++;
  1056. //printf("Class_AddClass: weapon %d %d %d", j, c, YSI_g_sClassCount);
  1057. return i;
  1058. }
  1059. /**--------------------------------------------------------------------------**\
  1060. <summary>Class_HasGroup</summary>
  1061. <param name="classid">The class to test.</param>
  1062. <param name="Group:group">The group to test setting of.</param>
  1063. <returns>
  1064. Does this class add players to the given group on spawn?
  1065. </returns>
  1066. <remarks>
  1067. -
  1068. </remarks>
  1069. \**--------------------------------------------------------------------------**/
  1070. foreign Class_HasGroup(classid, Group:group);
  1071. global Class_HasGroup(classid, Group:group)
  1072. {
  1073. return YSI_g_sClasses[classid][E_CLASS_GROUP] == group;
  1074. }
  1075. /**--------------------------------------------------------------------------**\
  1076. <summary>Class_Enable</summary>
  1077. <returns>
  1078. -
  1079. </returns>
  1080. <remarks>
  1081. -
  1082. </remarks>
  1083. \**--------------------------------------------------------------------------**/
  1084. foreign Class_Enable(classid, bool:toggle);
  1085. global Class_Enable(classid, bool:toggle)
  1086. {
  1087. if (Class_IsValid(classid))
  1088. {
  1089. if (toggle)
  1090. {
  1091. YSI_g_sClasses[classid][E_CLASS_FLAGS] |= e_CLASS_FLAGS_ENABLED;
  1092. }
  1093. else
  1094. {
  1095. YSI_g_sClasses[classid][E_CLASS_FLAGS] &= ~e_CLASS_FLAGS_ENABLED;
  1096. // TODO! Hide the class for anyone currently viewing it.
  1097. // foreach (new playerid : Player)
  1098. // {
  1099. // new
  1100. // e_PLAYER_CLASS:curclass = YSI_g_sPlayerClass[playerid];
  1101. // P:4("Class_Delete: %d %d %d", playerid, curclass, e_PLAYER_CLASS_SELECT);
  1102. // if (curclass & e_PLAYER_CLASS_SELECT)
  1103. // {
  1104. // if (e_PLAYER_CLASS:classid == curclass & e_PLAYER_CLASS_SKIN) Class_Goto(playerid, Class_FindNew(playerid, e_PLAYER_CLASS:classid, CLASS_MOVE_RIGHT));
  1105. // }
  1106. // }
  1107. }
  1108. return 1;
  1109. }
  1110. return 0;
  1111. }
  1112. /**--------------------------------------------------------------------------**\
  1113. <summary>Class_Delete</summary>
  1114. <param name="classid">Class to delete.</param>
  1115. <returns>
  1116. -
  1117. </returns>
  1118. <remarks>
  1119. Completely removes a class from the system.
  1120. </remarks>
  1121. \**--------------------------------------------------------------------------**/
  1122. foreign void:Class_Delete(classid);
  1123. global void:Class_Delete(classid)
  1124. {
  1125. P:2("Class_Delete called: %i", classid);
  1126. if (Class_Enable(classid, false))
  1127. {
  1128. YSI_g_sClasses[classid][E_CLASS_FLAGS] = e_CLASS_FLAGS:0;
  1129. }
  1130. //return 1;
  1131. }
  1132. /**--------------------------------------------------------------------------**\
  1133. <summary>Class_SetPlayer</summary>
  1134. <param name="classid">Class to set permissions for.</param>
  1135. <param name="playerid">Player to set for.</param>
  1136. <param name="set">Whether or not they can use this class.</param>
  1137. <returns>
  1138. -
  1139. </returns>
  1140. <remarks>
  1141. -
  1142. </remarks>
  1143. \**--------------------------------------------------------------------------**/
  1144. foreign void:Class_SetPlayer(cl, pid, bool:s);
  1145. global void:Class_SetPlayer(cl, pid, bool:s)
  1146. {
  1147. //printf("CLASS SET PLAYER: %d %d %d", cl, pid, s);
  1148. PA_Set(YSI_g_sClasses[cl][E_CLASS_PLAYERS], pid, s);
  1149. }
  1150. /**--------------------------------------------------------------------------**\
  1151. <summary>Class_GetPlayer</summary>
  1152. <param name="classid">Class to set permissions for.</param>
  1153. <param name="playerid">Player to set for.</param>
  1154. <returns>
  1155. -
  1156. </returns>
  1157. <remarks>
  1158. -
  1159. </remarks>
  1160. \**--------------------------------------------------------------------------**/
  1161. foreign bool:Class_GetPlayer(cl,pid);
  1162. global bool:Class_GetPlayer(cl,pid)
  1163. {
  1164. return PA_Get(YSI_g_sClasses[cl][E_CLASS_PLAYERS], pid);
  1165. }
  1166. /**--------------------------------------------------------------------------**\
  1167. <summary>Class_Get</summary>
  1168. <param name="playerid">Player to get the current class of.</param>
  1169. <returns>
  1170. -
  1171. </returns>
  1172. <remarks>
  1173. -
  1174. </remarks>
  1175. \**--------------------------------------------------------------------------**/
  1176. foreign Class_Get(playerid);
  1177. global Class_Get(playerid)
  1178. {
  1179. if (0 <= playerid < MAX_PLAYERS)
  1180. {
  1181. return _:(YSI_g_sPlayerClass[playerid] & e_PLAYER_CLASS_SKIN);
  1182. }
  1183. return -1;
  1184. }
  1185. foreign void:Class_DisableSelection(playerid);
  1186. global void:Class_DisableSelection(playerid)
  1187. {
  1188. if (YSI_g_sPlayerClass[playerid] & e_PLAYER_CLASS_INSELECT)
  1189. {
  1190. Class_Spectate(playerid);
  1191. Class_TK(playerid);
  1192. }
  1193. //return 1;
  1194. }
  1195. foreign void:Class_DisableReselection(playerid);
  1196. global void:Class_DisableReselection(playerid)
  1197. {
  1198. YSI_g_sPlayerClass[playerid] |= (e_PLAYER_CLASS_DISABLED);
  1199. // Disable "F4".
  1200. //ForceClassSelection(playerid);
  1201. //return 1;
  1202. }
  1203. foreign void:Class_EnableReselection(playerid);
  1204. global void:Class_EnableReselection(playerid)
  1205. {
  1206. YSI_g_sPlayerClass[playerid] &= ~(e_PLAYER_CLASS_DISABLED);
  1207. //return 1;
  1208. }
  1209. foreign void:Class_ForceReselection(playerid);
  1210. global void:Class_ForceReselection(playerid)
  1211. {
  1212. YSI_g_sPlayerClass[playerid] = (YSI_g_sPlayerClass[playerid] | e_PLAYER_CLASS_RETURNED) & ~(e_PLAYER_CLASS_SPAWNSINCE);
  1213. ForceClassSelection(playerid);
  1214. //return 1;
  1215. }
  1216. foreign void:Class_ReturnToSelection(playerid);
  1217. global void:Class_ReturnToSelection(playerid)
  1218. {
  1219. YSI_g_sPlayerClass[playerid] |= (e_PLAYER_CLASS_INSTANT);
  1220. Class_ForceReselection(playerid);
  1221. TogglePlayerSpectating(playerid, false);
  1222. //return 1;
  1223. }
  1224. static stock Class_Spectate(playerid)
  1225. {
  1226. new
  1227. Float:x1,
  1228. Float:y1,
  1229. Float:z1;
  1230. GetPlayerCameraPos(playerid, x1, y1, z1);
  1231. new
  1232. Float:x2,
  1233. Float:y2,
  1234. Float:z2;
  1235. GetPlayerCameraFrontVector(playerid, x2, y2, z2);
  1236. TogglePlayerSpectating(playerid, true);
  1237. SetPlayerCameraPos(playerid, x1, y1, z1);
  1238. SetPlayerCameraLookAt(playerid, x2, y2, z2);
  1239. PlayerSpectatePlayer(playerid, playerid, SPECTATE_MODE_FIXED);
  1240. }
  1241. #if defined _ALS_AddPlayerClass
  1242. #undef AddPlayerClass
  1243. #else
  1244. #define _ALS_AddPlayerClass
  1245. #endif
  1246. #define AddPlayerClass Class_Add
  1247. //#define YSI_SET_LAST_GROUP 22
  1248. #include "internal\y_grouprevert"