y_classes.inc 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328
  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. #include "internal\y_version"
  130. #include "y_bit"
  131. #include "y_debug"
  132. #define YSIM_U_DISABLE
  133. #include "y_master"
  134. #include "y_iterate"
  135. #include "y_hooks"
  136. #include "internal\y_natives"
  137. #if !defined MAX_CLASSES
  138. #define MAX_CLASSES (256)
  139. #endif
  140. #if !defined MAX_CLASS_SPAWN_WEAPONS
  141. #define MAX_CLASS_SPAWN_WEAPONS (13)
  142. #endif
  143. #if !defined WEAPON_ARMOUR
  144. #define WEAPON_ARMOUR (100)
  145. #endif
  146. //#define OnPlayerRequestClassEx(%0) OnPlayerRequestClassEx_(%0)if(!YSI_gOPRCE)return 0;else
  147. //#define OnPlayerRequestSpawnEx(%0) OnPlayerRequestSpawnEx_(%0)if(!YSI_gOPRCE)return 0;else
  148. //forward OnPlayerRequestClassEx_(playerid, classid);
  149. //forward OnPlayerRequestSpawnEx_(playerid, classid);
  150. forward _Class_OnPlayerRequestClass(playerid, classid);
  151. forward _Class_OnPlayerRequestSpawn(playerid);
  152. forward _Class_OtherRequestClass(playerid, classid);
  153. forward _Class_OtherRequestSpawn(playerid);
  154. #define INFINATE_ARMOUR (0x00800000)
  155. #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);}
  156. #define _GROUP_MAKE_NAME_CLASSES<%0...%1> %0Class%1
  157. #define _GROUP_MAKE_LIMIT_CLASSES MAX_CLASSES
  158. forward Class_ResolveGroups(class, Group:forgroup, bool:cp);
  159. #include "y_groups"
  160. #include "y_playerarray"
  161. #include "y_iterate"
  162. enum e_CLASS_FLAGS (<<= 1)
  163. {
  164. e_CLASS_FLAGS_SKIN = 0x0000FFFF,
  165. e_CLASS_FLAGS_ENABLED = 0x00010000,
  166. e_CLASS_FLAGS_ACTIVE
  167. }
  168. enum E_CLASS
  169. {
  170. e_CLASS_FLAGS:E_CLASS_FLAGS,
  171. Float:E_CLASS_X,
  172. Float:E_CLASS_Y,
  173. Float:E_CLASS_Z,
  174. Float:E_CLASS_A,
  175. E_CLASS_WEAPONS[MAX_CLASS_SPAWN_WEAPONS + 1],
  176. Group:E_CLASS_GROUP,
  177. PlayerArray:E_CLASS_PLAYERS<MAX_PLAYERS>
  178. }
  179. enum e_PLAYER_CLASS (<<= 1)
  180. {
  181. e_PLAYER_CLASS_NONE = 0,
  182. e_PLAYER_CLASS_SKIN = 0x000FFFFF,
  183. e_PLAYER_CLASS_PRESS = 0x00700000,
  184. e_PLAYER_CLASS_RIGHT = 0x00100000,
  185. e_PLAYER_CLASS_MIDDLE,
  186. e_PLAYER_CLASS_LEFT,
  187. // Control flags.
  188. e_PLAYER_CLASS_RETURNED, // Back in class selection.
  189. e_PLAYER_CLASS_SPAWNSINCE, // Spawned after class selection.
  190. e_PLAYER_CLASS_DISABLED, // Class selection disabled.
  191. e_PLAYER_CLASS_HADFIRST, // Spawned ever.
  192. e_PLAYER_CLASS_INSTANT, // Sent straight to class selection.
  193. e_PLAYER_CLASS_INSELECT, // In class selection.
  194. e_PLAYER_CLASS_IGNORE_ONCE
  195. }
  196. enum e_CLASS_SETTINGS (<<= 1)
  197. {
  198. e_CLASS_SETTING_NORE = 1,
  199. e_CLASS_SETTING_OPRCE,
  200. e_CLASS_SETTING_OPRSE
  201. }
  202. #define CLASS_MOVE_LEFT (-1)
  203. #define CLASS_MOVE_RIGHT (1)
  204. #define CLASS_MOVE_NONE (0)
  205. static stock
  206. YSI_g_sClasses[MAX_CLASSES][E_CLASS],
  207. e_PLAYER_CLASS:YSI_g_sPlayerClass[MAX_PLAYERS],
  208. YSI_g_sTimer[MAX_PLAYERS],
  209. YSI_g_sLeft,
  210. YSI_g_sMiddle,
  211. YSI_g_sRight,
  212. e_CLASS_SETTINGS:YSI_g_sSettings,
  213. YSI_g_sClassCount,
  214. YSI_g_sHookC,
  215. YSI_g_sHookS,
  216. YSI_g_sLastRefuse[MAX_PLAYERS];
  217. stock
  218. bool:YSI_gOPRCE = true;
  219. stock Class_ResolveGroups(class, Group:forgroup, bool:cp) <YSI_has_groups : n>
  220. {
  221. #pragma unused forgroup
  222. P:2("Class_ResolveGroups<n>: call Resolve %d %d %d", class, _:forgroup, cp);
  223. if (!cp) PA_Init(YSI_g_sClasses[class][E_CLASS_PLAYERS], true);
  224. //else if (forgroup) {}
  225. //Bit_SetAll(YSI_g_sClasses[class][E_CLASS_PLAYERS], true, bits<MAX_PLAYERS>);
  226. }
  227. stock Class_ResolveGroups(class, Group:forgroup, bool:cp) <>
  228. {
  229. #pragma unused forgroup
  230. P:2("Class_ResolveGroups<>: call Resolve %d %d %d", class, _:forgroup, cp);
  231. if (!cp) PA_Init(YSI_g_sClasses[class][E_CLASS_PLAYERS], true);
  232. //else if (forgroup) {}
  233. //Bit_SetAll(YSI_g_sClasses[class][E_CLASS_PLAYERS], true, bits<MAX_PLAYERS>);
  234. }
  235. /*----------------------------------------------------------------------------*\
  236. Function:
  237. Class_IsValid
  238. Params:
  239. classid - Class to check if valid.
  240. Return:
  241. -
  242. Notes:
  243. -
  244. \*----------------------------------------------------------------------------*/
  245. #define Class_IsValid(%1) (0<=(%1)<MAX_CLASSES&&Class_IsActive(%1))
  246. /*----------------------------------------------------------------------------*\
  247. Function:
  248. Class_IsValid
  249. Params:
  250. classid - Class to check if active.
  251. Return:
  252. -
  253. Notes:
  254. -
  255. \*----------------------------------------------------------------------------*/
  256. #define Class_IsActive(%1) (YSI_g_sClasses[(%1)][E_CLASS_FLAGS]&e_CLASS_FLAGS_ACTIVE)
  257. /*----------------------------------------------------------------------------*\
  258. Function:
  259. Class_Enabled
  260. Params:
  261. classid - Class to check.
  262. Return:
  263. -
  264. Notes:
  265. -
  266. \*----------------------------------------------------------------------------*/
  267. #define Class_Enabled(%1) (YSI_g_sClasses[(%1)][E_CLASS_FLAGS]&e_CLASS_FLAGS_ENABLED)
  268. /*----------------------------------------------------------------------------*\
  269. Function:
  270. Class_X
  271. Params:
  272. classid - Class to get X location for.
  273. Return:
  274. -
  275. Notes:
  276. -
  277. \*----------------------------------------------------------------------------*/
  278. #define Class_X(%1) YSI_g_sClasses[(%1)][E_CLASS_X]
  279. /*----------------------------------------------------------------------------*\
  280. Function:
  281. Class_Y
  282. Params:
  283. classid - Class to get Y location for.
  284. Return:
  285. -
  286. Notes:
  287. -
  288. \*----------------------------------------------------------------------------*/
  289. #define Class_Y(%1) YSI_g_sClasses[(%1)][E_CLASS_Y]
  290. /*----------------------------------------------------------------------------*\
  291. Function:
  292. Class_Z
  293. Params:
  294. classid - Class to get Z location for.
  295. Return:
  296. -
  297. Notes:
  298. -
  299. \*----------------------------------------------------------------------------*/
  300. #define Class_Z(%1) YSI_g_sClasses[(%1)][E_CLASS_Z]
  301. /*----------------------------------------------------------------------------*\
  302. Function:
  303. Class_A
  304. Params:
  305. classid - Class to get angle for.
  306. Return:
  307. -
  308. Notes:
  309. -
  310. \*----------------------------------------------------------------------------*/
  311. #define Class_A(%1) YSI_g_sClasses[(%1)][E_CLASS_A]
  312. /*----------------------------------------------------------------------------*\
  313. Function:
  314. Class_Skin
  315. Params:
  316. classid - Class to get skin for.
  317. Return:
  318. -
  319. Notes:
  320. -
  321. \*----------------------------------------------------------------------------*/
  322. #define Class_Skin(%1) (YSI_g_sClasses[(%1)][E_CLASS_FLAGS]&e_CLASS_FLAGS_SKIN)
  323. /*----------------------------------------------------------------------------*\
  324. Function:
  325. Class_Class
  326. Params:
  327. -
  328. Return:
  329. -
  330. Notes:
  331. Creates three real player classes so you can scroll correctly with the
  332. direction being detected.
  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. #endif
  354. CallRemoteFunction(#_YCM, "");
  355. #if _YSIM_IS_CLOUD
  356. // Fully master.
  357. state _YCM:y;
  358. #endif
  359. #endif
  360. }
  361. #endif
  362. //Hooks_RedirectPublic("OnPlayerRequestClass", "_Class_OnPlayerRequestClass");
  363. //Hooks_RedirectPublic("OnPlayerRequestSpawn", "_Class_OnPlayerRequestSpawn");
  364. YSI_g_sHookC = Hooks_RedirectPublic("OnPlayerRequestClass", "_Class_OnPlayerRequestClass");
  365. YSI_g_sHookS = Hooks_RedirectPublic("OnPlayerRequestSpawn", "_Class_OnPlayerRequestSpawn");
  366. return 1;
  367. }
  368. /*----------------------------------------------------------------------------*\
  369. Function:
  370. Class_OnPlayerRequestClass
  371. Params:
  372. playerid - Player who requested a class.
  373. class - Class they requested.
  374. Return:
  375. -
  376. Notes:
  377. The input is one of the three real classes used to detect selected
  378. direction of alteration. Scans for a class the player is allowed to use
  379. and hot swaps it out. Uses SetPlayerSkin AND SetSpawnInfo to combat bugs
  380. with calling this from OnPlayerRequestSpawn (e.g. the example team script).
  381. Calls OnPlayerRequestClassEx with the current internal class not the real
  382. one.
  383. \*----------------------------------------------------------------------------*/
  384. static stock Class_FindNew(playerid, playerclass, dir)
  385. {
  386. P:4("Class_FindNew called: %i, %i, %i", playerid, playerclass, dir);
  387. // Handles the special case where "dir" = 0 very nicely with no extra code
  388. // slowing down the common case (as it should be)! This is simply because
  389. // "playerclass != old" will fail on the first loop with "+ 0";
  390. new
  391. old = playerclass % YSI_g_sClassCount;
  392. do
  393. {
  394. playerclass = (playerclass + dir) % YSI_g_sClassCount;
  395. P:4("Class_FindNew: %d %d", playerclass, playerid);
  396. }
  397. while (playerclass != old && (!Class_Enabled(playerclass) || !PA_Get(YSI_g_sClasses[playerclass][E_CLASS_PLAYERS], playerid)));
  398. return playerclass;
  399. }
  400. public _Class_OtherRequestClass(playerid, classid)
  401. {
  402. if (YSI_g_sHookC)
  403. {
  404. #emit PUSH.S classid
  405. #emit PUSH.S playerid
  406. #emit PUSH.C 8
  407. #emit LCTRL 6
  408. #emit ADD.C 28
  409. #emit PUSH.pri
  410. #emit LOAD.pri YSI_g_sHookC
  411. #emit SCTRL 6
  412. #emit RETN
  413. }
  414. }
  415. #if !defined YSI_NO_MASTER && _YSIM_IS_CLIENT
  416. public _Class_OnPlayerRequestClass(playerid, classid)
  417. {
  418. return 1;
  419. }
  420. #else
  421. #if !defined YSI_NO_MASTER && _YSIM_IS_CLOUD
  422. //mhook OnPlayerRequestClass(playerid, classid)
  423. public _Class_OnPlayerRequestClass(playerid, classid) <>
  424. {
  425. return 1;
  426. }
  427. //mhook OnPlayerRequestClass(playerid, classid)
  428. public _Class_OnPlayerRequestClass(playerid, classid) <_YCM:y>
  429. {
  430. #else
  431. //mhook OnPlayerRequestClass(playerid, classid)
  432. public _Class_OnPlayerRequestClass(playerid, classid)
  433. {
  434. #endif
  435. if (YSI_g_sPlayerClass[playerid] & (e_PLAYER_CLASS_IGNORE_ONCE))
  436. {
  437. SetTimerEx("_Class_SpawnPlayer3", 10, 0, "i", playerid);
  438. return 1;
  439. }
  440. P:1("_Class_OnPlayerRequestClass called: %d %d", playerid, classid);
  441. Class_TK(playerid);
  442. new
  443. dir = CLASS_MOVE_RIGHT;
  444. // Spawned from returning to class selection but not meant to.
  445. //P:5("Class_OnPlayerRequestClass(): Spawn check %d %d", playerclass, playerclass); //(playerclass & e_PLAYER_CLASS_SPAWN_CHECK), e_PLAYER_CLASS_SPAWN_CHECK);
  446. // Find which direction they pressed.
  447. switch (YSI_g_sPlayerClass[playerid] & e_PLAYER_CLASS_PRESS)
  448. {
  449. case e_PLAYER_CLASS_RIGHT:
  450. {
  451. if (classid == YSI_g_sMiddle)
  452. {
  453. // Went from the right to the middle - that's a move left.
  454. dir = CLASS_MOVE_LEFT;
  455. }
  456. else if (classid != YSI_g_sLeft)
  457. {
  458. dir = CLASS_MOVE_NONE;
  459. }
  460. }
  461. case e_PLAYER_CLASS_MIDDLE:
  462. {
  463. if (classid == YSI_g_sLeft)
  464. {
  465. // Went from the middle to the left - that's a move left.
  466. dir = CLASS_MOVE_LEFT;
  467. }
  468. else if (classid != YSI_g_sRight)
  469. {
  470. dir = CLASS_MOVE_NONE;
  471. }
  472. }
  473. default:
  474. {
  475. if (classid == YSI_g_sRight)
  476. {
  477. // Went from the left to the right - that's a wrap move left.
  478. dir = CLASS_MOVE_LEFT;
  479. }
  480. else if (classid != YSI_g_sMiddle)
  481. {
  482. dir = CLASS_MOVE_NONE;
  483. }
  484. }
  485. }
  486. new Group:oldgroup = YSI_g_sClasses[(YSI_g_sPlayerClass[playerid] & e_PLAYER_CLASS_SKIN)][E_CLASS_GROUP];
  487. if (oldgroup != GROUP_GLOBAL)
  488. Group_SetPlayer(oldgroup, playerid, false);
  489. // Store which class they are now on.
  490. //printf("%d %d %d %d", classid, YSI_g_sMiddle, YSI_g_sLeft, YSI_g_sRight);
  491. if (classid == YSI_g_sMiddle)
  492. {
  493. YSI_g_sPlayerClass[playerid] = (YSI_g_sPlayerClass[playerid] & ~e_PLAYER_CLASS_PRESS) | e_PLAYER_CLASS_MIDDLE | e_PLAYER_CLASS_INSELECT;
  494. }
  495. else if (classid == YSI_g_sLeft)
  496. {
  497. YSI_g_sPlayerClass[playerid] = (YSI_g_sPlayerClass[playerid] & ~e_PLAYER_CLASS_PRESS) | e_PLAYER_CLASS_LEFT | e_PLAYER_CLASS_INSELECT;
  498. }
  499. else if (classid == YSI_g_sRight)
  500. {
  501. YSI_g_sPlayerClass[playerid] = (YSI_g_sPlayerClass[playerid] & ~e_PLAYER_CLASS_PRESS) | e_PLAYER_CLASS_RIGHT | e_PLAYER_CLASS_INSELECT;
  502. }
  503. P:C(else {P:E("y_classes unidentified classid.");YSI_g_sPlayerClass[playerid] |= e_PLAYER_CLASS_INSELECT;});
  504. classid = (YSI_g_sPlayerClass[playerid] & e_PLAYER_CLASS_SKIN);
  505. if (YSI_g_sClassCount)
  506. {
  507. // Find the next available skin for this player. I'm still not sure how
  508. // this handles the case where you can't use any skin. I'll have to
  509. // look in to that.
  510. // Don't want to get stuck constantly adding "0".
  511. classid = Class_FindNew(playerid, classid, dir);
  512. P:5("Class_OnPlayerRequestClass() selected: %d", classid);
  513. Class_Goto(playerid, _:classid);
  514. }
  515. else
  516. {
  517. SetSpawnInfo(playerid, NO_TEAM, 0, 1958.0, 1343.0, 15.0, 269.0, 0, 0, 0, 0, 0, 0);
  518. SetPlayerSkin(playerid, 0);
  519. P:E("No YSI classes found");
  520. classid = -1;
  521. }
  522. // Now sort out if they actually should be spawned.
  523. /*if (YSI_g_sPlayerClass[playerid] & (e_PLAYER_CLASS_IGNORE_ONCE))
  524. {
  525. YSI_g_sPlayerClass[playerid] &= ~(e_PLAYER_CLASS_IGNORE_ONCE);
  526. return 1;
  527. }
  528. else*/
  529. if (YSI_g_sPlayerClass[playerid] & (e_PLAYER_CLASS_RETURNED | e_PLAYER_CLASS_SPAWNSINCE) == (e_PLAYER_CLASS_RETURNED | e_PLAYER_CLASS_SPAWNSINCE))
  530. {
  531. YSI_g_sPlayerClass[playerid] &= ~(e_PLAYER_CLASS_RETURNED | e_PLAYER_CLASS_SPAWNSINCE);
  532. Class_Spectate(playerid);
  533. //SpawnPlayer(playerid);
  534. //printf("0");
  535. SetTimerEx("_Class_SpawnPlayer2", 10, 0, "i", playerid);
  536. YSI_g_sTimer[playerid] = SetTimerEx("_Class_SpawnPlayer4", 50, 0, "i", playerid);
  537. /*if (YSI_g_sHookC)
  538. {
  539. #emit PUSH.C 0xFFFFFFFF
  540. #emit PUSH.S playerid
  541. #emit PUSH.C 8
  542. #emit LCTRL 6
  543. #emit ADD.C 28
  544. #emit PUSH.pri
  545. #emit LOAD.pri YSI_g_sHookC
  546. #emit SCTRL 6
  547. //#emit RETN
  548. }*/
  549. CallRemoteFunction("_Class_OtherRequestClass", "ii", playerid, -1);
  550. }
  551. 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))
  552. {
  553. // If class selection is disabled for this player, they have already selected
  554. // a class and we haven't manually sent them back to the menu.
  555. //YSI_g_sPlayerClass[playerid] &= ~(e_PLAYER_CLASS_RETURNED | e_PLAYER_CLASS_SPAWNSINCE);
  556. Class_Spectate(playerid);
  557. //SpawnPlayer(playerid);
  558. //printf("1");
  559. SetTimerEx("_Class_SpawnPlayer1", 10, 0, "i", playerid);
  560. /*if (YSI_g_sHookC)
  561. {
  562. #emit PUSH.C 0xFFFFFFFF
  563. #emit PUSH.S playerid
  564. #emit PUSH.C 8
  565. #emit LCTRL 6
  566. #emit ADD.C 28
  567. #emit PUSH.pri
  568. #emit LOAD.pri YSI_g_sHookC
  569. #emit SCTRL 6
  570. //#emit RETN
  571. }*/
  572. CallRemoteFunction("_Class_OtherRequestClass", "ii", playerid, -1);
  573. }
  574. else
  575. {
  576. /*if (YSI_g_sHookC)
  577. {
  578. #emit PUSH.S classid
  579. #emit PUSH.S playerid
  580. #emit PUSH.C 8
  581. #emit LCTRL 6
  582. #emit ADD.C 28
  583. #emit PUSH.pri
  584. #emit LOAD.pri YSI_g_sHookC
  585. #emit SCTRL 6
  586. //#emit RETN
  587. }*/
  588. CallRemoteFunction("_Class_OtherRequestClass", "ii", playerid, classid);
  589. }
  590. return 1;
  591. }
  592. #endif
  593. foreign Class_Goto(playerid, playerclass);
  594. global Class_Goto(playerid, playerclass)
  595. {
  596. P:2("Class_Goto called: %i, %i", playerid, playerclass);
  597. // This now sets the REAL spawn information, including spawn location.
  598. 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);
  599. SetPlayerSkin(playerid, Class_Skin(e_PLAYER_CLASS:playerclass));
  600. YSI_g_sPlayerClass[playerid] = (YSI_g_sPlayerClass[playerid] & ~(e_PLAYER_CLASS_SKIN)) | (e_PLAYER_CLASS:playerclass);
  601. // Save the last viewed class so that we know which direction the person
  602. // went next time OnPlayerRequestClass is called.
  603. P:2("Class_Goto() end %08h %08h %d", YSI_g_sSettings, _:e_CLASS_SETTING_OPRCE, playerclass);
  604. return 1;
  605. }
  606. /*----------------------------------------------------------------------------*\
  607. Function:
  608. Class_OnPlayerRequestSpawn
  609. Params:
  610. playerid - Player who selected a spawn.
  611. Return:
  612. -
  613. Notes:
  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. \*----------------------------------------------------------------------------*/
  619. public _Class_OtherRequestSpawn(playerid)
  620. {
  621. if (YSI_g_sHookS)
  622. {
  623. #emit PUSH.S playerid
  624. #emit PUSH.C 4
  625. #emit LCTRL 6
  626. #emit ADD.C 28
  627. #emit PUSH.pri
  628. #emit LOAD.pri YSI_g_sHookC
  629. #emit SCTRL 6
  630. #emit RETN
  631. }
  632. }
  633. //mhook OnPlayerRequestSpawn(playerid)
  634. #if !defined YSI_NO_MASTER && _YSIM_IS_CLIENT
  635. public _Class_OnPlayerRequestSpawn(playerid)
  636. {
  637. return 1;
  638. }
  639. #else
  640. #if !defined YSI_NO_MASTER && _YSIM_IS_CLOUD
  641. //mhook OnPlayerRequestClass(playerid, classid)
  642. public _Class_OnPlayerRequestSpawn(playerid) <>
  643. {
  644. return 1;
  645. }
  646. //mhook OnPlayerRequestClass(playerid, classid)
  647. public _Class_OnPlayerRequestSpawn(playerid) <_YCM:y>
  648. {
  649. #else
  650. //mhook OnPlayerRequestClass(playerid, classid)
  651. public _Class_OnPlayerRequestSpawn(playerid)
  652. {
  653. #endif
  654. P:2("hook Class_OnPlayerRequestSpawn called: %d", playerid);
  655. new
  656. time = GetTickCount();
  657. if ((time - YSI_g_sLastRefuse[playerid]) >= 1000)
  658. {
  659. //YSI_gOPRSE = false;
  660. //new
  661. // ret = 1;
  662. //if (YSI_g_sClassOptions & e_CLASS_OPTION_HAS_RS_CALLBACK)
  663. //{
  664. // YSI_gOPRSE = true;
  665. // ret = CallLocalFunction("OnPlayerRequestSpawnEx_", "ii", playerid, playerclass);
  666. //}
  667. new
  668. ret = CallRemoteFunction("_Class_OtherRequestSpawn", "i", playerid);
  669. P:4("Class_OnPlayerRequestSpawn() return: %d", ret);
  670. if (ret)
  671. {
  672. //#if defined _YSI_SYSTEM_GROUPS
  673. new
  674. Group:newgroup = YSI_g_sClasses[(YSI_g_sPlayerClass[playerid] & e_PLAYER_CLASS_SKIN)][E_CLASS_GROUP];
  675. P:4("Class_OnPlayerRequestSpawn() newgroup: %d", _:newgroup);
  676. if (newgroup != Group:-1) Class_ResolveGroups(playerid, newgroup, true); //Group_AddPlayer(newgroup, playerid);
  677. //#endif
  678. if (ret == -1)
  679. {
  680. YSI_g_sPlayerClass[playerid] |= e_PLAYER_CLASS_SKIN;
  681. // The order is VERY important here - this will actually
  682. // call the function further down (directly below in fact).
  683. //OnPlayerRequestClass(playerid, YSI_g_sLeft);
  684. //Class_DoOnPlayerRequestClass(playerid, YSI_g_sLeft);
  685. switch (YSI_g_sPlayerClass[playerid] & e_PLAYER_CLASS_PRESS)
  686. {
  687. case e_PLAYER_CLASS_RIGHT:
  688. {
  689. _Class_OnPlayerRequestClass(playerid, YSI_g_sLeft);
  690. }
  691. case e_PLAYER_CLASS_MIDDLE:
  692. {
  693. _Class_OnPlayerRequestClass(playerid, YSI_g_sRight);
  694. }
  695. case e_PLAYER_CLASS_LEFT:
  696. {
  697. _Class_OnPlayerRequestClass(playerid, YSI_g_sMiddle);
  698. }
  699. }
  700. }
  701. else
  702. {
  703. return 1;
  704. }
  705. }
  706. }
  707. YSI_g_sLastRefuse[playerid] = time;
  708. //Class_ResumeRefresh(playerid);
  709. P:5("Class_OnPlayerRequestSpawn: Return 0");
  710. return 0;
  711. }
  712. #endif
  713. /*----------------------------------------------------------------------------*\
  714. Function:
  715. Class_OnPlayerSpawn
  716. Params:
  717. playerid - Player who spawned.
  718. Return:
  719. -
  720. Notes:
  721. Sets a player's position based on skin.
  722. \*----------------------------------------------------------------------------*/
  723. mhook OnPlayerSpawn(playerid)
  724. {
  725. P:2("Class_OnPlayerSpawn called: %d", playerid);
  726. Class_TK(playerid);
  727. new
  728. playerclass = _:(YSI_g_sPlayerClass[playerid] & e_PLAYER_CLASS_SKIN),
  729. weapon;
  730. //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;
  731. for (new i = 0; i != MAX_CLASS_SPAWN_WEAPONS; ++i)
  732. {
  733. weapon = YSI_g_sClasses[playerclass][E_CLASS_WEAPONS][i];
  734. //if (weapon == WEAPON_ARMOUR) SetPlayerArmour(playerid, 100.0);
  735. if (weapon)
  736. {
  737. GivePlayerWeapon(playerid, weapon & 0xFF, weapon >>> 8);
  738. }
  739. else
  740. {
  741. break;
  742. }
  743. }
  744. weapon = YSI_g_sClasses[playerclass][E_CLASS_WEAPONS][MAX_CLASS_SPAWN_WEAPONS];
  745. P:5("Class_OnPlayerSpawn: Armour %d %d %d", weapon, weapon & 0xFF, WEAPON_ARMOUR);
  746. if ((weapon & 0xFF) == WEAPON_ARMOUR)
  747. {
  748. weapon >>>= 8;
  749. if (weapon == 0x00800000)
  750. {
  751. // INFINITY
  752. SetPlayerArmour(playerid, Float:0x7F800000);
  753. }
  754. else
  755. {
  756. SetPlayerArmour(playerid, weapon);
  757. }
  758. }
  759. // Now update reselection variables.
  760. YSI_g_sPlayerClass[playerid] = (YSI_g_sPlayerClass[playerid] & ~(e_PLAYER_CLASS_INSELECT | e_PLAYER_CLASS_IGNORE_ONCE)) | (e_PLAYER_CLASS_HADFIRST);
  761. if (YSI_g_sPlayerClass[playerid] & (e_PLAYER_CLASS_RETURNED))
  762. {
  763. if (YSI_g_sPlayerClass[playerid] & (e_PLAYER_CLASS_INSTANT))
  764. {
  765. YSI_g_sPlayerClass[playerid] |= (e_PLAYER_CLASS_SPAWNSINCE);
  766. }
  767. else
  768. {
  769. YSI_g_sPlayerClass[playerid] &= ~(e_PLAYER_CLASS_RETURNED);
  770. }
  771. }
  772. //if (YSI_g_sPlayerClass[playerid] & (e_PLAYER_CLASS_DISABLED))
  773. //{
  774. // I know it may seem odd to force class selection when it is explicitly
  775. // disabled, but this will disable the "F4" message too.
  776. //ForceClassSelection(playerid);
  777. //}
  778. return 1;
  779. }
  780. forward _Class_SpawnPlayer1(playerid);
  781. public _Class_SpawnPlayer1(playerid)
  782. {
  783. P:1("_Class_SpawnPlayer1 called: %d", playerid);
  784. //SpawnPlayer(playerid);
  785. YSI_g_sPlayerClass[playerid] |= (e_PLAYER_CLASS_IGNORE_ONCE);
  786. TogglePlayerSpectating(playerid, false);
  787. //SpawnPlayer(playerid);
  788. //YSI_g_sTimer[playerid] = SetTimerEx("_Class_SpawnPlayer3", 20, 0, "i", playerid);
  789. //Class_TK(playerid);
  790. }
  791. forward _Class_SpawnPlayer2(playerid);
  792. public _Class_SpawnPlayer2(playerid)
  793. {
  794. P:1("_Class_SpawnPlayer2 called: %d", playerid);
  795. //SpawnPlayer(playerid);
  796. //YSI_g_sPlayerClass[playerid] |= (e_PLAYER_CLASS_IGNORE_ONCE);
  797. TogglePlayerSpectating(playerid, false);
  798. //Class_TK(playerid);
  799. }
  800. forward _Class_SpawnPlayer3(playerid);
  801. public _Class_SpawnPlayer3(playerid)
  802. {
  803. P:1("_Class_SpawnPlayer3 called: %d", playerid);
  804. SpawnPlayer(playerid);
  805. //Class_TK(playerid);
  806. //YSI_g_sPlayerClass[playerid] |= (e_PLAYER_CLASS_IGNORE_ONCE);
  807. //TogglePlayerSpectating(playerid, false);
  808. //Class_TK(playerid);
  809. }
  810. forward _Class_SpawnPlayer4(playerid);
  811. public _Class_SpawnPlayer4(playerid)
  812. {
  813. P:1("_Class_SpawnPlayer4 called: %d", playerid);
  814. //SpawnPlayer(playerid);
  815. Class_Spectate(playerid);
  816. if (YSI_g_sPlayerClass[playerid] & (e_PLAYER_CLASS_DISABLED))
  817. {
  818. YSI_g_sTimer[playerid] = SetTimerEx("_Class_SpawnPlayer1", 10, 0, "i", playerid);
  819. }
  820. else
  821. {
  822. YSI_g_sTimer[playerid] = SetTimerEx("_Class_SpawnPlayer2", 10, 0, "i", playerid);
  823. }
  824. //Class_TK(playerid);
  825. //YSI_g_sPlayerClass[playerid] |= (e_PLAYER_CLASS_IGNORE_ONCE);
  826. //TogglePlayerSpectating(playerid, false);
  827. //Class_TK(playerid);
  828. }
  829. forward _Class_Return(playerid);
  830. public _Class_Return(playerid)
  831. {
  832. P:1("_Class_Return called: %d", playerid);
  833. Class_ReturnToSelection(playerid);
  834. //Class_TK(playerid);
  835. //YSI_g_sTimer[playerid] = SetTimerEx("_Class_NotSpawned", 500, 0, "i", playerid);
  836. }
  837. forward _Class_NotSpawned(playerid);
  838. public _Class_NotSpawned(playerid)
  839. {
  840. P:1("_Class_NotSpawned called: %d", playerid);
  841. // Called if they don't connect properly.
  842. Class_DisableSelection(playerid);
  843. //SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  844. //SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  845. SetTimerEx("_Class_Return", 10, 0, "i", playerid);
  846. YSI_g_sPlayerClass[playerid] |= (e_PLAYER_CLASS_RETURNED | e_PLAYER_CLASS_INSTANT);
  847. }
  848. static stock Class_TK(playerid)
  849. {
  850. // "Timer Kill".
  851. if (YSI_g_sTimer[playerid])
  852. {
  853. KillTimer(YSI_g_sTimer[playerid]);
  854. YSI_g_sTimer[playerid] = 0;
  855. }
  856. }
  857. mhook OnPlayerConnect(playerid)
  858. {
  859. //printf("OnPlayerConnect %d", playerid);
  860. YSI_g_sPlayerClass[playerid] = (e_PLAYER_CLASS_NONE);
  861. YSI_g_sTimer[playerid] = SetTimerEx("_Class_NotSpawned", 500, 0, "i", playerid);
  862. return 1;
  863. }
  864. /*mhook OnPlayerDeath(playerid, killerid, reason)
  865. {
  866. }
  867. mhook OnPlayerRequestSpawn(playerid)
  868. {
  869. }
  870. mhook OnPlayerDisconnect(playerid, reason)
  871. {
  872. }*/
  873. /*----------------------------------------------------------------------------*\
  874. Function:
  875. Class_Add
  876. Params:
  877. skin - Skin of the class.
  878. Float:x - X spawn location.
  879. Float:y - Y spawn location.
  880. Float:z - Z spawn location.
  881. Float:a - A spawn location.
  882. ... - Spawn weapons and ammo (weapon then ammo)
  883. Return:
  884. -
  885. Notes:
  886. Pretty much AddPlayerClass but allows greater control over the classes.
  887. Now has infinate (MAX_CLASS_SPAWN_WEAPONS) spawn weapons. This is one of
  888. the few API functions which is not entirely remote. This is because it has
  889. variable parameters which is need to collect in to a single array to pass to
  890. the remote function.
  891. \*----------------------------------------------------------------------------*/
  892. stock Class_Add(skin, Float:x, Float:y, Float:z, Float:a, ...)
  893. {
  894. P:3("Class_Add called: %i, %i, %i, %i, %i, %i (+%i)", skin, x, y, z, a, numargs() - 5);
  895. new
  896. n = numargs(),
  897. w = 5,
  898. s,
  899. weapons[MAX_CLASS_SPAWN_WEAPONS + 1],
  900. cw;
  901. _CLASS_WEAPON_CODE
  902. return Class_AddClass(skin, x, y, z, a, weapons, MAX_CLASS_SPAWN_WEAPONS + 1, Group:-1, Group:-1);
  903. }
  904. /*----------------------------------------------------------------------------*\
  905. Function:
  906. Class_AddEx
  907. Params:
  908. forgroup - Group that can use the skin.
  909. setgroup - Group to add the player to on selection.
  910. skin - Skin of the class.
  911. Float:x - X spawn location.
  912. Float:y - Y spawn location.
  913. Float:z - Z spawn location.
  914. Float:a - A spawn location.
  915. ... - Spawn weapons and ammo (weapon then ammo)
  916. Return:
  917. -
  918. Notes:
  919. Pretty much AddPlayerClass but allows greater control over the classes.
  920. Now has infinate (MAX_CLASS_SPAWN_WEAPONS) spawn weapons.
  921. \*----------------------------------------------------------------------------*/
  922. stock Class_AddEx(Group:forgroup, Group:setgroup, skin, Float:x, Float:y, Float:z, Float:a, ...)
  923. {
  924. P:3("Class_AddEx called: %i, %i, %i, %f, %f, %f, %f (+%i)", _:forgroup, _:setgroup, skin, x, y, z, a, numargs() - 7);
  925. new
  926. n = numargs(),
  927. w = 7,
  928. s,
  929. weapons[MAX_CLASS_SPAWN_WEAPONS + 1],
  930. cw;
  931. _CLASS_WEAPON_CODE
  932. return Class_AddClass(skin, x, y, z, a, weapons, MAX_CLASS_SPAWN_WEAPONS + 1, forgroup, setgroup);
  933. }
  934. /*----------------------------------------------------------------------------*\
  935. Function:
  936. Class_AddForGroup
  937. Params:
  938. group - Group to allow to use the class.
  939. skin - Skin of the class.
  940. Float:x - X spawn location.
  941. Float:y - Y spawn location.
  942. Float:z - Z spawn location.
  943. Float:a - A spawn location.
  944. ... - Weapon data.
  945. Return:
  946. -
  947. Notes:
  948. Adds a class only people in the specified group can use.
  949. \*----------------------------------------------------------------------------*/
  950. stock Class_AddForGroup(Group:group, skin, Float:x, Float:y, Float:z, Float:a, ...)
  951. {
  952. P:3("Class_AddForGroup called: %i, %i, %f, %f, %f, %f (+%i)", _:group, skin, x, y, z, a, numargs() - 6);
  953. new
  954. n = numargs(),
  955. w = 6,
  956. s,
  957. weapons[MAX_CLASS_SPAWN_WEAPONS + 1],
  958. cw;
  959. _CLASS_WEAPON_CODE
  960. return Class_AddClass(skin, x, y, z, a, weapons, MAX_CLASS_SPAWN_WEAPONS + 1, group, Group:-1);
  961. }
  962. /*----------------------------------------------------------------------------*\
  963. Function:
  964. Class_AddWithGroupSet
  965. Params:
  966. group - Group to make players who use this group.
  967. skin - Skin of the class.
  968. Float:x - X spawn location.
  969. Float:y - Y spawn location.
  970. Float:z - Z spawn location.
  971. Float:a - A spawn location.
  972. ... - Spawn weapons.
  973. Return:
  974. -
  975. Notes:
  976. Adds a class which puts you in the specified group when selected.
  977. \*----------------------------------------------------------------------------*/
  978. stock Class_AddWithGroupSet(Group:group, skin, Float:x, Float:y, Float:z, Float:a, ...)
  979. {
  980. P:3("Class_AddWithGroupSet called: %i, %i, %f, %f, %f, %f (+%i)", _:group, skin, x, y, z, a, numargs() - 6);
  981. new
  982. n = numargs(),
  983. w = 6,
  984. s,
  985. weapons[MAX_CLASS_SPAWN_WEAPONS + 1],
  986. cw;
  987. _CLASS_WEAPON_CODE
  988. return Class_AddClass(skin, x, y, z, a, weapons, MAX_CLASS_SPAWN_WEAPONS + 1, Group:-1, group);
  989. }
  990. /*----------------------------------------------------------------------------*\
  991. Function:
  992. Class_AddClass
  993. Params:
  994. skin - Skin of the class.
  995. Float:x - X spawn location.
  996. Float:y - Y spawn location.
  997. Float:z - Z spawn location.
  998. Float:a - A spawn location.
  999. weapons[] - Array of spawn weapon data.
  1000. count - Number of weapons added.
  1001. forgroup - Group that can use the class.
  1002. asgroup - Group to assign people to with this class.
  1003. Return:
  1004. -
  1005. Notes:
  1006. Does the hard work. This took a long time to get working correctly with the
  1007. new master system, infact getting just this one function to compile took a
  1008. major re-working of the macros to reduce the length of intermediate stages.
  1009. \*----------------------------------------------------------------------------*/
  1010. foreign Class_AddClass(s,Float:x,Float:y,Float:z,Float:a,w[],c,Group:f,Group:g);
  1011. global Class_AddClass(s,Float:x,Float:y,Float:z,Float:a,w[],c,Group:f,Group:g)
  1012. {
  1013. P:2("Class_AddClass called: %i, %f, %f, %f, %f, %a, %i, %i, %i", s, x, y, z, a, w, c, _:f, _:g);
  1014. new
  1015. i;
  1016. while (i < MAX_CLASSES)
  1017. {
  1018. if (!Class_IsActive(i)) break;
  1019. i++;
  1020. }
  1021. if (i == MAX_CLASSES) return -1;
  1022. YSI_g_sClasses[i][E_CLASS_FLAGS] = e_CLASS_FLAGS_ACTIVE | e_CLASS_FLAGS_ENABLED | e_CLASS_FLAGS:s;
  1023. YSI_g_sClasses[i][E_CLASS_X] = x;
  1024. YSI_g_sClasses[i][E_CLASS_Y] = y;
  1025. YSI_g_sClasses[i][E_CLASS_Z] = z;
  1026. YSI_g_sClasses[i][E_CLASS_A] = a;
  1027. new
  1028. j;
  1029. // This may be better with a memcpy.
  1030. while (j < c)
  1031. {
  1032. P:5("Class_AddClass: weapon %d %d %d", j, c, w[j]);
  1033. YSI_g_sClasses[i][E_CLASS_WEAPONS][j] = w[j];
  1034. ++j;
  1035. }
  1036. PA_FastInit(YSI_g_sClasses[i][E_CLASS_PLAYERS]);
  1037. Class_ResolveGroups(i, f, false);
  1038. YSI_g_sClasses[i][E_CLASS_GROUP] = g;
  1039. YSI_g_sClassCount++;
  1040. return i;
  1041. }
  1042. foreign Class_Enable(classid, bool:toggle);
  1043. global Class_Enable(classid, bool:toggle)
  1044. {
  1045. if (Class_IsValid(classid))
  1046. {
  1047. if (toggle)
  1048. {
  1049. YSI_g_sClasses[classid][E_CLASS_FLAGS] |= e_CLASS_FLAGS_ENABLED;
  1050. }
  1051. else
  1052. {
  1053. YSI_g_sClasses[classid][E_CLASS_FLAGS] &= ~e_CLASS_FLAGS_ENABLED;
  1054. // TODO! Hide the class for anyone currently viewing it.
  1055. // foreach (new playerid : Player)
  1056. // {
  1057. // new
  1058. // e_PLAYER_CLASS:curclass = YSI_g_sPlayerClass[playerid];
  1059. // P:4("Class_Delete: %d %d %d", playerid, curclass, e_PLAYER_CLASS_SELECT);
  1060. // if (curclass & e_PLAYER_CLASS_SELECT)
  1061. // {
  1062. // if (e_PLAYER_CLASS:classid == curclass & e_PLAYER_CLASS_SKIN) Class_Goto(playerid, Class_FindNew(playerid, e_PLAYER_CLASS:classid, CLASS_MOVE_RIGHT));
  1063. // }
  1064. // }
  1065. }
  1066. return 1;
  1067. }
  1068. return 0;
  1069. }
  1070. /*----------------------------------------------------------------------------*\
  1071. Function:
  1072. Class_Delete
  1073. Params:
  1074. classid - Class to delete.
  1075. Return:
  1076. -
  1077. Notes:
  1078. Completely removes a class from the system.
  1079. \*----------------------------------------------------------------------------*/
  1080. foreign Class_Delete(classid);
  1081. global Class_Delete(classid)
  1082. {
  1083. P:2("Class_Delete called: %i", classid);
  1084. if (Class_Enable(classid, false))
  1085. {
  1086. YSI_g_sClasses[classid][E_CLASS_FLAGS] = e_CLASS_FLAGS:0;
  1087. }
  1088. return 1;
  1089. }
  1090. /*----------------------------------------------------------------------------*\
  1091. Function:
  1092. Class_SetPlayer
  1093. Params:
  1094. classid - Class to set permissions for.
  1095. playerid - Player to set for.
  1096. set - Whether or not they can use this class.
  1097. Return:
  1098. -
  1099. Notes:
  1100. -
  1101. \*----------------------------------------------------------------------------*/
  1102. foreign Class_SetPlayer(cl, pid, bool:s);
  1103. global Class_SetPlayer(cl, pid, bool:s)
  1104. {
  1105. //printf("CLASS SET PLAYER: %d %d %d", cl, pid, s);
  1106. return PA_Set(YSI_g_sClasses[cl][E_CLASS_PLAYERS], pid, s);
  1107. }
  1108. /*----------------------------------------------------------------------------*\
  1109. Function:
  1110. Class_GetPlayer
  1111. Params:
  1112. classid - Class to set permissions for.
  1113. playerid - Player to set for.
  1114. Return:
  1115. -
  1116. Notes:
  1117. -
  1118. \*----------------------------------------------------------------------------*/
  1119. foreign bool:Class_GetPlayer(cl,pid);
  1120. global bool:Class_GetPlayer(cl,pid)
  1121. {
  1122. return PA_Get(YSI_g_sClasses[cl][E_CLASS_PLAYERS], pid);
  1123. }
  1124. /*----------------------------------------------------------------------------*\
  1125. Function:
  1126. Class_Get
  1127. Params:
  1128. playerid - Player to get the current class of.
  1129. Return:
  1130. -
  1131. Notes:
  1132. -
  1133. \*----------------------------------------------------------------------------*/
  1134. foreign Class_Get(playerid);
  1135. global Class_Get(playerid)
  1136. {
  1137. if (0 <= playerid < MAX_PLAYERS)
  1138. {
  1139. return _:(YSI_g_sPlayerClass[playerid] & e_PLAYER_CLASS_SKIN);
  1140. }
  1141. return -1;
  1142. }
  1143. foreign Class_DisableSelection(playerid);
  1144. global Class_DisableSelection(playerid)
  1145. {
  1146. if (YSI_g_sPlayerClass[playerid] & e_PLAYER_CLASS_INSELECT)
  1147. {
  1148. Class_Spectate(playerid);
  1149. Class_TK(playerid);
  1150. }
  1151. return 1;
  1152. }
  1153. foreign Class_DisableReselection(playerid);
  1154. global Class_DisableReselection(playerid)
  1155. {
  1156. YSI_g_sPlayerClass[playerid] |= (e_PLAYER_CLASS_DISABLED);
  1157. // Disable "F4".
  1158. //ForceClassSelection(playerid);
  1159. return 1;
  1160. }
  1161. foreign Class_EnableReselection(playerid);
  1162. global Class_EnableReselection(playerid)
  1163. {
  1164. YSI_g_sPlayerClass[playerid] &= ~(e_PLAYER_CLASS_DISABLED);
  1165. return 1;
  1166. }
  1167. foreign Class_ForceReselection(playerid);
  1168. global Class_ForceReselection(playerid)
  1169. {
  1170. YSI_g_sPlayerClass[playerid] = (YSI_g_sPlayerClass[playerid] | e_PLAYER_CLASS_RETURNED) & ~(e_PLAYER_CLASS_SPAWNSINCE);
  1171. ForceClassSelection(playerid);
  1172. return 1;
  1173. }
  1174. foreign Class_ReturnToSelection(playerid);
  1175. global Class_ReturnToSelection(playerid)
  1176. {
  1177. YSI_g_sPlayerClass[playerid] |= (e_PLAYER_CLASS_INSTANT);
  1178. Class_ForceReselection(playerid);
  1179. TogglePlayerSpectating(playerid, false);
  1180. return 1;
  1181. }
  1182. static stock Class_Spectate(playerid)
  1183. {
  1184. new
  1185. Float:x1,
  1186. Float:y1,
  1187. Float:z1;
  1188. GetPlayerCameraPos(playerid, x1, y1, z1);
  1189. new
  1190. Float:x2,
  1191. Float:y2,
  1192. Float:z2;
  1193. GetPlayerCameraFrontVector(playerid, x2, y2, z2);
  1194. TogglePlayerSpectating(playerid, true);
  1195. SetPlayerCameraPos(playerid, x1, y1, z1);
  1196. SetPlayerCameraLookAt(playerid, x2, y2, z2);
  1197. PlayerSpectatePlayer(playerid, playerid, SPECTATE_MODE_FIXED);
  1198. }
  1199. #if defined _ALS_AddPlayerClass
  1200. #undef AddPlayerClass
  1201. #else
  1202. #define _ALS_AddPlayerClass
  1203. #endif
  1204. #define AddPlayerClass Class_Add
  1205. //#define YSI_SET_LAST_GROUP 22
  1206. #include "internal\y_grouprevert"