Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Easy and automatically connecting NPCs to the server, by Amit_B
- #include "a_samp"
- #define MAX_NPCS 10 // Max NPCs in the server
- #define SERVER_IP "127.0.0.1" // IP of your server
- enum NPCsData
- {
- npcFile[16],
- npcName[MAX_PLAYER_NAME],
- npcVehicle,
- npcVehicleSeat,
- Text3D:npcText,
- npcSkin,
- npcVehicleModel,
- Float:npcPos[4],
- npcVehicleColor[2],
- npcInterior,
- npcWorld,
- npcColor
- };
- new npcVehicles[MAX_NPCS] = {INVALID_VEHICLE_ID,...};
- new NPCs[][NPCsData] =
- { // file, name, vehicle, vseat, text, skin, veh model, veh xyza, veh colors, interior, world, color
- // These ones are examples. You need to edit this list to your NPCs so it will work fine.
- {"racer","DM_Racer",1,0,(Text3D:1024),255,451,{2097.7175,834.4070,6.4447,271.0308},{246,246},0,0,0},
- {"bus","DM_Bus",1,0,(Text3D:1024),255,431,{1734.6570,1626.7157,9.2003,163.3937},{132,131},0,0,0},
- {"shamal","DM_Plane",1,0,(Text3D:1024),61,519,{0.0,0.0,0.0,0.0},{-1,-1},0,0,0},
- {"idle","DM_Bank",0,0,(Text3D:1024),147,0,{-23.3069,-57.6647,1003.5469,357.6211},{-1,-1},6,0,0},
- {"idle","DM_Bank2",0,0,(Text3D:1024),147,0,{278.1820,-1611.4216,114.4512,262.8170},{-1,-1},6,0,0}
- };
- public OnFilterScriptInit()
- {
- new maxnpc[16], maxnpcs = sizeof(NPCs);
- format(maxnpc,sizeof(maxnpc),"maxnpc %d",maxnpcs);
- SendRconCommand(maxnpc);
- for(new i = 0; i < maxnpcs; i++)
- {
- ConnectNPC(NPCs[i][npcName],NPCs[i][npcFile]);
- NPCs[i][npcColor] = rgba2hex(random(256),random(256),random(256),255);
- NPCs[i][npcText] = Create3DTextLabel(NPCs[i][npcName],(NPCs[i][npcColor] & 0xFFFFFF00) | 175,0.0,0.0,0.0,50.0,0,0);
- if(NPCs[i][npcVehicle])
- {
- 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);
- LinkVehicleToInterior(npcVehicles[i],NPCs[i][npcInterior]);
- SetVehicleVirtualWorld(npcVehicles[i],NPCs[i][npcWorld]);
- }
- }
- return 1;
- }
- public OnFilterScriptExit()
- {
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- if(IsPlayerNPC(playerid))
- {
- new npcIP[16], npcN[MAX_PLAYER_NAME], bool:flag = false;
- GetPlayerIp(playerid,npcIP,16);
- GetPlayerName(playerid,npcN,MAX_PLAYER_NAME);
- for(new i = 0; i < sizeof(NPCs) && !flag; i++) if(!strcmp(npcN,NPCs[i][npcName])) flag = true;
- if(flag && strcmp(npcIP,SERVER_IP) != 0) flag = false;
- if(!flag) return Kick(playerid), 0;
- }
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- if(IsPlayerNPC(playerid))
- {
- new n[MAX_PLAYER_NAME];
- GetPlayerName(playerid,n,sizeof(n));
- new npcid = GetNPCID(n);
- if(npcid == -1) return 1;
- if(NPCs[npcid][npcVehicle]) PutPlayerInVehicle(playerid,npcVehicles[npcid],NPCs[npcid][npcVehicleSeat]);
- else if(NPCs[npcid][npcPos][0] != 0.0)
- {
- SetPlayerPos(playerid,NPCs[npcid][npcPos][0],NPCs[npcid][npcPos][1],NPCs[npcid][npcPos][2]);
- SetPlayerFacingAngle(playerid,NPCs[npcid][npcPos][3]);
- }
- SetPlayerInterior(playerid,NPCs[npcid][npcInterior]);
- SetPlayerVirtualWorld(playerid,NPCs[npcid][npcWorld]);
- Attach3DTextLabelToPlayer(NPCs[npcid][npcText],playerid,0.0,0.0,0.2);
- SetPlayerSkin(playerid,NPCs[npcid][npcSkin]);
- SetPlayerColor(playerid,NPCs[npcid][npcColor]);
- }
- return 1;
- }
- stock rgba2hex(r,g,b,a) return (r*16777216) + (g*65536) + (b*256) + a;
- stock GetNPCID(name[])
- {
- for(new i = 0; i < sizeof(NPCs); i++) if(!strcmp(NPCs[i][npcName],name)) return i;
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement