Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================[ ACTORS ]=======================================
- #define MAX_NPCS 100
- #define ACTOR_DEFAULT 0
- #define ACTOR_PEDESTRIAN 1
- #define ACTOR_ROBABLE 2
- #define ACTOR_DEALER 3
- #define ACTOR_MISSION 4
- enum NPCData {
- NPCbaseID,
- NPCName[ 32 ],
- NPCSkinID,
- Float:NPCPos_X,
- Float:NPCPos_Y,
- Float:NPCPos_Z,
- Float:NPCPos_A,
- NPCVW,
- NPCType,
- NPCInteractive,
- NPCActorID = INVALID_ACTOR_ID
- }
- new NPCInfo[ MAX_NPCS ][ NPCData ];
- stock getNearestNPC( playerid ) {
- new NPCID = -1;
- for( new i = 0; i < MAX_NPCS; i++) {
- if( NPCInfo[ i ][ NPCbaseID ] > 0 && IsPlayerInRangeOfPoint(playerid, 3.0, NPCInfo[ i ][ NPCPos_X ], NPCInfo[ i ][ NPCPos_Y ], NPCInfo[ i ][ NPCPos_Z]) ) {
- NPCID = i;
- break;
- }
- }
- return NPCID;
- }
- forward OnNPCsLoad( );
- public OnNPCsLoad( ) {
- ServerInfo[ NPCsCounter ] = 0;
- new rows, fields, NPCID;
- cache_get_data( rows, fields, _dbConnector );
- if( rows ) {
- for( new i = 0; i < rows; i ++ ) {
- NPCID = ServerInfo[ NPCsCounter ];
- NPCInfo[ NPCID ][ NPCbaseID ] = cache_get_field_content_int( i, "npcID" );
- cache_get_field_content( i, "npcName", NPCInfo[ NPCID ][ NPCName ], _dbConnector, MAX_PLAYER_NAME );
- NPCInfo[ NPCID ][ NPCSkinID ] = cache_get_field_content_int( i, "npcSkin" );
- NPCInfo[ NPCID ][ NPCPos_X ] = cache_get_field_content_float( i, "npcPos_x" );
- NPCInfo[ NPCID ][ NPCPos_Y ] = cache_get_field_content_float( i, "npcPos_y" );
- NPCInfo[ NPCID ][ NPCPos_Z ] = cache_get_field_content_float( i, "npcPos_z" );
- NPCInfo[ NPCID ][ NPCPos_A ] = cache_get_field_content_float( i, "npcPos_a" );
- NPCInfo[ NPCID ][ NPCVW ] = cache_get_field_content_int( i, "npcVW" );
- NPCInfo[ NPCID ][ NPCInteractive ] = cache_get_field_content_int( i, "acInteractive" );
- NPCInfo[ NPCID ][ NPCType ] = cache_get_field_content_int( i, "acType" );
- 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 ]);
- ServerInfo[ NPCsCounter ]++;
- }
- }
- printf( "[ucitano] %d NPCa", ServerInfo[ NPCsCounter ] );
- return (true);
- }
- stock sql_create_npc( playerid, name[], skinID) {
- new NPCID = -1;
- for( new i = 0; i < MAX_NPCS; i++) {
- if( NPCInfo[ i ][ NPCbaseID ] == 0 ) {
- NPCID = i;
- break;
- }
- }
- if( NPCID == -1 ) return SendErrorMessage( playerid, "Dostignut je maksimalni broj kreiranih npcova." );
- new Float:X, Float:Y, Float:Z, Float:A;
- GetPlayerPos( playerid, X, Y, Z );
- GetPlayerFacingAngle( playerid, A );
- NPCInfo[ NPCID ][ NPCbaseID ] = 0;
- NPCInfo[ NPCID ][ NPCSkinID ] = skinID;
- NPCInfo[ NPCID ][ NPCPos_X ] = X;
- NPCInfo[ NPCID ][ NPCPos_Y ] = Y;
- NPCInfo[ NPCID ][ NPCPos_Z ] = Z;
- NPCInfo[ NPCID ][ NPCPos_A ] = A;
- NPCInfo[ NPCID ][ NPCVW ] = GetPlayerVirtualWorld( playerid );
- NPCInfo[ NPCID ][ NPCType ] = 0;
- NPCInfo[ NPCID ][ NPCInteractive ] = 0;
- strmid( NPCInfo[ NPCID ][ NPCName ], "Prazno", 0, strlen( "Prazno" ), 32);
- 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 ]);
- new query[ 256 ];
- mysql_format( _dbConnector, query, sizeof( query ), "INSERT INTO `NPCs` (npcSkin, npcName, npcPos_x, npcPos_y, npcPos_z, npcPos_a, npcVW, npcInteractive)" );
- mysql_format( _dbConnector, query, sizeof( query ), "%s VALUES( '%d', '%e', '%f', '%f', '%f', '%f', '%d', '%d')",
- query,
- NPCInfo[ NPCID ][ NPCSkinID ],
- NPCInfo[ NPCID ][ NPCName ],
- NPCInfo[ NPCID ][ NPCPos_X ],
- NPCInfo[ NPCID ][ NPCPos_Y ],
- NPCInfo[ NPCID ][ NPCPos_Z ],
- NPCInfo[ NPCID ][ NPCPos_A ],
- NPCInfo[ NPCID ][ NPCVW ],
- NPCInfo[ NPCID ][ NPCInteractive ] );
- mysql_pquery( _dbConnector, query, "OnActorCreated", "ii", playerid, NPCID );
- KGEyes_SetPlayerPos( playerid, X, Y+1, Z+3 );
- return (true);
- }
- forward OnActorCreated( playerid, NPCID );
- public OnActorCreated( playerid, NPCID ){
- NPCInfo[ NPCID ][ NPCbaseID ] = cache_insert_id();
- SendInfoMessage( playerid, "Uspesno ste kreirali NPC." );
- ServerInfo[ NPCsCounter ]++;
- return true;
- }
- CMD:createnpc( playerid, params[] ) {
- if( PlayerInfo[ playerid ][ xAdmin ] >= 10 ) {
- if( !AdminDuty[ playerid ] ) return SendErrorMessage( playerid, "Morate biti na admin duty!" );
- new botime, kolicina;
- if( sscanf( params, "s[24]i", botime , kolicina ) ) {
- SendUsageMessage( playerid, "/createnpc [ Ime ] [ Skin ID ]");
- return 1;
- }
- if( kolicina < 1 || kolicina > 311 ) return SendErrorMessage( playerid, "Broj skina ide od 1 do 311." );
- sql_create_npc( playerid, botime, skinID );
- }
- else return SendErrorMessage( playerid, "Nemate ovlascenje da koristite ovu komandu.");
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement