Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Speedlimit created by VanGans
- #include <a_samp>
- #include <sscanf>
- #define COLOR_WHITE 0xFFFFFFAA
- #define COLOR_GREY 0xAFAFAFAA
- #define COLOR_LIGHTBLUE 0x33CCFFAA`
- // Speedlimit
- new Speedlimit[MAX_PLAYERS];
- #define SpeedCheck(%0,%1,%2,%3,%4) floatround(floatsqroot(%4?(%0*%0+%1*%1+%2*%2):(%0*%0+%1*%1) ) *%3*1.6)
- public OnFilterScriptInit()
- {
- return 1;
- }
- public OnFilterScriptExit()
- {
- return 1;
- }
- public OnGameModeInit()
- {
- return 1;
- }
- public OnGameModeExit()
- {
- return 1;
- }
- public OnPlayerRequestClass(playerid, classid)
- {
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- Speedlimit[playerid] = 0;
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- return 1;
- }
- public OnVehicleSpawn(vehicleid)
- {
- return 1;
- }
- public OnVehicleDeath(vehicleid, killerid)
- {
- return 1;
- }
- public OnPlayerText(playerid, text[])
- {
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if (strcmp("/speedlimit", cmdtext, true, 10) == 0)
- {
- new string[128], speed;
- if(sscanf(cmdtext, "i", speed)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /speedlimit [Max MPH]");
- if(speed < 0) return SendClientMessage(playerid, COLOR_GREY, "Invalid MPH speed.");
- Speedlimit[playerid] = speed;
- if(speed == 0) format(string, sizeof(string), " You have turned your speed limit off.", speed);
- else format(string, sizeof(string), " You have set your speed limit to %d MPH, any vehicle you drive will not go past this limit.", speed);
- SendClientMessage(playerid, COLOR_GREY, string);
- }
- return 1;
- }
- public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
- {
- return 1;
- }
- public OnPlayerExitVehicle(playerid, vehicleid)
- {
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- return 1;
- }
- public OnPlayerEnterCheckpoint(playerid)
- {
- return 1;
- }
- public OnPlayerLeaveCheckpoint(playerid)
- {
- return 1;
- }
- public OnPlayerEnterRaceCheckpoint(playerid)
- {
- return 1;
- }
- public OnPlayerLeaveRaceCheckpoint(playerid)
- {
- return 1;
- }
- public OnRconCommand(cmd[])
- {
- return 1;
- }
- public OnPlayerRequestSpawn(playerid)
- {
- return 1;
- }
- public OnObjectMoved(objectid)
- {
- return 1;
- }
- public OnPlayerObjectMoved(playerid, objectid)
- {
- return 1;
- }
- public OnPlayerPickUpPickup(playerid, pickupid)
- {
- return 1;
- }
- public OnVehicleMod(playerid, vehicleid, componentid)
- {
- return 1;
- }
- public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
- {
- return 1;
- }
- public OnVehicleRespray(playerid, vehicleid, color1, color2)
- {
- return 1;
- }
- public OnPlayerSelectedMenuRow(playerid, row)
- {
- return 1;
- }
- public OnPlayerExitedMenu(playerid)
- {
- return 1;
- }
- public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
- {
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- return 1;
- }
- public OnRconLoginAttempt(ip[], password[], success)
- {
- return 1;
- }
- public OnPlayerUpdate(playerid)
- {
- // Speedlimit
- if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER && Speedlimit[playerid])
- {
- new a, b, c;
- GetPlayerKeys(playerid, a, b ,c);
- if(a == 8 && GetVehicleSpeed(GetPlayerVehicleID(playerid), 0) > Speedlimit[playerid])
- {
- new newspeed = GetVehicleSpeed(GetPlayerVehicleID(playerid), 0) - Speedlimit[playerid];
- ModifyVehicleSpeed(GetPlayerVehicleID(playerid), -newspeed);
- }
- }
- return 1;
- }
- public OnPlayerStreamIn(playerid, forplayerid)
- {
- return 1;
- }
- public OnPlayerStreamOut(playerid, forplayerid)
- {
- return 1;
- }
- public OnVehicleStreamIn(vehicleid, forplayerid)
- {
- return 1;
- }
- public OnVehicleStreamOut(vehicleid, forplayerid)
- {
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- return 1;
- }
- public OnPlayerClickPlayer(playerid, clickedplayerid, source)
- {
- return 1;
- }
- stock GetVehicleSpeed(vehicleid, get3d)
- {
- new Float:x, Float:y, Float:z;
- GetVehicleVelocity(vehicleid, x, y, z);
- return SpeedCheck(x, y, z, 100.0, get3d);
- }
- stock ModifyVehicleSpeed(vehicleid,mph) //Miles Per Hour
- {
- new Float:Vx,Float:Vy,Float:Vz,Float:DV,Float:multiple;
- GetVehicleVelocity(vehicleid,Vx,Vy,Vz);
- DV = floatsqroot(Vx*Vx + Vy*Vy + Vz*Vz);
- if(DV > 0) //Directional velocity must be greater than 0 (display strobes if 0)
- {
- multiple = ((mph + DV * 100) / (DV * 100)); //Multiplying DV by 100 calculates speed in MPH
- return SetVehicleVelocity(vehicleid,Vx*multiple,Vy*multiple,Vz*multiple);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment