pawn Код:
//Arriba
forward ChoqueTimer(playerid);
new Float:Choques_vida[MAX_PLAYERS][MAX_VEHICLES];
new bool:PCinturon[MAX_PLAYERS];
stock Float:VehiculoVida(v)//by Gantzyo
{
new Float:v_vida;
GetVehicleHealth(v,v_vida);
return v_vida;
}
stock Float:RestarVida(playerid,Float:cantidad)//by Gantzyo
{
new Float:p_vida;
GetPlayerHealth(playerid,p_vida);
p_vida = floatsub(p_vida,cantidad);
SetPlayerHealth(playerid,p_vida);
return p_vida;
}
#define CHOQUE_FLOJO 100//Cantidad de vida que pierde el vehiculo
#define CHOQUE_MEDIO 200//Cantidad de vida que pierde el vehiculo
//Debajo de OnGameModeInit
for(new i=0;i<MAX_PLAYERS;i++)
{
for(new v=0;v<MAX_PLAYERS;v++)
{
Choques_vida[i][v] = 1000;
}
SetTimerEx("ChoqueTimer",200,0,"d",i);
}
//Debajo de OnPlayerStateChange
if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
{
Choques_vida[playerid][GetPlayerVehicleID(playerid)] = VehiculoVida(GetPlayerVehicleID(playerid));
}
if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
{
PCinturon[playerid] = false;
}
//Debajo de OnPlayerCommandText
if(strcmp("/cinturon",cmdtext,true)==0)
{
if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER && GetPlayerState(playerid) != PLAYER_STATE_PASSENGER) return SendClientMessage(playerid,0xff0000ff,"No estas en ningun vehiculo");
if(PCinturon[playerid])
{
PCinturon[playerid] = false;
SendClientMessage(playerid,0xffffffff,"Cinturon quitado");
}
else
{
PCinturon[playerid] = true;
SendClientMessage(playerid,0xffffffff,"Cinturon puesto");
}
return 1;
}
//Al final
public ChoqueTimer(playerid)
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
{
if(VehiculoVida(GetPlayerVehicleID(playerid)) < Choques_vida[playerid][GetPlayerVehicleID(playerid)])
{
new Float:v_x,Float:v_y,Float:v_z,Float:tmp_vvida;
GetVehiclePos(GetPlayerVehicleID(playerid),v_x,v_y,v_z);
if((Choques_vida[playerid][GetPlayerVehicleID(playerid)]-VehiculoVida(GetPlayerVehicleID(playerid))) <= float(CHOQUE_FLOJO))
{
for(new i=0;i<MAX_PLAYERS;i++)
{
if(IsPlayerInRangeOfPoint(i,75.0,v_x,v_y,v_z) && i != playerid)GameTextForPlayer(i,"~r~Escuchas el ruido de un vehiculo chocar con algo, no parece muy fuerte el choque.",3000,3);
}
}
else if((Choques_vida[playerid][GetPlayerVehicleID(playerid)]-VehiculoVida(GetPlayerVehicleID(playerid))) <= float(CHOQUE_MEDIO))
{
for(new i=0;i<MAX_PLAYERS;i++)
{
if(IsPlayerInRangeOfPoint(i,150.0,v_x,v_y,v_z) && i != playerid)GameTextForPlayer(i,"~r~Escuchas el ruido de un vehiculo chocar con algo, parece que el choque le destrozo algo.",3000,3);
}
}
else
{
for(new i=0;i<MAX_PLAYERS;i++)
{
if(IsPlayerInRangeOfPoint(i,300.0,v_x,v_y,v_z) && i != playerid)GameTextForPlayer(i,"~r~Escuchas el ruido de un vehiculo chocar con algo, parece que el Habitante esta muy herido.",3000,3);
}
}
tmp_vvida = Choques_vida[playerid][GetPlayerVehicleID(playerid)];
tmp_vvida = floatsub(tmp_vvida,VehiculoVida(GetPlayerVehicleID(playerid)));
tmp_vvida = floatmul(tmp_vvida,100.0);
tmp_vvida = floatdiv(tmp_vvida,750.0);//Si quieres que se pierda menos vida al chocar, cambia 750.0 por un numero mayor, 750.0 esta como divisor.
if(PCinturon[playerid])
{
tmp_vvida = floatdiv(tmp_vvida,2.0);
RestarVida(playerid,tmp_vvida);
}
else RestarVida(playerid,tmp_vvida);
Choques_vida[playerid][GetPlayerVehicleID(playerid)] = VehiculoVida(GetPlayerVehicleID(playerid));
}
else if(VehiculoVida(GetPlayerVehicleID(playerid)) > Choques_vida[playerid][GetPlayerVehicleID(playerid)]) Choques_vida[playerid][GetPlayerVehicleID(playerid)] = VehiculoVida(GetPlayerVehicleID(playerid));
}
SetTimerEx("ChoqueTimer",200,0,"d",playerid);
return 1;
}