Guest User

Untitled

a guest
Jun 29th, 2012
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.70 KB | None | 0 0
  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.     {"racer","DM_Racer",1,0,(Text3D:1024),255,451,{2097.7175,834.4070,6.4447,271.0308},{246,246},0,0,0},
  24.     {"pilot","DM_Pilot",1,0,(Text3D:1024),61,511,{1388.7698,1666.8741,12.1944,179.9533},{130,128},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.     {"idle","DM_PhoneShop",0,0,(Text3D:1024),172,0,{557.0210,1664.4828,539.7238,177.6691},{-1,-1},0,0,0},
  30.     {"idle","DM_BombShop",0,0,(Text3D:1024),179,0,{2570.9924,-2197.4797,-0.2188,4.7310},{-1,-1},0,0,0},
  31.     {"idle","DM_PetShop",0,0,(Text3D:1024),11,0,{512.8277,-1951.2592,2.6859,89.6683},{-1,-1},0,0,0}
  32. };
  33. public OnFilterScriptInit()
  34. {
  35.     new maxnpc[16], maxnpcs = sizeof(NPCs);
  36.     format(maxnpc,sizeof(maxnpc),"maxnpc %d",maxnpcs);
  37.     SendRconCommand(maxnpc);
  38.     for(new i = 0; i < maxnpcs; i++)
  39.     {
  40.         ConnectNPC(NPCs[i][npcName],NPCs[i][npcFile]);
  41.         NPCs[i][npcColor] = rgba2hex(random(256),random(256),random(256),255);
  42.         NPCs[i][npcText] = Create3DTextLabel(NPCs[i][npcName],(NPCs[i][npcColor] & 0xFFFFFF00) | 175,0.0,0.0,0.0,50.0,0,0);
  43.         if(NPCs[i][npcVehicle])
  44.         {
  45.             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);
  46.             LinkVehicleToInterior(npcVehicles[i],NPCs[i][npcInterior]);
  47.             SetVehicleVirtualWorld(npcVehicles[i],NPCs[i][npcWorld]);
  48.         }
  49.     }
  50.     return 1;
  51. }
  52. public OnFilterScriptExit()
  53. {
  54.     return 1;
  55. }
  56. public OnPlayerConnect(playerid)
  57. {
  58.     if(IsPlayerNPC(playerid))
  59.     {
  60.         new npcIP[16], npcN[MAX_PLAYER_NAME], bool:flag = false;
  61.         GetPlayerIp(playerid,npcIP,16);
  62.         GetPlayerName(playerid,npcN,MAX_PLAYER_NAME);
  63.         for(new i = 0; i < sizeof(NPCs) && !flag; i++) if(!strcmp(npcN,NPCs[i][npcName])) flag = true;
  64.         if(flag && strcmp(npcIP,SERVER_IP) != 0) flag = false;
  65.         if(!flag) return Kick(playerid), 0;
  66.     }
  67.     return 1;
  68. }
  69. public OnPlayerSpawn(playerid)
  70. {
  71.     if(IsPlayerNPC(playerid))
  72.     {
  73.         new n[MAX_PLAYER_NAME];
  74.         GetPlayerName(playerid,n,sizeof(n));
  75.         new npcid = GetNPCID(n);
  76.         if(npcid == -1) return 1;
  77.         if(NPCs[npcid][npcVehicle]) PutPlayerInVehicle(playerid,npcVehicles[npcid],NPCs[npcid][npcVehicleSeat]);
  78.         else if(NPCs[npcid][npcPos][0] != 0.0)
  79.         {
  80.             SetPlayerPos(playerid,NPCs[npcid][npcPos][0],NPCs[npcid][npcPos][1],NPCs[npcid][npcPos][2]);
  81.             SetPlayerFacingAngle(playerid,NPCs[npcid][npcPos][3]);
  82.         }
  83.         SetPlayerInterior(playerid,NPCs[npcid][npcInterior]);
  84.         SetPlayerVirtualWorld(playerid,NPCs[npcid][npcWorld]);
  85.         Attach3DTextLabelToPlayer(NPCs[npcid][npcText],playerid,0.0,0.0,0.2);
  86.         SetPlayerSkin(playerid,NPCs[npcid][npcSkin]);
  87.         SetPlayerColor(playerid,NPCs[npcid][npcColor]);
  88.     }
  89.     return 1;
  90. }
  91. stock rgba2hex(r,g,b,a) return (r*16777216) + (g*65536) + (b*256) + a;
  92. stock GetNPCID(name[])
  93. {
  94.     for(new i = 0; i < sizeof(NPCs); i++) if(!strcmp(NPCs[i][npcName],name)) return i;
  95.     return -1;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment