Advertisement
Vuzimir

SA-MP tutorial for Dynamic System by Vuzimir

Jun 21st, 2015
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 11.08 KB | None | 0 0
  1. // This is a comment
  2. // uncomment the line below if you want to write a filterscript
  3. //#define FILTERSCRIPT
  4.  
  5. #include <a_samp>
  6. #include <sscanf2>
  7. #include <zcmd>
  8. #include <YSI\y_ini>
  9.  
  10. new idoffile[MAX_PLAYERS];
  11. #define VEHICLE_FOLDER "Vehicles/Vehicle_%d.ini" //This will be path were will be saved files of vehicles
  12. //Now let's create an enumerator that holds vehicle's information
  13. enum vfInfo //We name our enumerator as vfInfo. You can name it however you want.
  14. {
  15.     dID,
  16.     dModel,   //This will be used to save model of vehicle
  17.     Float:dX, //This will be used to save X cordinate of vehicle
  18.     Float:dY, //This will be used to save Y cordinate of vehicle
  19.     Float:dZ, //This will be used to save Z cordinate of vehicle
  20.     Float:dA, //This will be used to save Angle of vehicle
  21.     dColor1,  //This will be used to save Vehicle color1
  22.     dColor2,  //This will be used to save Vehicle color2
  23. };
  24. new DVehicles[MAX_VEHICLES][vfInfo]; //Variable that stores enumerator above
  25.  
  26. main()
  27. {
  28.     print("\n----------------------------------");
  29.     print(" SA-MP tutorial by Dusan01(Vuzimir)");
  30.     print("----------------------------------\n");
  31. }
  32.  
  33. public OnGameModeInit()
  34. {
  35.     // Don't use these lines if it's a filterscript
  36.     SetGameModeText("Blank Script");
  37.     AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  38.     for(new b = 0; b < sizeof(DVehicles); b++) //loop
  39.     {
  40.         new gFile[35]; //string
  41.         format(gFile, 50, VEHICLE_FOLDER ,b); //formating string
  42.         if(fexist(gFile)) //checking does file exist witch is in format
  43.         {
  44.              INI_ParseFile(gFile, "LoadVehicle", .bExtra = true, .extra = b); //Y_INI function to load from vehicles
  45.              if(DVehicles[b][dModel] != 0) //if model is everytning expect 0
  46.              {
  47.              DVehicles[b][dID] = CreateVehicle(DVehicles[b][dModel], DVehicles[b][dX],DVehicles[b][dY],DVehicles[b][dZ],DVehicles[b][dA], DVehicles[b][dColor1], DVehicles[b][dColor2], 0); //creating vehicle
  48.              }
  49.         }
  50.     }
  51.     return 1;
  52. }
  53.  
  54. public OnGameModeExit()
  55. {
  56.     return 1;
  57. }
  58.  
  59. public OnPlayerRequestClass(playerid, classid)
  60. {
  61.     SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  62.     SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  63.     SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  64.     return 1;
  65. }
  66.  
  67. public OnPlayerConnect(playerid)
  68. {
  69.     idoffile[playerid] = -1;
  70.     return 1;
  71. }
  72.  
  73. public OnPlayerDisconnect(playerid, reason)
  74. {
  75.     return 1;
  76. }
  77.  
  78. public OnPlayerSpawn(playerid)
  79. {
  80.     return 1;
  81. }
  82.  
  83. public OnPlayerDeath(playerid, killerid, reason)
  84. {
  85.     return 1;
  86. }
  87.  
  88. public OnVehicleSpawn(vehicleid)
  89. {
  90.     return 1;
  91. }
  92.  
  93. public OnVehicleDeath(vehicleid, killerid)
  94. {
  95.     return 1;
  96. }
  97.  
  98. public OnPlayerText(playerid, text[])
  99. {
  100.     return 1;
  101. }
  102.  
  103. public OnPlayerCommandText(playerid, cmdtext[])
  104. {
  105.     if (strcmp("/mycommand", cmdtext, true, 10) == 0)
  106.     {
  107.         // Do something here
  108.         return 1;
  109.     }
  110.     return 0;
  111. }
  112.  
  113. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  114. {
  115.     return 1;
  116. }
  117.  
  118. public OnPlayerExitVehicle(playerid, vehicleid)
  119. {
  120.     return 1;
  121. }
  122.  
  123. public OnPlayerStateChange(playerid, newstate, oldstate)
  124. {
  125.     return 1;
  126. }
  127.  
  128. public OnPlayerEnterCheckpoint(playerid)
  129. {
  130.     return 1;
  131. }
  132.  
  133. public OnPlayerLeaveCheckpoint(playerid)
  134. {
  135.     return 1;
  136. }
  137.  
  138. public OnPlayerEnterRaceCheckpoint(playerid)
  139. {
  140.     return 1;
  141. }
  142.  
  143. public OnPlayerLeaveRaceCheckpoint(playerid)
  144. {
  145.     return 1;
  146. }
  147.  
  148. public OnRconCommand(cmd[])
  149. {
  150.     return 1;
  151. }
  152.  
  153. public OnPlayerRequestSpawn(playerid)
  154. {
  155.     return 1;
  156. }
  157.  
  158. public OnObjectMoved(objectid)
  159. {
  160.     return 1;
  161. }
  162.  
  163. public OnPlayerObjectMoved(playerid, objectid)
  164. {
  165.     return 1;
  166. }
  167.  
  168. public OnPlayerPickUpPickup(playerid, pickupid)
  169. {
  170.     return 1;
  171. }
  172.  
  173. public OnVehicleMod(playerid, vehicleid, componentid)
  174. {
  175.     return 1;
  176. }
  177.  
  178. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  179. {
  180.     return 1;
  181. }
  182.  
  183. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  184. {
  185.     return 1;
  186. }
  187.  
  188. public OnPlayerSelectedMenuRow(playerid, row)
  189. {
  190.     return 1;
  191. }
  192.  
  193. public OnPlayerExitedMenu(playerid)
  194. {
  195.     return 1;
  196. }
  197.  
  198. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  199. {
  200.     return 1;
  201. }
  202.  
  203. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  204. {
  205. if(newkeys & KEY_YES) //if player pres KEY_YES that is 'Y'
  206. {
  207.         if(idoffile[playerid] > -1) //if id of file is bigger then -1
  208.         {
  209.         new fileid = idoffile[playerid]; //geting id of file
  210.         new vehz = GetPlayerVehicleID(playerid); //geting player vehicle id
  211.         new Float:X,Float:Y,Float:Z,Float:A; //variables for pos of vehicle
  212.         GetVehicleZAngle(vehz, A); //geting vehicle Angle
  213.         GetPlayerPos(playerid, X,Y,Z); //Getting player position and storing i to X,Y,Z
  214.         DVehicles[fileid][dX] = X; //setting new cordinate X for vehicle
  215.         DVehicles[fileid][dY] = Y; //setting new cordinate Y for vehicle
  216.         DVehicles[fileid][dZ] = Z; //setting new cordinate Z for vehicle
  217.         DVehicles[fileid][dA] = A; //setting Angle for vehicle
  218.         DestroyVehicle(vehz); //Destronying vehicle
  219.         CreateVehicle(DVehicles[fileid][dModel], DVehicles[fileid][dX],DVehicles[fileid][dY],DVehicles[fileid][dZ],DVehicles[fileid][dA], DVehicles[fileid][dColor1], DVehicles[fileid][dColor2], 0); //creating new vehicle with saved variables
  220.         SaveVehicle(fileid); //Now saving vehicle to file
  221.         idoffile[playerid] = -1; //seting player variable to -1
  222.         RemovePlayerFromVehicle(playerid); //Removing player from vehicle
  223.         SendClientMessage(playerid,-1,"U have cretated vehicle, congratz!");
  224.         return 1;
  225.         }
  226. }
  227. return 1;
  228. }
  229.  
  230. public OnRconLoginAttempt(ip[], password[], success)
  231. {
  232.     return 1;
  233. }
  234.  
  235. public OnPlayerUpdate(playerid)
  236. {
  237.     return 1;
  238. }
  239.  
  240. public OnPlayerStreamIn(playerid, forplayerid)
  241. {
  242.     return 1;
  243. }
  244.  
  245. public OnPlayerStreamOut(playerid, forplayerid)
  246. {
  247.     return 1;
  248. }
  249.  
  250. public OnVehicleStreamIn(vehicleid, forplayerid)
  251. {
  252.     return 1;
  253. }
  254.  
  255. public OnVehicleStreamOut(vehicleid, forplayerid)
  256. {
  257.     return 1;
  258. }
  259.  
  260. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  261. {
  262.     return 1;
  263. }
  264.  
  265. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  266. {
  267.     return 1;
  268. }
  269.  
  270. //now lets add callback for saving and loading
  271. forward SaveVehicle(fileid); //This will forward for callback SaveVehicle
  272. public SaveVehicle(fileid)
  273. {
  274.     new dFile[128]; //This is string witch will search for file
  275.     format(dFile, sizeof(dFile),VEHICLE_FOLDER,fileid); //Formating string
  276.     new INI:File = INI_Open(dFile); //Opening file
  277.     INI_WriteInt(File,"Model",DVehicles[fileid][dModel]); //Saving Model to file from variable dModel
  278.     INI_WriteFloat(File,"X",DVehicles[fileid][dX]);  //Saving Cordinate X to file from variable dX
  279.     INI_WriteFloat(File,"Y",DVehicles[fileid][dY]);  //Saving Cordinate Y to file from variable dY
  280.     INI_WriteFloat(File,"Z",DVehicles[fileid][dZ]);  //Saving Cordinate Z to file from variable dZ
  281.     INI_WriteFloat(File,"A",DVehicles[fileid][dA]);  //Saving Angle to file from variable dA
  282.     INI_WriteInt(File,"Color1",DVehicles[fileid][dColor1]); //Saving Color1 to file from variable dColor1
  283.     INI_WriteInt(File,"Color2",DVehicles[fileid][dColor2]); //Saving Color2 to file from variable dColor2
  284.     INI_Close(File);
  285.     return 1;
  286. }
  287.  
  288.  
  289. forward LoadVehicle(fileid, name[], value[]); //This will forward for callback LoadVehicle
  290. public LoadVehicle(fileid, name[], value[])
  291. {
  292.     INI_Int("Model",DVehicles[fileid][dModel]); //This will reard Model from file and store it to dModel
  293.     INI_Float("X",DVehicles[fileid][dX]); //This will reard Cordinate X from file and store it to dX
  294.     INI_Float("Y",DVehicles[fileid][dY]); //This will reard Cordinate Y from file and store it to dY
  295.     INI_Float("Z",DVehicles[fileid][dZ]); //This will reard Cordinate Z from file and store it to dZ
  296.     INI_Float("A",DVehicles[fileid][dA]); //This will reard Angle from file and store it to dA
  297.     INI_Int("Color1",DVehicles[fileid][dColor1]); //This will reard Color1 from file and store it to dColor1
  298.     INI_Int("Color2",DVehicles[fileid][dColor2]); //This will reard Color1 from file and store it to dColor1
  299.     return 1;
  300. }
  301.  
  302. CMD:createveh(playerid, params[]) //command for create vehicle
  303. {
  304.     new fileid = 0; //variable for file counting, witch file is not created
  305.     new Float:X,Float:Y,Float:Z; //Varables for position
  306.     GetPlayerPos(playerid, X,Y,Z); //Getting player position and storing i to X,Y,Z
  307.     for(new b = 0; b < sizeof(DVehicles); b++) //this is loop
  308.     {
  309.         if(DVehicles[b][dModel] != 0) //checking witch files are free (not created)
  310.         {
  311.             fileid = b+1; //Saving file ID to fileid
  312.         }
  313.     }
  314.     if(fileid > MAX_VEHICLES) return SendClientMessage(playerid, -1, "MAX_VEHICLES reached, u cannot create more vehicles"); //if MAX_VEHICLE reach's you will not be in able to create more vehicles
  315.     new model,color1, color2; //Againg more variables for parameters
  316.     if(sscanf(params, "iii", model, color1, color2)) //In this part we will use sscanf, this is checking are all parameters filled to script can create vehicle
  317.     {
  318.         SendClientMessage(playerid, -1, "/createveh [Model] [Color1] [Color2]");
  319.         return 1;
  320.     }
  321.     DVehicles[fileid][dModel] = model; //this will save parameters witch we filled in to variables
  322.     DVehicles[fileid][dX] = X; //this will save parameters witch we filled in to variables
  323.     DVehicles[fileid][dY] = Y; //this will save parameters witch we filled in to variables
  324.     DVehicles[fileid][dZ] = Z; //this will save parameters witch we filled in to variables
  325.     DVehicles[fileid][dColor1] = color1; //this will save parameters witch we filled in to variables
  326.     DVehicles[fileid][dColor2] = color2; //this will save parameters witch we filled in to variables
  327.     DVehicles[fileid][dID] = CreateVehicle(model, X,Y,Z,0, color1, color2, 0); //creating vehicle
  328.     PutPlayerInVehicle(playerid, DVehicles[fileid][dID], 0); //Putting player in vehicle witch player created
  329.     idoffile[playerid] = fileid;
  330.     SendClientMessage(playerid, -1, "You have created vehicle, now select angle in witch direction you want and press 'Y' to finish and save file.");
  331.     return 1;
  332. }
  333.  
  334. CMD:destroyveh(playerid, params[]) //command for destroy vehilce
  335. {
  336.     new fileid; //filed for sscanf
  337.     if(sscanf(params, "i", fileid)) //In this part we will use sscanf, this is checking are all parameters filled to script can create vehicle
  338.     {
  339.         SendClientMessage(playerid, -1, "/destroyveh [FILE ID]");
  340.         return 1;
  341.     }
  342.     new dFile[128]; //This is string witch will search for file
  343.     format(dFile, sizeof(dFile),VEHICLE_FOLDER,fileid); //Formating string
  344.     if(!fexist(dFile)) return SendClientMessage(playerid, -1, "That file does not exist!");//checking does file exist witch is in format
  345.     fremove(dFile); //Removing file
  346.     DestroyVehicle(DVehicles[fileid][dID]); //Destroying vehicle
  347.     DVehicles[fileid][dModel] = 0; //Setting variables to default
  348.     DVehicles[fileid][dX] = 0.0; //Setting variables to default
  349.     DVehicles[fileid][dY] = 0.0; //Setting variables to default
  350.     DVehicles[fileid][dZ] = 0.0; //Setting variables to default
  351.     DVehicles[fileid][dA] = 0.0; //Setting variables to default
  352.     DVehicles[fileid][dColor1] = 0; //Setting variables to default
  353.     DVehicles[fileid][dColor2] = 0; //Setting variables to default
  354.     SendClientMessage(playerid, -1, "You have been destroyed vehicle");
  355.     return 1;
  356. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement