Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*-------------------------------------------------*
- | Sistema de Da�o por Choque o Aceleraci�n Brutal |
- | =============================================== |
- | Autor: Miguel C. (SAWC) |
- | Versi�n: 1.0 |
- | Licencia: P�blica. |
- *-------------------------------------------------*/
- /*
- Este filterscript contiene un sistema para disminuir la salud del jugador
- al momento de un choque o aceleraci�n brutal. Todo lo que est� dentro de
- este codigo puede ser modificado, aunque no es recomendable sin saber lo
- que se est� haciendo o modificando. Se han dejado una serie de lineas
- comentadas (en color verde) las cuales indican muchas cosas importantes
- al momento de cambiar o quitar algo, se recomienda leerlas y tratar de
- no obviarlas.
- */
- #include <a_samp>
- #define FILTERSCRIPT
- #define BLANCO 0xFFFFFFFF
- #define VERDE 0x009F38FF
- #define AZUL 0x0000E6FF
- #define MARRON 0x800000FF
- #define ROJO 0xD70000FF
- #define GRIS 0xC0C0C0FF
- #define NARANJA 0xD56A00FF
- #define NEGRO 0x000000FF
- #define TDC 200 // Intervalo de tiempo en el cual se chequea la aceleraci�n. Se recomienda dejar entre 100 y 300.
- #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
- #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)
- #define EX_MOTOS true // true para que el sistema funcione en las motos tambien y false todo lo contrario
- #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
- new
- Exepciones[4], // 0 == motos, 1 autos, 2 acuaticos, 3 aereos
- Velocimetro[MAX_PLAYERS], // 0 si no quieres que se muestre y 1 si quieres lo contrario
- Acelerometro[MAX_PLAYERS], // igual que el anterior
- Estado[MAX_PLAYERS], // 0 si el sistema est� activado y 1 si no lo est�.
- Float:Velocidad[MAX_PLAYERS][2], // slot 0 para la velocidad inicial y slot 1 para la final.
- Text:Textdraw[4]; // 0 = Rapidez, 1 = Aceleraci�n, 2 = Km/h y 3 = m/s
- forward Chequeo();
- public OnFilterScriptInit()
- {
- print(" *-------------------------------------------------*");
- print(" | Sistema de Da�o por Choque o Aceleraci�n Brutal |");
- print(" | =============================================== |");
- print(" | Autor: Miguel C. (SAWC) |");
- print(" | Versi�n: 1.0 |");
- print(" | Licencia: P�blica |");
- print(" *-------------------------------------------------*");
- Exepciones[0] = EX_MOTOS;
- SetTimer("Chequeo", TDC, true);
- Textdraw[0] = TextDrawCreate(61.000000, 288.000000, "0");
- TextDrawAlignment(Textdraw[0], 2);
- TextDrawBackgroundColor(Textdraw[0], 255);
- TextDrawFont(Textdraw[0], 3);
- TextDrawLetterSize(Textdraw[0], 0.600000, 2.199999);
- TextDrawColor(Textdraw[0], 0xFFFFFFFF);
- TextDrawSetOutline(Textdraw[0], 1);
- TextDrawSetProportional(Textdraw[0], 1);
- Textdraw[1] = TextDrawCreate(112.000000, 288.000000, "km/h");
- TextDrawAlignment(Textdraw[1], 2);
- TextDrawBackgroundColor(Textdraw[1], 255);
- TextDrawFont(Textdraw[1], 3);
- TextDrawLetterSize(Textdraw[1], 0.600000, 2.199999);
- TextDrawColor(Textdraw[1], 0xD56A00FF);
- TextDrawSetOutline(Textdraw[1], 1);
- TextDrawSetProportional(Textdraw[1], 1);
- Textdraw[2] = TextDrawCreate(61.000000, 309.000000, "0");
- TextDrawAlignment(Textdraw[2], 2);
- TextDrawBackgroundColor(Textdraw[2], 255);
- TextDrawFont(Textdraw[2], 3);
- TextDrawLetterSize(Textdraw[2], 0.600000, 2.199999);
- TextDrawColor(Textdraw[2], 0xFFFFFFFF);
- TextDrawSetOutline(Textdraw[2], 1);
- TextDrawSetProportional(Textdraw[2], 1);
- Textdraw[3] = TextDrawCreate(104.870000, 309.000000, "m/s");
- TextDrawAlignment(Textdraw[3], 2);
- TextDrawBackgroundColor(Textdraw[3], 255);
- TextDrawFont(Textdraw[3], 3);
- TextDrawLetterSize(Textdraw[3], 0.579999, 2.200000);
- TextDrawColor(Textdraw[3], 0xD56A00FF);
- TextDrawSetOutline(Textdraw[3], 1);
- TextDrawSetProportional(Textdraw[3], 1);
- return 1;
- }
- public OnFilterScriptExit()
- {
- for(new i = 0; i < MAX_PLAYERS; i ++)
- {
- TextDrawHideForPlayer(i, Textdraw[0]);
- TextDrawHideForPlayer(i, Textdraw[1]);
- TextDrawHideForPlayer(i, Textdraw[2]);
- TextDrawHideForPlayer(i, Textdraw[3]);
- }
- print(" *----------------------------------------------------------*");
- print(" | Cerrando Sistema de Da�o por Choque o Aceleraci�n Brutal |");
- print(" *----------------------------------------------------------*");
- return 1;
- }
- public Chequeo()
- {
- for(new i = 0; i < MAX_PLAYERS; i ++)
- {
- if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))
- {
- new
- Float:x,
- Float:y,
- Float:z,
- string[10],
- Float:Aceleracion;
- GetVehicleVelocity(GetPlayerVehicleID(i), x, y, z);
- Velocidad[i][1] = floatdiv(floatsqroot(x*x + y*y + z*z)*200000, 3600);
- format(string, sizeof(string), "%.0f", floatdiv(Velocidad[i][1] * 3600, 1000));
- TextDrawSetString(Textdraw[0], string);
- Aceleracion = floatdiv(Velocidad[i][1] - Velocidad[i][0], floatdiv(TDC, 1000));
- if(0 > Aceleracion > -1)
- {
- if(Aceleracion >= 0.5) format(string, sizeof(string), "%.0f", "1");
- else if(Aceleracion <= -0.5) format(string, sizeof(string), "%.0f", "-1");
- else format(string, sizeof(string), "%.0f", -1 * Aceleracion);
- }
- else format(string, sizeof(string), "%.0f", Aceleracion);
- TextDrawSetString(Textdraw[2], string);
- Velocidad[i][0] = Velocidad[i][1];
- if(Exepciones[0] == 1)
- {
- switch(GetVehicleModel(GetPlayerVehicleID(i)))
- {
- case 581, 509, 481, 462, 521, 463, 510, 522, 461, 448, 471, 468, 586:
- {
- return 1; // no funcionara en las motos si EX_MOTOS esta en true
- }
- }
- }
- if(Aceleracion > MAX_ACE && Estado[i] == 1)
- {
- new
- Float:acthealth;
- GetPlayerHealth(i, acthealth);
- SetPlayerHealth(i, acthealth - floatdiv(Aceleracion, PROPORCION));
- }
- if(Aceleracion < -MAX_ACE && Estado[i] == 1)
- {
- new
- Float:acthealth;
- GetPlayerHealth(i, acthealth);
- SetPlayerHealth(i, acthealth - (-1 * floatdiv(Aceleracion, PROPORCION)));
- }
- }
- }
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- if(newstate == PLAYER_STATE_ONFOOT) TextDrawHideForPlayer(playerid, Textdraw[0]), TextDrawHideForPlayer(playerid, Textdraw[1]), TextDrawHideForPlayer(playerid, Textdraw[2]), TextDrawHideForPlayer(playerid, Textdraw[3]);
- else if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
- {
- if(Velocimetro[playerid] == 1) TextDrawShowForPlayer(playerid, Textdraw[0]), TextDrawShowForPlayer(playerid, Textdraw[1]);
- if(Acelerometro[playerid] == 1) TextDrawShowForPlayer(playerid, Textdraw[2]), TextDrawShowForPlayer(playerid, Textdraw[3]);
- }
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- dcmd(mi, 2, cmdtext);
- return 0;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- TextDrawHideForPlayer(playerid, Textdraw[0]);
- TextDrawHideForPlayer(playerid, Textdraw[1]);
- TextDrawHideForPlayer(playerid, Textdraw[2]);
- TextDrawHideForPlayer(playerid, Textdraw[3]);
- return 1;
- }
- dcmd_mi(playerid, params[])
- {
- new
- sub[15],
- subpar[11];
- if(sscanf(params, "s ", sub)) return SendClientMessage(playerid, ROJO, "Uso: /mi [ velocimetro / acelerometro / sda ] [ activar / desactivar ]");
- else if(strcmp(sub, "velocimetro", true) == 0)
- {
- if(sscanf(params, "ss", sub, subpar)) return SendClientMessage(playerid, ROJO, "Uso: /mi velocimetro [ activar / desactivar ]");
- else if(strcmp(subpar, "activar", true) == 0)
- {
- if(Velocimetro[playerid] == 1) return SendClientMessage(playerid, ROJO, "El veloc�metro ya esta activado!");
- else
- {
- if(IsPlayerInAnyVehicle(playerid)) TextDrawShowForPlayer(playerid, Textdraw[0]), TextDrawShowForPlayer(playerid, Textdraw[1]);
- Velocimetro[playerid] = 1;
- SendClientMessage(playerid, VERDE, "Has activado el veloc�metro!");
- }
- }
- else if(strcmp(subpar, "desactivar", true) == 0)
- {
- if(Velocimetro[playerid] == 0) return SendClientMessage(playerid, ROJO, "El veloc�metro ya esta desactivado!");
- else
- {
- Velocimetro[playerid] = 0;
- SendClientMessage(playerid, VERDE, "Has desactivado el veloc�metro!");
- TextDrawHideForPlayer(playerid, Textdraw[0]);
- TextDrawHideForPlayer(playerid, Textdraw[1]);
- }
- }
- else SendClientMessage(playerid, ROJO, "Uso: /mi velocimetro [ activar / desactivar ]");
- }
- else if(strcmp(sub, "acelerometro", true) == 0)
- {
- if(sscanf(params, "ss", sub, subpar)) return SendClientMessage(playerid, ROJO, "Uso: /mi acelerometro [ activar / desactivar ]");
- else if(strcmp(subpar, "activar", true) == 0)
- {
- if(Acelerometro[playerid] == 1) return SendClientMessage(playerid, ROJO, "El aceler�metro ya esta activado!");
- else
- {
- if(IsPlayerInAnyVehicle(playerid)) TextDrawShowForPlayer(playerid, Textdraw[2]), TextDrawShowForPlayer(playerid, Textdraw[3]);
- Acelerometro[playerid] = 1;
- SendClientMessage(playerid, VERDE, "Has activado el aceler�metro!");
- }
- }
- else if(strcmp(subpar, "desactivar", true) == 0)
- {
- if(Acelerometro[playerid] == 0) return SendClientMessage(playerid, ROJO, "El aceler�metro ya esta desactivado!");
- else
- {
- Acelerometro[playerid] = 0;
- SendClientMessage(playerid, VERDE, "Has desactivado el aceler�metro!");
- TextDrawHideForPlayer(playerid, Textdraw[2]);
- TextDrawHideForPlayer(playerid, Textdraw[3]);
- }
- }
- else SendClientMessage(playerid, ROJO, "Uso: /mi acelerometro [ activar / desactivar ]");
- }
- else if(strcmp(sub, "sda", true) == 0)
- {
- if(sscanf(params, "ss", sub, subpar)) return SendClientMessage(playerid, ROJO, "Uso: /mi sda [ activar / desactivar ]");
- else if(strcmp(subpar, "activar", true) == 0)
- {
- if(Estado[playerid] == 1) return SendClientMessage(playerid, ROJO, "El sistema de aceleraci�n ya esta activado!");
- else
- {
- Estado[playerid] = 1;
- SendClientMessage(playerid, VERDE, "Has activado el sistema de aceleraci�n!");
- }
- }
- else if(strcmp(subpar, "desactivar", true) == 0)
- {
- if(Estado[playerid] == 0) return SendClientMessage(playerid, ROJO, "El sistema de aceleraci�n ya esta desactivado!");
- else
- {
- Estado[playerid] = 0;
- SendClientMessage(playerid, VERDE, "Has desactivado el sistema de aceleraci�n!");
- }
- }
- else SendClientMessage(playerid, ROJO, "Uso: /mi sda [ activar / desactivar ]");
- }
- else SendClientMessage(playerid, ROJO, "Uso: /mi [ velocimetro / acelerometro / sda ] [ activar / desactivar ]");
- return 1;
- }
- stock sscanf(string[], format[], {Float,_}:...)
- {
- #if defined isnull
- if (isnull(string))
- #else
- if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
- #endif
- {
- return format[0];
- }
- #pragma tabsize 4
- new
- formatPos = 0,
- stringPos = 0,
- paramPos = 2,
- paramCount = numargs(),
- delim = ' ';
- while (string[stringPos] && string[stringPos] <= ' ')
- {
- stringPos++;
- }
- while (paramPos < paramCount && string[stringPos])
- {
- switch (format[formatPos++])
- {
- case '\0':
- {
- return 0;
- }
- case 'i', 'd':
- {
- new
- neg = 1,
- num = 0,
- ch = string[stringPos];
- if (ch == '-')
- {
- neg = -1;
- ch = string[++stringPos];
- }
- do
- {
- stringPos++;
- if ('0' <= ch <= '9')
- {
- num = (num * 10) + (ch - '0');
- }
- else
- {
- return -1;
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num * neg);
- }
- case 'h', 'x':
- {
- new
- num = 0,
- ch = string[stringPos];
- do
- {
- stringPos++;
- switch (ch)
- {
- case 'x', 'X':
- {
- num = 0;
- continue;
- }
- case '0' .. '9':
- {
- num = (num << 4) | (ch - '0');
- }
- case 'a' .. 'f':
- {
- num = (num << 4) | (ch - ('a' - 10));
- }
- case 'A' .. 'F':
- {
- num = (num << 4) | (ch - ('A' - 10));
- }
- default:
- {
- return -1;
- }
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num);
- }
- case 'c':
- {
- setarg(paramPos, 0, string[stringPos++]);
- }
- case 'f':
- {
- new changestr[16], changepos = 0, strpos = stringPos;
- while(changepos < 16 && string[strpos] && string[strpos] != delim)
- {
- changestr[changepos++] = string[strpos++];
- }
- changestr[changepos] = '\0';
- setarg(paramPos,0,_:floatstr(changestr));
- }
- case 'p':
- {
- delim = format[formatPos++];
- continue;
- }
- case '\'':
- {
- new
- end = formatPos - 1,
- ch;
- while ((ch = format[++end]) && ch != '\'') {}
- if (!ch)
- {
- return -1;
- }
- format[end] = '\0';
- if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
- {
- if (format[end + 1])
- {
- return -1;
- }
- return 0;
- }
- format[end] = '\'';
- stringPos = ch + (end - formatPos);
- formatPos = end + 1;
- }
- case 'u':
- {
- new
- end = stringPos - 1,
- id = 0,
- bool:num = true,
- ch;
- while ((ch = string[++end]) && ch != delim)
- {
- if (num)
- {
- if ('0' <= ch <= '9')
- {
- id = (id * 10) + (ch - '0');
- }
- else
- {
- num = false;
- }
- }
- }
- if (num && IsPlayerConnected(id))
- {
- setarg(paramPos, 0, id);
- }
- else
- {
- #if !defined foreach
- #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
- #define __SSCANF_FOREACH__
- #endif
- string[end] = '\0';
- num = false;
- new
- name[MAX_PLAYER_NAME];
- id = end - stringPos;
- foreach (Player, playerid)
- {
- GetPlayerName(playerid, name, sizeof (name));
- if (!strcmp(name, string[stringPos], true, id))
- {
- setarg(paramPos, 0, playerid);
- num = true;
- break;
- }
- }
- if (!num)
- {
- setarg(paramPos, 0, INVALID_PLAYER_ID);
- }
- string[end] = ch;
- #if defined __SSCANF_FOREACH__
- #undef foreach
- #undef __SSCANF_FOREACH__
- #endif
- }
- stringPos = end;
- }
- case 's', 'z':
- {
- new
- i = 0,
- ch;
- if (format[formatPos])
- {
- while ((ch = string[stringPos++]) && ch != delim)
- {
- setarg(paramPos, i++, ch);
- }
- if (!i)
- {
- return -1;
- }
- }
- else
- {
- while ((ch = string[stringPos++]))
- {
- setarg(paramPos, i++, ch);
- }
- }
- stringPos--;
- setarg(paramPos, i, '\0');
- }
- default:
- {
- continue;
- }
- }
- while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
- {
- stringPos++;
- }
- while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
- {
- stringPos++;
- }
- paramPos++;
- }
- do
- {
- if ((delim = format[formatPos++]) > ' ')
- {
- if (delim == '\'')
- {
- while ((delim = format[formatPos++]) && delim != '\'') {}
- }
- else if (delim != 'z')
- {
- return delim;
- }
- }
- }
- while (delim > ' ');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement