PDA

View Full Version : Cruise Control works only for ID 0


DJGama101
01/08/2012, 07:37 PM
Hi. I've found cruise control script, but it works only for ID 0.


#include <a_samp>

#define VERSION "4.0"
#define FILTERSCRIPT
#define COLOR1 0xf65d5dff //kolor wiadomości, która wyświetla błąd "Tempomat jest już włączony."
#define COLOR2 0xf65d5dff //kolor wiadomości, która wyświetla błąd "Komenda /tempomat działa tylko w pojeździe."
#define COLOR3 0x5ed927ff //kolor wiadomości, która wyświetla się, gdy tempomat zostaje włączony
#define COLOR4 0xd9c227ff //kolor wiadomości, która wyświetla się, gdy tempomat zostaje wyłączony
#define TIMER_DELAY 500 //czas, co jaki ma być ustawiana szybkość pojazdu
// (mała wartość zmniejsza optymalizację, lecz jazda wygląda płynniej przy niższych szybkościach)

#define ENABLING 3
// 1 - włączanie komendą
// 2 - włączanie klawiszem mini-misji
// 3 - oba powyższe

#define foreach(Player,%1) for(new %1; %1 <= HighestPlayerID; %1++) if(IsPlayerConnected(playerid) && !IsPlayerNPC(playerid))
#define GetAngleBetweenCoordinates(%1,%2,%3,%4) (atan2(floatabs(%3 - %1), floatabs(%4 - %2)))

new Slots,
HighestPlayerID;

forward Tempomat_Refresh();
forward Tempomat_Version(index, response_code, data[]);

Float:GetHeadingAngle(Float:targetX, Float:targetY, Float:entityX, Float:entityY) //autor: Destrojer
{
new
Float:vectorX = targetX - entityX,
Float:vectorY = targetY - entityY,
Float:HeadingAngle;

HeadingAngle = atan(-(vectorX/vectorY));

if(vectorY < 0)
HeadingAngle = (HeadingAngle >= 180) ? HeadingAngle - 180.0 : HeadingAngle + 180.0;

return HeadingAngle;
}

public OnFilterScriptInit()
{
Slots = GetMaxPlayers();

for(new playerid; playerid < Slots; playerid++)
if(IsPlayerConnected(playerid) && !IsPlayerNPC(playerid))
HighestPlayerID = playerid;

SetTimer("Tempomat_Refresh", TIMER_DELAY, 1);
print("Włączono tempomat "VERSION" by DiggeR.");
return 1;
}

public OnFilterScriptExit()
return print("Wyłączono tempomat "VERSION" by DiggeR.");

public OnPlayerConnect(playerid)
{
if(playerid > HighestPlayerID && !IsPlayerNPC(playerid))
HighestPlayerID = playerid;
return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
for(new player; player < Slots; player++)
if(IsPlayerConnected(player) && !IsPlayerNPC(player))
HighestPlayerID = playerid;
return 1;
}

#if ENABLING == 1 || ENABLING == 3
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "/tempomat", true) //zcmd do jednej komendy?
|| !strcmp(cmdtext, "/cruise-control", true)
|| !strcmp(cmdtext, "/cruisecontrol", true))
return EnableCruiseControl(playerid);
return 0;
}
#endif

public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(oldstate == PLAYER_STATE_DRIVER && GetPVarInt(playerid, "Tempomat_Enabled") == 1)
DisableCruiseControl(playerid);
return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(IsPlayerInAnyVehicle(playerid))
{
if(GetPVarInt(playerid, "Tempomat_Enabled") == 1)
{
#if ENABLING == 2 || ENABLING == 3
if((newkeys & KEY_SUBMISSION) && (newkeys & KEY_LOOK_LEFT))
return DisableCruiseControl(playerid);
#endif

if(newkeys & 8 || newkeys & 32 || newkeys & 128)
return DisableCruiseControl(playerid);
}
#if ENABLING == 2 || ENABLING == 3
else
{
if((newkeys & KEY_SUBMISSION) && (newkeys & KEY_LOOK_LEFT))
return EnableCruiseControl(playerid);
}
#endif
}
return 1;
}

public Tempomat_Refresh()
{
new vehicleid,
Float:rotZ,
Float:velX,
Float:velY,
Float:velZ,
Float:speed;

foreach(Player, playerid)
{
vehicleid = GetPlayerVehicleID(playerid);

if(vehicleid != 0 && GetPVarInt(playerid, "Tempomat_Enabled") == 1)
{
speed = GetPVarFloat(playerid, "Tempomat_Speed");
GetVehicleVelocity(vehicleid, velX, velY, velZ);

if(velX == 0.0 && velY == 0.0 && velZ == 0.0)
GetVehicleZAngle(vehicleid, rotZ);
else
rotZ = Float:GetHeadingAngle(velX, velY, 0.0, 0.0);

SetVehicleVelocity(vehicleid, speed * floatsin(-rotZ, degrees), speed * floatcos(-rotZ, degrees), velZ);
}
}
return 1;
}

EnableCruiseControl(playerid)
{
if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER)
return 1;
else if(GetPVarInt(playerid, "Tempomat_Enabled") != 0)
return 1;
else
{
new vehicleid = GetPlayerVehicleID(playerid),
Float:velX,
Float:velY,
Float:velZ;

GetVehicleVelocity(vehicleid, velX, velY, velZ);

new Float:speed = floatsqroot(velX * velX + velY * velY + velZ * velZ);

if(speed > 0.1)
{
SetPVarFloat(playerid, "Tempomat_Speed", speed);

SetPVarInt(playerid, "Tempomat_Enabled", 1);
}
else
return 1;
}
return 1;
}

DisableCruiseControl(playerid)
{
DeletePVar(playerid, "Tempomat_Enabled");
DeletePVar(playerid, "Tempomat_Speed");
return 1;
}



How can i fix that? I need that this will work for all players not only for id 0.

Vince
01/08/2012, 08:27 PM
Use brackets, dude. You have lots of unconditional statements that don't make sense.

SEnergy
01/08/2012, 09:39 PM
Use brackets, dude. You have lots of unconditional statements that don't make sense.

he is using brackets, but he should totally use tabs