[Include] SpeedCap
#1

Hello everyone today i created SpeedCap include wich detects if player goes over speed limit or enters speed limit
zone.

functions list:

____________

CreateSpeedCap(capid, Float:х, Float:у, Float:z, Float:radius, Float:Speed_limit) creates a speed capture zone.


RemoveSpeedCap(capid) removes speed capture zone.


RemoveAllSpeedCap() removes all capture zone.


GetSpeedCapSpeedLimit(capid) gets the value of the speed capture zone speed limit.



__________________________________



CallBacks:

_________


OnPlayerDriveFast(playerid, capid) When player drives over the speed limit of the speed capture zone. (Checks if player is in speed capture zone and speeding)

____________________________________________

VIDEO:

_______

PASTEBIN (INC): https://pastebin.com/Fuppdte8

PASTEBIN (EXAMPLE FS): https://pastebin.com/9JTWiktF

Credits to:
WhatName (me): for SpeedCap.
NaS: for useful suggestions.
Incognito: streamer.
Pottus: for helping
SAMP team: for a_samp
Reply
#2

Try to use Incognito's Streamer Plugin and take advantage of Areas. This would also allow to create spheres, cubes, rectangles, polygons etc. If you don't want to do that, you could use an iterator or a list to store the Zones a player is in. That definitely doesn't have to be checked in OnPlayerUpdate.

Also, instead of getting the speed from the Vehicle's Velocity over and over again (which doesnt change within one block of code) you can save it to a variable before looping, then compare the stored value to the limit of each zone. That saves a few calculations and native calls per player (this sums up - it's check per zone per player).
Also Passengers shouldn't be check for, at least I don't see why - but that could be handled in the Script.

Furthermore OnPlayerEnterSpeedCap will be repeatedly called while a Player is in a Speed Cap Zone (actually every time OnPlayerUpdate is called). That's not how it should work I guess :P
Reply
#3

Giving me an error
Код:
error 021: symbol already defined: "OnGameModeInit"
Reply
#4

@NaS Updated!
Reply
#5

-REMOVED-
Reply
#6

Updated: -REMOVED
Reply
#7

Why not do it like this there is no point of using CallLocalFunction() if someone is going to use their include then they will be using OnPlayerDriveFast() no matter what.

Код:
forward OnPlayerDriveFast(playerid, areaid);

public OnPlayerEnterDynamicArea(playerid, areaid)
{
     if(!INVALID_PLAYER_ID || !IsPlayerNPC(playerid))
     {
        new v_speed = sl_GetSpeed(playerid);

        for(new x = 0; x < MAX_SPEED_CAP;x++)
        {
	        if(areaid == SL_Speed[x][sl_areaid])
	        {
	           if(GetPlayerVehicleID(playerid) != 0)
	           {
	               if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	               {
	                   if(v_speed > SL_Speed[x][sl_speed])
	                   {
	                       	OnPlayerDriveFast(playerid, x);
							break;
	                   }
	               }
	           }
			}
		}
     }
     #if defined SL_OnPlayerEnterDyanmicArea
         SL_OnPlayerEnterDyanmicArea();
     #endif
     return 1;
}
Reply
#8

Quote:
Originally Posted by Pottus
Посмотреть сообщение
Why not do it like this there is no point of using CallLocalFunction() if someone is going to use their include then they will be using OnPlayerDriveFast() no matter what.

Код:
forward OnPlayerDriveFast(playerid, areaid);

public OnPlayerEnterDynamicArea(playerid, areaid)
{
     if(!INVALID_PLAYER_ID || !IsPlayerNPC(playerid))
     {
        new v_speed = sl_GetSpeed(playerid);

        for(new x = 0; x < MAX_SPEED_CAP;x++)
        {
	        if(areaid == SL_Speed[x][sl_areaid])
	        {
	           if(GetPlayerVehicleID(playerid) != 0)
	           {
	               if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	               {
	                   if(v_speed > SL_Speed[x][sl_speed])
	                   {
	                       	OnPlayerDriveFast(playerid, x);
							break;
	                   }
	               }
	           }
			}
		}
     }
     #if defined SL_OnPlayerEnterDyanmicArea
         SL_OnPlayerEnterDyanmicArea();
     #endif
     return 1;
}
Thx
updated: https://pastebin.com/Fuppdte8
Reply
#9

Yeah I have some other ideas for you too.

OnPlayerEnterSpeedArea()
OnPlayerExitSpeedArea()

Log all events in sqlite
CREATE TABLE IF NOT EXISTS `SpeedLog`(`ID` INTEGER PRIMARY KEY AUTOINCREMENT, `PlayerName` VARCHAR(24) NOT NULL, `EventType` INTEGER, `VehicleModel` INTEGER, `Speed` REAL, `Time` INTEGER)

You actually have a pretty good code base going on and with a few "cream-of-the-crop" additions you will get exponential usefulness value out of your release.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)