multiclass.inc 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. /*
  2. Legal:
  3. Version: MPL 1.1
  4. The contents of this file are subject to the Mozilla Public License Version
  5. 1.1 the "License"; you may not use this file except in compliance with
  6. the License. You may obtain a copy of the License at
  7. http://www.mozilla.org/MPL/
  8. Software distributed under the License is distributed on an "AS IS" basis,
  9. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  10. for the specific language governing rights and limitations under the
  11. License.
  12. The Original Code is the YSI framework.
  13. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  14. Portions created by the Initial Developer are Copyright C 2011
  15. the Initial Developer. All Rights Reserved.
  16. Contributors:
  17. Y_Less
  18. koolk
  19. JoeBullet/Google63
  20. g_aSlice/Slice
  21. Misiur
  22. samphunter
  23. tianmeta
  24. maddinat0r
  25. spacemud
  26. Crayder
  27. Dayvison
  28. Ahmad45123
  29. Zeex
  30. irinel1996
  31. Yiin-
  32. Chaprnks
  33. Konstantinos
  34. Masterchen09
  35. Southclaws
  36. PatchwerkQWER
  37. m0k1
  38. paulommu
  39. udan111
  40. Thanks:
  41. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  42. ZeeX - Very productive conversations.
  43. koolk - IsPlayerinAreaEx code.
  44. TheAlpha - Danish translation.
  45. breadfish - German translation.
  46. Fireburn - Dutch translation.
  47. yom - French translation.
  48. 50p - Polish translation.
  49. Zamaroht - Spanish translation.
  50. Los - Portuguese translation.
  51. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
  52. me to strive to better.
  53. Pixels^ - Running XScripters where the idea was born.
  54. Matite - Pestering me to release it and using it.
  55. Very special thanks to:
  56. Thiadmer - PAWN, whose limits continue to amaze me!
  57. Kye/Kalcor - SA:MP.
  58. SA:MP Team past, present and future - SA:MP.
  59. Optional plugins:
  60. Gamer_Z - GPS.
  61. Incognito - Streamer.
  62. Me - sscanf2, fixes2, Whirlpool.
  63. */
  64. PRE_HOOK(Class)
  65. #undef CHAIN_ORDER
  66. #define CHAIN_ORDER @CO_Class
  67. forward Class_ResolveGroups(class, Group:forgroup, bool:cp);
  68. enum e_CLASS_FLAGS (<<= 1)
  69. {
  70. e_CLASS_FLAGS_SKIN = 0x0000FFFF,
  71. e_CLASS_FLAGS_ENABLED = 0x00010000,
  72. e_CLASS_FLAGS_ACTIVE
  73. }
  74. enum E_CLASS
  75. {
  76. e_CLASS_FLAGS:E_CLASS_FLAGS,
  77. Float:E_CLASS_X,
  78. Float:E_CLASS_Y,
  79. Float:E_CLASS_Z,
  80. Float:E_CLASS_A,
  81. E_CLASS_WEAPONS[MAX_CLASS_SPAWN_WEAPONS + 1],
  82. Group:E_CLASS_GROUP,
  83. PlayerArray:E_CLASS_PLAYERS<MAX_PLAYERS>
  84. }
  85. static stock
  86. YSI_g_sClasses[MAX_CLASSES][E_CLASS],
  87. YSI_g_sPlayerClass[MAX_PLAYERS],
  88. YSI_g_sInternalClass[MAX_PLAYERS],
  89. YSI_g_sClassCount,
  90. YSI_g_sLastRefuse[MAX_PLAYERS];
  91. stock Class_ResolveGroups(class, Group:forgroup, bool:cp) <YSI_has_groups : n>
  92. {
  93. #pragma unused forgroup
  94. P:2("Class_ResolveGroups<n>: call Resolve %d %d %d", class, _:forgroup, cp);
  95. if (!cp) PA_Init(YSI_g_sClasses[class][E_CLASS_PLAYERS], true);
  96. }
  97. stock Class_ResolveGroups(class, Group:forgroup, bool:cp) <>
  98. {
  99. #pragma unused forgroup
  100. P:2("Class_ResolveGroups<>: call Resolve %d %d %d", class, _:forgroup, cp);
  101. if (!cp) PA_Init(YSI_g_sClasses[class][E_CLASS_PLAYERS], true);
  102. }
  103. /*-------------------------------------------------------------------------*//**
  104. * <param name="classid">Class to check if active.</param>
  105. *//*------------------------------------------------------------------------**/
  106. P:D(bool:_Class_IsActive(classid));
  107. #define _Class_IsActive(%1) (YSI_g_sClasses[(%1)][E_CLASS_FLAGS] & e_CLASS_FLAGS_ACTIVE)
  108. /*-------------------------------------------------------------------------*//**
  109. * <param name="classid">Class to check if valid.</param>
  110. *//*------------------------------------------------------------------------**/
  111. P:D(bool:_Class_IsValid(classid));
  112. #define _Class_IsValid(%1) (IS_IN_RANGE((%1), 0, MAX_CLASSES) && _Class_IsActive(%1))
  113. /*-------------------------------------------------------------------------*//**
  114. * <param name="classid">Class to check.</param>
  115. *//*------------------------------------------------------------------------**/
  116. P:D(bool:_Class_Enabled(classid));
  117. #define _Class_Enabled(%1) (YSI_g_sClasses[(%1)][E_CLASS_FLAGS] & e_CLASS_FLAGS_ENABLED)
  118. /*-------------------------------------------------------------------------*//**
  119. * <param name="classid">Class to get X location for.</param>
  120. *//*------------------------------------------------------------------------**/
  121. P:D(Float:Class_X(classid));
  122. #define Class_X(%1) YSI_g_sClasses[(%1)][E_CLASS_X]
  123. /*-------------------------------------------------------------------------*//**
  124. * <param name="classid">Class to get Y location for.</param>
  125. *//*------------------------------------------------------------------------**/
  126. P:D(Float:Class_Y(classid));
  127. #define Class_Y(%1) YSI_g_sClasses[(%1)][E_CLASS_Y]
  128. /*-------------------------------------------------------------------------*//**
  129. * <param name="classid">Class to get Z location for.</param>
  130. *//*------------------------------------------------------------------------**/
  131. P:D(Float:Class_Z(classid));
  132. #define Class_Z(%1) YSI_g_sClasses[(%1)][E_CLASS_Z]
  133. /*-------------------------------------------------------------------------*//**
  134. * <param name="classid">Class to get angle for.</param>
  135. *//*------------------------------------------------------------------------**/
  136. P:D(Float:Class_A(classid));
  137. #define Class_A(%1) YSI_g_sClasses[(%1)][E_CLASS_A]
  138. /*-------------------------------------------------------------------------*//**
  139. * <param name="classid">Class to get skin for.</param>
  140. *//*------------------------------------------------------------------------**/
  141. P:D(Class_Skin(classid));
  142. #define Class_Skin(%1) (YSI_g_sClasses[(%1)][E_CLASS_FLAGS] & e_CLASS_FLAGS_SKIN)
  143. /*-------------------------------------------------------------------------*//**
  144. * <remarks>
  145. * Creates three real player classes so you can scroll correctly with the
  146. * direction being detected.
  147. * </remarks>
  148. * <transition keep="true" target="_YCM : u"/>
  149. * <transition keep="true" target="_YCM : y"/>
  150. *//*------------------------------------------------------------------------**/
  151. hook OnScriptInit()
  152. {
  153. #if !_YSIM_IS_CLIENT
  154. if (!YSI_FILTERSCRIPT)
  155. {
  156. // This code placement is not generic.
  157. new
  158. classLeft = AddPlayerClass(0, 1958.0, 1343.0, 15.0, 269.0, 0, 0, 0, 0, 0, 0),
  159. classMiddle = AddPlayerClass(0, 1958.0, 1343.0, 15.0, 269.0, 0, 0, 0, 0, 0, 0),
  160. classRight = AddPlayerClass(0, 1958.0, 1343.0, 15.0, 269.0, 0, 0, 0, 0, 0, 0);
  161. if (classLeft != 0 || classMiddle != 1 || classRight != 2)
  162. {
  163. P:E("y_classes assumptions failed. Do you have \"AddPlayerClass\" in your modes?");
  164. }
  165. //printf("==========================");
  166. P:4("Class_OnScriptInit: classes = %d %d %d", classLeft, classMiddle, classRight);
  167. //printf("==========================");
  168. #if !defined YSI_NO_MASTER
  169. if (_Master_Get(#_YCM, true))
  170. {
  171. // Nothing changed, or we took it without force.
  172. state _YCM:y;
  173. _YCM@ = _E_YCM@y;
  174. }
  175. else
  176. {
  177. // Something changed, tell other scripts.
  178. state _YCM:u;
  179. _YCM@ = _E_YCM@u;
  180. // Determine the next unique name.
  181. CallRemoteFunction(#_YCM, "");
  182. // There is a note in y_master about this being safe
  183. // because servers always get the data. This is the server
  184. // code, but may be in use by cloud systems. This, however,
  185. // is still not a problem because we never fully pass off.
  186. }
  187. #endif
  188. }
  189. #endif
  190. return 1;
  191. }
  192. static stock Class_FindNew(playerid, playerclass, dir)
  193. {
  194. P:4("Class_FindNew called: %i, %i, %i", playerid, playerclass, dir);
  195. if (dir == 0)
  196. {
  197. // No change, check the current skin is still valid. There are plenty
  198. // of reasons for this: Removed skin, returned -1, disabled, returned to
  199. // class selection. This used to not be handled explicitly, but now it
  200. // is.
  201. if (_Class_Enabled(playerclass) && PA_Get(YSI_g_sClasses[playerclass][E_CLASS_PLAYERS], playerid)) return playerclass;
  202. ++dir;
  203. }
  204. new
  205. old = playerclass % YSI_g_sClassCount;
  206. do
  207. {
  208. playerclass = (playerclass + dir) % YSI_g_sClassCount;
  209. P:4("Class_FindNew: %d %d", playerclass, playerid);
  210. }
  211. while (playerclass != old && (!_Class_Enabled(playerclass) || !PA_Get(YSI_g_sClasses[playerclass][E_CLASS_PLAYERS], playerid)));
  212. // (!(playerclass == old || (_Class_Enabled(playerclass) && PA_Get(YSI_g_sClasses[playerclass][E_CLASS_PLAYERS], playerid))))
  213. return playerclass;
  214. }
  215. /*-------------------------------------------------------------------------*//**
  216. * <param name="playerid">Player who is changing class.</param>
  217. * <param name="playerclass">The internal class they are switching to.</param>
  218. * <remarks>
  219. * Does the visual faking through "SetPlayerSkin", and also calls
  220. * "SetSpawnInfo" to avoid any lag from "SetPlayerPos" under "OnPlayerSpawn".
  221. * </remarks>
  222. *//*------------------------------------------------------------------------**/
  223. foreign void:Class_Goto(playerid, playerclass);
  224. global void:Class_Goto(playerid, playerclass)
  225. {
  226. P:2("Class_Goto called: %i, %i", playerid, playerclass);
  227. // This now sets the REAL spawn information, including spawn location.
  228. 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);
  229. SetPlayerSkin(playerid, Class_Skin(e_PLAYER_CLASS:playerclass));
  230. YSI_g_sPlayerClass[playerid] = playerclass; //(YSI_g_sPlayerClass[playerid] & ~e_PLAYER_CLASS_SKIN) | (e_PLAYER_CLASS:playerclass);
  231. }
  232. /*-------------------------------------------------------------------------*//**
  233. * <param name="playerid">Player who selected a spawn.</param>
  234. * <remarks>
  235. * Has inbuilt protection for a bug where selections aren't correctly
  236. * debounced so you can press shift twice at once which can mess up some
  237. * scripts (e.g. the example team selection script). Calls
  238. * OnPlayerRequestSpawnEx with an additional class parameter.
  239. * </remarks>
  240. *//*------------------------------------------------------------------------**/
  241. #if !defined YSI_NO_MASTER && (_YSIM_IS_CLIENT || _YSIM_IS_STUB)
  242. public OnPlayerRequestSpawn(playerid)
  243. {
  244. return 1;
  245. }
  246. #else
  247. #if !defined YSI_NO_MASTER && _YSIM_IS_CLOUD
  248. public OnPlayerRequestSpawn(playerid) <>
  249. {
  250. return 1;
  251. }
  252. public OnPlayerRequestSpawn(playerid) <_YCM:y>
  253. #else
  254. public OnPlayerRequestSpawn(playerid)
  255. #endif
  256. {
  257. P:1("Class_OnPlayerRequestSpawn called: %d", playerid);
  258. new
  259. time = GetTickCount();
  260. if ((time - YSI_g_sLastRefuse[playerid]) >= 500)
  261. {
  262. new
  263. ret = CallRemoteFunction("Class_OnPlayerRequestSpawn", "i", playerid);
  264. P:4("Class_OnPlayerRequestSpawn() return: %d", ret);
  265. if (ret)
  266. {
  267. new
  268. Group:newgroup = YSI_g_sClasses[YSI_g_sPlayerClass[playerid]][E_CLASS_GROUP];
  269. P:4("Class_OnPlayerRequestSpawn() newgroup: %d", _:newgroup);
  270. if (newgroup != Group:-1) Class_ResolveGroups(playerid, newgroup, true);
  271. if (ret == -1)
  272. {
  273. // Send the player back to class selection.
  274. _Class_OnPlayerRequestClass(playerid, YSI_g_sInternalClass[playerid]);
  275. }
  276. else
  277. {
  278. return 1;
  279. }
  280. }
  281. }
  282. P:5("Class_OnPlayerRequestSpawn: Return 0");
  283. return
  284. YSI_g_sLastRefuse[playerid] = time,
  285. 0;
  286. }
  287. #endif
  288. HOOK_FORWARD:Class_OnPlayerRequestSpawn(playerid);
  289. #if defined _ALS_OnPlayerRequestSpawn
  290. #undef OnPlayerRequestSpawn
  291. #else
  292. #define _ALS_OnPlayerRequestSpawn
  293. #endif
  294. #define OnPlayerRequestSpawn(%0) Class_OnPlayerRequestSpawn(%0) <_ALS : _ALS_go>
  295. /*-------------------------------------------------------------------------*//**
  296. * <param name="playerid">Player who spawned.</param>
  297. * <remarks>
  298. * Sets a player's position based on skin.
  299. * </remarks>
  300. *//*------------------------------------------------------------------------**/
  301. mhook OnPlayerSpawn(playerid)
  302. {
  303. P:2("Class_OnPlayerSpawn called: %d", playerid);
  304. new
  305. playerclass = YSI_g_sPlayerClass[playerid],
  306. weapon;
  307. for (new i = 0; i != MAX_CLASS_SPAWN_WEAPONS; ++i)
  308. {
  309. weapon = YSI_g_sClasses[playerclass][E_CLASS_WEAPONS][i];
  310. if (weapon)
  311. {
  312. GivePlayerWeapon(playerid, weapon & 0xFF, weapon >>> 8);
  313. }
  314. else
  315. {
  316. break;
  317. }
  318. }
  319. weapon = YSI_g_sClasses[playerclass][E_CLASS_WEAPONS][MAX_CLASS_SPAWN_WEAPONS];
  320. P:5("Class_OnPlayerSpawn: Armour %d %d %d", weapon, weapon & 0xFF, WEAPON_ARMOUR);
  321. if ((weapon & 0xFF) == WEAPON_ARMOUR)
  322. {
  323. weapon >>>= 8;
  324. if (weapon == 0x00800000)
  325. {
  326. // INFINITY
  327. SetPlayerArmour(playerid, Float:0x7F800000);
  328. }
  329. else
  330. {
  331. SetPlayerArmour(playerid, weapon);
  332. }
  333. }
  334. return 1;
  335. }
  336. /*-------------------------------------------------------------------------*//**
  337. * <param name="playerid">Player who joined the server.</param>
  338. * <remarks>
  339. * Reset all the data on this player's current classes.
  340. * </remarks>
  341. *//*------------------------------------------------------------------------**/
  342. mhook OnPlayerConnect(playerid)
  343. {
  344. YSI_g_sPlayerClass[playerid] = -1,
  345. YSI_g_sInternalClass[playerid] = -1;
  346. NO_GROUPS()
  347. {
  348. new
  349. slot = PA_Slot(playerid),
  350. Bit:mask = PA_Mask(playerid);
  351. for (new i = 0; i != MAX_CLASSES; ++i)
  352. {
  353. YSI_g_sClasses[i][E_CLASS_PLAYERS][slot] |= mask;
  354. }
  355. }
  356. return 1;
  357. }
  358. /*-------------------------------------------------------------------------*//**
  359. * <remarks>
  360. * Converts the variable arguments to an array.
  361. * </remarks>
  362. *//*------------------------------------------------------------------------**/
  363. #define _CLASS_WEAPON_CODE \
  364. {if((n-w+1)/2>MAX_CLASS_SPAWN_WEAPONS) P:E("Excessive class weapon data."); \
  365. 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);} \
  366. else{while(w!=n)weapons[((cw=getarg(w++))==WEAPON_ARMOUR)?MAX_CLASS_SPAWN_WEAPONS:(s++)]=(cw&0xFF)|(getarg(w++)<<8);}}
  367. /*-------------------------------------------------------------------------*//**
  368. * <param name="skin">Skin of the class.</param>
  369. * <param name="x">X spawn location.</param>
  370. * <param name="y">Y spawn location.</param>
  371. * <param name="z">Z spawn location.</param>
  372. * <param name="a">A spawn location.</param>
  373. * <param name="">Spawn weapons and ammo (weapon then ammo)</param>
  374. * <remarks>
  375. * Pretty much AddPlayerClass but allows greater control over the classes.
  376. * Now has infinate (MAX_CLASS_SPAWN_WEAPONS) spawn weapons. This is one of
  377. * the few API functions which is not entirely remote. This is because it has
  378. * variable parameters which is need to collect in to a single array to pass to
  379. * the remote function.
  380. * </remarks>
  381. *//*------------------------------------------------------------------------**/
  382. stock Class_Add(skin, Float:x, Float:y, Float:z, Float:a, ...)
  383. {
  384. P:3("Class_Add called: %i, %f, %f, %f, %f, (+%i)", skin, x, y, z, a, numargs() - 5);
  385. new
  386. n = numargs(),
  387. w = 5,
  388. s,
  389. weapons[MAX_CLASS_SPAWN_WEAPONS + 1],
  390. cw;
  391. _CLASS_WEAPON_CODE
  392. return Class_AddClass(skin, x, y, z, a, weapons, MAX_CLASS_SPAWN_WEAPONS + 1, Group:-1, Group:-1);
  393. }
  394. /*-------------------------------------------------------------------------*//**
  395. * <param name="forgroup">Group that can use the skin.</param>
  396. * <param name="setgroup">Group to add the player to on selection.</param>
  397. * <param name="skin">Skin of the class.</param>
  398. * <param name="x">X spawn location.</param>
  399. * <param name="y">Y spawn location.</param>
  400. * <param name="z">Z spawn location.</param>
  401. * <param name="a">A spawn location.</param>
  402. * <param name="">Spawn weapons and ammo (weapon then ammo)</param>
  403. * <remarks>
  404. * Pretty much AddPlayerClass but allows greater control over the classes.
  405. * Now has infinate (MAX_CLASS_SPAWN_WEAPONS) spawn weapons.
  406. * </remarks>
  407. *//*------------------------------------------------------------------------**/
  408. stock Class_AddEx(Group:forgroup, Group:setgroup, skin, Float:x, Float:y, Float:z, Float:a, ...)
  409. {
  410. P:3("Class_AddEx called: %i, %i, %i, %f, %f, %f, %f (+%i)", _:forgroup, _:setgroup, skin, x, y, z, a, numargs() - 7);
  411. new
  412. n = numargs(),
  413. w = 7,
  414. s,
  415. weapons[MAX_CLASS_SPAWN_WEAPONS + 1],
  416. cw;
  417. _CLASS_WEAPON_CODE
  418. return Class_AddClass(skin, x, y, z, a, weapons, MAX_CLASS_SPAWN_WEAPONS + 1, forgroup, setgroup);
  419. }
  420. /*-------------------------------------------------------------------------*//**
  421. * <param name="group">Group to allow to use the class.</param>
  422. * <param name="skin">Skin of the class.</param>
  423. * <param name="x">X spawn location.</param>
  424. * <param name="y">Y spawn location.</param>
  425. * <param name="z">Z spawn location.</param>
  426. * <param name="a">A spawn location.</param>
  427. * <param name="">Weapon data.</param>
  428. * <remarks>
  429. * Adds a class only people in the specified group can use.
  430. * </remarks>
  431. *//*------------------------------------------------------------------------**/
  432. stock Class_AddForGroup(Group:group, skin, Float:x, Float:y, Float:z, Float:a, ...)
  433. {
  434. P:3("Class_AddForGroup called: %i, %i, %f, %f, %f, %f (+%i)", _:group, skin, x, y, z, a, numargs() - 6);
  435. new
  436. n = numargs(),
  437. w = 6,
  438. s,
  439. weapons[MAX_CLASS_SPAWN_WEAPONS + 1],
  440. cw;
  441. _CLASS_WEAPON_CODE
  442. return Class_AddClass(skin, x, y, z, a, weapons, MAX_CLASS_SPAWN_WEAPONS + 1, group, Group:-1);
  443. }
  444. /*-------------------------------------------------------------------------*//**
  445. * <param name="group">Group to make players who use this group.</param>
  446. * <param name="skin">Skin of the class.</param>
  447. * <param name="x">X spawn location.</param>
  448. * <param name="y">Y spawn location.</param>
  449. * <param name="z">Z spawn location.</param>
  450. * <param name="a">A spawn location.</param>
  451. * <param name="">Spawn weapons.</param>
  452. * <remarks>
  453. * Adds a class which puts you in the specified group when selected.
  454. * </remarks>
  455. *//*------------------------------------------------------------------------**/
  456. stock Class_AddWithGroupSet(Group:group, skin, Float:x, Float:y, Float:z, Float:a, ...)
  457. {
  458. P:3("Class_AddWithGroupSet called: %i, %i, %f, %f, %f, %f (+%i)", _:group, skin, x, y, z, a, numargs() - 6);
  459. new
  460. n = numargs(),
  461. w = 6,
  462. s,
  463. weapons[MAX_CLASS_SPAWN_WEAPONS + 1],
  464. cw;
  465. _CLASS_WEAPON_CODE
  466. return Class_AddClass(skin, x, y, z, a, weapons, MAX_CLASS_SPAWN_WEAPONS + 1, Group:-1, group);
  467. }
  468. /*-------------------------------------------------------------------------*//**
  469. * <param name="skin">Skin of the class.</param>
  470. * <param name="x">X spawn location.</param>
  471. * <param name="y">Y spawn location.</param>
  472. * <param name="z">Z spawn location.</param>
  473. * <param name="a">A spawn location.</param>
  474. * <param name="weapons">Array of spawn weapon data.</param>
  475. * <param name="count">Number of weapons added.</param>
  476. * <param name="forgroup">Group that can use the class.</param>
  477. * <param name="asgroup">Group to assign people to with this class.</param>
  478. * <remarks>
  479. * Does the hard work. This took a long time to get working correctly with the
  480. * new master system, infact getting just this one function to compile took a
  481. * major re-working of the macros to reduce the length of intermediate stages.
  482. * </remarks>
  483. *//*------------------------------------------------------------------------**/
  484. foreign Class_AddClass(s,Float:x,Float:y,Float:z,Float:a,w[],c,Group:f,Group:g);
  485. global Class_AddClass(s,Float:x,Float:y,Float:z,Float:a,w[],c,Group:f,Group:g)
  486. {
  487. #pragma unused c
  488. 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);
  489. new
  490. i;
  491. while (i != MAX_CLASSES && _Class_IsActive(i)) ++i;
  492. if (i == MAX_CLASSES) return -1;
  493. YSI_g_sClasses[i][E_CLASS_FLAGS] = e_CLASS_FLAGS_ACTIVE | e_CLASS_FLAGS_ENABLED | e_CLASS_FLAGS:s,
  494. YSI_g_sClasses[i][E_CLASS_X] = x,
  495. YSI_g_sClasses[i][E_CLASS_Y] = y,
  496. YSI_g_sClasses[i][E_CLASS_Z] = z,
  497. YSI_g_sClasses[i][E_CLASS_A] = a,
  498. memcpy(YSI_g_sClasses[i][E_CLASS_WEAPONS], w, 0, (MAX_CLASS_SPAWN_WEAPONS + 1) * 4, MAX_CLASS_SPAWN_WEAPONS + 1);
  499. // P:7("Class_AddClass: weapon %d %d %d", j, c, i);
  500. PA_FastInit(YSI_g_sClasses[i][E_CLASS_PLAYERS]);
  501. // P:7("Class_AddClass: weapon %d %d %d", j, c, f);
  502. Class_ResolveGroups(i, f, false);
  503. // P:7("Class_AddClass: weapon %d %d %d", j, c, g);
  504. YSI_g_sClasses[i][E_CLASS_GROUP] = g;
  505. YSI_g_sClassCount++;
  506. // P:7("Class_AddClass: weapon %d %d %d", j, c, YSI_g_sClassCount);
  507. return i;
  508. }
  509. /*-------------------------------------------------------------------------*//**
  510. * <param name="classid">The class to test.</param>
  511. * <param name="group">The group to test setting of.</param>
  512. * <returns>
  513. * Does this class add players to the given group on spawn?
  514. * </returns>
  515. *//*------------------------------------------------------------------------**/
  516. foreign Class_HasGroup(classid, Group:group);
  517. global Class_HasGroup(classid, Group:group)
  518. {
  519. return YSI_g_sClasses[classid][E_CLASS_GROUP] == group;
  520. }
  521. /*-------------------------------------------------------------------------*//**
  522. *//*------------------------------------------------------------------------**/
  523. foreign Class_Enable(classid, bool:toggle);
  524. global Class_Enable(classid, bool:toggle)
  525. {
  526. if (_Class_IsValid(classid))
  527. {
  528. if (toggle)
  529. {
  530. YSI_g_sClasses[classid][E_CLASS_FLAGS] |= e_CLASS_FLAGS_ENABLED;
  531. }
  532. else
  533. {
  534. YSI_g_sClasses[classid][E_CLASS_FLAGS] &= ~e_CLASS_FLAGS_ENABLED;
  535. // Hide the class for anyone currently viewing it.
  536. foreach (new playerid : Player)
  537. {
  538. P:5("Class_Enable: %d %d %d", playerid, _:YSI_g_sPlayerClass[playerid], _:e_PLAYER_CLASS_IN_SELECTION);
  539. if (Player_InSelection(playerid))
  540. {
  541. _Class_OnPlayerRequestClass(playerid, YSI_g_sInternalClass[playerid]);
  542. }
  543. }
  544. }
  545. return 1;
  546. }
  547. return 0;
  548. }
  549. /*-------------------------------------------------------------------------*//**
  550. * <param name="classid">Class to delete.</param>
  551. * <remarks>
  552. * Completely removes a class from the system.
  553. * </remarks>
  554. *//*------------------------------------------------------------------------**/
  555. foreign void:Class_Delete(classid);
  556. global void:Class_Delete(classid)
  557. {
  558. P:2("Class_Delete called: %i", classid);
  559. if (Class_Enable(classid, false))
  560. {
  561. YSI_g_sClasses[classid][E_CLASS_FLAGS] = e_CLASS_FLAGS:0;
  562. }
  563. }
  564. /*-------------------------------------------------------------------------*//**
  565. * <param name="classid">Class to set permissions for.</param>
  566. * <param name="playerid">Player to set for.</param>
  567. * <param name="set">Whether or not they can use this class.</param>
  568. *//*------------------------------------------------------------------------**/
  569. foreign void:Class_SetPlayer(cl, pid, bool:s);
  570. global void:Class_SetPlayer(cl, pid, bool:s)
  571. {
  572. PA_Set(YSI_g_sClasses[cl][E_CLASS_PLAYERS], pid, s);
  573. }
  574. /*-------------------------------------------------------------------------*//**
  575. * <param name="classid">Class to set permissions for.</param>
  576. * <param name="playerid">Player to set for.</param>
  577. *//*------------------------------------------------------------------------**/
  578. foreign bool:Class_GetPlayer(cl,pid);
  579. global bool:Class_GetPlayer(cl,pid)
  580. {
  581. return PA_Get(YSI_g_sClasses[cl][E_CLASS_PLAYERS], pid);
  582. }
  583. /*-------------------------------------------------------------------------*//**
  584. * <param name="playerid">Player to get the current class of.</param>
  585. *//*------------------------------------------------------------------------**/
  586. foreign Class_Get(playerid);
  587. global Class_Get(playerid)
  588. {
  589. if (VALID_PLAYERID(playerid))
  590. {
  591. return YSI_g_sPlayerClass[playerid];
  592. }
  593. return -1;
  594. }
  595. #if defined _ALS_AddPlayerClass
  596. #undef AddPlayerClass
  597. #else
  598. #define _ALS_AddPlayerClass
  599. #endif
  600. #define AddPlayerClass Class_Add
  601. /*-------------------------------------------------------------------------*//**
  602. * <param name="playerid">Player whose current class view may need to change.</param>
  603. * <remarks>
  604. * If you change a player's groups while they are in class selection, call this
  605. * function to potentially update the currently displayed class.
  606. * </remarks>
  607. *//*------------------------------------------------------------------------**/
  608. stock Class_Reprocess(playerid)
  609. {
  610. if (!Player_InSelection(playerid))
  611. return 0;
  612. new
  613. classid = -1;
  614. if (YSI_g_sClassCount)
  615. {
  616. // Find the next available skin for this player. I'm still not
  617. // sure how this handles the case where you can't use any skin.
  618. // I'll have to look in to that - don't want to get stuck
  619. // constantly adding "0".
  620. classid = Class_FindNew(playerid, YSI_g_sPlayerClass[playerid], 0),
  621. Class_Goto(playerid, classid);
  622. P:5("Class_Reprocess() selected: %d", classid);
  623. }
  624. else
  625. {
  626. P:E("No YSI classes found");
  627. SetSpawnInfo(playerid, NO_TEAM, 0, 1958.0, 1343.0, 15.0, 269.0, 0, 0, 0, 0, 0, 0),
  628. SetPlayerSkin(playerid, 0);
  629. }
  630. return CallRemoteFunction("Class_OnPlayerRequestClass", "ii", playerid, classid);
  631. }
  632. /*-------------------------------------------------------------------------*//**
  633. * <param name="playerid">Player who requested a class.</param>
  634. * <param name="class">Class they requested.</param>
  635. * <remarks>
  636. * The input is one of the three real classes used to detect selected
  637. * direction of alteration. Scans for a class the player is allowed to use
  638. * and hot swaps it out. Uses SetPlayerSkin AND SetSpawnInfo to combat bugs
  639. * with calling this from OnPlayerRequestSpawn (e.g. the example team script).
  640. * Calls OnPlayerRequestClassEx with the current internal class not the real
  641. * one.
  642. *
  643. * Last thing in the file to be simpler to call directly. If we ever have a
  644. * more complex ALS hook on this callback the main body of this code will have
  645. * to be moved in to its own function. As indeed it now does!
  646. * </remarks>
  647. *//*------------------------------------------------------------------------**/
  648. public OnPlayerRequestClass(playerid, classid)
  649. {
  650. return _Class_OnPlayerRequestClass(playerid, classid);
  651. }
  652. // Pre-empt y_hooks.
  653. #if !defined YSI_NO_MASTER && _YSIM_IS_CLIENT
  654. static stock _Class_OnPlayerRequestClass(playerid, classid)
  655. {
  656. #pragma unused playerid, classid
  657. return 1;
  658. }
  659. #else
  660. #if !defined YSI_NO_MASTER && _YSIM_IS_CLOUD
  661. static stock _Class_OnPlayerRequestClass(playerid, classid) <>
  662. {
  663. #pragma unused playerid, classid
  664. return 1;
  665. }
  666. static stock _Class_OnPlayerRequestClass(playerid, classid) <_YCM:y>
  667. #else
  668. static stock _Class_OnPlayerRequestClass(playerid, classid)
  669. #endif
  670. {
  671. P:1("Class_OnPlayerRequestClass called: %d %d", playerid, classid);
  672. // Find which direction they pressed.
  673. if (YSI_g_sClassCount)
  674. {
  675. // Find the next available skin for this player. I'm still not
  676. // sure how this handles the case where you can't use any skin.
  677. // I'll have to look in to that - don't want to get stuck
  678. // constantly adding "0".
  679. new
  680. cid = classid;
  681. classid = Class_FindNew(playerid, YSI_g_sPlayerClass[playerid], ((classid - YSI_g_sInternalClass[playerid]) + 1) % 3 - 1),
  682. YSI_g_sInternalClass[playerid] = cid,
  683. Class_Goto(playerid, classid);
  684. P:5("Class_OnPlayerRequestClass() selected: %d", classid);
  685. }
  686. else
  687. {
  688. P:E("No YSI classes found");
  689. SetSpawnInfo(playerid, NO_TEAM, 0, 1958.0, 1343.0, 15.0, 269.0, 0, 0, 0, 0, 0, 0),
  690. SetPlayerSkin(playerid, 0),
  691. classid = -1;
  692. }
  693. return CallRemoteFunction("Class_OnPlayerRequestClass", "ii", playerid, classid);
  694. }
  695. #endif
  696. // Use the special pre-y_hooks hook method.
  697. HOOK_FORWARD:Class_OnPlayerRequestClass(playerid, classid);
  698. #if defined _ALS_OnPlayerRequestClass
  699. #undef OnPlayerRequestClass
  700. #else
  701. #define _ALS_OnPlayerRequestClass
  702. #endif
  703. #define OnPlayerRequestClass(%0) Class_OnPlayerRequestClass(%0) <_ALS : _ALS_go>