[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
#2

Very nice, I will be trying this out. I'd suggest you add callback also, for when a vehicle's tires get popped.

Hmm, why is the code in a filterscript? Seems an odd way to do things.. I guess to be able to use this in any script (GM/FS)? Even so, filterscripts have a low limit - if every include did this it'd be chaos. Can you make an inc-only version please?
Reply
#3

There's is an include script that communicates with the filterscript. I feel it's better as a filterscript, you can easily (un)loadfs etc. I was actually unsure which one to make and chose filterscript, but I might do a full include version some time later.
Reply
#4

Why would you want to unload it?

Anyway, I've tested it and it doesn't work. I added a print to print the value of 'distance' and it never goes below 0.24 - not even close. (Print was JUST before 'if (distance < 0.24)').

I've transferred the entire thing in to an inc, but I guarantee you I haven't 'broken' anything.

It doesn't seem to go below 0.6.

EDIT: Fixed by changing to this: if (distance < 1)

EDIT #2: Okay, I made some changes, hope you don't mind: http://pastebin.com/mqKa4Gj0

- Added callback OnSpikeStripPop(vehicleid, spikeid)
- Ground offset is now OPTIONAL (added a param to the creation function)
- Changed the < 0.24 thing to < 1 (it wasn't working!)
- Added bool:FindZ param to the creation function to disable the 'ground offset' thing (my script handled it itself with MapAndreas)
- Added 'ArePlayerTiresPoppable' - declare this function (with params 'playerid') and return 0 in there if the player's tires can't be popped (for example if they're a cop). Perhaps SpikeStrip_ToggleVehicleTiresPoppable or something would be better than spamming this, but oh well.
- And of course it's just an include now.

Feel free to use that as your release. I don't want any credit, I haven't done much really - I've just done your work for you. Hope you don't mind. Great work though!
Reply
#5

Quote:
Originally Posted by MP2
Посмотреть сообщение
Why would you want to unload it?
I think it's better performance wise to have it as a filterscript. Filterscript is like an include file with the exception that you can unload it anytime and increase server performance (without the need to restart the server). Anyways, everyone has their own opinions.
Quote:
Originally Posted by MP2
Посмотреть сообщение
Anyway, I've tested it and it doesn't work. I added a print to print the value of 'distance' and it never goes below 0.24 - not even close. (Print was JUST before 'if (distance < 0.24)').

I've transferred the entire thing in to an inc, but I guarantee you I haven't 'broken' anything.

It doesn't seem to go below 0.6.

EDIT: Fixed by changing to this: if (distance < 1)
That's weird, what vehicle did you test? I tested like 50% vehicles and all worked fine.
Reply
#6

I tested many vehicles. See my previous post, I edited it a few times. I've taken the liberty of doing some stuff. I did it because I need it like that for my own server, and decided to release it for you to possibly use. If you don't want to that's fine, but I need the revisions I made.
Reply
#7

EDIT: I'll check out your code later.
Reply
#8

You can use something like http://www.diffchecker.com/ to find out what I changed if you wish. All of the stuff from the .inc is at the top, and the FS stuff under it.
Reply
#9

Okay, I think I may have an idea why you had to change the distance. You've added an optional parameter (FindZ), but if you're not using it (if you're using MapAndreas to find Z), you also need to change:
pawn Код:
g_Spike_zA[idx] = z - 0.9;
// to
g_Spike_zA[idx] = z - ((FindZ) ? 0.9 : 0.0);
Otherwise that will set Z coordinate 0.9 meters below spike strip's actual position. By changing the distance to 1, you've really changed it to 0.1 and that's good enough for most vehicles, but some vehicle's may need higher distance.

Anyways, you have nice additions in your edit. I'll update the filterscript version with some of those.
Reply
#10

Nice script!

I'll be using it, thanks alot! ;d

EDIT: You need to make it so if the OnVehiclePop callback is called, it is called once and not 4 times. (amount of tires = amount of times called).
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)