Guest User

Untitled

a guest
Oct 9th, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.26 KB | None | 0 0
  1. #include <a_samp>
  2. #include <streamer>
  3. #include <ocmd>
  4.  
  5. //DEFINES
  6. #define SPAWN 1568.4768,-1690.7144,5.8906 //Hier die Koordinaten eingeben, wo der Spieler spawnen soll. (DERZEIT: LSPD)
  7.  
  8. //FARBEN
  9. #define Blau 0x0019FFFF
  10. #define Grau 0xB4B4B4FF
  11.  
  12.  
  13. new Text:TDEditor_TD[1];
  14.  
  15. main()
  16. {
  17. print("\n----------------------------------");
  18. print(" Blank-Script by Impressiv_");
  19. print("----------------------------------\n");
  20. }
  21. stock LoadAllNormalObjects()
  22. {
  23. //Alle CreateObj
  24. }
  25.  
  26. stock LoadAllDynamicObjects()
  27. {
  28. //Ganghaus
  29. CreateDynamicObject(2847, 946.97522, -47.89420, 1000.50348, 0.00000, 0.00000, 0.00000);
  30. CreateDynamicObject(2847, 947.05072, -48.73700, 1000.49951, 0.00000, 0.00000, 0.00000);
  31. CreateDynamicObject(1516, 943.64996, -41.08196, 1000.11383, 0.00000, 0.00000, 0.00000);
  32. CreateDynamicObject(1516, 944.78998, -41.11319, 1000.11383, 0.00000, 0.00000, 0.00000);
  33. CreateDynamicObject(1516, 945.95013, -41.12462, 1000.11383, 0.00000, 0.00000, 0.00000);
  34. CreateDynamicObject(1516, 947.09094, -41.08952, 1000.11383, 0.00000, 0.00000, 0.00000);
  35. CreateDynamicObject(356, 943.44043, -40.63888, 1000.74298, 0.00000, 0.00000, 0.00000);
  36. CreateDynamicObject(348, 944.53027, -40.65422, 1000.77087, 0.00000, 0.00000, 0.00000);
  37. CreateDynamicObject(353, 945.66034, -40.66950, 1000.74432, 0.00000, 0.00000, 0.00000);
  38. CreateDynamicObject(358, 946.90784, -40.72879, 1000.85181, 0.00000, 0.00000, 0.00000);
  39. CreateDynamicObject(1575, 943.66058, -41.37770, 1000.62500, 0.00000, 0.00000, 0.00000);
  40. CreateDynamicObject(19893, 944.78510, -41.29601, 1000.63928, 0.00000, 0.00000, 0.00000);
  41. CreateDynamicObject(19893, 945.88507, -41.32236, 1000.63928, 0.00000, 0.00000, 0.00000);
  42. CreateDynamicObject(1575, 947.09052, -41.35910, 1000.63409, 0.00000, 0.00000, 0.00000);
  43. CreateDynamicObject(1550, 943.61310, -61.54331, 1000.96820, 0.00000, 0.00000, 0.00000);
  44. CreateDynamicObject(1550, 943.58820, -61.16838, 1000.96820, 0.00000, 0.00000, 0.00000);
  45. CreateDynamicObject(1550, 943.50885, -60.77787, 1000.96820, 0.00000, 0.00000, 0.00000);
  46. CreateDynamicObject(1550, 943.94440, -60.69658, 1000.96820, 0.00000, 0.00000, 0.00000);
  47. CreateDynamicObject(1550, 943.94415, -61.10840, 1000.96820, 0.00000, 0.00000, 0.00000);
  48. CreateDynamicObject(1550, 943.92419, -61.48524, 1000.96820, 0.00000, 0.00000, 0.00000);
  49. CreateDynamicObject(1771, 955.19379, -58.90397, 1000.42291, 0.00000, 0.00000, 0.00000);
  50. CreateDynamicObject(1771, 953.87238, -58.89467, 1000.42291, 0.00000, 0.00000, 0.00000);
  51. CreateDynamicObject(1771, 952.55090, -58.88537, 1000.42291, 0.00000, 0.00000, 0.00000);
  52. CreateDynamicObject(1771, 951.23083, -58.89224, 1000.42291, 0.00000, 0.00000, 0.00000);
  53. CreateDynamicObject(1771, 949.91095, -58.89911, 1001.44305, 0.00000, 0.00000, 0.00000);
  54. CreateDynamicObject(1771, 949.91095, -58.89911, 1000.42291, 0.00000, 0.00000, 0.00000);
  55. CreateDynamicObject(1771, 951.21613, -58.87814, 1001.44305, 0.00000, 0.00000, 0.00000);
  56. CreateDynamicObject(1771, 952.53839, -58.89857, 1001.44305, 0.00000, 0.00000, 0.00000);
  57. CreateDynamicObject(1771, 953.86206, -58.89642, 1001.44305, 0.00000, 0.00000, 0.00000);
  58. CreateDynamicObject(1771, 955.16583, -58.89277, 1001.44305, 0.00000, 0.00000, 0.00000);
  59. CreateDynamicObject(2573, 955.35474, -53.02866, 1000.10052, 356.85840, 0.00000, -1.57080);
  60. CreateDynamicObject(1829, 949.58264, -42.71042, 1000.55859, 0.00000, 0.00000, 359.59393);
  61. CreateDynamicObject(1829, 950.41351, -42.71128, 1000.55859, 0.00000, 0.00000, 359.59393);
  62. CreateDynamicObject(1829, 951.23297, -42.71462, 1000.55859, 0.00000, 0.00000, 359.59393);
  63. CreateDynamicObject(1829, 952.03522, -42.71156, 1000.55859, 0.00000, 0.00000, 359.59393);
  64. CreateDynamicObject(1829, 952.85602, -42.70201, 1000.55859, 0.00000, 0.00000, 359.59393);
  65. CreateDynamicObject(1829, 953.67517, -42.69471, 1000.55859, 0.00000, 0.00000, 359.59393);
  66. CreateDynamicObject(1829, 954.49689, -42.67956, 1000.55859, 0.00000, 0.00000, 359.59393);
  67. CreateDynamicObject(1829, 955.31824, -42.70424, 1000.55859, 0.00000, 0.00000, 359.59393);
  68. CreateDynamicObject(3111, 952.12518, -42.06370, 1001.72498, 90.00000, 0.00000, 0.00000);
  69. CreateDynamicObject(1575, 961.13165, -57.47996, 1000.93146, 0.00000, 0.00000, 0.00000);
  70. CreateDynamicObject(1575, 960.44421, -57.47557, 1000.93146, 0.00000, 0.00000, 0.00000);
  71. CreateDynamicObject(1508, 964.98975, -54.81554, 1001.84961, 0.00000, 0.00000, 0.00000);
  72. CreateDynamicObject(1575, 947.36761, -47.24274, 1000.51404, 0.00000, 0.00000, 0.00000);
  73. CreateDynamicObject(1575, 947.38116, -47.62302, 1000.51404, 0.00000, 0.00000, 0.00000);
  74. CreateDynamicObject(1575, 952.59882, -41.91056, 1000.51404, 0.00000, 0.00000, 0.00000);
  75. CreateDynamicObject(1575, 947.39417, -48.04330, 1000.51404, 0.00000, 0.00000, 0.00000);
  76. //Advent
  77. CreateDynamicObject(19076, 223.28917, -1824.40308, 2.57629, 0.00000, 0.00000, 0.00000);
  78. CreateDynamicObject(19076, 221.86356, -1851.64282, 2.57629, 0.00000, 0.00000, 0.00000);
  79. CreateDynamicObject(19076, 257.42389, -1849.54431, 2.57629, 0.00000, 0.00000, 0.00000);
  80. CreateDynamicObject(19054, 227.41986, -1826.96021, 3.57884, 0.00000, 0.00000, 0.00000);
  81. CreateDynamicObject(19054, 227.43547, -1825.02747, 3.57884, 0.00000, 0.00000, 0.00000);
  82. CreateDynamicObject(19054, 227.35078, -1823.08057, 3.57884, 0.00000, 0.00000, 0.00000);
  83. CreateDynamicObject(19054, 221.01001, -1822.40576, 3.57884, 0.00000, 0.00000, 0.00000);
  84. CreateDynamicObject(19054, 220.97661, -1824.22534, 3.57884, 0.00000, 0.00000, 0.00000);
  85. CreateDynamicObject(19054, 221.17661, -1826.40747, 3.57884, 0.00000, 0.00000, 0.00000);
  86. CreateDynamicObject(19054, 221.76637, -1848.64709, 2.90582, 0.00000, 0.00000, 0.00000);
  87. CreateDynamicObject(19054, 221.74638, -1850.05835, 2.90582, 0.00000, 0.00000, 0.00000);
  88. CreateDynamicObject(19054, 221.69194, -1851.47864, 2.90582, 0.00000, 0.00000, 0.00000);
  89. CreateDynamicObject(19054, 226.39082, -1851.70483, 2.90582, 0.00000, 0.00000, 0.00000);
  90. CreateDynamicObject(19054, 226.54633, -1849.67847, 2.90582, 0.00000, 0.00000, 0.00000);
  91. CreateDynamicObject(19054, 226.60495, -1847.87573, 2.90582, 0.00000, 0.00000, 0.00000);
  92. CreateDynamicObject(19054, 260.09338, -1850.08716, 2.80730, 0.00000, 0.00000, 0.00000);
  93. CreateDynamicObject(19054, 260.08215, -1848.61597, 2.80730, 0.00000, 0.00000, 0.00000);
  94. CreateDynamicObject(19054, 259.73782, -1847.06604, 2.80730, 0.00000, 0.00000, 0.00000);
  95. CreateDynamicObject(19054, 256.63138, -1849.88391, 2.80730, 0.00000, 0.00000, 0.00000);
  96. CreateDynamicObject(19054, 256.41461, -1848.26599, 2.80730, 0.00000, 0.00000, 0.00000);
  97. CreateDynamicObject(19054, 256.45490, -1846.90271, 2.80730, 0.00000, 0.00000, 0.00000);
  98. CreateDynamicObject(19054, 260.64746, -1824.95300, 3.41568, 0.00000, 0.00000, 0.00000);
  99. CreateDynamicObject(19054, 260.69281, -1823.06616, 3.41568, 0.00000, 0.00000, 0.00000);
  100. CreateDynamicObject(19054, 260.56763, -1821.16772, 3.41568, 0.00000, 0.00000, 0.00000);
  101. CreateDynamicObject(19054, 255.81464, -1821.07837, 3.41568, 0.00000, 0.00000, 0.00000);
  102. CreateDynamicObject(19054, 255.46877, -1823.05835, 3.41568, 0.00000, 0.00000, 0.00000);
  103. CreateDynamicObject(19054, 255.73152, -1824.85120, 3.41568, 0.00000, 0.00000, 0.00000);
  104. CreateDynamicObject(19076, 258.09116, -1823.21045, 2.95146, 0.00000, 0.00000, 0.00000);
  105. CreateDynamicObject(19129, 242.61790, -1835.51733, 2.72630, 1.05200, 0.00000, 359.43091);
  106. CreateDynamicObject(18090, 237.26100, -1855.54749, 4.58257, 0.00000, 0.00000, 264.27795);
  107. CreateDynamicObject(19446, 237.39339, -1857.51733, 3.28600, 0.00000, 0.00000, 86.44100);
  108. CreateDynamicObject(19363, 232.67952, -1855.04187, 3.30459, 0.00000, 0.00000, 0.00000);
  109. CreateDynamicObject(1486, 237.12230, -1853.99951, 3.20560, 0.00000, 0.00000, 0.00000);
  110. CreateDynamicObject(1486, 236.07149, -1853.83521, 3.20560, 0.00000, 0.00000, 0.00000);
  111. CreateDynamicObject(1486, 234.14748, -1853.73767, 3.20560, 0.00000, 0.00000, 0.00000);
  112. CreateDynamicObject(1486, 238.69794, -1854.13623, 3.20560, 0.00000, 0.00000, 0.00000);
  113. CreateDynamicObject(1486, 241.02480, -1854.36279, 3.20560, 0.00000, 0.00000, 0.00000);
  114. CreateDynamicObject(1486, 237.01973, -1857.07825, 3.81768, 0.00000, 0.00000, 0.00000);
  115. CreateDynamicObject(1486, 237.98662, -1856.91858, 3.81768, 0.00000, 0.00000, 0.00000);
  116. CreateDynamicObject(19363, 232.66821, -1855.56335, 3.30459, 0.00000, 0.00000, 0.00000);
  117. CreateDynamicObject(19363, 242.10658, -1856.09863, 3.30459, 0.00000, 0.00000, 0.00000);
  118. //Drogendealer Beatch
  119. CreateDynamicObject(29, 380.48901, -1879.67712, 2.61162, 90.00000, 0.00000, 0.00000);
  120. CreateDynamicObject(1516, 380.52124, -1880.82202, 1.78816, 0.00000, 0.00000, 0.00000);
  121. CreateDynamicObject(348, 380.16962, -1879.67786, 2.68000, 0.00000, 90.00000, 9.00000);
  122. CreateDynamicObject(1575, 380.51065, -1880.83862, 2.31395, 0.00000, 0.00000, 0.00000);
  123. //Drogendealer Glenpark
  124. CreateDynamicObject(29, 380.48901, -1879.67712, 2.61162, 90.00000, 0.00000, 0.00000);
  125. CreateDynamicObject(1516, 380.52124, -1880.82202, 1.78816, 0.00000, 0.00000, 0.00000);
  126. CreateDynamicObject(348, 380.16962, -1879.67786, 2.68000, 0.00000, 90.00000, 9.00000);
  127. CreateDynamicObject(1575, 380.51065, -1880.83862, 2.31395, 0.00000, 0.00000, 0.00000);
  128. CreateDynamicObject(29, 1965.94702, -1155.05481, 20.97966, 90.00000, 0.00000, 0.00000);
  129. CreateDynamicObject(1516, 1965.82300, -1155.97974, 20.06935, 0.00000, 0.00000, 0.00000);
  130. CreateDynamicObject(1575, 1965.77966, -1156.08508, 20.59494, 0.00000, 0.00000, 0.00000);
  131. CreateDynamicObject(348, 1965.74426, -1155.07617, 21.05060, 0.00000, 90.00000, 90.00000);
  132. }
  133. public OnGameModeInit()
  134. {
  135. TDEditor_TD[0] = TextDrawCreate(2.666627, 433.496643, "Hier_kommt_dein_Text._Viel_Spass!_-_Impressiv_");
  136. TextDrawLetterSize(TDEditor_TD[0], 0.293999, 1.384296);
  137. TextDrawAlignment(TDEditor_TD[0], 1);
  138. TextDrawColor(TDEditor_TD[0], -1);
  139. TextDrawSetShadow(TDEditor_TD[0], 0);
  140. TextDrawSetOutline(TDEditor_TD[0], 0);
  141. TextDrawBackgroundColor(TDEditor_TD[0], 255);
  142. TextDrawFont(TDEditor_TD[0], 1);
  143. TextDrawSetProportional(TDEditor_TD[0], 1);
  144. TextDrawSetShadow(TDEditor_TD[0], 0);
  145. }
  146.  
  147. //NORMALE-OBJEKTE
  148. LoadAllNormalObjects();
  149. //DYNAMIC-OBJEKTE
  150. LoadAllDynamicObjects();
  151.  
  152. SetGameModeText("Blank Script");
  153. AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  154. return 1;
  155. }
  156.  
  157. public OnGameModeExit()
  158. {
  159. return 1;
  160. }
  161.  
  162. public OnPlayerRequestClass(playerid, classid)
  163. {
  164. SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  165. SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  166. SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  167. return 1;
  168. }
  169.  
  170. public OnPlayerConnect(playerid)
  171. {
  172. //Remove von Ganghaus
  173. RemoveBuildingForPlayer(playerid, 1491, 944.5625, -52.7031, 1000.1172, 0.25);
  174. RemoveBuildingForPlayer(playerid, 14817, 949.4844, -50.8359, 1001.8672, 0.25);
  175. RemoveBuildingForPlayer(playerid, 1491, 944.1016, -49.3203, 1000.1172, 0.25);
  176. RemoveBuildingForPlayer(playerid, 1491, 951.0547, -52.7031, 1000.1172, 0.25);
  177. RemoveBuildingForPlayer(playerid, 1491, 951.0078, -49.3203, 1000.1172, 0.25);
  178. RemoveBuildingForPlayer(playerid, 1725, 951.9844, -46.2813, 1000.1250, 0.25);
  179. RemoveBuildingForPlayer(playerid, 1803, 952.9609, -57.4375, 1000.0938, 0.25);
  180. RemoveBuildingForPlayer(playerid, 2576, 955.1953, -55.4531, 1000.1016, 0.25);
  181. RemoveBuildingForPlayer(playerid, 2573, 955.3281, -43.5547, 1000.1016, 0.25);
  182. //Remove von Advent
  183. RemoveBuildingForPlayer(playerid, 3778, 245.5391, -1875.0000, 2.6875, 0.25);
  184. RemoveBuildingForPlayer(playerid, 3778, 200.4844, -1875.0000, 3.0781, 0.25);
  185. RemoveBuildingForPlayer(playerid, 3615, 200.4844, -1875.0000, 3.0781, 0.25);
  186. RemoveBuildingForPlayer(playerid, 3615, 245.5391, -1875.0000, 2.6875, 0.25);
  187. //Remove von DD an der Beatch
  188. RemoveBuildingForPlayer(playerid, 18109, 311.0703, -137.4453, 1005.0078, 0.25);
  189. RemoveBuildingForPlayer(playerid, 1977, 316.8750, -140.3516, 998.5859, 0.25);
  190. //Remove von DD an dem Glenpark
  191. RemoveBuildingForPlayer(playerid, 18109, 311.0703, -137.4453, 1005.0078, 0.25);
  192. RemoveBuildingForPlayer(playerid, 1977, 316.8750, -140.3516, 998.5859, 0.25);
  193. return 1;
  194. }
  195.  
  196. public OnPlayerDisconnect(playerid, reason)
  197. {
  198. return 1;
  199. }
  200.  
  201. public OnPlayerSpawn(playerid)
  202. {
  203. SetPlayerPos(playerid, SPAWN);
  204. return 1;
  205. }
  206.  
  207. public OnPlayerDeath(playerid, killerid, reason)
  208. {
  209. SetPlayerPos(playerid, SPAWN);
  210. return 1;
  211. }
  212.  
  213. public OnVehicleSpawn(vehicleid)
  214. {
  215. return 1;
  216. }
  217.  
  218. public OnVehicleDeath(vehicleid, killerid)
  219. {
  220. return 1;
  221. }
  222.  
  223. public OnPlayerText(playerid, text[])
  224. {
  225. return 1;
  226. }
  227.  
  228. public OnPlayerCommandText(playerid, cmdtext[])
  229. {
  230. if (strcmp("/mycommand", cmdtext, true, 10) == 0)
  231. {
  232. // Do something here
  233. return 1;
  234. }
  235. return 0;
  236. }
  237.  
  238. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  239. {
  240. return 1;
  241. }
  242.  
  243. public OnPlayerExitVehicle(playerid, vehicleid)
  244. {
  245. return 1;
  246. }
  247.  
  248. public OnPlayerStateChange(playerid, newstate, oldstate)
  249. {
  250. return 1;
  251. }
  252.  
  253. public OnPlayerEnterCheckpoint(playerid)
  254. {
  255. return 1;
  256. }
  257.  
  258. public OnPlayerLeaveCheckpoint(playerid)
  259. {
  260. return 1;
  261. }
  262.  
  263. public OnPlayerEnterRaceCheckpoint(playerid)
  264. {
  265. return 1;
  266. }
  267.  
  268. public OnPlayerLeaveRaceCheckpoint(playerid)
  269. {
  270. return 1;
  271. }
  272.  
  273. public OnRconCommand(cmd[])
  274. {
  275. return 1;
  276. }
  277.  
  278. public OnPlayerRequestSpawn(playerid)
  279. {
  280. return 1;
  281. }
  282.  
  283. public OnObjectMoved(objectid)
  284. {
  285. return 1;
  286. }
  287.  
  288. public OnPlayerObjectMoved(playerid, objectid)
  289. {
  290. return 1;
  291. }
  292.  
  293. public OnPlayerPickUpPickup(playerid, pickupid)
  294. {
  295. return 1;
  296. }
  297.  
  298. public OnVehicleMod(playerid, vehicleid, componentid)
  299. {
  300. return 1;
  301. }
  302.  
  303. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  304. {
  305. return 1;
  306. }
  307.  
  308. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  309. {
  310. return 1;
  311. }
  312.  
  313. public OnPlayerSelectedMenuRow(playerid, row)
  314. {
  315. return 1;
  316. }
  317.  
  318. public OnPlayerExitedMenu(playerid)
  319. {
  320. return 1;
  321. }
  322.  
  323. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  324. {
  325. return 1;
  326. }
  327.  
  328. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  329. {
  330. return 1;
  331. }
  332.  
  333. public OnRconLoginAttempt(ip[], password[], success)
  334. {
  335. return 1;
  336. }
  337.  
  338. public OnPlayerUpdate(playerid)
  339. {
  340. return 1;
  341. }
  342.  
  343. public OnPlayerStreamIn(playerid, forplayerid)
  344. {
  345. return 1;
  346. }
  347.  
  348. public OnPlayerStreamOut(playerid, forplayerid)
  349. {
  350. return 1;
  351. }
  352.  
  353. public OnVehicleStreamIn(vehicleid, forplayerid)
  354. {
  355. return 1;
  356. }
  357.  
  358. public OnVehicleStreamOut(vehicleid, forplayerid)
  359. {
  360. return 1;
  361. }
  362.  
  363. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  364. {
  365. return 1;
  366. }
  367.  
  368. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  369. {
  370. return 1;
  371. }
  372. ocmd:werke(playerid,params[])
  373. {
  374. SendClientMessage(playerid,Blau,"Advent Map: /advent");
  375. SendClientMessage(playerid,Blau,"Airport Map: /airport");
  376. SendClientMessage(playerid,Blau,"Ganghaus Map: /ganghaus");
  377. SendClientMessage(playerid,Grau,"Es kommen noch weitere Maps");
  378. return 1;
  379. }
  380. ocmd:advent(playerid,params[])
  381. {
  382. SetPlayerPos(playerid, 241.8955,-1838.3055,3.7453);
  383. SetPlayerInterior(playerid, 0);
  384. return SendClientMessage(playerid,Grau,"Du hast dich zur Advent Map geportet!");
  385. }
  386. ocmd:airport(playerid,params[])
  387. {
  388. SetPlayerPos(playerid, 2791.6528,-2561.2771,13.6311);
  389. SetPlayerInterior(playerid, 0);
  390. return SendClientMessage(playerid,Grau,"Du hast dich zur Airport Map geportet!");
  391. }
  392. ocmd:ganghaus(playerid,params[])
  393. {
  394. SetPlayerPos(playerid, 960.5604,-52.6111,1001.1172);
  395. SetPlayerInterior(playerid, 3);
  396. return SendClientMessage(playerid,Grau,"Du hast dich zur Ganghaus Map geportet!");
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419. //SSCANF CODE
  420. /*----------------------------------------------------------------------------*-
  421. Function:
  422. sscanf
  423. Params:
  424. string[] - String to extract parameters from.
  425. format[] - Parameter types to get.
  426. {Float,_}:... - Data return variables.
  427. Return:
  428. 0 - Successful, not 0 - fail.
  429. Notes:
  430. A fail is either insufficient variables to store the data or insufficient
  431. data for the format string - excess data is disgarded.
  432.  
  433. A string in the middle of the input data is extracted as a single word, a
  434. string at the end of the data collects all remaining text.
  435.  
  436. The format codes are:
  437.  
  438. c - A character.
  439. d, i - An integer.
  440. h, x - A hex number (e.g. a colour).
  441. f - A float.
  442. s - A string.
  443. z - An optional string.
  444. pX - An additional delimiter where X is another character.
  445. '' - Encloses a litteral string to locate.
  446. u - User, takes a name, part of a name or an id and returns the id if they're connected.
  447.  
  448. Now has IsNumeric integrated into the code.
  449.  
  450. Added additional delimiters in the form of all whitespace and an
  451. optioanlly specified one in the format string.
  452. -*----------------------------------------------------------------------------*/
  453.  
  454. stock sscanf(string[], format[], {Float,_}:...)
  455. {
  456. #if defined isnull
  457. if (isnull(string))
  458. #else
  459. if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  460. #endif
  461. {
  462. return format[0];
  463. }
  464. #pragma tabsize 4
  465. new
  466. formatPos = 0,
  467. stringPos = 0,
  468. paramPos = 2,
  469. paramCount = numargs(),
  470. delim = ' ';
  471. while (string[stringPos] && string[stringPos] <= ' ')
  472. {
  473. stringPos++;
  474. }
  475. while (paramPos < paramCount && string[stringPos])
  476. {
  477. switch (format[formatPos++])
  478. {
  479. case '\0':
  480. {
  481. return 0;
  482. }
  483. case 'i', 'd':
  484. {
  485. new
  486. neg = 1,
  487. num = 0,
  488. ch = string[stringPos];
  489. if (ch == '-')
  490. {
  491. neg = -1;
  492. ch = string[++stringPos];
  493. }
  494. do
  495. {
  496. stringPos++;
  497. if ('0' <= ch <= '9')
  498. {
  499. num = (num * 10) + (ch - '0');
  500. }
  501. else
  502. {
  503. return -1;
  504. }
  505. }
  506. while ((ch = string[stringPos]) > ' ' && ch != delim);
  507. setarg(paramPos, 0, num * neg);
  508. }
  509. case 'h', 'x':
  510. {
  511. new
  512. num = 0,
  513. ch = string[stringPos];
  514. do
  515. {
  516. stringPos++;
  517. switch (ch)
  518. {
  519. case 'x', 'X':
  520. {
  521. num = 0;
  522. continue;
  523. }
  524. case '0' .. '9':
  525. {
  526. num = (num << 4) | (ch - '0');
  527. }
  528. case 'a' .. 'f':
  529. {
  530. num = (num << 4) | (ch - ('a' - 10));
  531. }
  532. case 'A' .. 'F':
  533. {
  534. num = (num << 4) | (ch - ('A' - 10));
  535. }
  536. default:
  537. {
  538. return -1;
  539. }
  540. }
  541. }
  542. while ((ch = string[stringPos]) > ' ' && ch != delim);
  543. setarg(paramPos, 0, num);
  544. }
  545. case 'c':
  546. {
  547. setarg(paramPos, 0, string[stringPos++]);
  548. }
  549. case 'f':
  550. {
  551.  
  552. new changestr[16], changepos = 0, strpos = stringPos;
  553. while(changepos < 16 && string[strpos] && string[strpos] != delim)
  554. {
  555. changestr[changepos++] = string[strpos++];
  556. }
  557. changestr[changepos] = '\0';
  558. setarg(paramPos,0,_:floatstr(changestr));
  559. }
  560. case 'p':
  561. {
  562. delim = format[formatPos++];
  563. continue;
  564. }
  565. case '\'':
  566. {
  567. new
  568. end = formatPos - 1,
  569. ch;
  570. while ((ch = format[++end]) && ch != '\'') {}
  571. if (!ch)
  572. {
  573. return -1;
  574. }
  575. format[end] = '\0';
  576. if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  577. {
  578. if (format[end + 1])
  579. {
  580. return -1;
  581. }
  582. return 0;
  583. }
  584. format[end] = '\'';
  585. stringPos = ch + (end - formatPos);
  586. formatPos = end + 1;
  587. }
  588. case 'u':
  589. {
  590. new
  591. end = stringPos - 1,
  592. id = 0,
  593. bool:num = true,
  594. ch;
  595. while ((ch = string[++end]) && ch != delim)
  596. {
  597. if (num)
  598. {
  599. if ('0' <= ch <= '9')
  600. {
  601. id = (id * 10) + (ch - '0');
  602. }
  603. else
  604. {
  605. num = false;
  606. }
  607. }
  608. }
  609. if (num && IsPlayerConnected(id))
  610. {
  611. setarg(paramPos, 0, id);
  612. }
  613. else
  614. {
  615. #if !defined foreach
  616. #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  617. #define __SSCANF_FOREACH__
  618. #endif
  619. string[end] = '\0';
  620. num = false;
  621. new
  622. name[MAX_PLAYER_NAME];
  623. id = end - stringPos;
  624. foreach (Player, playerid)
  625. {
  626. GetPlayerName(playerid, name, sizeof (name));
  627. if (!strcmp(name, string[stringPos], true, id))
  628. {
  629. setarg(paramPos, 0, playerid);
  630. num = true;
  631. break;
  632. }
  633. }
  634. if (!num)
  635. {
  636. setarg(paramPos, 0, INVALID_PLAYER_ID);
  637. }
  638. string[end] = ch;
  639. #if defined __SSCANF_FOREACH__
  640. #undef foreach
  641. #undef __SSCANF_FOREACH__
  642. #endif
  643. }
  644. stringPos = end;
  645. }
  646. case 's', 'z':
  647. {
  648. new
  649. i = 0,
  650. ch;
  651. if (format[formatPos])
  652. {
  653. while ((ch = string[stringPos++]) && ch != delim)
  654. {
  655. setarg(paramPos, i++, ch);
  656. }
  657. if (!i)
  658. {
  659. return -1;
  660. }
  661. }
  662. else
  663. {
  664. while ((ch = string[stringPos++]))
  665. {
  666. setarg(paramPos, i++, ch);
  667. }
  668. }
  669. stringPos--;
  670. setarg(paramPos, i, '\0');
  671. }
  672. default:
  673. {
  674. continue;
  675. }
  676. }
  677. while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  678. {
  679. stringPos++;
  680. }
  681. while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  682. {
  683. stringPos++;
  684. }
  685. paramPos++;
  686. }
  687. do
  688. {
  689. if ((delim = format[formatPos++]) > ' ')
  690. {
  691. if (delim == '\'')
  692. {
  693. while ((delim = format[formatPos++]) && delim != '\'') {}
  694. }
  695. else if (delim != 'z')
  696. {
  697. return delim;
  698. }
  699. }
  700. }
  701. while (delim > ' ');
  702. return 0;
  703. }
Advertisement
Add Comment
Please, Sign In to add comment