Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. #include < YSI\y_iterate >
  2.  
  3. #define MAX_ATMS ( 500 )
  4.  
  5. #define INVALID_ATM_ID ( -1 )
  6.  
  7. new Iterator: Atms< MAX_ATMS >;
  8.  
  9. enum ATM
  10. {
  11. Float: atm_X,
  12. Float: atm_Y,
  13. Float: atm_Z,
  14. AtmObject,
  15. bool:Save
  16. }
  17.  
  18. new AtmInfo[ MAX_ATMS ] [ ATM ];
  19.  
  20. forward LoadATMS();
  21. public LoadATMS()
  22. {
  23. new rows = cache_num_rows( );
  24. if( rows )
  25. {
  26. new id, loaded;
  27. while( loaded < rows )
  28. {
  29. id = cache_get_field_content_int( loaded, "ID" );
  30. AtmInfo [ id ] [ atm_X ] = cache_get_field_content_float( loaded, "atm_X" );
  31. AtmInfo [ id ] [ atm_Y ] = cache_get_field_content_float( loaded, "atm_Y" );
  32. AtmInfo [ id ] [ atm_Z ] = cache_get_field_content_float( loaded, "atm_Z" );
  33. AtmInfo[ id ] [ AtmObject ] = CreateObject( 19324, AtmInfo [ id ] [ atm_X ], AtmInfo [ id ] [ atm_Y ], AtmInfo [ id ] [ atm_Z ], 0, 0, 0, 50 );
  34. AtmInfo[ id ] [ Save ] = true;
  35. Iter_Add( Atms, id );
  36. loaded ++;
  37. }
  38.  
  39. printf( "Loaded %d ATMs.", loaded );
  40. }
  41.  
  42. return 1;
  43. }
  44.  
  45. CMD:createatm( playerid, params[] )
  46. {
  47. new id = Iter_Free( Atms ), Float: x, Float: y, Float: z, query[500];
  48. if( id == -1 ) return SendClientMessage(playerid, -1, "MAX ATMS has reached");
  49. GetPlayerPos( playerid, x, y, z );
  50. AtmInfo[ id ] [ AtmObject ] = CreateObject( 19324, x, y, z, 0, 0, 0, 50 );
  51. AtmInfo[ id ] [ Save ] = true;
  52. mysql_format( sqlGameConnection, query, sizeof( query ), "INSERT INTO `atm` SET `ID`='%d', `atm_X`='%f', `atm_Y`='%f', `atm_Z`='%f'", id, x, y, z );
  53. mysql_tquery( sqlGameConnection, query, "", "" );
  54. Iter_Add(Atms, id);
  55. return 1;
  56. }
  57.  
  58. CMD:deleteatm( playerid, params[] )
  59. {
  60. new id, query[100];
  61. if( sscanf( params, "i", id ) ) return SendClientMessage( playerid, -1, "Usage: /deleteatm <ID>" );
  62. if( !Iter_Contains(Atms, id ) ) return SendClientMessage( playerid, -1, "The ATM ID you entered does not exist!" );
  63. DestroyObject( AtmInfo[ id ] [ AtmObject ] );
  64. AtmInfo [ id ] [ atm_X ] = 0;
  65. AtmInfo [ id ] [ atm_Y ] = 0;
  66. AtmInfo [ id ] [ atm_Z ] = 0;
  67. Iter_Remove( Atms, id );
  68. mysql_format( sqlGameConnection, query, sizeof( query ), "DELETE FROM `atm` WHERE `ID`='%d'", id);
  69. mysql_tquery( sqlGameConnection, query, "", "" );
  70. SendClientMessage( playerid, -1, "ATM deleted" );
  71. return 1;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement