Advertisement
Guest User

J-NPC v1.0

a guest
Aug 24th, 2011
1,415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.49 KB | None | 0 0
  1. //--------------------------------------------------------------------------------------------
  2. //------------------------------- Jochem Non Playing Character -------------------------------
  3. //------------------------------------------- J-NPC ------------------------------------------
  4. //------------------------------- Copyright © GTA Productions --------------------------------
  5. //--------------------------------------------------------------------------------------------
  6.  
  7. #include <a_samp>
  8.  
  9. #define ONFOOT 2
  10. #define INVEHICLE 1
  11.  
  12. #define COLOR_WHITE -1
  13. #define COLOR_RED 0xFF0F0FFF
  14. #define COLOR_YELLOW 0xFFFF00FF
  15.  
  16. #define DIALOG_REC 6769
  17.  
  18. #define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  19.  
  20. stock Playername(playerid)
  21. {
  22.     new name[MAX_PLAYER_NAME];
  23.     GetPlayerName(playerid,name,sizeof(name));
  24.     return name;
  25. }
  26.  
  27. public OnFilterScriptInit()
  28. {
  29.     print("\n--------------------------------------");
  30.     print(" Successfully loaded J-NPC [by Jochemd] ");
  31.     print("--------------------------------------\n");
  32.     return 1;
  33. }
  34.  
  35. public OnFilterScriptExit()
  36. {
  37.     print("\n--------------------------------------");
  38.     print(" Successfully unloaded J-NPC [by Jochemd] ");
  39.     print("--------------------------------------\n");
  40.     return 1;
  41. }
  42.  
  43. public OnPlayerText(playerid, text[])
  44. {
  45.     return 1;
  46. }
  47.  
  48. public OnPlayerCommandText(playerid, cmdtext[])
  49. {
  50.     dcmd(npcrecord,9,cmdtext);
  51.     dcmd(stoprecord,10,cmdtext);
  52.     return 0;
  53. }
  54.  
  55. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  56. {
  57.     if(dialogid == DIALOG_REC && response == 1)
  58.     {
  59.         new filename[31],rectype = GetPVarInt(playerid,"RecType");
  60.         GetPVarString(playerid,"FileName",filename,31);
  61.         if(rectype == INVEHICLE)
  62.         {
  63.             SetPVarInt(playerid,"Recording",INVEHICLE);
  64.             SetPVarInt(playerid,"npcvehid",GetVehicleModel(GetPlayerVehicleID(playerid)));
  65.             StartRecordingPlayerData(playerid,PLAYER_RECORDING_TYPE_DRIVER,filename);
  66.         }
  67.         else
  68.         {
  69.             SetPVarInt(playerid,"Recording",ONFOOT);
  70.             StartRecordingPlayerData(playerid,PLAYER_RECORDING_TYPE_DRIVER,filename);
  71.         }
  72.         SendClientMessage(playerid,COLOR_WHITE,"Succes: You have started recording. To stop, type /stoprecord.");
  73.         printf("J-NPC: %s started recording a NPC. Type: %d",Playername(playerid),rectype);
  74.         return 1;
  75.     }
  76.     return 1;
  77. }
  78.  
  79. dcmd_npcrecord(playerid,params[])
  80. {
  81.     if(IsPlayerAdmin(playerid))
  82.     {
  83.         if(strlen(params) > 0 && strlen(params) < 31)
  84.         {
  85.             new str[35];
  86.             format(str,sizeof(str),"%s.rec",params);
  87.             if(!fexist(str))
  88.             {
  89.                 new st = GetPlayerState(playerid);
  90.                 if(st == PLAYER_STATE_DRIVER || st == PLAYER_STATE_PASSENGER)
  91.                 {
  92.                     SetPVarInt(playerid,"RecType",INVEHICLE);
  93.                     ShowPlayerDialog(playerid,DIALOG_REC,DIALOG_STYLE_MSGBOX,"J-NPC","Do you want to record a NPC\nin this vehicle?","Yes, start","No, wait");
  94.                 }      
  95.                 else if(st == PLAYER_STATE_ONFOOT)
  96.                 {
  97.                     SetPVarInt(playerid,"RecType",ONFOOT);
  98.                     ShowPlayerDialog(playerid,DIALOG_REC,DIALOG_STYLE_MSGBOX,"J-NPC","Do you want to record a NPC\non foot?","Yes, start","No, wait");
  99.                 }
  100.                 SetPVarString(playerid,"FileName",params);
  101.                 return 1;
  102.             }
  103.             else return SendClientMessage(playerid,COLOR_RED,"Error: File already exists, please choose another name.");
  104.         }
  105.         else return SendClientMessage(playerid,COLOR_RED,"Error: Please specify a filename longer than 0 characters and shorter than 31 characters.");
  106.     }
  107.     else return 0;
  108. }
  109.  
  110. dcmd_stoprecord(playerid,params[])
  111. {
  112.     #pragma unused params
  113.     new Recording = GetPVarInt(playerid,"Recording");
  114.     if(Recording != 0)
  115.     {
  116.         new tick,File:file,str[700],filename[31];
  117.         StopRecordingPlayerData(playerid);
  118.         SendClientMessage(playerid,COLOR_WHITE,"Succes: You have successfully stopped recording. Please wait, your script is being built...");
  119.         tick = GetTickCount();
  120.         GetPVarString(playerid,"FileName",filename,31);
  121.         format(str,sizeof(str),"%s.pwn",filename);
  122.         file = fopen(str,io_write);
  123.         format(str,sizeof(str),"#define RECORDING \"%s\"\r\n#define RECORDING_TYPE %d\r\n \r\n",filename,Recording);
  124.         fwrite(file,str);
  125.         fwrite(file,"#include <a_npc>\nmain() {}\r\n \r\npublic OnRecordingPlaybackEnd() StartRecordingPlayback(RECORDING_TYPE, RECORDING);\r\n \r\n#if RECORDING_TYPE == 1\r\n  public OnNPCEnterVehicle(vehicleid, seatid) StartRecordingPlayback(RECORDING_TYPE, RECORDING);\r\n  public OnNPCExitVehicle() StopRecordingPlayback();\r\n");
  126.         fwrite(file,"#else\r\n  public OnNPCSpawn() StartRecordingPlayback(RECORDING_TYPE, RECORDING);\r\n#endif");
  127.         fclose(file);
  128.         format(str,sizeof(str),"%s_gamemode_script.txt",filename);
  129.         file = fopen(str,io_write);
  130.         if(GetPVarInt(playerid,"Recording") == ONFOOT)
  131.         {
  132.             format(str,sizeof(str),"// Put the script down here in your gamemode. You might have to merge functions.\r\n \r\npublic OnGameModeInit()\r\n{\r\n   ConnectNPC(\"npc_name_here\",%s);\r\n   return 1;\r\n}",filename);
  133.             fwrite(file,str);
  134.         }
  135.         else
  136.         {
  137.             format(str,sizeof(str),"// Put the script down here in your gamemode. You might have to merge functions. Also, don't forget to replace 'npc_name_here' with the name of the NPC ingame.\r\n\r\nnew npc_name_here_vehicle; \r\n\r\npublic OnGameModeInit()\r\n{\r\n  npc_name_here_vehicle = CreateVehicle(%d,0.0,0.0,0.0,0.0,-1,-1,-1);\r\n ConnectNPC(\"npc_name_here\",%s);\r\n   return 1;\r\n}\r\n \r\npublic OnPlayerSpawn(playerid)\r\n{\r\n",GetPVarInt(playerid,"npcvehid"),filename);
  138.             fwrite(file,str);
  139.             fwrite(file,"   if(IsPlayerNPC(playerid))\r\n   {\r\n       new name[MAX_PLAYER_NAME];\r\n      GetPlayerName(playerid,name,sizeof(name));\r\n      if(!strcmp(name,\"npc_name_here\",false))\r\n       {\r\n           PutPlayerInVehicle(playerid,npc_name_here_vehicle,0);\r\n       }\r\n       return 1;\r\n   }\r\n   return 1;\r\n}");
  140.         }
  141.         fclose(file);
  142.         printf("Succes: Script has been built in %d ms.",GetTickCount() - tick);
  143.         SendClientMessage(playerid,COLOR_YELLOW,"Now all you need to do is move a couple of files;");
  144.         format(str,sizeof(str),"- %s.rec has to be moved to /server_root/npcmodes/recordings.",filename);
  145.         SendClientMessage(playerid,COLOR_WHITE,str);
  146.         format(str,sizeof(str),"- %s.pwn has to be moved to /server_root/npcmodes.",filename);
  147.         SendClientMessage(playerid,COLOR_WHITE,str);
  148.         format(str,sizeof(str),"    Also, don't forget to look in %s.txt which contains script to run the NPC.",filename);
  149.         SendClientMessage(playerid,COLOR_YELLOW,str);
  150.         return 1;
  151.     }
  152.     else return SendClientMessage(playerid,COLOR_RED,"Error: You are not recording any NPC.");
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement