[FilterScript] SA-MP Spike Strips
#1

SA-MP Spike Strips

Description
(spike strip, traffic spikes, tire shredders, one-way traffic treadles, stingers, stop sticks, tire deflation device)
This is the most accurate spike strip script ever made. It uses line segment intersection detection algorithm. A line segment is a line that has a start point and an end point, and each wheel, when a player is driving, creates a line segment. That way it's possible to detect if a vehicle (more precisely a wheel) drives over a spike strip as each spike strip has line segment(s) of its own. The script will happily pop the tires of a vehicle that drives over a spike strip even if the vehicle is driving at 500 km/h.


Functions

SpikeStrip_Create
  • Parameters:
    • modelid - The modelid of the spike strip.
    • Float:x - The X coordinate to create the spike strip at.
    • Float:y - The Y coordinate to create the spike strip at.
    • Float:z - The Z coordinate to create the spike strip at.
    • Float:a - The angle of the spike strip.
  • Returns
    • The ID of the spike strip.
SpikeStrip_Delete
  • Parameters:
    • spikeid - The ID of the spike strip you want to delete.
  • Returns
    • This function doesn't return a specific value.
SpikeStrip_DeleteAll
  • Parameters:
    • This function has no parameters
  • Returns
    • This function doesn't return a specific value.
SpikeStrip_IsValid
  • Parameters:
    • spikeid - The ID of the spike strip you want to check the validity of.
  • Returns
    • 1 if the spike strip exists, otherwise 0.
SpikeStrip_SetGhost
  • Parameters:
    • playerid - The ID of the player whose ghost mode you want to set.
    • bool:toggle - 1 to enable the player's ghost mode, 0 to disable.
  • Returns
    • This function doesn't return a specific value.
SpikeStrip_IsGhost
  • Parameters:
    • playerid - The ID of the player whose ghost mode you want to check.
  • Returns
    • 1 if the player is in ghost mode, otherwise 0.

Callbacks

OnSpikeStripPopTire
  • Description:
    • Called when a vehicle's tire is popped by a spike strip.
  • Parameters:
    • spikeid - The ID of the spike strip that popped the tire.
    • vehicleid - The ID of the vehicle whose tire was popped.
    • playerid - The ID of the player who is driving the vehicle.
    • tire - The tire that was popped.
  • Returns
    • This callback does not handle returns.
Configuration

pawn Код:
#define MAX_SPIKE_STRIPS        (128)
The maximum amount of spike strips.

pawn Код:
#define SS_TIME_INTERVAL        (250)
Time interval between checks.

pawn Код:
#define SS_LINE_SEGMENTS        (2)
The amount of line segments a spike strip should have. This value can be set to 1, 2 or 4. The more line segments, the higher accuracy, but also the more computing time is required. Choose the one that best fits your needs.

Spike strip with 1 segment:


Spike strip with 2 segments:


Spike strip with 4 segments:



Testing

Test filterscript:
pawn Код:
// Test filterscript
#define FILTERSCRIPT

#include <a_samp>
#include <sscanf2>
#include <spikestrip>
#include <zcmd>
#tryinclude <mapandreas>

public OnFilterScriptInit()
{
    // Uncomment if you're using MapAndreas plugin
    // MapAndreas_Init(2);
    return 1;
}

CMD:sadd(playerid, params[])
{
    if (IsPlayerAdmin(playerid))
    {
        if (!strlen(params[0]))
        {
            return SendClientMessage(playerid, 0xC0C0C0FF, "Usage: /sadd <modelid> [0 = SHORT, 1 = LONG]");
        }
        new
            model,
            index,
            Float:px,
            Float:py,
            Float:pz,
            Float:pa;
        model = strval(params);
        GetPlayerPos(playerid, px, py, pz);
        if (!IsPlayerInAnyVehicle(playerid))
        {
            GetPlayerFacingAngle(playerid, pa);
        }
        else
        {
            GetVehicleZAngle(GetPlayerVehicleID(playerid), pa);
        }
        #if defined _inc_mapandreas
       
        pz = GetPointZPos(px, py);

        #endif
        model != 0 && (model = SPIKE_STRIP_LONG) || (model = SPIKE_STRIP_SHORT);
        if ((index = SpikeStrip_Create(model, px, py, pz, pa)) != INVALID_OBJECT_ID)
        {
            new
                str[32];
            format(str, 32, "Spike Strip ID %d created.", index);
            SendClientMessage(playerid, 0xC0C0C0FF, str);
        }
        else
        {
            SendClientMessage(playerid, 0xC0C0C0FF, "ERROR: Spike strip could not be created.");
        }
        return 1;
    }
    return 0;
}

CMD:sdel(playerid, params[])
{
    if (IsPlayerAdmin(playerid))
    {
        if (!strlen(params[0]))
        {
            return SendClientMessage(playerid, 0xC0C0C0FF, "Usage: /sdel <spikeid>");
        }
        new
            index;
        index = strval(params);
        if (SpikeStrip_IsValid(index))
        {
            new
                str[32];
            format(str, 32, "Spike Strip ID %d deleted.", index);
            SendClientMessage(playerid, 0xC0C0C0FF, str);

            SpikeStrip_Delete(index);
        }
        else
        {
            SendClientMessage(playerid, 0xC0C0C0FF, "ERROR: Invalid spike strip ID.");
        }
        return 1;
    }
    return 0;
}

CMD:sghost(playerid, params[])
{
    if (IsPlayerAdmin(playerid))
    {
        new
            player,
            status;
        if(sscanf(params, "ui", player, status))
        {
            return SendClientMessage(playerid, 0xC0C0C0FF, "Usage: /sghost <playerid> <ghost>");
        }
        if (player != INVALID_PLAYER_ID)
        {
            new
                str[64];
            format(str, 64, "Player ID %d ghost mode set to %d.", player, !!status);
            SendClientMessage(playerid, 0xC0C0C0FF, str);

            SpikeStrip_SetGhost(player, !!status);
        }
        return 1;
    }
    return 0;
}
Notes
  • No support for unoccupied vehicles.
  • No support for trailers attached to vehicles.
  • No support for middle wheels in six wheel vehicles.
  • Some vehicles are not affected by spike strips (e.g. Dune and Quad).
Download (UPDATE 2)

spikestrip (filterscript)
spikestrip.inc (include)

Filterscript will no longer be updated. Download the latest include version:
https://sampforum.blast.hk/showthread.php?pid=2656907#pid2656907

Other requirements

Requires y_iterate/foreach


Thanks

****** - y_iterate/foreach
Kalcor & SA-MP Team - SA-MP
MP2 - Valuable suggestions
Reply


Messages In This Thread
SA-MP Spike Strips - by Stylock - 02.07.2013, 22:51
Re: SA-MP Spike Strips - by MP2 - 02.07.2013, 23:12
Re: SA-MP Spike Strips - by Stylock - 02.07.2013, 23:19
Re: SA-MP Spike Strips - by MP2 - 02.07.2013, 23:40
Re: SA-MP Spike Strips - by Stylock - 03.07.2013, 00:16
Re: SA-MP Spike Strips - by MP2 - 03.07.2013, 00:17
Re: SA-MP Spike Strips - by Stylock - 03.07.2013, 00:18
Re: SA-MP Spike Strips - by MP2 - 03.07.2013, 00:19
Re: SA-MP Spike Strips - by Stylock - 03.07.2013, 10:19
Re: SA-MP Spike Strips - by Kyle - 03.07.2013, 10:26

Forum Jump:


Users browsing this thread: 1 Guest(s)