19.09.2015, 03:19
Bom peguei um fs de piloto automatico, mais quando eu aperto a tecla aparece, ativado e desativado no chat ao mesmo tempo..
PHP код:
#include <a_samp>
#define COLOR_MESSAGE_YELLOW 0xFFDD00AA
#define COLOR_GREY 0xAFAFAFAA
new Float:PlayerCruiseSpeed[MAX_PLAYERS];
new Float:PlayerHeadingAngle[MAX_PLAYERS];
new CCKey = KEY_ACTION; //Cruise Control Key - change this if you need
/* keys that can be used:
KEY_ACTION (LCTRL)
KEY_FIRE (mouse click)
KEY_SUBMISSION (2)
KEY_LOOK_BEHIND
or others you know
*/
forward CruiseControl(playerid);
public OnFilterScriptInit()
{
print("[Cruise Control system by Mick88: LOADED]");
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
new cmd[256];
new idx;
cmd = strtok(cmdtext, idx);
if (strcmp(cmd, "/cc", true) == 0)
{
SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, ":: Piloto automбtico feito pelos .:XTREME's:. ::");
SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "*Piloto automбtico vai ajudar vocк ficar em uma mesma velocidade apertando o botгo de atalho");
SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "*Para usar, verefique a sua velocidade desejada no carro e segure o botгo de atalho (CTRL'ESQUERDO).");
SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "*Segurando apertado vocк pode virar seu carro avontade, subir montanhas e etc.");
SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "*E para voltar ao normal apenas solte o botгo de atalho (CTRL'ESQUERDO).");
return 1;
}
return 0;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if ((newkeys & CCKey) && !(oldkeys & CCKey) && IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new vid = GetPlayerVehicleID(playerid);
if (GetVehicleSpeed(vid) == 0) return false;
new Float:x, Float:y, Float:z;
GetVehicleVelocity(vid, x, y, z);
GetVehicleZAngle(vid, PlayerHeadingAngle[playerid]);
DistanceFlat(0, 0, x, y, PlayerCruiseSpeed[playerid]);
SetTimerEx("CruiseControl", 100, false, "d", playerid);
SendClientMessage(playerid, COLOR_GREY, "* Piloto automбtico {00ff00}Ativado"); // === Remove this if not needed ===
}
else if (PlayerCruiseSpeed[playerid] != 0.00 && (newkeys & KEY_HANDBRAKE))
{
PlayerCruiseSpeed[playerid] = 0.00;
}
return 1;
}
GetVehicleSpeed(vehicleid)
{
new Float:Vx, Float:Vy, Float:Vz;
GetVehicleVelocity(vehicleid, Vx, Vy, Vz);
new Float:rtn;
rtn = floatsqroot(floatpower(Vx*100,2) + floatpower(Vy*100,2));
rtn = floatsqroot(floatpower(rtn,2) + floatpower(Vz*100,2));
return floatround(rtn);
}
DistanceFlat(Float:ax, Float:ay, Float:bx,Float:by, &Float:distance)
{
distance = floatsqroot(floatpower(bx-ax,2)+floatpower(by-ay,2));
return floatround(distance);
}
public CruiseControl(playerid)
{
new vid = GetPlayerVehicleID(playerid);
new Float:x, Float:y, Float:z;
GetVehicleVelocity(vid, x, y, z);
new keys, ud, lr;
GetPlayerKeys(playerid, keys, ud, lr);
new Float:angle, Float:heading, Float:speed;
GetVehicleZAngle(vid, angle);
GetVehicleHeadingAngle(vid, heading);
DistanceFlat(0, 0, x, y, speed);
if (!(keys & CCKey) || PlayerCruiseSpeed[playerid] == 0.00 || //If player released LCTRL or CruiseSpeed got cancelled by other means (spacebar press)
GetPlayerState(playerid) != PLAYER_STATE_DRIVER ||
(speed < 0.7 * PlayerCruiseSpeed[playerid]) || //if player slowed down too much
z > 1 || //if car is going upwards too fast
(floatabs(angle - heading) > 50 && floatabs(angle - heading) < 310))//if vehicle goes sideways
{ //Cruise control will turn off:
PlayerCruiseSpeed[playerid] = 0.00;
SendClientMessage(playerid, COLOR_GREY, "* Piloto automбtico {ff0000}Desativado"); // === Remove this if not needed ===
return false;
}
GetVehicleZAngle(vid, PlayerHeadingAngle[playerid]);
GetXYVelocity(vid, x, y, PlayerCruiseSpeed[playerid]);
SetVehicleVelocity(vid, x, y, z);
return SetTimerEx("CruiseControl", 100, false, "d", playerid);
}
GetXYVelocity(vehicleid, &Float:x, &Float:y, Float:speed)
{
new Float:a;
x = 0.0;
y = 0.0;
GetVehicleZAngle(vehicleid, a);
x += (speed * floatsin(-a, degrees));
y += (speed * floatcos(-a, degrees));
}
GetAngleToXY(Float:X, Float:Y, Float:CurrentX, Float:CurrentY, &Float:Angle)
{
Angle = atan2(Y-CurrentY, X-CurrentX);
Angle = floatsub(Angle, 90.0);
if(Angle < 0.0) Angle = floatadd(Angle, 360.0);
}
GetVehicleHeadingAngle(vehicleid, &Float:a)
{
new Float:x, Float:y, Float:z;
GetVehicleVelocity(vehicleid, x, y, z);
GetAngleToXY(x, y, 0, 0, a);
}
strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' '))
{
index++;
}
new offset = index;
new result[20];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}