sprayTag.inc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /*
  2. @project_name
  3. Cyanide's Spray Tag System
  4. @project_author
  5. Cyanide
  6. @license
  7. http://www.mozilla.org/MPL/
  8. @description
  9. Cyanide's Spray Tag System allows a player to spray gangzones similar
  10. to GTA:SA singleplayer. The sprag tag system also includes crouch support,
  11. loading and saving, and completely plug n play.
  12. @functions (Scripters Only)
  13. Spray::givePlayerPermission( clientid, bool:permissionToggle ) - Allows you to give permission to a sprayer.
  14. Spray::createSprayAtPlayerPos( clientid ) - Creates a spray at the player's position.
  15. Spray::Delete( sprayID ) - Deletes a spray.
  16. Spray::Load( ) - Loads sprays, already called on server start.
  17. Spray::doesPlayerHavePermission( clientid ) - Checks if a player has spraying permission.
  18. OnPlayerReceiveSprayPermission( playerid, errorID ) - Called during Spray::givePlayerPermission
  19. OnPlayerCreateSpray( playerid, sprayID ) - When someone performs a spray.
  20. OnSprayDelete( sprayID ) - Called when a spray is deleted.
  21. Spray::UpdateTag( sprayID, sprayTag ) Updates a tag's spray, refer to the codes below.
  22. @codes
  23. SPRAY_TAG_FYB_1 Front Yard Ballas
  24. SPRAY_TAG_FYB_2 Front Yard Ballas 2
  25. SPRAY_TAG_FYB_3 Front Yard Ballas 3
  26. SPRAY_TAG_RIFA San Fierro Rifa
  27. SPRAY_TAG_RHB Rollin Heights Ballas
  28. SPRAY_TAG_SEVILLE Seville Families
  29. SPRAY_TAG_TEMPLE Temple Drive
  30. SPRAY_TAG_AZTECAS Aztecas
  31. @commands
  32. @errors
  33. 1 - Error with sending / giving permission.
  34. 2 - Player is not connected.
  35. @credits
  36. Cyanide - Project Launcher & Developer
  37. Bakr - Helping with trigonometry functions.
  38. Y_Less - YSI
  39. Incognito - Global Variable plugin.
  40. SA-MP Team - San Andreas Multiplayer Modification.
  41. */
  42. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  43. #include <a_samp> // Package 0.3c RC3 | http://www.sa-mp.com
  44. #include <gvar> // Version 1.3 | http://forum.sa-mp.com/showthread.php?t=151076
  45. #include <YSI\y_hooks> // N/A | http://forum.sa-mp.com/showthread.php?p=884701
  46. #include <YSI\y_bit> // N/A | http://forum.sa-mp.com/showthread.php?p=884701
  47. #if defined sprayTag_included
  48. #endinput
  49. #endif
  50. #define sprayTag_included
  51. #define Spray:: Spray_
  52. #define SPRAY_DIALOG_0 (90)
  53. #define SPRAY_DIALOG_1 (100)
  54. #define SPRAY_TAG_FYB_1 (1490)
  55. #define SPRAY_TAG_FYB_2 (1524)
  56. #define SPRAY_TAG_FYB_3 (1525)
  57. #define SPRAY_TAG_RIFA (1526)
  58. #define SPRAY_TAG_RHB (1527)
  59. #define SPRAY_TAG_SEVILLE (1528)
  60. #define SPRAY_TAG_TEMPLE (1529)
  61. #define SPRAY_TAG_VAGOS (1530)
  62. #define SPRAY_TAG_AZTECAS (1531)
  63. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  64. forward OnPlayerReceiveSprayPermission( playerid, errorID );
  65. forward OnPlayerCreateSpray( playerid, sprayID );
  66. forward OnSprayDelete( sprayID );
  67. forward OnSprayLoaded( sprayID );
  68. forward OnSpraySaved( sprayID );
  69. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  70. stock
  71. totalSprays = 1,
  72. sp_g_string[ 300 ],
  73. DB:spray_db,
  74. DBResult:spray_q_result,
  75. BitArray:spray_permission < MAX_PLAYERS >
  76. ;
  77. stock
  78. jump_anims[ ][ ] =
  79. {
  80. "JUMP_glide",
  81. "JUMP_land",
  82. "JUMP_launch",
  83. "JUMP_launch_R",
  84. "FALL_FALL"
  85. };
  86. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  87. Hook:spray_OnFilterScriptExit()
  88. {
  89. for( new i; i != totalSprays; i ++ )
  90. Spray::Save( i );
  91. }
  92. Hook:spray_OnGameModeExit()
  93. {
  94. for( new i; i != totalSprays; i ++ )
  95. Spray::Save( i );
  96. }
  97. Hook:spray_OnFilterScriptInit()
  98. {
  99. Spray::Load( );
  100. }
  101. Hook:spray_OnGameModeInit()
  102. {
  103. Spray::Load( );
  104. }
  105. Hook:spray_OnPlayerKeyStateChange( playerid, newkeys, oldkeys )
  106. {
  107. if( Spray::doesPlayerHavePermission( playerid ) && ( GetPlayerWeapon( playerid ) == 41 ) && (newkeys & (KEY_FIRE)) == (KEY_FIRE))
  108. {
  109. if( GetPlayerAnimationIndex( playerid ) )
  110. {
  111. static
  112. s_animName[ 32 ]
  113. ;
  114. GetAnimationName( GetPlayerAnimationIndex( playerid ), sp_g_string, sizeof sp_g_string, s_animName, sizeof s_animName );
  115. if( !strcmp( sp_g_string, "PED", true ) )
  116. for( new i; i != sizeof jump_anims; i ++ )
  117. if( !strcmp( s_animName, jump_anims[ i ], true ) )
  118. return true;
  119. }
  120. ShowPlayerDialog( playerid, SPRAY_DIALOG_0, DIALOG_STYLE_MSGBOX, "Spray -> Main Menu", "Would you like to create a gang spray at your position?", "Yes", "No" );
  121. }
  122. return true;
  123. }
  124. Hook:spray_OnDialogResponse( clientid, dialogid, response, listitem, inputtext[ ] )
  125. {
  126. switch( dialogid )
  127. {
  128. case SPRAY_DIALOG_0:
  129. {
  130. if( response )
  131. ShowPlayerDialog( clientid, SPRAY_DIALOG_1, DIALOG_STYLE_LIST, "Spray -> Main Menu -> Selecting Your Tag", "Front Yard Ballas: Gang Tag #1\nFront Yard Ballas: Gang Tag #2\nFront Yard Ballas: Gang Tag #3\nSan Fierro Rifa\nRollin' Heights Ballas\nSeville Families\nTemple Drive Families\nLos Santos Vagos\nVarrio Los Aztecas", "Select", "Cancel" );
  132. }
  133. case SPRAY_DIALOG_1:
  134. {
  135. if( response )
  136. {
  137. switch( listitem )
  138. {
  139. case 0:
  140. Spray::createSprayAtPlayerPos( clientid, 1490 );
  141. case 1:
  142. Spray::createSprayAtPlayerPos( clientid, 1524 );
  143. case 2:
  144. Spray::createSprayAtPlayerPos( clientid, 1525 );
  145. case 3:
  146. Spray::createSprayAtPlayerPos( clientid, 1526 );
  147. case 4:
  148. Spray::createSprayAtPlayerPos( clientid, 1527 );
  149. case 5:
  150. Spray::createSprayAtPlayerPos( clientid, 1528 );
  151. case 6:
  152. Spray::createSprayAtPlayerPos( clientid, 1529 );
  153. case 7:
  154. Spray::createSprayAtPlayerPos( clientid, 1530 );
  155. case 8:
  156. Spray::createSprayAtPlayerPos( clientid, 1531 );
  157. }
  158. }
  159. }
  160. }
  161. }
  162. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  163. stock Spray::UpdateTag( sprayID, sprayTag )
  164. {
  165. if( !GetGVarType( "sprayObject", sprayTag ) )
  166. return false;
  167. DestroyObject( GetGVarInt( "sprayObject", sprayTag ) );
  168. SetGVarInt( "spray_object", sprayTag, sprayID );
  169. SetGVarInt( "sprayObject", CreateObject( sprayTag, GetGVarFloat( "spray_x", sprayID ), GetGVarFloat( "spray_y", sprayID ), GetGVarFloat( "spray_z", sprayID ) - 0.3, 0.0, 0.0, GetGVarFloat( "spray_a", sprayID ) ), sprayID );
  170. Spray::Save( sprayTag );
  171. return true;
  172. }
  173. stock Spray::Save( id )
  174. {
  175. spray_db = db_open( "sprays.db " );
  176. format( sp_g_string, sizeof sp_g_string, "SELECT SQLID FROM `sprays` WHERE SQLID = %i", id );
  177. spray_q_result = db_query( spray_db, sp_g_string );
  178. GetGVarString( "spray_name", sp_g_string, .id = id );
  179. if( db_num_rows( spray_q_result ) )
  180. {
  181. format( sp_g_string, sizeof sp_g_string, "UPDATE `sprays` SET sprayer = '%s', object = %i, pos_x = '%f', pos_y = '%f', pos_z = '%f', pos_a = '%f' WHERE SQLID = %i", sp_g_string, GetGVarInt( "spray_object", id ), GetGVarFloat( "spray_x", id ), GetGVarFloat( "spray_y", id ), GetGVarFloat( "spray_z", id ), GetGVarFloat( "spray_a", id ), id);
  182. db_free_result( db_query( spray_db, sp_g_string ) );
  183. }
  184. else
  185. {
  186. format( sp_g_string, sizeof sp_g_string, "INSERT INTO `sprays` (`sprayer`, `object`, `pos_x`, `pos_y`, `pos_z`, `pos_a`) VALUES('%s', %i, '%f', '%f', '%f', '%f');", sp_g_string, GetGVarInt( "spray_object", id ), GetGVarFloat( "spray_x", id ), GetGVarFloat( "spray_y", id ), GetGVarFloat( "spray_z", id ), GetGVarFloat( "spray_a", id ) );
  187. db_free_result( spray_q_result );
  188. db_free_result( db_query( spray_db, sp_g_string ) );
  189. }
  190. db_close( spray_db );
  191. CallRemoteFunction( "OnSpraySaved", "i", id );
  192. }
  193. stock Spray::Load( )
  194. {
  195. sp_g_string = "CREATE TABLE IF NOT EXISTS `sprays` ( \
  196. SQLID INTEGER PRIMARY KEY AUTOINCREMENT,\
  197. sprayer VARCHAR(24), \
  198. object INTEGER, \
  199. pos_x FLOAT, \
  200. pos_y FLOAT, \
  201. pos_z FLOAT, \
  202. pos_a FLOAT \
  203. )";
  204. spray_db = db_open( "sprays.db " );
  205. db_free_result( db_query( spray_db, sp_g_string ) );
  206. spray_q_result = db_query( spray_db, "SELECT * FROM sprays" );
  207. if( !db_num_rows( spray_q_result ) )
  208. db_free_result( spray_q_result );
  209. else
  210. {
  211. totalSprays = db_num_rows( spray_q_result );
  212. for( new i; i != totalSprays + 1; ++ i )
  213. {
  214. db_get_field_assoc(spray_q_result, "pos_x", sp_g_string, 10);
  215. SetGVarFloat( "spray_x", floatstr( sp_g_string ), i );
  216. db_get_field_assoc(spray_q_result, "pos_y", sp_g_string, 10);
  217. SetGVarFloat( "spray_y", floatstr( sp_g_string ), i );
  218. db_get_field_assoc(spray_q_result, "pos_z", sp_g_string, 10);
  219. SetGVarFloat( "spray_z", floatstr( sp_g_string ), i );
  220. db_get_field_assoc(spray_q_result, "pos_a", sp_g_string, 10);
  221. SetGVarFloat( "spray_a", floatstr( sp_g_string ), i );
  222. db_get_field_assoc(spray_q_result, "object", sp_g_string, 10);
  223. SetGVarInt( "spray_object", strval( sp_g_string ), i );
  224. db_get_field_assoc(spray_q_result, "sprayer", sp_g_string, MAX_PLAYER_NAME);
  225. SetGVarString( "spray_name", sp_g_string, i );
  226. format( sp_g_string, sizeof sp_g_string, "Sprayed by {008000}%s", sp_g_string );
  227. SetGVarInt( "spray3D", _:Create3DTextLabel( sp_g_string, 0xFF0000FF, GetGVarFloat( "spray_x", i ), GetGVarFloat( "spray_y", i ), GetGVarFloat( "spray_z", i ) + 1.0, 20.0, 0, 1 ), i);
  228. SetGVarInt( "sprayObject", CreateObject( GetGVarInt( "spray_object", i ), GetGVarFloat( "spray_x", i ), GetGVarFloat( "spray_y", i ), GetGVarFloat( "spray_z", i ), 0.0, 0.0, GetGVarFloat( "spray_a", i ) ), i );
  229. CallRemoteFunction( "OnSprayLoaded", "i", i );
  230. db_next_row( spray_q_result );
  231. }
  232. }
  233. db_close( spray_db );
  234. }
  235. stock Spray::createSprayAtPlayerPos( clientid, tag, Float:clientDistance = 1.2 )
  236. {
  237. new
  238. Float:player_pos[ 4 ]
  239. ;
  240. GetPlayerPos( clientid, player_pos[ 0 ], player_pos[ 1 ], player_pos [ 2 ] );
  241. GetPlayerFacingAngle( clientid, player_pos[ 3 ] );
  242. player_pos[ 0 ] += clientDistance * floatsin( -player_pos[ 3 ], degrees );
  243. player_pos[ 1 ] += clientDistance * floatcos( -player_pos[ 3 ], degrees );
  244. player_pos[ 3 ] += 90.0;
  245. if( GetPlayerSpecialAction( clientid ) == SPECIAL_ACTION_DUCK )
  246. SetGVarInt( "sprayObject", CreateObject( tag, player_pos[ 0 ], player_pos[ 1 ], player_pos[ 2 ] - 0.3, 0.0, 0.0, player_pos[ 3 ] ), totalSprays );
  247. else
  248. SetGVarInt( "sprayObject", CreateObject( tag, player_pos[ 0 ], player_pos[ 1 ], player_pos[ 2 ], 0.0, 0.0, player_pos[ 3 ] ), totalSprays );
  249. SetGVarFloat( "spray_x", player_pos[ 0 ], totalSprays );
  250. SetGVarFloat( "spray_y", player_pos[ 1 ], totalSprays );
  251. SetGVarFloat( "spray_z", player_pos[ 2 ], totalSprays );
  252. SetGVarFloat( "spray_a", player_pos[ 3 ], totalSprays );
  253. SetGVarInt( "spray_object", tag, totalSprays );
  254. GetPlayerName( clientid, sp_g_string, MAX_PLAYER_NAME );
  255. SetGVarString( "spray_name", sp_g_string, totalSprays );
  256. format( sp_g_string, sizeof sp_g_string, "Sprayed by {008000}%s", sp_g_string );
  257. SetGVarInt( "spray3D", _:Create3DTextLabel( sp_g_string, 0xFF0000FF, player_pos[ 0 ], player_pos[ 1 ], player_pos[ 2 ] + 1.0, 20.0, 0, 1 ), totalSprays);
  258. Spray::Save( totalSprays );
  259. CallRemoteFunction( "OnPlayerCreateSpray", "i", clientid, totalSprays );
  260. ApplyAnimation( clientid, "SPRAYCAN", "spraycan_full", 4.0, 0, 0, 0, 0, 0 );
  261. totalSprays ++;
  262. return true;
  263. }
  264. stock Spray::Delete( sprayID )
  265. {
  266. Delete3DTextLabel( Text3D:GetGVarInt( "spray3D", sprayID ) );
  267. DestroyObject( GetGVarInt( "sprayObject", sprayID ) );
  268. DeleteGVar( "sprayObject", sprayID );
  269. DeleteGVar( "spray3D", sprayID );
  270. DeleteGVar( "spray_x", sprayID );
  271. DeleteGVar( "spray_y", sprayID );
  272. DeleteGVar( "spray_z", sprayID );
  273. DeleteGVar( "spray_name", sprayID );
  274. CallRemoteFunction( "OnSprayDelete", "i", sprayID );
  275. totalSprays --;
  276. return true;
  277. }
  278. stock Spray::givePlayerPermission( clientid, bool:permissionToggle )
  279. {
  280. if( clientid == INVALID_PLAYER_ID )
  281. return print( "Error: The Spray Tag System tried to give permission to a player who is not connected." ), CallRemoteFunction( "OnPlayerReceiveSprayPermission", "ii", clientid, 2 );
  282. if( !Bit_Get( spray_permission, clientid ) && permissionToggle )
  283. return print( "Error: The Spray Tag System tried to give permission to a player who already has permission." ), CallRemoteFunction( "OnPlayerReceiveSprayPermission", "ii", clientid, 1 );
  284. if( !Bit_Get( spray_permission, clientid ) && !permissionToggle )
  285. return print( "Error: The Spray Tag System tried to remove permission to a player who doesn't have it already." ), CallRemoteFunction( "OnPlayerReceiveSprayPermission", "ii", clientid, 1 );
  286. if( permissionToggle )
  287. Bit_Set( spray_permission, clientid, true );
  288. else if( !permissionToggle )
  289. Bit_Set( spray_permission, clientid, false );
  290. CallRemoteFunction( "OnPlayerReceiveSprayPermission", "ii", clientid, 0 );
  291. return true;
  292. }
  293. stock Spray::doesPlayerHavePermission( clientid )
  294. return Bit_Get( spray_permission, clientid ) ? true : false;