Advertisement
Guest User

NPC Tutorial

a guest
Aug 23rd, 2010
3,105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.41 KB | None | 0 0
  1. /*
  2.                                 NPC Help by Sayaron
  3.                                
  4.                                
  5. This is a small guide that helps you to make NPCs in vehicles
  6.  
  7. What is required for it to work?:
  8. -A NPC record (Use the filterscript npc_record wich is included in the sa-mp folder at download. The file will be in "npcmodes" > "recordings")
  9. -A npcmode that reefers to the NPC record (Look in the folder "npcmodes" to see how its done)
  10.  
  11. */
  12. #include <a_samp>
  13.  
  14. new YourVehicle; // The name of your vehicle
  15.  
  16.  
  17. public OnGameModeInit()
  18. {
  19.     ConnectNPC("YourNPC","RecordName"); // The name of your NPC and the record. The record need to match an record with the same name. The NPC name can be anything
  20.  
  21.     YourVehicle = AddStaticVehicle(448,2076.4067,2227.7834,10.4165,178.8465,6,6); // Creating your vehicle, this can be done ingame by typing /save. Then go to your SA-MP folder and find the folder "savedpositions"
  22.  
  23.     return 1;
  24. }
  25. public OnPlayerSpawn(playerid)
  26. {
  27.     if(!IsPlayerNPC(playerid)) return 0; // If the player is not a NPC, nothing will happend
  28.  
  29.     new playername[64]; //Player String
  30.     GetPlayerName(playerid,playername,64); //This is to get the NPC's name
  31.  
  32.     if(!strcmp(playername, "YourNPC", true)) { // Detecting if the NPC is spawned. If it is not spawned or the name is wrong, nothing will happend
  33.         SetSpawnInfo( playerid, 0, 255, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0 );
  34.         //SetSpawnInfo( playerid, Team, Skin, x, y, z, rotation, weapon1, ammo for weapon1, w2, ammo2, w3, ammo3 );
  35.         SetPlayerColor(playerid,0xFFFFFFFF); // Chose any color you want, this is currently white
  36.         PutPlayerInVehicle(playerid, YourVehicle, 0);
  37.         //PutPlayerInVehicle(playerid, vehiclename, seat);
  38.     }
  39.     return 1;
  40. }
  41. // This is to stop remote bots to connect, it will only let your bots connect
  42. // If you dont want it, you may remove it
  43. public OnPlayerConnect(playerid)
  44. {
  45.     if(IsPlayerNPC(playerid)) {
  46.         new ip_addr_npc[64+1];
  47.         new ip_addr_server[64+1];
  48.         GetServerVarAsString("bind",ip_addr_server,64);
  49.         GetPlayerIp(playerid,ip_addr_npc,64);
  50.  
  51.         if(!strlen(ip_addr_server)) {
  52.             ip_addr_server = "127.0.0.1";
  53.         }
  54.  
  55.         if(strcmp(ip_addr_npc,ip_addr_server,true) != 0) {
  56.             // this bot is remote connecting
  57.             printf("NPC: Got a remote NPC connecting from %s and I'm kicking it.",ip_addr_npc);
  58.             Kick(playerid);
  59.             return 0;
  60.         }
  61.         printf("NPC: Connection from %s is allowed.",ip_addr_npc);
  62.     }
  63.  
  64.     return 1;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement