Advertisement
Guest User

bVehicle Saving System

a guest
Jul 19th, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.85 KB | None | 0 0
  1. /* ------------------------- */
  2. /* bVehicle Saving System */
  3. /* Erstellt am 19 Juli 2012 */
  4. /* von [RcS]Big_Ben */
  5. /* ------------------------- */
  6. /* Falls im Gamemode der SSCANF Code enthalten ist einfach den SSCANF Code in der Include entfernen ! */
  7. /* ------------------------- */
  8.  
  9. #include <a_samp>
  10. #include <zcmd>
  11.  
  12. new bcar,
  13. bvID,
  14. bc1,
  15. bc2,
  16. Float:bx,
  17. Float:by,
  18. Float:bz,
  19. Float:ba,
  20. bstr[258];
  21.  
  22. CMD:bv(playerid,params[])
  23. {
  24. if(IsPlayerConnected(playerid) || !IsPlayerNPC(playerid))
  25. {
  26. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,-1,"Fehler : Du bist nicht als RCON Admin eingeloggt !");
  27. if(sscanf(params,"ddd",bvID,bc1,bc2)) return SendClientMessage(playerid,-1,"Benutze : /bv [Vehicle ID] [Farbe 1] [Farbe 2]");
  28. if(bvID < 400 || bvID > 611) return SendClientMessage(playerid,-1,"Fehler : Die Vehicle ID darf nicht unter 400 oder über 611 liegen !");
  29. if(bc1 < 0 || bc1 > 252) return SendClientMessage(playerid,-1,"Fehler : Die Farbe 1 kann nicht niedriger als 0 und nicht größer als 252 sein !");
  30. if(bc2 < 0 || bc2 > 252) return SendClientMessage(playerid,-1,"Fehler : Die Farbe 2 kann nicht niedriger als 0 und nicht größer als 252 sein !");
  31. GetPlayerPos(playerid,bx,by,bz);
  32. GetPlayerFacingAngle(playerid,ba);
  33. bcar = CreateVehicle(bvID,bx+2,by,bz,ba,bc1,bc2,-1);
  34. }
  35. return 1;
  36. }
  37. CMD:bs(playerid,params[])
  38. {
  39. if(IsPlayerConnected(playerid) || !IsPlayerNPC(playerid))
  40. {
  41. if(GetPlayerVehicleID(playerid) == bcar)
  42. {
  43. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,-1,"Fehler : Du bist nicht als RCON Admin eingeloggt !");
  44. new File:autofile=fopen("savedautos.txt", io_append);
  45. GetPlayerPos(playerid,bx,by,bz);
  46. GetPlayerFacingAngle(playerid,ba);
  47. format(bstr, sizeof(bstr), "CreateVehicle(%d, %f, %f, %f, %f, %d, %d, -1);\r\n", bvID, bx, by, bz, ba, bc1, bc2);
  48. fwrite(autofile, bstr);
  49. fclose(autofile);
  50. print(bstr);
  51. SendClientMessage(playerid,-1,"Vehicle wurde erfolgreich in der savedautos.txt gespeichert !");
  52. }
  53. }
  54. return 1;
  55. }
  56.  
  57. stock sscanf(sstring[], format[], {Float,_}:...)
  58. {
  59. #if defined isnull
  60. if (isnull(sstring))
  61. #else
  62. if (sstring[0] == 0 || (sstring[0] == 1 && sstring[1] == 0))
  63. #endif
  64. {
  65. return format[0];
  66. }
  67. #pragma tabsize 4
  68. new
  69. formatPos = 0,
  70. sstringPos = 0,
  71. paramPos = 2,
  72. paramCount = numargs(),
  73. delim = ' ';
  74. while (sstring[sstringPos] && sstring[sstringPos] <= ' ')
  75. {
  76. sstringPos++;
  77. }
  78. while (paramPos < paramCount && sstring[sstringPos])
  79. {
  80. switch (format[formatPos++])
  81. {
  82. case '\0':
  83. {
  84. return 0;
  85. }
  86. case 'i', 'd':
  87. {
  88. new
  89. neg = 1,
  90. num = 0,
  91. ch = sstring[sstringPos];
  92. if (ch == '-')
  93. {
  94. neg = -1;
  95. ch = sstring[++sstringPos];
  96. }
  97. do
  98. {
  99. sstringPos++;
  100. if ('0' <= ch <= '9')
  101. {
  102. num = (num * 10) + (ch - '0');
  103. }
  104. else
  105. {
  106. return -1;
  107. }
  108. }
  109. while ((ch = sstring[sstringPos]) > ' ' && ch != delim);
  110. setarg(paramPos, 0, num * neg);
  111. }
  112. case 'h', 'x':
  113. {
  114. new
  115. num = 0,
  116. ch = sstring[sstringPos];
  117. do
  118. {
  119. sstringPos++;
  120. switch (ch)
  121. {
  122. case 'x', 'X':
  123. {
  124. num = 0;
  125. continue;
  126. }
  127. case '0' .. '9':
  128. {
  129. num = (num << 4) | (ch - '0');
  130. }
  131. case 'a' .. 'f':
  132. {
  133. num = (num << 4) | (ch - ('a' - 10));
  134. }
  135. case 'A' .. 'F':
  136. {
  137. num = (num << 4) | (ch - ('A' - 10));
  138. }
  139. default:
  140. {
  141. return -1;
  142. }
  143. }
  144. }
  145. while ((ch = sstring[sstringPos]) > ' ' && ch != delim);
  146. setarg(paramPos, 0, num);
  147. }
  148. case 'c':
  149. {
  150. setarg(paramPos, 0, sstring[sstringPos++]);
  151. }
  152. case 'f':
  153. {
  154.  
  155. new changestr[16], changepos = 0, strpos = sstringPos;
  156. while(changepos < 16 && sstring[strpos] && sstring[strpos] != delim)
  157. {
  158. changestr[changepos++] = sstring[strpos++];
  159. }
  160. changestr[changepos] = '\0';
  161. setarg(paramPos,0,_:floatstr(changestr));
  162. }
  163. case 'p':
  164. {
  165. delim = format[formatPos++];
  166. continue;
  167. }
  168. case '\'':
  169. {
  170. new
  171. end = formatPos - 1,
  172. ch;
  173. while ((ch = format[++end]) && ch != '\'') {}
  174. if (!ch)
  175. {
  176. return -1;
  177. }
  178. format[end] = '\0';
  179. if ((ch = strfind(sstring, format[formatPos], false, sstringPos)) == -1)
  180. {
  181. if (format[end + 1])
  182. {
  183. return -1;
  184. }
  185. return 0;
  186. }
  187. format[end] = '\'';
  188. sstringPos = ch + (end - formatPos);
  189. formatPos = end + 1;
  190. }
  191. case 'u':
  192. {
  193. new
  194. end = sstringPos - 1,
  195. id = 0,
  196. bool:num = true,
  197. ch;
  198. while ((ch = sstring[++end]) && ch != delim)
  199. {
  200. if (num)
  201. {
  202. if ('0' <= ch <= '9')
  203. {
  204. id = (id * 10) + (ch - '0');
  205. }
  206. else
  207. {
  208. num = false;
  209. }
  210. }
  211. }
  212. if (num && IsPlayerConnected(id))
  213. {
  214. setarg(paramPos, 0, id);
  215. }
  216. else
  217. {
  218. #if !defined foreach
  219. #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  220. #define __SSCANF_FOREACH__
  221. #endif
  222. sstring[end] = '\0';
  223. num = false;
  224. new
  225. name[MAX_PLAYER_NAME];
  226. id = end - sstringPos;
  227. foreach (Player, playerid)
  228. {
  229. GetPlayerName(playerid, name, sizeof (name));
  230. if (!strcmp(name, sstring[sstringPos], true, id))
  231. {
  232. setarg(paramPos, 0, playerid);
  233. num = true;
  234. break;
  235. }
  236. }
  237. if (!num)
  238. {
  239. setarg(paramPos, 0, INVALID_PLAYER_ID);
  240. }
  241. sstring[end] = ch;
  242. #if defined __SSCANF_FOREACH__
  243. #undef foreach
  244. #undef __SSCANF_FOREACH__
  245. #endif
  246. }
  247. sstringPos = end;
  248. }
  249. case 's', 'z':
  250. {
  251. new
  252. i = 0,
  253. ch;
  254. if (format[formatPos])
  255. {
  256. while ((ch = sstring[sstringPos++]) && ch != delim)
  257. {
  258. setarg(paramPos, i++, ch);
  259. }
  260. if (!i)
  261. {
  262. return -1;
  263. }
  264. }
  265. else
  266. {
  267. while ((ch = sstring[sstringPos++]))
  268. {
  269. setarg(paramPos, i++, ch);
  270. }
  271. }
  272. sstringPos--;
  273. setarg(paramPos, i, '\0');
  274. }
  275. default:
  276. {
  277. continue;
  278. }
  279. }
  280. while (sstring[sstringPos] && sstring[sstringPos] != delim && sstring[sstringPos] > ' ')
  281. {
  282. sstringPos++;
  283. }
  284. while (sstring[sstringPos] && (sstring[sstringPos] == delim || sstring[sstringPos] <= ' '))
  285. {
  286. sstringPos++;
  287. }
  288. paramPos++;
  289. }
  290. do
  291. {
  292. if ((delim = format[formatPos++]) > ' ')
  293. {
  294. if (delim == '\'')
  295. {
  296. while ((delim = format[formatPos++]) && delim != '\'') {}
  297. }
  298. else if (delim != 'z')
  299. {
  300. return delim;
  301. }
  302. }
  303. }
  304. while (delim > ' ');
  305. return 0;
  306. }
  307.  
  308. /* ------------------------- */
  309. #define Copyright 2012 by [RcS]Big_Ben
  310. /* ------------------------- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement