classcontrol.inc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  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_sPlayerFlags - 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. enum e_SPAWN_FLAGS (<<= 1)
  130. {
  131. e_SPAWN_FLAGS_NONE = 0,
  132. // Control flags.
  133. e_SPAWN_FLAGS_RETURNED = 1, // Back in class selection.
  134. e_SPAWN_FLAGS_SPAWNSINCE, // Spawned after class selection.
  135. e_SPAWN_FLAGS_ENABLED, // Class selection disabled.
  136. e_SPAWN_FLAGS_RESELECT, // Class reselection disabled.
  137. e_SPAWN_FLAGS_HADFIRST, // Spawned ever.
  138. e_SPAWN_FLAGS_INSTANT, // Sent straight to class selection.
  139. e_SPAWN_FLAGS_FORCED, // Sent to class selection manually.
  140. e_SPAWN_FLAGS_INSELECT, // In class selection.
  141. e_SPAWN_FLAGS_IGNORE_ONCE,
  142. e_SPAWN_FLAGS_HELD // Can't see, but in, class selection.
  143. }
  144. static stock
  145. e_SPAWN_FLAGS:YSI_g_sPlayerFlags[MAX_PLAYERS];
  146. /**--------------------------------------------------------------------------**\
  147. <summary>Player_InSelection</summary>
  148. <param name="playerid">Player to check.</param>
  149. <returns>
  150. Is this player currently in the class selection screen?
  151. </returns>
  152. <remarks>
  153. -
  154. </remarks>
  155. \**--------------------------------------------------------------------------**/
  156. foreign bool:Player_InSelection(playerid);
  157. global bool:Player_InSelection(playerid)
  158. {
  159. return bool:(YSI_g_sPlayerFlags[playerid] & e_SPAWN_FLAGS_INSELECT);
  160. }
  161. /**--------------------------------------------------------------------------**\
  162. <summary>Player_HasSpawned</summary>
  163. <param name="playerid">Player to check.</param>
  164. <returns>
  165. Has this player ever spawned?
  166. </returns>
  167. <remarks>
  168. -
  169. </remarks>
  170. \**--------------------------------------------------------------------------**/
  171. foreign bool:Player_HasSpawned(playerid);
  172. global bool:Player_HasSpawned(playerid)
  173. {
  174. return bool:(YSI_g_sPlayerFlags[playerid] & e_SPAWN_FLAGS_HADFIRST);
  175. }
  176. /**--------------------------------------------------------------------------**\
  177. <summary>Player_IsSpawned</summary>
  178. <param name="playerid">Player to check.</param>
  179. <returns>
  180. Is this player spawned now?
  181. </returns>
  182. <remarks>
  183. Returns true if they are not in class selection, and if they have ever
  184. spawned. It could be that both "Player_IsSpawned" and "Player_InSelection"
  185. return "false" - if they haven't even reached the class selection screen yet
  186. (mainly happens in "OnPlayerConnect").
  187. </remarks>
  188. \**--------------------------------------------------------------------------**/
  189. foreign bool:Player_IsSpawned(playerid);
  190. global bool:Player_IsSpawned(playerid)
  191. {
  192. return (YSI_g_sPlayerFlags[playerid] & (e_SPAWN_FLAGS_INSELECT | e_SPAWN_FLAGS_HADFIRST)) == e_SPAWN_FLAGS_HADFIRST;
  193. }
  194. /**--------------------------------------------------------------------------**\
  195. <summary>Class_OnPlayerConnect</summary>
  196. <param name="playerid">Player who joined the server.</param>
  197. <returns>
  198. -
  199. </returns>
  200. <remarks>
  201. Reset all the data on this player's current classes.
  202. </remarks>
  203. \**--------------------------------------------------------------------------**/
  204. mhook OnPlayerConnect(playerid)
  205. {
  206. YSI_g_sPlayerFlags[playerid] = e_SPAWN_FLAGS_RESELECT | e_SPAWN_FLAGS_ENABLED;
  207. return 1;
  208. }
  209. /**--------------------------------------------------------------------------**\
  210. <summary>Class_OnPlayerRequestClass</summary>
  211. <param name="playerid">Player who requested a class.</param>
  212. <param name="class">Class they requested.</param>
  213. <returns>
  214. -
  215. </returns>
  216. <remarks>
  217. Not the first call of this function by y_classes.
  218. </remarks>
  219. \**--------------------------------------------------------------------------**/
  220. stock Class_Spawn(playerid)
  221. {
  222. TogglePlayerSpectating(playerid, true);
  223. PlayerSpectatePlayer(playerid, playerid, SPECTATE_MODE_NORMAL);
  224. SpawnPlayer(playerid);
  225. TogglePlayerSpectating(playerid, false);
  226. SetCameraBehindPlayer(playerid);
  227. }
  228. stock Class_ShowHold(playerid)
  229. {
  230. SpawnPlayer(playerid);
  231. YSI_g_sPlayerFlags[playerid] |= e_SPAWN_FLAGS_HELD;
  232. TogglePlayerSpectating(playerid, true);
  233. TogglePlayerControllable(playerid, false);
  234. //ForceClassSelection(playerid);
  235. }
  236. stock Class_HideHold(playerid)
  237. {
  238. YSI_g_sPlayerFlags[playerid] &= ~e_SPAWN_FLAGS_HELD;
  239. TogglePlayerSpectating(playerid, false);
  240. ForceClassSelection(playerid);
  241. // SetPlayerHealth(playerid, 0.0);
  242. TogglePlayerSpectating(playerid, true);
  243. PlayerSpectatePlayer(playerid, playerid, SPECTATE_MODE_NORMAL);
  244. TogglePlayerSpectating(playerid, false);
  245. TogglePlayerControllable(playerid, false);
  246. //SetCameraBehindPlayer(playerid);
  247. //SpawnPlayer(playerid);
  248. }
  249. mhook OnPlayerRequestClass(playerid, classid)
  250. {
  251. //TogglePlayerSpectating(playerid, true);
  252. YSI_g_sPlayerFlags[playerid] |= e_SPAWN_FLAGS_INSELECT;
  253. new
  254. e_SPAWN_FLAGS:flags = YSI_g_sPlayerFlags[playerid];
  255. // These are all the cases where class selection is allowed.
  256. if (flags & e_SPAWN_FLAGS_FORCED)
  257. {
  258. return 1;
  259. }
  260. if (flags & e_SPAWN_FLAGS_HADFIRST)
  261. {
  262. if (flags & e_SPAWN_FLAGS_RESELECT)
  263. {
  264. return 1;
  265. }
  266. SpawnPlayer(playerid);
  267. //Class_Spawn(playerid);
  268. }
  269. else
  270. {
  271. if (flags & e_SPAWN_FLAGS_ENABLED)
  272. {
  273. return 1;
  274. }
  275. Class_ShowHold(playerid);
  276. }
  277. //Class_Spawn(playerid);
  278. return -2;
  279. }
  280. /**--------------------------------------------------------------------------**\
  281. <summary>Class_OnPlayerSpawn</summary>
  282. <param name="playerid">Player who spawned.</param>
  283. <returns>
  284. -
  285. </returns>
  286. <remarks>
  287. Sets a player's position based on skin.
  288. </remarks>
  289. \**--------------------------------------------------------------------------**/
  290. mhook OnPlayerSpawn(playerid)
  291. {
  292. P:2("Class_OnPlayerSpawn called: %d", playerid);
  293. if (YSI_g_sPlayerFlags[playerid] & e_SPAWN_FLAGS_HELD) return -1;
  294. if (!(YSI_g_sPlayerFlags[playerid] & e_SPAWN_FLAGS_RESELECT))
  295. {
  296. // Seems backwards, but this disables the message.
  297. ForceClassSelection(playerid);
  298. }
  299. YSI_g_sPlayerFlags[playerid] = (YSI_g_sPlayerFlags[playerid] & ~e_SPAWN_FLAGS_INSELECT) | e_SPAWN_FLAGS_HADFIRST;
  300. return 1;
  301. }
  302. // forward _Class_SpawnPlayer1(playerid);
  303. // public _Class_SpawnPlayer1(playerid)
  304. // {
  305. // P:1("_Class_SpawnPlayer1 called: %d", playerid);
  306. // //SpawnPlayer(playerid);
  307. // YSI_g_sPlayerFlags[playerid] |= (e_SPAWN_FLAGS_IGNORE_ONCE);
  308. // TogglePlayerSpectating(playerid, false);
  309. // //SpawnPlayer(playerid);
  310. // //YSI_g_sTimer[playerid] = SetTimerEx("_Class_SpawnPlayer3", 20, 0, "i", playerid);
  311. // //Class_TK(playerid);
  312. // }
  313. // forward _Class_SpawnPlayer2(playerid);
  314. // public _Class_SpawnPlayer2(playerid)
  315. // {
  316. // P:1("_Class_SpawnPlayer2 called: %d", playerid);
  317. // //SpawnPlayer(playerid);
  318. // //YSI_g_sPlayerFlags[playerid] |= (e_SPAWN_FLAGS_IGNORE_ONCE);
  319. // TogglePlayerSpectating(playerid, false);
  320. // //Class_TK(playerid);
  321. // }
  322. // forward _Class_SpawnPlayer3(playerid);
  323. // public _Class_SpawnPlayer3(playerid)
  324. // {
  325. // P:1("_Class_SpawnPlayer3 called: %d", playerid);
  326. // SpawnPlayer(playerid);
  327. // //Class_TK(playerid);
  328. // //YSI_g_sPlayerFlags[playerid] |= (e_SPAWN_FLAGS_IGNORE_ONCE);
  329. // //TogglePlayerSpectating(playerid, false);
  330. // //Class_TK(playerid);
  331. // }
  332. // forward _Class_SpawnPlayer4(playerid);
  333. // public _Class_SpawnPlayer4(playerid)
  334. // {
  335. // P:1("_Class_SpawnPlayer4 called: %d", playerid);
  336. // //SpawnPlayer(playerid);
  337. // Class_Spectate(playerid);
  338. // if (YSI_g_sPlayerFlags[playerid] & (e_SPAWN_FLAGS_ENABLED))
  339. // {
  340. // YSI_g_sTimer[playerid] = SetTimerEx("_Class_SpawnPlayer1", 10, 0, "i", playerid);
  341. // }
  342. // else
  343. // {
  344. // YSI_g_sTimer[playerid] = SetTimerEx("_Class_SpawnPlayer2", 10, 0, "i", playerid);
  345. // }
  346. // //Class_TK(playerid);
  347. // //YSI_g_sPlayerFlags[playerid] |= (e_SPAWN_FLAGS_IGNORE_ONCE);
  348. // //TogglePlayerSpectating(playerid, false);
  349. // //Class_TK(playerid);
  350. // }
  351. // forward _Class_Return(playerid);
  352. // public _Class_Return(playerid)
  353. // {
  354. // P:1("_Class_Return called: %d", playerid);
  355. // Class_ReturnToSelection(playerid);
  356. // //Class_TK(playerid);
  357. // //YSI_g_sTimer[playerid] = SetTimerEx("_Class_NotSpawned", 500, 0, "i", playerid);
  358. // }
  359. // forward _Class_NotSpawned(playerid);
  360. // public _Class_NotSpawned(playerid)
  361. // {
  362. // P:1("_Class_NotSpawned called: %d", playerid);
  363. // // Called if they don't connect properly.
  364. // Class_DisableSelection(playerid);
  365. // //SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  366. // //SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  367. // SetTimerEx("_Class_Return", 10, 0, "i", playerid);
  368. // YSI_g_sPlayerFlags[playerid] |= (e_SPAWN_FLAGS_RETURNED | e_SPAWN_FLAGS_INSTANT);
  369. // }
  370. // static stock Class_TK(playerid)
  371. // {
  372. // // "Timer Kill".
  373. // if (YSI_g_sTimer[playerid])
  374. // {
  375. // KillTimer(YSI_g_sTimer[playerid]);
  376. // YSI_g_sTimer[playerid] = 0;
  377. // }
  378. // }
  379. stock void:Class_DisableReselection(playerid)
  380. {
  381. Class_SetReselection(playerid, false);
  382. }
  383. stock void:Class_EnableReselection(playerid)
  384. {
  385. Class_SetReselection(playerid, true);
  386. }
  387. foreign void:Class_SetReselection(playerid, bool:s);
  388. global void:Class_SetReselection(playerid, bool:s)
  389. {
  390. if (s) YSI_g_sPlayerFlags[playerid] |= (e_SPAWN_FLAGS_RESELECT);
  391. else YSI_g_sPlayerFlags[playerid] &= ~(e_SPAWN_FLAGS_RESELECT);
  392. }
  393. foreign void:Class_ForceReselection(playerid);
  394. global void:Class_ForceReselection(playerid)
  395. {
  396. YSI_g_sPlayerFlags[playerid] |= e_SPAWN_FLAGS_FORCED;
  397. ForceClassSelection(playerid);
  398. }
  399. stock void:Class_DisableSelection(playerid)
  400. {
  401. Class_SetSelection(playerid, false);
  402. }
  403. stock void:Class_EnableSelection(playerid)
  404. {
  405. Class_SetSelection(playerid, true);
  406. }
  407. foreign void:Class_SetSelection(playerid, bool:s);
  408. global void:Class_SetSelection(playerid, bool:s)
  409. {
  410. if (s)
  411. {
  412. YSI_g_sPlayerFlags[playerid] |= (e_SPAWN_FLAGS_ENABLED);
  413. if (YSI_g_sPlayerFlags[playerid] & e_SPAWN_FLAGS_HELD)
  414. {
  415. Class_HideHold(playerid);
  416. }
  417. }
  418. else
  419. {
  420. YSI_g_sPlayerFlags[playerid] &= ~(e_SPAWN_FLAGS_ENABLED);
  421. if (YSI_g_sPlayerFlags[playerid] & e_SPAWN_FLAGS_INSELECT)
  422. {
  423. Class_ShowHold(playerid);
  424. // Class_TK(playerid);
  425. }
  426. }
  427. //return 1;
  428. }
  429. foreign void:Class_ReturnToSelection(playerid);
  430. global void:Class_ReturnToSelection(playerid)
  431. {
  432. YSI_g_sPlayerFlags[playerid] |= (e_SPAWN_FLAGS_INSTANT);
  433. Class_ForceReselection(playerid);
  434. TogglePlayerSpectating(playerid, false);
  435. //return 1;
  436. }
  437. // static stock Class_Spectate(playerid)
  438. // {
  439. // new
  440. // Float:x1,
  441. // Float:y1,
  442. // Float:z1;
  443. // GetPlayerCameraPos(playerid, x1, y1, z1);
  444. // new
  445. // Float:x2,
  446. // Float:y2,
  447. // Float:z2;
  448. // GetPlayerCameraFrontVector(playerid, x2, y2, z2);
  449. // TogglePlayerSpectating(playerid, true);
  450. // SetPlayerCameraPos(playerid, x1, y1, z1);
  451. // SetPlayerCameraLookAt(playerid, x2, y2, z2);
  452. // PlayerSpectatePlayer(playerid, playerid, SPECTATE_MODE_FIXED);
  453. // }