Advertisement
Guest User

Miguel

a guest
Feb 4th, 2010
1,168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.39 KB | None | 0 0
  1. /*-------------------------------------------------*
  2. | Sistema de Da�o por Choque o Aceleraci�n Brutal |
  3. | =============================================== |
  4. | Autor: Miguel C. (SAWC) |
  5. | Versi�n: 1.0 |
  6. | Licencia: P�blica. |
  7. *-------------------------------------------------*/
  8.  
  9. /*
  10. Este filterscript contiene un sistema para disminuir la salud del jugador
  11. al momento de un choque o aceleraci�n brutal. Todo lo que est� dentro de
  12. este codigo puede ser modificado, aunque no es recomendable sin saber lo
  13. que se est� haciendo o modificando. Se han dejado una serie de lineas
  14. comentadas (en color verde) las cuales indican muchas cosas importantes
  15. al momento de cambiar o quitar algo, se recomienda leerlas y tratar de
  16. no obviarlas.
  17. */
  18.  
  19. #include <a_samp>
  20.  
  21. #define FILTERSCRIPT
  22.  
  23. #define BLANCO 0xFFFFFFFF
  24. #define VERDE 0x009F38FF
  25. #define AZUL 0x0000E6FF
  26. #define MARRON 0x800000FF
  27. #define ROJO 0xD70000FF
  28. #define GRIS 0xC0C0C0FF
  29. #define NARANJA 0xD56A00FF
  30. #define NEGRO 0x000000FF
  31.  
  32. #define TDC 200 // Intervalo de tiempo en el cual se chequea la aceleraci�n. Se recomienda dejar entre 100 y 300.
  33. #define MAX_ACE 45 // valor m�ximo de aceleraci�n...es decir, despu�s de pasar X m/s el jugador empezar� a perder salud
  34. #define PROPORCION 25 // mientras mayor el valor menor ser� la cantidad de vida que se le quite al jugador a x velocidad (25 = -45/25 == -1.8)
  35. #define EX_MOTOS true // true para que el sistema funcione en las motos tambien y false todo lo contrario
  36.  
  37. #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
  38.  
  39. new
  40. Exepciones[4], // 0 == motos, 1 autos, 2 acuaticos, 3 aereos
  41. Velocimetro[MAX_PLAYERS], // 0 si no quieres que se muestre y 1 si quieres lo contrario
  42. Acelerometro[MAX_PLAYERS], // igual que el anterior
  43. Estado[MAX_PLAYERS], // 0 si el sistema est� activado y 1 si no lo est�.
  44. Float:Velocidad[MAX_PLAYERS][2], // slot 0 para la velocidad inicial y slot 1 para la final.
  45. Text:Textdraw[4]; // 0 = Rapidez, 1 = Aceleraci�n, 2 = Km/h y 3 = m/s
  46.  
  47. forward Chequeo();
  48.  
  49. public OnFilterScriptInit()
  50. {
  51. print(" *-------------------------------------------------*");
  52. print(" | Sistema de Da�o por Choque o Aceleraci�n Brutal |");
  53. print(" | =============================================== |");
  54. print(" | Autor: Miguel C. (SAWC) |");
  55. print(" | Versi�n: 1.0 |");
  56. print(" | Licencia: P�blica |");
  57. print(" *-------------------------------------------------*");
  58.  
  59. Exepciones[0] = EX_MOTOS;
  60.  
  61. SetTimer("Chequeo", TDC, true);
  62.  
  63. Textdraw[0] = TextDrawCreate(61.000000, 288.000000, "0");
  64. TextDrawAlignment(Textdraw[0], 2);
  65. TextDrawBackgroundColor(Textdraw[0], 255);
  66. TextDrawFont(Textdraw[0], 3);
  67. TextDrawLetterSize(Textdraw[0], 0.600000, 2.199999);
  68. TextDrawColor(Textdraw[0], 0xFFFFFFFF);
  69. TextDrawSetOutline(Textdraw[0], 1);
  70. TextDrawSetProportional(Textdraw[0], 1);
  71.  
  72. Textdraw[1] = TextDrawCreate(112.000000, 288.000000, "km/h");
  73. TextDrawAlignment(Textdraw[1], 2);
  74. TextDrawBackgroundColor(Textdraw[1], 255);
  75. TextDrawFont(Textdraw[1], 3);
  76. TextDrawLetterSize(Textdraw[1], 0.600000, 2.199999);
  77. TextDrawColor(Textdraw[1], 0xD56A00FF);
  78. TextDrawSetOutline(Textdraw[1], 1);
  79. TextDrawSetProportional(Textdraw[1], 1);
  80.  
  81. Textdraw[2] = TextDrawCreate(61.000000, 309.000000, "0");
  82. TextDrawAlignment(Textdraw[2], 2);
  83. TextDrawBackgroundColor(Textdraw[2], 255);
  84. TextDrawFont(Textdraw[2], 3);
  85. TextDrawLetterSize(Textdraw[2], 0.600000, 2.199999);
  86. TextDrawColor(Textdraw[2], 0xFFFFFFFF);
  87. TextDrawSetOutline(Textdraw[2], 1);
  88. TextDrawSetProportional(Textdraw[2], 1);
  89.  
  90.  
  91. Textdraw[3] = TextDrawCreate(104.870000, 309.000000, "m/s");
  92. TextDrawAlignment(Textdraw[3], 2);
  93. TextDrawBackgroundColor(Textdraw[3], 255);
  94. TextDrawFont(Textdraw[3], 3);
  95. TextDrawLetterSize(Textdraw[3], 0.579999, 2.200000);
  96. TextDrawColor(Textdraw[3], 0xD56A00FF);
  97. TextDrawSetOutline(Textdraw[3], 1);
  98. TextDrawSetProportional(Textdraw[3], 1);
  99.  
  100. return 1;
  101. }
  102.  
  103. public OnFilterScriptExit()
  104. {
  105. for(new i = 0; i < MAX_PLAYERS; i ++)
  106. {
  107. TextDrawHideForPlayer(i, Textdraw[0]);
  108. TextDrawHideForPlayer(i, Textdraw[1]);
  109. TextDrawHideForPlayer(i, Textdraw[2]);
  110. TextDrawHideForPlayer(i, Textdraw[3]);
  111. }
  112. print(" *----------------------------------------------------------*");
  113. print(" | Cerrando Sistema de Da�o por Choque o Aceleraci�n Brutal |");
  114. print(" *----------------------------------------------------------*");
  115. return 1;
  116. }
  117.  
  118. public Chequeo()
  119. {
  120. for(new i = 0; i < MAX_PLAYERS; i ++)
  121. {
  122. if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))
  123. {
  124. new
  125. Float:x,
  126. Float:y,
  127. Float:z,
  128. string[10],
  129. Float:Aceleracion;
  130.  
  131. GetVehicleVelocity(GetPlayerVehicleID(i), x, y, z);
  132. Velocidad[i][1] = floatdiv(floatsqroot(x*x + y*y + z*z)*200000, 3600);
  133. format(string, sizeof(string), "%.0f", floatdiv(Velocidad[i][1] * 3600, 1000));
  134. TextDrawSetString(Textdraw[0], string);
  135. Aceleracion = floatdiv(Velocidad[i][1] - Velocidad[i][0], floatdiv(TDC, 1000));
  136. if(0 > Aceleracion > -1)
  137. {
  138. if(Aceleracion >= 0.5) format(string, sizeof(string), "%.0f", "1");
  139. else if(Aceleracion <= -0.5) format(string, sizeof(string), "%.0f", "-1");
  140. else format(string, sizeof(string), "%.0f", -1 * Aceleracion);
  141. }
  142. else format(string, sizeof(string), "%.0f", Aceleracion);
  143. TextDrawSetString(Textdraw[2], string);
  144. Velocidad[i][0] = Velocidad[i][1];
  145. if(Exepciones[0] == 1)
  146. {
  147. switch(GetVehicleModel(GetPlayerVehicleID(i)))
  148. {
  149. case 581, 509, 481, 462, 521, 463, 510, 522, 461, 448, 471, 468, 586:
  150. {
  151. return 1; // no funcionara en las motos si EX_MOTOS esta en true
  152. }
  153. }
  154. }
  155. if(Aceleracion > MAX_ACE && Estado[i] == 1)
  156. {
  157. new
  158. Float:acthealth;
  159.  
  160. GetPlayerHealth(i, acthealth);
  161. SetPlayerHealth(i, acthealth - floatdiv(Aceleracion, PROPORCION));
  162. }
  163. if(Aceleracion < -MAX_ACE && Estado[i] == 1)
  164. {
  165. new
  166. Float:acthealth;
  167.  
  168. GetPlayerHealth(i, acthealth);
  169. SetPlayerHealth(i, acthealth - (-1 * floatdiv(Aceleracion, PROPORCION)));
  170. }
  171. }
  172. }
  173. return 1;
  174. }
  175.  
  176. public OnPlayerStateChange(playerid, newstate, oldstate)
  177. {
  178. if(newstate == PLAYER_STATE_ONFOOT) TextDrawHideForPlayer(playerid, Textdraw[0]), TextDrawHideForPlayer(playerid, Textdraw[1]), TextDrawHideForPlayer(playerid, Textdraw[2]), TextDrawHideForPlayer(playerid, Textdraw[3]);
  179. else if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
  180. {
  181. if(Velocimetro[playerid] == 1) TextDrawShowForPlayer(playerid, Textdraw[0]), TextDrawShowForPlayer(playerid, Textdraw[1]);
  182. if(Acelerometro[playerid] == 1) TextDrawShowForPlayer(playerid, Textdraw[2]), TextDrawShowForPlayer(playerid, Textdraw[3]);
  183. }
  184. return 1;
  185. }
  186.  
  187. public OnPlayerCommandText(playerid, cmdtext[])
  188. {
  189. dcmd(mi, 2, cmdtext);
  190. return 0;
  191. }
  192.  
  193. public OnPlayerDeath(playerid, killerid, reason)
  194. {
  195. TextDrawHideForPlayer(playerid, Textdraw[0]);
  196. TextDrawHideForPlayer(playerid, Textdraw[1]);
  197. TextDrawHideForPlayer(playerid, Textdraw[2]);
  198. TextDrawHideForPlayer(playerid, Textdraw[3]);
  199. return 1;
  200. }
  201.  
  202. dcmd_mi(playerid, params[])
  203. {
  204. new
  205. sub[15],
  206. subpar[11];
  207.  
  208. if(sscanf(params, "s ", sub)) return SendClientMessage(playerid, ROJO, "Uso: /mi [ velocimetro / acelerometro / sda ] [ activar / desactivar ]");
  209.  
  210. else if(strcmp(sub, "velocimetro", true) == 0)
  211. {
  212. if(sscanf(params, "ss", sub, subpar)) return SendClientMessage(playerid, ROJO, "Uso: /mi velocimetro [ activar / desactivar ]");
  213. else if(strcmp(subpar, "activar", true) == 0)
  214. {
  215. if(Velocimetro[playerid] == 1) return SendClientMessage(playerid, ROJO, "El veloc�metro ya esta activado!");
  216. else
  217. {
  218. if(IsPlayerInAnyVehicle(playerid)) TextDrawShowForPlayer(playerid, Textdraw[0]), TextDrawShowForPlayer(playerid, Textdraw[1]);
  219. Velocimetro[playerid] = 1;
  220. SendClientMessage(playerid, VERDE, "Has activado el veloc�metro!");
  221. }
  222. }
  223. else if(strcmp(subpar, "desactivar", true) == 0)
  224. {
  225. if(Velocimetro[playerid] == 0) return SendClientMessage(playerid, ROJO, "El veloc�metro ya esta desactivado!");
  226. else
  227. {
  228. Velocimetro[playerid] = 0;
  229. SendClientMessage(playerid, VERDE, "Has desactivado el veloc�metro!");
  230. TextDrawHideForPlayer(playerid, Textdraw[0]);
  231. TextDrawHideForPlayer(playerid, Textdraw[1]);
  232. }
  233. }
  234. else SendClientMessage(playerid, ROJO, "Uso: /mi velocimetro [ activar / desactivar ]");
  235. }
  236.  
  237. else if(strcmp(sub, "acelerometro", true) == 0)
  238. {
  239. if(sscanf(params, "ss", sub, subpar)) return SendClientMessage(playerid, ROJO, "Uso: /mi acelerometro [ activar / desactivar ]");
  240. else if(strcmp(subpar, "activar", true) == 0)
  241. {
  242. if(Acelerometro[playerid] == 1) return SendClientMessage(playerid, ROJO, "El aceler�metro ya esta activado!");
  243. else
  244. {
  245. if(IsPlayerInAnyVehicle(playerid)) TextDrawShowForPlayer(playerid, Textdraw[2]), TextDrawShowForPlayer(playerid, Textdraw[3]);
  246. Acelerometro[playerid] = 1;
  247. SendClientMessage(playerid, VERDE, "Has activado el aceler�metro!");
  248. }
  249. }
  250. else if(strcmp(subpar, "desactivar", true) == 0)
  251. {
  252. if(Acelerometro[playerid] == 0) return SendClientMessage(playerid, ROJO, "El aceler�metro ya esta desactivado!");
  253. else
  254. {
  255. Acelerometro[playerid] = 0;
  256. SendClientMessage(playerid, VERDE, "Has desactivado el aceler�metro!");
  257. TextDrawHideForPlayer(playerid, Textdraw[2]);
  258. TextDrawHideForPlayer(playerid, Textdraw[3]);
  259. }
  260. }
  261. else SendClientMessage(playerid, ROJO, "Uso: /mi acelerometro [ activar / desactivar ]");
  262. }
  263.  
  264. else if(strcmp(sub, "sda", true) == 0)
  265. {
  266. if(sscanf(params, "ss", sub, subpar)) return SendClientMessage(playerid, ROJO, "Uso: /mi sda [ activar / desactivar ]");
  267. else if(strcmp(subpar, "activar", true) == 0)
  268. {
  269. if(Estado[playerid] == 1) return SendClientMessage(playerid, ROJO, "El sistema de aceleraci�n ya esta activado!");
  270. else
  271. {
  272. Estado[playerid] = 1;
  273. SendClientMessage(playerid, VERDE, "Has activado el sistema de aceleraci�n!");
  274. }
  275. }
  276. else if(strcmp(subpar, "desactivar", true) == 0)
  277. {
  278. if(Estado[playerid] == 0) return SendClientMessage(playerid, ROJO, "El sistema de aceleraci�n ya esta desactivado!");
  279. else
  280. {
  281. Estado[playerid] = 0;
  282. SendClientMessage(playerid, VERDE, "Has desactivado el sistema de aceleraci�n!");
  283. }
  284. }
  285. else SendClientMessage(playerid, ROJO, "Uso: /mi sda [ activar / desactivar ]");
  286. }
  287. else SendClientMessage(playerid, ROJO, "Uso: /mi [ velocimetro / acelerometro / sda ] [ activar / desactivar ]");
  288. return 1;
  289. }
  290.  
  291. stock sscanf(string[], format[], {Float,_}:...)
  292. {
  293. #if defined isnull
  294. if (isnull(string))
  295. #else
  296. if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  297. #endif
  298. {
  299. return format[0];
  300. }
  301. #pragma tabsize 4
  302. new
  303. formatPos = 0,
  304. stringPos = 0,
  305. paramPos = 2,
  306. paramCount = numargs(),
  307. delim = ' ';
  308. while (string[stringPos] && string[stringPos] <= ' ')
  309. {
  310. stringPos++;
  311. }
  312. while (paramPos < paramCount && string[stringPos])
  313. {
  314. switch (format[formatPos++])
  315. {
  316. case '\0':
  317. {
  318. return 0;
  319. }
  320. case 'i', 'd':
  321. {
  322. new
  323. neg = 1,
  324. num = 0,
  325. ch = string[stringPos];
  326. if (ch == '-')
  327. {
  328. neg = -1;
  329. ch = string[++stringPos];
  330. }
  331. do
  332. {
  333. stringPos++;
  334. if ('0' <= ch <= '9')
  335. {
  336. num = (num * 10) + (ch - '0');
  337. }
  338. else
  339. {
  340. return -1;
  341. }
  342. }
  343. while ((ch = string[stringPos]) > ' ' && ch != delim);
  344. setarg(paramPos, 0, num * neg);
  345. }
  346. case 'h', 'x':
  347. {
  348. new
  349. num = 0,
  350. ch = string[stringPos];
  351. do
  352. {
  353. stringPos++;
  354. switch (ch)
  355. {
  356. case 'x', 'X':
  357. {
  358. num = 0;
  359. continue;
  360. }
  361. case '0' .. '9':
  362. {
  363. num = (num << 4) | (ch - '0');
  364. }
  365. case 'a' .. 'f':
  366. {
  367. num = (num << 4) | (ch - ('a' - 10));
  368. }
  369. case 'A' .. 'F':
  370. {
  371. num = (num << 4) | (ch - ('A' - 10));
  372. }
  373. default:
  374. {
  375. return -1;
  376. }
  377. }
  378. }
  379. while ((ch = string[stringPos]) > ' ' && ch != delim);
  380. setarg(paramPos, 0, num);
  381. }
  382. case 'c':
  383. {
  384. setarg(paramPos, 0, string[stringPos++]);
  385. }
  386. case 'f':
  387. {
  388.  
  389. new changestr[16], changepos = 0, strpos = stringPos;
  390. while(changepos < 16 && string[strpos] && string[strpos] != delim)
  391. {
  392. changestr[changepos++] = string[strpos++];
  393. }
  394. changestr[changepos] = '\0';
  395. setarg(paramPos,0,_:floatstr(changestr));
  396. }
  397. case 'p':
  398. {
  399. delim = format[formatPos++];
  400. continue;
  401. }
  402. case '\'':
  403. {
  404. new
  405. end = formatPos - 1,
  406. ch;
  407. while ((ch = format[++end]) && ch != '\'') {}
  408. if (!ch)
  409. {
  410. return -1;
  411. }
  412. format[end] = '\0';
  413. if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  414. {
  415. if (format[end + 1])
  416. {
  417. return -1;
  418. }
  419. return 0;
  420. }
  421. format[end] = '\'';
  422. stringPos = ch + (end - formatPos);
  423. formatPos = end + 1;
  424. }
  425. case 'u':
  426. {
  427. new
  428. end = stringPos - 1,
  429. id = 0,
  430. bool:num = true,
  431. ch;
  432. while ((ch = string[++end]) && ch != delim)
  433. {
  434. if (num)
  435. {
  436. if ('0' <= ch <= '9')
  437. {
  438. id = (id * 10) + (ch - '0');
  439. }
  440. else
  441. {
  442. num = false;
  443. }
  444. }
  445. }
  446. if (num && IsPlayerConnected(id))
  447. {
  448. setarg(paramPos, 0, id);
  449. }
  450. else
  451. {
  452. #if !defined foreach
  453. #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  454. #define __SSCANF_FOREACH__
  455. #endif
  456. string[end] = '\0';
  457. num = false;
  458. new
  459. name[MAX_PLAYER_NAME];
  460. id = end - stringPos;
  461. foreach (Player, playerid)
  462. {
  463. GetPlayerName(playerid, name, sizeof (name));
  464. if (!strcmp(name, string[stringPos], true, id))
  465. {
  466. setarg(paramPos, 0, playerid);
  467. num = true;
  468. break;
  469. }
  470. }
  471. if (!num)
  472. {
  473. setarg(paramPos, 0, INVALID_PLAYER_ID);
  474. }
  475. string[end] = ch;
  476. #if defined __SSCANF_FOREACH__
  477. #undef foreach
  478. #undef __SSCANF_FOREACH__
  479. #endif
  480. }
  481. stringPos = end;
  482. }
  483. case 's', 'z':
  484. {
  485. new
  486. i = 0,
  487. ch;
  488. if (format[formatPos])
  489. {
  490. while ((ch = string[stringPos++]) && ch != delim)
  491. {
  492. setarg(paramPos, i++, ch);
  493. }
  494. if (!i)
  495. {
  496. return -1;
  497. }
  498. }
  499. else
  500. {
  501. while ((ch = string[stringPos++]))
  502. {
  503. setarg(paramPos, i++, ch);
  504. }
  505. }
  506. stringPos--;
  507. setarg(paramPos, i, '\0');
  508. }
  509. default:
  510. {
  511. continue;
  512. }
  513. }
  514. while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  515. {
  516. stringPos++;
  517. }
  518. while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  519. {
  520. stringPos++;
  521. }
  522. paramPos++;
  523. }
  524. do
  525. {
  526. if ((delim = format[formatPos++]) > ' ')
  527. {
  528. if (delim == '\'')
  529. {
  530. while ((delim = format[formatPos++]) && delim != '\'') {}
  531. }
  532. else if (delim != 'z')
  533. {
  534. return delim;
  535. }
  536. }
  537. }
  538. while (delim > ' ');
  539. return 0;
  540. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement