Advertisement
DiazSRB

Untitled

Jan 8th, 2021
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 KB | None | 0 0
  1. //=============================[ ACTORS ]=======================================
  2. #define MAX_NPCS 100
  3.  
  4. #define ACTOR_DEFAULT 0
  5. #define ACTOR_PEDESTRIAN 1
  6. #define ACTOR_ROBABLE 2
  7. #define ACTOR_DEALER 3
  8. #define ACTOR_MISSION 4
  9.  
  10. enum NPCData {
  11.  
  12. NPCbaseID,
  13. NPCName[ 32 ],
  14. NPCSkinID,
  15. Float:NPCPos_X,
  16. Float:NPCPos_Y,
  17. Float:NPCPos_Z,
  18. Float:NPCPos_A,
  19. NPCVW,
  20. NPCType,
  21. NPCInteractive,
  22. NPCActorID = INVALID_ACTOR_ID
  23. }
  24. new NPCInfo[ MAX_NPCS ][ NPCData ];
  25.  
  26. stock getNearestNPC( playerid ) {
  27. new NPCID = -1;
  28. for( new i = 0; i < MAX_NPCS; i++) {
  29. if( NPCInfo[ i ][ NPCbaseID ] > 0 && IsPlayerInRangeOfPoint(playerid, 3.0, NPCInfo[ i ][ NPCPos_X ], NPCInfo[ i ][ NPCPos_Y ], NPCInfo[ i ][ NPCPos_Z]) ) {
  30. NPCID = i;
  31. break;
  32. }
  33. }
  34. return NPCID;
  35. }
  36.  
  37. forward OnNPCsLoad( );
  38. public OnNPCsLoad( ) {
  39.  
  40. ServerInfo[ NPCsCounter ] = 0;
  41. new rows, fields, NPCID;
  42. cache_get_data( rows, fields, _dbConnector );
  43.  
  44. if( rows ) {
  45. for( new i = 0; i < rows; i ++ ) {
  46.  
  47. NPCID = ServerInfo[ NPCsCounter ];
  48.  
  49. NPCInfo[ NPCID ][ NPCbaseID ] = cache_get_field_content_int( i, "npcID" );
  50. cache_get_field_content( i, "npcName", NPCInfo[ NPCID ][ NPCName ], _dbConnector, MAX_PLAYER_NAME );
  51. NPCInfo[ NPCID ][ NPCSkinID ] = cache_get_field_content_int( i, "npcSkin" );
  52. NPCInfo[ NPCID ][ NPCPos_X ] = cache_get_field_content_float( i, "npcPos_x" );
  53. NPCInfo[ NPCID ][ NPCPos_Y ] = cache_get_field_content_float( i, "npcPos_y" );
  54. NPCInfo[ NPCID ][ NPCPos_Z ] = cache_get_field_content_float( i, "npcPos_z" );
  55. NPCInfo[ NPCID ][ NPCPos_A ] = cache_get_field_content_float( i, "npcPos_a" );
  56. NPCInfo[ NPCID ][ NPCVW ] = cache_get_field_content_int( i, "npcVW" );
  57. NPCInfo[ NPCID ][ NPCInteractive ] = cache_get_field_content_int( i, "acInteractive" );
  58. NPCInfo[ NPCID ][ NPCType ] = cache_get_field_content_int( i, "acType" );
  59.  
  60. NPCInfo[ NPCID ][ NPCActorID ] = CreateDynamicActor( NPCInfo[ NPCID ][ NPCSkinID ], Float:NPCInfo[ NPCID ][ NPCPos_X ], Float:NPCInfo[ NPCID ][ NPCPos_Y ], Float:NPCInfo[ NPCID ][ NPCPos_Z ], Float:NPCInfo[ NPCID ][ NPCPos_A ]);
  61. ServerInfo[ NPCsCounter ]++;
  62. }
  63. }
  64. printf( "[ucitano] %d NPCa", ServerInfo[ NPCsCounter ] );
  65. return (true);
  66. }
  67.  
  68. stock sql_create_npc( playerid, name[], skinID) {
  69.  
  70. new NPCID = -1;
  71. for( new i = 0; i < MAX_NPCS; i++) {
  72. if( NPCInfo[ i ][ NPCbaseID ] == 0 ) {
  73. NPCID = i;
  74. break;
  75. }
  76. }
  77. if( NPCID == -1 ) return SendErrorMessage( playerid, "Dostignut je maksimalni broj kreiranih npcova." );
  78.  
  79. new Float:X, Float:Y, Float:Z, Float:A;
  80. GetPlayerPos( playerid, X, Y, Z );
  81. GetPlayerFacingAngle( playerid, A );
  82.  
  83. NPCInfo[ NPCID ][ NPCbaseID ] = 0;
  84. NPCInfo[ NPCID ][ NPCSkinID ] = skinID;
  85. NPCInfo[ NPCID ][ NPCPos_X ] = X;
  86. NPCInfo[ NPCID ][ NPCPos_Y ] = Y;
  87. NPCInfo[ NPCID ][ NPCPos_Z ] = Z;
  88. NPCInfo[ NPCID ][ NPCPos_A ] = A;
  89. NPCInfo[ NPCID ][ NPCVW ] = GetPlayerVirtualWorld( playerid );
  90. NPCInfo[ NPCID ][ NPCType ] = 0;
  91. NPCInfo[ NPCID ][ NPCInteractive ] = 0;
  92. strmid( NPCInfo[ NPCID ][ NPCName ], "Prazno", 0, strlen( "Prazno" ), 32);
  93.  
  94.  
  95. NPCInfo[ NPCID ][ NPCActorID ] = CreateDynamicActor( NPCInfo[ NPCID ][ NPCSkinID ], Float:NPCInfo[ NPCID ][ NPCPos_X ], Float:NPCInfo[ NPCID ][ NPCPos_Y ], Float:NPCInfo[ NPCID ][ NPCPos_Z ], Float:NPCInfo[ NPCID ][ NPCPos_A ]);
  96.  
  97. new query[ 256 ];
  98. mysql_format( _dbConnector, query, sizeof( query ), "INSERT INTO `NPCs` (npcSkin, npcName, npcPos_x, npcPos_y, npcPos_z, npcPos_a, npcVW, npcInteractive)" );
  99.  
  100. mysql_format( _dbConnector, query, sizeof( query ), "%s VALUES( '%d', '%e', '%f', '%f', '%f', '%f', '%d', '%d')",
  101. query,
  102. NPCInfo[ NPCID ][ NPCSkinID ],
  103. NPCInfo[ NPCID ][ NPCName ],
  104. NPCInfo[ NPCID ][ NPCPos_X ],
  105. NPCInfo[ NPCID ][ NPCPos_Y ],
  106. NPCInfo[ NPCID ][ NPCPos_Z ],
  107. NPCInfo[ NPCID ][ NPCPos_A ],
  108. NPCInfo[ NPCID ][ NPCVW ],
  109. NPCInfo[ NPCID ][ NPCInteractive ] );
  110.  
  111. mysql_pquery( _dbConnector, query, "OnActorCreated", "ii", playerid, NPCID );
  112.  
  113.  
  114. KGEyes_SetPlayerPos( playerid, X, Y+1, Z+3 );
  115. return (true);
  116. }
  117.  
  118. forward OnActorCreated( playerid, NPCID );
  119. public OnActorCreated( playerid, NPCID ){
  120.  
  121. NPCInfo[ NPCID ][ NPCbaseID ] = cache_insert_id();
  122. SendInfoMessage( playerid, "Uspesno ste kreirali NPC." );
  123.  
  124. ServerInfo[ NPCsCounter ]++;
  125. return true;
  126. }
  127.  
  128. CMD:createnpc( playerid, params[] ) {
  129. if( PlayerInfo[ playerid ][ xAdmin ] >= 10 ) {
  130.  
  131. if( !AdminDuty[ playerid ] ) return SendErrorMessage( playerid, "Morate biti na admin duty!" );
  132. new botime, kolicina;
  133. if( sscanf( params, "s[24]i", botime , kolicina ) ) {
  134. SendUsageMessage( playerid, "/createnpc [ Ime ] [ Skin ID ]");
  135. return 1;
  136. }
  137. if( kolicina < 1 || kolicina > 311 ) return SendErrorMessage( playerid, "Broj skina ide od 1 do 311." );
  138. sql_create_npc( playerid, botime, skinID );
  139. }
  140. else return SendErrorMessage( playerid, "Nemate ovlascenje da koristite ovu komandu.");
  141. return true;
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement