Advertisement
Guest User

Untitled

a guest
Jun 29th, 2012
2,147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Easy and automatically connecting NPCs to the server, by Amit_B
  2. #include "a_samp"
  3. #define MAX_NPCS 10 // Max NPCs in the server
  4. #define SERVER_IP "127.0.0.1" // IP of your server
  5. enum NPCsData
  6. {
  7.     npcFile[16],
  8.     npcName[MAX_PLAYER_NAME],
  9.     npcVehicle,
  10.     npcVehicleSeat,
  11.     Text3D:npcText,
  12.     npcSkin,
  13.     npcVehicleModel,
  14.     Float:npcPos[4],
  15.     npcVehicleColor[2],
  16.     npcInterior,
  17.     npcWorld,
  18.     npcColor
  19. };
  20. new npcVehicles[MAX_NPCS] = {INVALID_VEHICLE_ID,...};
  21. new NPCs[][NPCsData] =
  22. {   // file, name, vehicle, vseat, text, skin, veh model, veh xyza, veh colors, interior, world, color
  23.     // These ones are examples. You need to edit this list to your NPCs so it will work fine.
  24.     {"racer","DM_Racer",1,0,(Text3D:1024),255,451,{2097.7175,834.4070,6.4447,271.0308},{246,246},0,0,0},
  25.     {"bus","DM_Bus",1,0,(Text3D:1024),255,431,{1734.6570,1626.7157,9.2003,163.3937},{132,131},0,0,0},
  26.     {"shamal","DM_Plane",1,0,(Text3D:1024),61,519,{0.0,0.0,0.0,0.0},{-1,-1},0,0,0},
  27.     {"idle","DM_Bank",0,0,(Text3D:1024),147,0,{-23.3069,-57.6647,1003.5469,357.6211},{-1,-1},6,0,0},
  28.     {"idle","DM_Bank2",0,0,(Text3D:1024),147,0,{278.1820,-1611.4216,114.4512,262.8170},{-1,-1},6,0,0}
  29. };
  30. public OnFilterScriptInit()
  31. {
  32.     new maxnpc[16], maxnpcs = sizeof(NPCs);
  33.     format(maxnpc,sizeof(maxnpc),"maxnpc %d",maxnpcs);
  34.     SendRconCommand(maxnpc);
  35.     for(new i = 0; i < maxnpcs; i++)
  36.     {
  37.         ConnectNPC(NPCs[i][npcName],NPCs[i][npcFile]);
  38.         NPCs[i][npcColor] = rgba2hex(random(256),random(256),random(256),255);
  39.         NPCs[i][npcText] = Create3DTextLabel(NPCs[i][npcName],(NPCs[i][npcColor] & 0xFFFFFF00) | 175,0.0,0.0,0.0,50.0,0,0);
  40.         if(NPCs[i][npcVehicle])
  41.         {
  42.             npcVehicles[i] = CreateVehicle(NPCs[i][npcVehicleModel],NPCs[i][npcPos][0],NPCs[i][npcPos][1],NPCs[i][npcPos][2],NPCs[i][npcPos][3],NPCs[i][npcVehicleColor][0],NPCs[i][npcVehicleColor][1],180);
  43.             LinkVehicleToInterior(npcVehicles[i],NPCs[i][npcInterior]);
  44.             SetVehicleVirtualWorld(npcVehicles[i],NPCs[i][npcWorld]);
  45.         }
  46.     }
  47.     return 1;
  48. }
  49. public OnFilterScriptExit()
  50. {
  51.     return 1;
  52. }
  53. public OnPlayerConnect(playerid)
  54. {
  55.     if(IsPlayerNPC(playerid))
  56.     {
  57.         new npcIP[16], npcN[MAX_PLAYER_NAME], bool:flag = false;
  58.         GetPlayerIp(playerid,npcIP,16);
  59.         GetPlayerName(playerid,npcN,MAX_PLAYER_NAME);
  60.         for(new i = 0; i < sizeof(NPCs) && !flag; i++) if(!strcmp(npcN,NPCs[i][npcName])) flag = true;
  61.         if(flag && strcmp(npcIP,SERVER_IP) != 0) flag = false;
  62.         if(!flag) return Kick(playerid), 0;
  63.     }
  64.     return 1;
  65. }
  66. public OnPlayerSpawn(playerid)
  67. {
  68.     if(IsPlayerNPC(playerid))
  69.     {
  70.         new n[MAX_PLAYER_NAME];
  71.         GetPlayerName(playerid,n,sizeof(n));
  72.         new npcid = GetNPCID(n);
  73.         if(npcid == -1) return 1;
  74.         if(NPCs[npcid][npcVehicle]) PutPlayerInVehicle(playerid,npcVehicles[npcid],NPCs[npcid][npcVehicleSeat]);
  75.         else if(NPCs[npcid][npcPos][0] != 0.0)
  76.         {
  77.             SetPlayerPos(playerid,NPCs[npcid][npcPos][0],NPCs[npcid][npcPos][1],NPCs[npcid][npcPos][2]);
  78.             SetPlayerFacingAngle(playerid,NPCs[npcid][npcPos][3]);
  79.         }
  80.         SetPlayerInterior(playerid,NPCs[npcid][npcInterior]);
  81.         SetPlayerVirtualWorld(playerid,NPCs[npcid][npcWorld]);
  82.         Attach3DTextLabelToPlayer(NPCs[npcid][npcText],playerid,0.0,0.0,0.2);
  83.         SetPlayerSkin(playerid,NPCs[npcid][npcSkin]);
  84.         SetPlayerColor(playerid,NPCs[npcid][npcColor]);
  85.     }
  86.     return 1;
  87. }
  88. stock rgba2hex(r,g,b,a) return (r*16777216) + (g*65536) + (b*256) + a;
  89. stock GetNPCID(name[])
  90. {
  91.     for(new i = 0; i < sizeof(NPCs); i++) if(!strcmp(NPCs[i][npcName],name)) return i;
  92.     return -1;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement