Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // -----------------------------------------------------------------------------
- // Tempomat by Zalakaka45 Betöltve!
- // -----------------------------------------------------------------------------
- // Készült: 13/02/2012
- // -----------------------------------------------------------------------------
- #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;
- forward CruiseControl(playerid);
- public OnFilterScriptInit()
- {
- print("[Tempomat by Zalakaka45 Betöltve!]");
- return 1;
- }
- public OnFilterScriptExit()
- {
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- new cmd[256];
- new idx;
- cmd = strtok(cmdtext, idx);
- if (strcmp(cmd, "/tempomat", true) == 0)
- {
- SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "*Ha az ujjadat a BAL CONTROLON tartod akkor a jármü tartani fogja a megadott sebességet!");
- SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "*Csak Járműben Használhatod!");
- SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "::A tempomatért köszönet Zalakaka45-nek!");
- return 1;
- }
- return 0;
- }
- public OnPlayerConnect(playerid)
- {
- SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "* Tempomat Betöltve - Ird be /tempomat az infókért! ");
- return 1;
- }
- 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", 500, false, "d", playerid);
- SendClientMessage(playerid, COLOR_GREY, "* Tempomat Bekapcsolva");
- }
- 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 ||
- GetPlayerState(playerid) != PLAYER_STATE_DRIVER ||
- (speed < 0.7 * PlayerCruiseSpeed[playerid]) ||
- z > 1 ||
- (floatabs(angle - heading) > 50 && floatabs(angle - heading) < 310))
- {
- PlayerCruiseSpeed[playerid] = 0.00;
- SendClientMessage(playerid, COLOR_GREY, "*Tempomat Kikapcsolva");
- return false;
- }
- GetVehicleZAngle(vid, PlayerHeadingAngle[playerid]);
- GetXYVelocity(vid, x, y, PlayerCruiseSpeed[playerid]);
- SetVehicleVelocity(vid, x, y, z);
- return SetTimerEx("CruiseControl", 500, 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;
- }
Add Comment
Please, Sign In to add comment