Oq tem de errado?... -
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;
}
Re: Oq tem de errado?... -
Usa o Fs que vem no plugin routeconnector, impossнvel fazer um piloto automбtico q preste sem um pathfinding.
Re: Oq tem de errado?... -
PHP код:
//-------------------------------------------------
//
// NPC initialisation for Grand Larceny
//
//-------------------------------------------------
#pragma tabsize 0
#include <a_samp>
//-------------------------------------------------
public OnFilterScriptInit()
{
ConnectNPC("TrainDriverLV","train_lv");
ConnectNPC("TrainDriverLS","train_ls");
ConnectNPC("TrainDriverSF","train_sf");
ConnectNPC("PilotLV","at400_lv");
ConnectNPC("PilotSF","at400_sf");
ConnectNPC("PilotLS","at400_ls");
// Testing
//ConnectNPC("TestIdle","onfoot_test");
//ConnectNPC("TaxiTest","mat_test");
return 1;
}
//-------------------------------------------------
// IMPORTANT: This restricts NPCs connecting from
// an IP address outside this server. If you need
// to connect NPCs externally you will need to modify
// the code in this callback.
public OnPlayerConnect(playerid)
{
if(IsPlayerNPC(playerid)) {
new ip_addr_npc[64+1];
new ip_addr_server[64+1];
GetServerVarAsString("bind",ip_addr_server,64);
GetPlayerIp(playerid,ip_addr_npc,64);
if(!strlen(ip_addr_server)) {
ip_addr_server = "127.0.0.1";
}
if(strcmp(ip_addr_npc,ip_addr_server,true) != 0) {
// this bot is remote connecting
printf("NPC: Got a remote NPC connecting from %s and I'm kicking it.",ip_addr_npc);
Kick(playerid);
return 0;
}
printf("NPC: Connection from %s is allowed.",ip_addr_npc);
}
return 1;
}
//-------------------------------------------------
public OnPlayerRequestClass(playerid, classid)
{
if(!IsPlayerNPC(playerid)) return 1; // We only deal with NPC players in this script
new playername[64];
GetPlayerName(playerid,playername,64);
if(!strcmp(playername,"TrainDriverLV",true)) {
SetSpawnInfo(playerid,69,255,1462.0745,2630.8787,10.8203,0.0,-1,-1,-1,-1,-1,-1);
}
else if(!strcmp(playername,"TrainDriverSF",true)) {
SetSpawnInfo(playerid,69,255,-1942.7950,168.4164,27.0006,0.0,-1,-1,-1,-1,-1,-1);
}
else if(!strcmp(playername,"TrainDriverLS",true)) {
SetSpawnInfo(playerid,69,255,1700.7551,-1953.6531,14.8756,0.0,-1,-1,-1,-1,-1,-1);
}
else if(!strcmp(playername,"PilotLV",true)) {
SetSpawnInfo(playerid,69,61,0.0,0.0,0.0,0.0,-1,-1,-1,-1,-1,-1);
}
else if(!strcmp(playername,"PilotSF",true)) {
SetSpawnInfo(playerid,69,61,0.0,0.0,0.0,0.0,-1,-1,-1,-1,-1,-1);
}
else if(!strcmp(playername,"PilotLS",true)) {
SetSpawnInfo(playerid,69,61,0.0,0.0,0.0,0.0,-1,-1,-1,-1,-1,-1);
}
else if(!strcmp(playername,"TestIdleDriver",true)) {
SetSpawnInfo(playerid,69,61,0.0,0.0,0.0,0.0,-1,-1,-1,-1,-1,-1);
}
else if(!strcmp(playername,"TaxiTest",true)) {
SetSpawnInfo(playerid,69,61,0.0,0.0,0.0,0.0,-1,-1,-1,-1,-1,-1);
}
return 0;
}
//-------------------------------------------------
public OnPlayerSpawn(playerid)
{
if(!IsPlayerNPC(playerid)) return 1; // We only deal with NPC players in this script
new playername[64];
GetPlayerName(playerid,playername,64);
if(!strcmp(playername,"TrainDriverLV",true)) {
PutPlayerInVehicle(playerid,1,0);
SetPlayerColor(playerid,0xFFFFFFFF);
}
else if(!strcmp(playername,"TrainDriverSF",true)) {
PutPlayerInVehicle(playerid,5,0);
SetPlayerColor(playerid,0xFFFFFFFF);
}
else if(!strcmp(playername,"TrainDriverLS",true)) {
PutPlayerInVehicle(playerid,9,0);
SetPlayerColor(playerid,0xFFFFFFFF);
}
else if(!strcmp(playername,"PilotLV",true)) {
PutPlayerInVehicle(playerid,13,0);
SetPlayerColor(playerid,0xFFFFFFFF);
}
else if(!strcmp(playername,"PilotSF",true)) {
PutPlayerInVehicle(playerid,14,0);
SetPlayerColor(playerid,0xFFFFFFFF);
}
else if(!strcmp(playername,"PilotLS",true)) {
PutPlayerInVehicle(playerid,15,0);
SetPlayerColor(playerid,0xFFFFFFFF);
}
else if(!strcmp(playername,"TestIdleDriver",true)) {
PutPlayerInVehicle(playerid,43,0);
SetPlayerColor(playerid,0xFFFFFFFF);
}
else if(!strcmp(playername,"TaxiTest",true)) {
PutPlayerInVehicle(playerid,968,0);
SetPlayerColor(playerid,0xFFFFFFFF);
}
return 1;
}
//-------------------------------------------------
// EOF