multiclass.inc 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  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. \**--------------------------------------------------------------------------**/
  129. PRE_HOOK(Class)
  130. #undef CHAIN_ORDER
  131. #define CHAIN_ORDER @CO_Class
  132. forward Class_ResolveGroups(class, Group:forgroup, bool:cp);
  133. enum e_CLASS_FLAGS (<<= 1)
  134. {
  135. e_CLASS_FLAGS_SKIN = 0x0000FFFF,
  136. e_CLASS_FLAGS_ENABLED = 0x00010000,
  137. e_CLASS_FLAGS_ACTIVE
  138. }
  139. enum E_CLASS
  140. {
  141. e_CLASS_FLAGS:E_CLASS_FLAGS,
  142. Float:E_CLASS_X,
  143. Float:E_CLASS_Y,
  144. Float:E_CLASS_Z,
  145. Float:E_CLASS_A,
  146. E_CLASS_WEAPONS[MAX_CLASS_SPAWN_WEAPONS + 1],
  147. Group:E_CLASS_GROUP,
  148. PlayerArray:E_CLASS_PLAYERS<MAX_PLAYERS>
  149. }
  150. static stock
  151. YSI_g_sClasses[MAX_CLASSES][E_CLASS],
  152. YSI_g_sPlayerClass[MAX_PLAYERS],
  153. YSI_g_sInternalClass[MAX_PLAYERS],
  154. YSI_g_sClassCount,
  155. YSI_g_sLastRefuse[MAX_PLAYERS];
  156. stock Class_ResolveGroups(class, Group:forgroup, bool:cp) <YSI_has_groups : n>
  157. {
  158. #pragma unused forgroup
  159. P:2("Class_ResolveGroups<n>: call Resolve %d %d %d", class, _:forgroup, cp);
  160. if (!cp) PA_Init(YSI_g_sClasses[class][E_CLASS_PLAYERS], true);
  161. }
  162. stock Class_ResolveGroups(class, Group:forgroup, bool:cp) <>
  163. {
  164. #pragma unused forgroup
  165. P:2("Class_ResolveGroups<>: call Resolve %d %d %d", class, _:forgroup, cp);
  166. if (!cp) PA_Init(YSI_g_sClasses[class][E_CLASS_PLAYERS], true);
  167. }
  168. /**--------------------------------------------------------------------------**\
  169. <summary>_Class_IsActive</summary>
  170. <param name="classid">Class to check if active.</param>
  171. <returns>
  172. -
  173. </returns>
  174. <remarks>
  175. -
  176. </remarks>
  177. \**--------------------------------------------------------------------------**/
  178. #define _Class_IsActive(%1) (YSI_g_sClasses[(%1)][E_CLASS_FLAGS] & e_CLASS_FLAGS_ACTIVE)
  179. /**--------------------------------------------------------------------------**\
  180. <summary>_Class_IsValid</summary>
  181. <param name="classid">Class to check if valid.</param>
  182. <returns>
  183. -
  184. </returns>
  185. <remarks>
  186. -
  187. </remarks>
  188. \**--------------------------------------------------------------------------**/
  189. #define _Class_IsValid(%1) (IS_IN_RANGE((%1), 0, MAX_CLASSES) && _Class_IsActive(%1))
  190. /**--------------------------------------------------------------------------**\
  191. <summary>_Class_Enabled</summary>
  192. <param name="classid">Class to check.</param>
  193. <returns>
  194. -
  195. </returns>
  196. <remarks>
  197. -
  198. </remarks>
  199. \**--------------------------------------------------------------------------**/
  200. #define _Class_Enabled(%1) (YSI_g_sClasses[(%1)][E_CLASS_FLAGS] & e_CLASS_FLAGS_ENABLED)
  201. /**--------------------------------------------------------------------------**\
  202. <summary>Class_X</summary>
  203. <param name="classid">Class to get X location for.</param>
  204. <returns>
  205. -
  206. </returns>
  207. <remarks>
  208. -
  209. </remarks>
  210. \**--------------------------------------------------------------------------**/
  211. #define Class_X(%1) YSI_g_sClasses[(%1)][E_CLASS_X]
  212. /**--------------------------------------------------------------------------**\
  213. <summary>Class_Y</summary>
  214. <param name="classid">Class to get Y location for.</param>
  215. <returns>
  216. -
  217. </returns>
  218. <remarks>
  219. -
  220. </remarks>
  221. \**--------------------------------------------------------------------------**/
  222. #define Class_Y(%1) YSI_g_sClasses[(%1)][E_CLASS_Y]
  223. /**--------------------------------------------------------------------------**\
  224. <summary>Class_Z</summary>
  225. <param name="classid">Class to get Z location for.</param>
  226. <returns>
  227. -
  228. </returns>
  229. <remarks>
  230. -
  231. </remarks>
  232. \**--------------------------------------------------------------------------**/
  233. #define Class_Z(%1) YSI_g_sClasses[(%1)][E_CLASS_Z]
  234. /**--------------------------------------------------------------------------**\
  235. <summary>Class_A</summary>
  236. <param name="classid">Class to get angle for.</param>
  237. <returns>
  238. -
  239. </returns>
  240. <remarks>
  241. -
  242. </remarks>
  243. \**--------------------------------------------------------------------------**/
  244. #define Class_A(%1) YSI_g_sClasses[(%1)][E_CLASS_A]
  245. /**--------------------------------------------------------------------------**\
  246. <summary>Class_Skin</summary>
  247. <param name="classid">Class to get skin for.</param>
  248. <returns>
  249. -
  250. </returns>
  251. <remarks>
  252. -
  253. </remarks>
  254. \**--------------------------------------------------------------------------**/
  255. #define Class_Skin(%1) (YSI_g_sClasses[(%1)][E_CLASS_FLAGS] & e_CLASS_FLAGS_SKIN)
  256. /**--------------------------------------------------------------------------**\
  257. <summary>Class_Class</summary>
  258. <returns>
  259. -
  260. </returns>
  261. <remarks>
  262. Creates three real player classes so you can scroll correctly with the
  263. direction being detected.
  264. </remarks>
  265. \**--------------------------------------------------------------------------**/
  266. hook OnScriptInit()
  267. {
  268. #if !_YSIM_IS_CLIENT
  269. if (!YSI_FILTERSCRIPT)
  270. {
  271. // This code placement is not generic.
  272. new
  273. classLeft = AddPlayerClass(0, 1958.0, 1343.0, 15.0, 269.0, 0, 0, 0, 0, 0, 0),
  274. classMiddle = AddPlayerClass(0, 1958.0, 1343.0, 15.0, 269.0, 0, 0, 0, 0, 0, 0),
  275. classRight = AddPlayerClass(0, 1958.0, 1343.0, 15.0, 269.0, 0, 0, 0, 0, 0, 0);
  276. if (classLeft != 0 || classMiddle != 1 || classRight != 2)
  277. {
  278. P:E("y_classes assumptions failed. Do you have \"AddPlayerClass\" in your modes?");
  279. }
  280. //printf("==========================");
  281. P:4("Class_OnScriptInit: classes = %d %d %d", classLeft, classMiddle, classRight);
  282. //printf("==========================");
  283. #if !defined YSI_NO_MASTER
  284. if (_Master_Get(#_YCM, true))
  285. {
  286. // Nothing changed, or we took it without force.
  287. state _YCM:y;
  288. _YCM@ = _E_YCM@y;
  289. }
  290. else
  291. {
  292. // Something changed, tell other scripts.
  293. state _YCM:u;
  294. _YCM@ = _E_YCM@u;
  295. // Determine the next unique name.
  296. CallRemoteFunction(#_YCM, "");
  297. // There is a note in y_master about this being safe
  298. // because servers always get the data. This is the server
  299. // code, but may be in use by cloud systems. This, however,
  300. // is still not a problem because we never fully pass off.
  301. }
  302. #endif
  303. }
  304. #endif
  305. return 1;
  306. }
  307. static stock Class_FindNew(playerid, playerclass, dir)
  308. {
  309. P:4("Class_FindNew called: %i, %i, %i", playerid, playerclass, dir);
  310. if (dir == 0)
  311. {
  312. // No change, check the current skin is still valid. There are plenty
  313. // of reasons for this: Removed skin, returned -1, disabled, returned to
  314. // class selection. This used to not be handled explicitly, but now it
  315. // is.
  316. if (_Class_Enabled(playerclass) && PA_Get(YSI_g_sClasses[playerclass][E_CLASS_PLAYERS], playerid)) return playerclass;
  317. ++dir;
  318. }
  319. new
  320. old = playerclass % YSI_g_sClassCount;
  321. do
  322. {
  323. playerclass = (playerclass + dir) % YSI_g_sClassCount;
  324. P:4("Class_FindNew: %d %d", playerclass, playerid);
  325. }
  326. while (playerclass != old && (!_Class_Enabled(playerclass) || !PA_Get(YSI_g_sClasses[playerclass][E_CLASS_PLAYERS], playerid)));
  327. // (!(playerclass == old || (_Class_Enabled(playerclass) && PA_Get(YSI_g_sClasses[playerclass][E_CLASS_PLAYERS], playerid))))
  328. return playerclass;
  329. }
  330. /**--------------------------------------------------------------------------**\
  331. <summary>Class_Goto</summary>
  332. <param name="playerid">Player who is changing class.</param>
  333. <param name="playerclass">The internal class they are switching to.</param>
  334. <returns>
  335. -
  336. </returns>
  337. <remarks>
  338. Does the visual faking through "SetPlayerSkin", and also calls
  339. "SetSpawnInfo" to avoid any lag from "SetPlayerPos" under "OnPlayerSpawn".
  340. </remarks>
  341. \**--------------------------------------------------------------------------**/
  342. foreign void:Class_Goto(playerid, playerclass);
  343. global void:Class_Goto(playerid, playerclass)
  344. {
  345. P:2("Class_Goto called: %i, %i", playerid, playerclass);
  346. // This now sets the REAL spawn information, including spawn location.
  347. 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);
  348. SetPlayerSkin(playerid, Class_Skin(e_PLAYER_CLASS:playerclass));
  349. YSI_g_sPlayerClass[playerid] = playerclass; //(YSI_g_sPlayerClass[playerid] & ~e_PLAYER_CLASS_SKIN) | (e_PLAYER_CLASS:playerclass);
  350. }
  351. /**--------------------------------------------------------------------------**\
  352. <summary>Class_OnPlayerRequestSpawn</summary>
  353. <param name="playerid">Player who selected a spawn.</param>
  354. <returns>
  355. -
  356. </returns>
  357. <remarks>
  358. Has inbuilt protection for a bug where selections aren't correctly
  359. debounced so you can press shift twice at once which can mess up some
  360. scripts (e.g. the example team selection script). Calls
  361. OnPlayerRequestSpawnEx with an additional class parameter.
  362. </remarks>
  363. \**--------------------------------------------------------------------------**/
  364. #if !defined YSI_NO_MASTER && (_YSIM_IS_CLIENT || _YSIM_IS_STUB)
  365. public OnPlayerRequestSpawn(playerid)
  366. {
  367. return 1;
  368. }
  369. #else
  370. #if !defined YSI_NO_MASTER && _YSIM_IS_CLOUD
  371. public OnPlayerRequestSpawn(playerid) <>
  372. {
  373. return 1;
  374. }
  375. public OnPlayerRequestSpawn(playerid) <_YCM:y>
  376. #else
  377. public OnPlayerRequestSpawn(playerid)
  378. #endif
  379. {
  380. P:1("Class_OnPlayerRequestSpawn called: %d", playerid);
  381. new
  382. time = GetTickCount();
  383. if ((time - YSI_g_sLastRefuse[playerid]) >= 500)
  384. {
  385. new
  386. ret = CallRemoteFunction("Class_OnPlayerRequestSpawn", "i", playerid);
  387. P:4("Class_OnPlayerRequestSpawn() return: %d", ret);
  388. if (ret)
  389. {
  390. new
  391. Group:newgroup = YSI_g_sClasses[YSI_g_sPlayerClass[playerid]][E_CLASS_GROUP];
  392. P:4("Class_OnPlayerRequestSpawn() newgroup: %d", _:newgroup);
  393. if (newgroup != Group:-1) Class_ResolveGroups(playerid, newgroup, true);
  394. if (ret == -1)
  395. {
  396. // Send the player back to class selection.
  397. _Class_OnPlayerRequestClass(playerid, YSI_g_sInternalClass[playerid]);
  398. }
  399. else
  400. {
  401. return 1;
  402. }
  403. }
  404. }
  405. P:5("Class_OnPlayerRequestSpawn: Return 0");
  406. return
  407. YSI_g_sLastRefuse[playerid] = time,
  408. 0;
  409. }
  410. #endif
  411. HOOK_FORWARD:Class_OnPlayerRequestSpawn(playerid);
  412. #if defined _ALS_OnPlayerRequestSpawn
  413. #undef OnPlayerRequestSpawn
  414. #else
  415. #define _ALS_OnPlayerRequestSpawn
  416. #endif
  417. #define OnPlayerRequestSpawn(%0) Class_OnPlayerRequestSpawn(%0) <_ALS : _ALS_go>
  418. /**--------------------------------------------------------------------------**\
  419. <summary>Class_OnPlayerSpawn</summary>
  420. <param name="playerid">Player who spawned.</param>
  421. <returns>
  422. -
  423. </returns>
  424. <remarks>
  425. Sets a player's position based on skin.
  426. </remarks>
  427. \**--------------------------------------------------------------------------**/
  428. mhook OnPlayerSpawn(playerid)
  429. {
  430. P:2("Class_OnPlayerSpawn called: %d", playerid);
  431. new
  432. playerclass = YSI_g_sPlayerClass[playerid],
  433. weapon;
  434. for (new i = 0; i != MAX_CLASS_SPAWN_WEAPONS; ++i)
  435. {
  436. weapon = YSI_g_sClasses[playerclass][E_CLASS_WEAPONS][i];
  437. if (weapon)
  438. {
  439. GivePlayerWeapon(playerid, weapon & 0xFF, weapon >>> 8);
  440. }
  441. else
  442. {
  443. break;
  444. }
  445. }
  446. weapon = YSI_g_sClasses[playerclass][E_CLASS_WEAPONS][MAX_CLASS_SPAWN_WEAPONS];
  447. P:5("Class_OnPlayerSpawn: Armour %d %d %d", weapon, weapon & 0xFF, WEAPON_ARMOUR);
  448. if ((weapon & 0xFF) == WEAPON_ARMOUR)
  449. {
  450. weapon >>>= 8;
  451. if (weapon == 0x00800000)
  452. {
  453. // INFINITY
  454. SetPlayerArmour(playerid, Float:0x7F800000);
  455. }
  456. else
  457. {
  458. SetPlayerArmour(playerid, weapon);
  459. }
  460. }
  461. return 1;
  462. }
  463. /**--------------------------------------------------------------------------**\
  464. <summary>Class_OnPlayerConnect</summary>
  465. <param name="playerid">Player who joined the server.</param>
  466. <returns>
  467. -
  468. </returns>
  469. <remarks>
  470. Reset all the data on this player's current classes.
  471. </remarks>
  472. \**--------------------------------------------------------------------------**/
  473. mhook OnPlayerConnect(playerid)
  474. {
  475. YSI_g_sPlayerClass[playerid] = -1,
  476. YSI_g_sInternalClass[playerid] = -1;
  477. NO_GROUPS()
  478. {
  479. new
  480. slot = PA_Slot(playerid),
  481. Bit:mask = PA_Mask(playerid);
  482. for (new i = 0; i != MAX_CLASSES; ++i)
  483. {
  484. YSI_g_sClasses[i][E_CLASS_PLAYERS][slot] |= mask;
  485. }
  486. }
  487. return 1;
  488. }
  489. /**--------------------------------------------------------------------------**\
  490. <summary>_CLASS_WEAPON_CODE</summary>
  491. <returns>
  492. -
  493. </returns>
  494. <remarks>
  495. Converts the variable arguments to an array.
  496. </remarks>
  497. \**--------------------------------------------------------------------------**/
  498. #define _CLASS_WEAPON_CODE \
  499. {if((n-w+1)/2>MAX_CLASS_SPAWN_WEAPONS) P:E("Excessive class weapon data."); \
  500. if((n-w)&0x01){while(w!=n)if((cw=getarg(w++))==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);} \
  501. else{while(w!=n)weapons[((cw=getarg(w++))==WEAPON_ARMOUR)?MAX_CLASS_SPAWN_WEAPONS:(s++)]=(cw&0xFF)|(getarg(w++)<<8);}}
  502. /**--------------------------------------------------------------------------**\
  503. <summary>Class_Add</summary>
  504. <param name="skin">Skin of the class.</param>
  505. <param name="Float:x">X spawn location.</param>
  506. <param name="Float:y">Y spawn location.</param>
  507. <param name="Float:z">Z spawn location.</param>
  508. <param name="Float:a">A spawn location.</param>
  509. <param name="...">Spawn weapons and ammo (weapon then ammo)</param>
  510. <returns>
  511. -
  512. </returns>
  513. <remarks>
  514. Pretty much AddPlayerClass but allows greater control over the classes.
  515. Now has infinate (MAX_CLASS_SPAWN_WEAPONS) spawn weapons. This is one of
  516. the few API functions which is not entirely remote. This is because it has
  517. variable parameters which is need to collect in to a single array to pass to
  518. the remote function.
  519. </remarks>
  520. \**--------------------------------------------------------------------------**/
  521. stock Class_Add(skin, Float:x, Float:y, Float:z, Float:a, ...)
  522. {
  523. P:3("Class_Add called: %i, %f, %f, %f, %f, (+%i)", skin, x, y, z, a, numargs() - 5);
  524. new
  525. n = numargs(),
  526. w = 5,
  527. s,
  528. weapons[MAX_CLASS_SPAWN_WEAPONS + 1],
  529. cw;
  530. _CLASS_WEAPON_CODE
  531. return Class_AddClass(skin, x, y, z, a, weapons, MAX_CLASS_SPAWN_WEAPONS + 1, Group:-1, Group:-1);
  532. }
  533. /**--------------------------------------------------------------------------**\
  534. <summary>Class_AddEx</summary>
  535. <param name="forgroup">Group that can use the skin.</param>
  536. <param name="setgroup">Group to add the player to on selection.</param>
  537. <param name="skin">Skin of the class.</param>
  538. <param name="Float:x">X spawn location.</param>
  539. <param name="Float:y">Y spawn location.</param>
  540. <param name="Float:z">Z spawn location.</param>
  541. <param name="Float:a">A spawn location.</param>
  542. <param name="...">Spawn weapons and ammo (weapon then ammo)</param>
  543. <returns>
  544. -
  545. </returns>
  546. <remarks>
  547. Pretty much AddPlayerClass but allows greater control over the classes.
  548. Now has infinate (MAX_CLASS_SPAWN_WEAPONS) spawn weapons.
  549. </remarks>
  550. \**--------------------------------------------------------------------------**/
  551. stock Class_AddEx(Group:forgroup, Group:setgroup, skin, Float:x, Float:y, Float:z, Float:a, ...)
  552. {
  553. P:3("Class_AddEx called: %i, %i, %i, %f, %f, %f, %f (+%i)", _:forgroup, _:setgroup, skin, x, y, z, a, numargs() - 7);
  554. new
  555. n = numargs(),
  556. w = 7,
  557. s,
  558. weapons[MAX_CLASS_SPAWN_WEAPONS + 1],
  559. cw;
  560. _CLASS_WEAPON_CODE
  561. return Class_AddClass(skin, x, y, z, a, weapons, MAX_CLASS_SPAWN_WEAPONS + 1, forgroup, setgroup);
  562. }
  563. /**--------------------------------------------------------------------------**\
  564. <summary>Class_AddForGroup</summary>
  565. <param name="group">Group to allow to use the class.</param>
  566. <param name="skin">Skin of the class.</param>
  567. <param name="Float:x">X spawn location.</param>
  568. <param name="Float:y">Y spawn location.</param>
  569. <param name="Float:z">Z spawn location.</param>
  570. <param name="Float:a">A spawn location.</param>
  571. <param name="...">Weapon data.</param>
  572. <returns>
  573. -
  574. </returns>
  575. <remarks>
  576. Adds a class only people in the specified group can use.
  577. </remarks>
  578. \**--------------------------------------------------------------------------**/
  579. stock Class_AddForGroup(Group:group, skin, Float:x, Float:y, Float:z, Float:a, ...)
  580. {
  581. P:3("Class_AddForGroup called: %i, %i, %f, %f, %f, %f (+%i)", _:group, skin, x, y, z, a, numargs() - 6);
  582. new
  583. n = numargs(),
  584. w = 6,
  585. s,
  586. weapons[MAX_CLASS_SPAWN_WEAPONS + 1],
  587. cw;
  588. _CLASS_WEAPON_CODE
  589. return Class_AddClass(skin, x, y, z, a, weapons, MAX_CLASS_SPAWN_WEAPONS + 1, group, Group:-1);
  590. }
  591. /**--------------------------------------------------------------------------**\
  592. <summary>Class_AddWithGroupSet</summary>
  593. <param name="group">Group to make players who use this group.</param>
  594. <param name="skin">Skin of the class.</param>
  595. <param name="Float:x">X spawn location.</param>
  596. <param name="Float:y">Y spawn location.</param>
  597. <param name="Float:z">Z spawn location.</param>
  598. <param name="Float:a">A spawn location.</param>
  599. <param name="...">Spawn weapons.</param>
  600. <returns>
  601. -
  602. </returns>
  603. <remarks>
  604. Adds a class which puts you in the specified group when selected.
  605. </remarks>
  606. \**--------------------------------------------------------------------------**/
  607. stock Class_AddWithGroupSet(Group:group, skin, Float:x, Float:y, Float:z, Float:a, ...)
  608. {
  609. P:3("Class_AddWithGroupSet called: %i, %i, %f, %f, %f, %f (+%i)", _:group, skin, x, y, z, a, numargs() - 6);
  610. new
  611. n = numargs(),
  612. w = 6,
  613. s,
  614. weapons[MAX_CLASS_SPAWN_WEAPONS + 1],
  615. cw;
  616. _CLASS_WEAPON_CODE
  617. return Class_AddClass(skin, x, y, z, a, weapons, MAX_CLASS_SPAWN_WEAPONS + 1, Group:-1, group);
  618. }
  619. /**--------------------------------------------------------------------------**\
  620. <summary>Class_AddClass</summary>
  621. <param name="skin">Skin of the class.</param>
  622. <param name="Float:x">X spawn location.</param>
  623. <param name="Float:y">Y spawn location.</param>
  624. <param name="Float:z">Z spawn location.</param>
  625. <param name="Float:a">A spawn location.</param>
  626. <param name="weapons[]">Array of spawn weapon data.</param>
  627. <param name="count">Number of weapons added.</param>
  628. <param name="forgroup">Group that can use the class.</param>
  629. <param name="asgroup">Group to assign people to with this class.</param>
  630. <returns>
  631. -
  632. </returns>
  633. <remarks>
  634. Does the hard work. This took a long time to get working correctly with the
  635. new master system, infact getting just this one function to compile took a
  636. major re-working of the macros to reduce the length of intermediate stages.
  637. </remarks>
  638. \**--------------------------------------------------------------------------**/
  639. foreign Class_AddClass(s,Float:x,Float:y,Float:z,Float:a,w[],c,Group:f,Group:g);
  640. global Class_AddClass(s,Float:x,Float:y,Float:z,Float:a,w[],c,Group:f,Group:g)
  641. {
  642. #pragma unused c
  643. 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);
  644. new
  645. i;
  646. while (i != MAX_CLASSES && _Class_IsActive(i)) ++i;
  647. if (i == MAX_CLASSES) return -1;
  648. YSI_g_sClasses[i][E_CLASS_FLAGS] = e_CLASS_FLAGS_ACTIVE | e_CLASS_FLAGS_ENABLED | e_CLASS_FLAGS:s,
  649. YSI_g_sClasses[i][E_CLASS_X] = x,
  650. YSI_g_sClasses[i][E_CLASS_Y] = y,
  651. YSI_g_sClasses[i][E_CLASS_Z] = z,
  652. YSI_g_sClasses[i][E_CLASS_A] = a,
  653. memcpy(YSI_g_sClasses[i][E_CLASS_WEAPONS], w, 0, (MAX_CLASS_SPAWN_WEAPONS + 1) * 4, MAX_CLASS_SPAWN_WEAPONS + 1);
  654. // P:7("Class_AddClass: weapon %d %d %d", j, c, i);
  655. PA_FastInit(YSI_g_sClasses[i][E_CLASS_PLAYERS]);
  656. // P:7("Class_AddClass: weapon %d %d %d", j, c, f);
  657. Class_ResolveGroups(i, f, false);
  658. // P:7("Class_AddClass: weapon %d %d %d", j, c, g);
  659. YSI_g_sClasses[i][E_CLASS_GROUP] = g;
  660. YSI_g_sClassCount++;
  661. // P:7("Class_AddClass: weapon %d %d %d", j, c, YSI_g_sClassCount);
  662. return i;
  663. }
  664. /**--------------------------------------------------------------------------**\
  665. <summary>Class_HasGroup</summary>
  666. <param name="classid">The class to test.</param>
  667. <param name="Group:group">The group to test setting of.</param>
  668. <returns>
  669. Does this class add players to the given group on spawn?
  670. </returns>
  671. <remarks>
  672. -
  673. </remarks>
  674. \**--------------------------------------------------------------------------**/
  675. foreign Class_HasGroup(classid, Group:group);
  676. global Class_HasGroup(classid, Group:group)
  677. {
  678. return YSI_g_sClasses[classid][E_CLASS_GROUP] == group;
  679. }
  680. /**--------------------------------------------------------------------------**\
  681. <summary>Class_Enable</summary>
  682. <returns>
  683. -
  684. </returns>
  685. <remarks>
  686. -
  687. </remarks>
  688. \**--------------------------------------------------------------------------**/
  689. foreign Class_Enable(classid, bool:toggle);
  690. global Class_Enable(classid, bool:toggle)
  691. {
  692. if (_Class_IsValid(classid))
  693. {
  694. if (toggle)
  695. {
  696. YSI_g_sClasses[classid][E_CLASS_FLAGS] |= e_CLASS_FLAGS_ENABLED;
  697. }
  698. else
  699. {
  700. YSI_g_sClasses[classid][E_CLASS_FLAGS] &= ~e_CLASS_FLAGS_ENABLED;
  701. // Hide the class for anyone currently viewing it.
  702. foreach (new playerid : Player)
  703. {
  704. P:5("Class_Enable: %d %d %d", playerid, _:YSI_g_sPlayerClass[playerid], _:e_PLAYER_CLASS_IN_SELECTION);
  705. if (Player_InSelection(playerid))
  706. {
  707. _Class_OnPlayerRequestClass(playerid, YSI_g_sInternalClass[playerid]);
  708. }
  709. }
  710. }
  711. return 1;
  712. }
  713. return 0;
  714. }
  715. /**--------------------------------------------------------------------------**\
  716. <summary>Class_Delete</summary>
  717. <param name="classid">Class to delete.</param>
  718. <returns>
  719. -
  720. </returns>
  721. <remarks>
  722. Completely removes a class from the system.
  723. </remarks>
  724. \**--------------------------------------------------------------------------**/
  725. foreign void:Class_Delete(classid);
  726. global void:Class_Delete(classid)
  727. {
  728. P:2("Class_Delete called: %i", classid);
  729. if (Class_Enable(classid, false))
  730. {
  731. YSI_g_sClasses[classid][E_CLASS_FLAGS] = e_CLASS_FLAGS:0;
  732. }
  733. }
  734. /**--------------------------------------------------------------------------**\
  735. <summary>Class_SetPlayer</summary>
  736. <param name="classid">Class to set permissions for.</param>
  737. <param name="playerid">Player to set for.</param>
  738. <param name="set">Whether or not they can use this class.</param>
  739. <returns>
  740. -
  741. </returns>
  742. <remarks>
  743. -
  744. </remarks>
  745. \**--------------------------------------------------------------------------**/
  746. foreign void:Class_SetPlayer(cl, pid, bool:s);
  747. global void:Class_SetPlayer(cl, pid, bool:s)
  748. {
  749. PA_Set(YSI_g_sClasses[cl][E_CLASS_PLAYERS], pid, s);
  750. }
  751. /**--------------------------------------------------------------------------**\
  752. <summary>Class_GetPlayer</summary>
  753. <param name="classid">Class to set permissions for.</param>
  754. <param name="playerid">Player to set for.</param>
  755. <returns>
  756. -
  757. </returns>
  758. <remarks>
  759. -
  760. </remarks>
  761. \**--------------------------------------------------------------------------**/
  762. foreign bool:Class_GetPlayer(cl,pid);
  763. global bool:Class_GetPlayer(cl,pid)
  764. {
  765. return PA_Get(YSI_g_sClasses[cl][E_CLASS_PLAYERS], pid);
  766. }
  767. /**--------------------------------------------------------------------------**\
  768. <summary>Class_Get</summary>
  769. <param name="playerid">Player to get the current class of.</param>
  770. <returns>
  771. -
  772. </returns>
  773. <remarks>
  774. -
  775. </remarks>
  776. \**--------------------------------------------------------------------------**/
  777. foreign Class_Get(playerid);
  778. global Class_Get(playerid)
  779. {
  780. if (VALID_PLAYERID(playerid))
  781. {
  782. return YSI_g_sPlayerClass[playerid];
  783. }
  784. return -1;
  785. }
  786. #if defined _ALS_AddPlayerClass
  787. #undef AddPlayerClass
  788. #else
  789. #define _ALS_AddPlayerClass
  790. #endif
  791. #define AddPlayerClass Class_Add
  792. /**--------------------------------------------------------------------------**\
  793. <summary>Class_OnPlayerRequestClass</summary>
  794. <param name="playerid">Player who requested a class.</param>
  795. <param name="class">Class they requested.</param>
  796. <returns>
  797. -
  798. </returns>
  799. <remarks>
  800. The input is one of the three real classes used to detect selected
  801. direction of alteration. Scans for a class the player is allowed to use
  802. and hot swaps it out. Uses SetPlayerSkin AND SetSpawnInfo to combat bugs
  803. with calling this from OnPlayerRequestSpawn (e.g. the example team script).
  804. Calls OnPlayerRequestClassEx with the current internal class not the real
  805. one.
  806. Last thing in the file to be simpler to call directly. If we ever have a
  807. more complex ALS hook on this callback the main body of this code will have
  808. to be moved in to its own function. As indeed it now does!
  809. </remarks>
  810. \**--------------------------------------------------------------------------**/
  811. public OnPlayerRequestClass(playerid, classid)
  812. {
  813. return _Class_OnPlayerRequestClass(playerid, classid);
  814. }
  815. // Pre-empt y_hooks.
  816. #if !defined YSI_NO_MASTER && _YSIM_IS_CLIENT
  817. static stock _Class_OnPlayerRequestClass(playerid, classid)
  818. {
  819. #pragma unused playerid, classid
  820. return 1;
  821. }
  822. #else
  823. #if !defined YSI_NO_MASTER && _YSIM_IS_CLOUD
  824. static stock _Class_OnPlayerRequestClass(playerid, classid) <>
  825. {
  826. #pragma unused playerid, classid
  827. return 1;
  828. }
  829. static stock _Class_OnPlayerRequestClass(playerid, classid) <_YCM:y>
  830. #else
  831. static stock _Class_OnPlayerRequestClass(playerid, classid)
  832. #endif
  833. {
  834. P:1("Class_OnPlayerRequestClass called: %d %d", playerid, classid);
  835. // Find which direction they pressed.
  836. if (YSI_g_sClassCount)
  837. {
  838. // Find the next available skin for this player. I'm still not
  839. // sure how this handles the case where you can't use any skin.
  840. // I'll have to look in to that - don't want to get stuck
  841. // constantly adding "0".
  842. new
  843. cid = classid;
  844. classid = Class_FindNew(playerid, YSI_g_sPlayerClass[playerid], ((classid - YSI_g_sInternalClass[playerid]) + 1) % 3 - 1),
  845. YSI_g_sInternalClass[playerid] = cid,
  846. Class_Goto(playerid, classid);
  847. P:5("Class_OnPlayerRequestClass() selected: %d", classid);
  848. }
  849. else
  850. {
  851. P:E("No YSI classes found");
  852. SetSpawnInfo(playerid, NO_TEAM, 0, 1958.0, 1343.0, 15.0, 269.0, 0, 0, 0, 0, 0, 0),
  853. SetPlayerSkin(playerid, 0),
  854. classid = -1;
  855. }
  856. return CallRemoteFunction("Class_OnPlayerRequestClass", "ii", playerid, classid);
  857. }
  858. #endif
  859. // Use the special pre-y_hooks hook method.
  860. HOOK_FORWARD:Class_OnPlayerRequestClass(playerid, classid);
  861. #if defined _ALS_OnPlayerRequestClass
  862. #undef OnPlayerRequestClass
  863. #else
  864. #define _ALS_OnPlayerRequestClass
  865. #endif
  866. #define OnPlayerRequestClass(%0) Class_OnPlayerRequestClass(%0) <_ALS : _ALS_go>