Speedlimiter? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Speedlimiter? (
/showthread.php?tid=112351)
Speedlimiter? -
Carlito - 07.12.2009
Is it possible to make a speedlimiter with SetVehicleVelocity? u type /speedlimit 50 and u cant drive faster than 50kmh
Re: Speedlimiter? -
Joe Staff - 07.12.2009
Of course it's possible, and it requires more math and less scripting skill.
pawn Код:
new pSpeedLimit[MAX_PLAYERS]={-1,...};
new Float:gTempFloat[4];
public OnPlayerConnect(playerid)
{
pSpeedLimit[playerid]=-1;
return 1;
}
public OnPlayerCommandText(playerid,cmdtext[])
{
if(!strcmp(cmdtext[1],"setlimit",true,8))
{
pSpeedLimit[playerid]=strval(cmdtext[10]);
return SendClientMessage(playerid,0x99CC9900," Speed Limit Set");
}
}
public OnPlayerUpdate(playerid)
{
if(pSpeedLimit[playerid]>-1)
{
GetVehicleVelocity(GetPlayerVehicleID(playerid),gFloatTemp[0],gFloatTemp[1],gFloatTemp[2]);
gFloatTemp[3]=(floatsqroot(gFloatTemp[0]*gFloatTemp[0]+gFloatTemp[1]*gFloatTemp[1]+gFloatTemp[2]*gFloatTemp[2])*100)/pSpeedLimit[playerid];
if(gFloatTemp[3]>1)SetVehicleVelocity(GetPlayerVehicleID(playerid),gFloatTemp[0]/gFloatTemp[3],gFloatTemp[1]/gFloatTemp[3],gFloatTemp[2]/gFloatTemp[3]);
}
return 1;
}
Tested and works to 80% satisfaction
*issues: May cause lag at higher player bases and higher pings. Occasionally it doesn't work and player will have uncapped speeds until completely stopped (as far as I can tell)
I think maybe my speed calculation is incorrect, but it seems
fairly accurate.
Re: Speedlimiter? -
Backwardsman97 - 07.12.2009
I made this version and it worked fine. Not too much math in mine. :P
pawn Код:
#define MAX_SPEED 0.7
#define SLOW_FACTOR 0.7
forward Timer();
public OnFilterScriptInit()
{
SetTimer("Timer",1000,1);
return 1;
}
public Timer()
{
new Float:x,Float:y,Float:z,veh;
for(new i; i<MAX_PLAYERS; i++)
{
veh=GetPlayerVehicleID(i);
GetVehicleVelocity(veh,x,y,z);
if((x > MAX_SPEED || x < -MAX_SPEED) || (y > MAX_SPEED || y < -MAX_SPEED))
{
SetVehicleVelocity(veh,x*SLOW_FACTOR,y*SLOW_FACTOR,z);
}
}
}
Re: Speedlimiter? -
Joe Staff - 07.12.2009
I fixed mine and it's hilarious to drive a car off a building when the limit is 5km/h.
Re: Speedlimiter? -
Carlito - 07.12.2009
alright thx... its because i have speedcamaras (AddFlitspaal, a script here in the forum) and its hard to keep the same speed...