SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts

View Poll Results: Did you find this filterscript useful and helpful?
Yes. 12 80.00%
No. 3 20.00%
Voters: 15. You may not vote on this poll

Reply
 
Thread Tools Display Modes
Old 06/01/2020, 02:50 PM   #1
KevTheJoker
Big Clucker
 
KevTheJoker's Avatar
 
Join Date: Dec 2018
Location: South America
Posts: 80
Reputation: 7
Cool Chaotic's Custom Emergency Siren


This filterscript allows players who are driving emergency vehicles to play an Audio for all other nearby players (both, in vehicles and standing upright). If you'd like to make your server a bit similar to the way GTA 5 functions, you can use this. I haven't added my credits to it, so do what you want with it, fine by me. I've released this filterscript, because I've noticed some persons are having difficulties using the PlayAudioStreamForPlayer function. Before you continue to read the body of this thread, I must inform you that this script isn't configured to check if the player is in an emergency vehicle or not. You can configure it to suit that requirement. If you're unable to do it, I'll gladly assist after you comment with the issue(s) you have. Enjoy!


Code:
#define FILTERSCRIPT // This is to define the script as a FS
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#include <foreach>

#define MAX_DYNAMIC_CARS 500 // If this isn't already in your script, add it

enum VehicleSirenInfo
{
	EmergencyCopSiren
}

new VehicleInfo[MAX_DYNAMIC_CARS][VehicleSirenInfo];

// If a player moves out of the area, the siren will turn off (not fade out), and if they enter the zone with the siren again, it'll
// start the siren audio over again.

stock InAreaWithCopSiren(playerid) // This is to check if a player is in the area with the siren audio
{
	new Float:x, Float:y, Float:z;
	for(new i = 0; i < MAX_DYNAMIC_CARS; i ++)
	{
		GetVehiclePos(i, x, y, z);
		if(IsPlayerInRangeOfPoint(playerid, 100.0, x, y, z))
		{
			if(VehicleInfo[i][EmergencyCopSiren] != 0)
			{
				SetPVarFloat(playerid, "CopSirenX", x);
				SetPVarFloat(playerid, "CopSirenY", y);
				SetPVarFloat(playerid, "CopSirenZ", z);
				return 1;
			}
		}
	}
	return false;
}

public OnPlayerUpdate(playerid)
{
	if(InAreaWithCopSiren(playerid))
	{
			if(!GetPVarInt(playerid, "CopSiren"))
			{
				SetPVarInt(playerid,"CopSiren", 1);
				new link[128];
				format(link, 128, "https://falcon-host.org/uploads/siren.mp3"); // This is the siren which I made and merged, but you can change it.
				PlayAudioStreamForPlayer(playerid, link, GetPVarFloat(playerid, "CopSirenX"), GetPVarFloat(playerid, "CopSirenY"), GetPVarFloat(playerid, "CopSirenZ"), 100.0 , 0);
			}
	}
	else
	{
		if(GetPVarInt(playerid, "CopSiren") != 0)
		{
			DeletePVar(playerid, "CopSiren");
			StopAudioStreamForPlayer(playerid);
		}
	}
	return 1;
}

// This is mandatory because if several emergency cars are in the area at the same time, and the player disconnects, the siren will be turned off.
// It is also added to prevent bugs from occurring, to restart the server over and over.
public OnPlayerDisconnect(playerid, reason)
{											
	if(IsPlayerInAnyVehicle(playerid))
	{
		new Float:x, Float:y, Float:z;
		new VehicleID = GetPlayerVehicleID(playerid);
		if(VehicleInfo[VehicleID][EmergencyCopSiren] != 0)
		{
			GetVehiclePos(VehicleID, x, y, z);
			VehicleInfo[VehicleID][EmergencyCopSiren] = 0;
			foreach(new i : Player)
			{
				if(IsPlayerInRangeOfPoint(i, 100.0, x, y, z))
				{
					if(GetPVarInt(i, "CopSiren") != 0) 
                                        {
						StopAudioStreamForPlayer(i);
						SetPVarInt(i, "CopSiren", 0);
					}
				}
			}
		}
	}
	return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
	if(VehicleInfo[vehicleid][EmergencyCopSiren] != 0)
	{ 
		new Float:x, Float:y, Float:z;
		GetVehiclePos(vehicleid, x, y, z);
		foreach(new i : Player)
		{
			if(IsPlayerInRangeOfPoint(i, 100.0, x, y, z))
			{
				if(GetPVarInt(i,"CopSiren") != 0)
				{
					StopAudioStreamForPlayer(i);
					SetPVarInt(i, "CopSiren", 0);
				}
			}
		}
		VehicleInfo[vehicleid][EmergencyCopSiren] = 0;
	}
	return 1;
}

// This is the command to be used: /siren on = turns on the siren, and /siren off = turns it off.
CMD:siren(playerid, params[])
{
	new Float:x, Float:y, Float:z, VehicleID, option[16];
	if(sscanf(params, "s[16]", option))
	{
		SendClientMessage(playerid, 0xFF6347FF, "Usage: /siren [parameter]");
		SendClientMessage(playerid, 0xFF6347FF, "Parameters: {FFFFFF}on, off");
		return true;
	}
	if(strcmp(option, "on", true) == 0)
	{
		VehicleID = GetPlayerVehicleID(playerid);
		GetVehiclePos(VehicleID, x, y, z);
		new link[128];
		format(link, 128, "https://falcon-host.org/uploads/siren.mp3");
		foreach(new i : Player)
		{
			if(IsPlayerInRangeOfPoint(i, 100.0, x, y, z))
			{
				PlayAudioStreamForPlayer(i, link, x, y, z, 100.0, 0);
				SetPVarInt(i, "CopSiren", 1);
			}
		}
		VehicleInfo[VehicleID][EmergencyCopSiren] = 1; // 1 = true
	}
	if(strcmp(option, "off", true) == 0)
	{
		VehicleID = GetPlayerVehicleID(playerid);
		GetVehiclePos(VehicleID, x, y, z);
		foreach(new i : Player)
		{
			if(IsPlayerInRangeOfPoint(i, 100.0, x, y, z))
			{
				if(GetPVarInt(i,"CopSiren") != 0)
				{
					StopAudioStreamForPlayer(i);
					SetPVarInt(i, "CopSiren", 0);
				}
			}
		}
		VehicleInfo[VehicleID][EmergencyCopSiren] = 0; // 0 = not true
	}
	return 1;
}

Links: https://discordapp.com/invite/jr5Ywkm OR https://discord.io/ChaoticTheDev


sscanf Include: https://falcon-host.org/uploads/sscanf.rar
sscanf Plugin: https://falcon-host.org/uploads/sscanf-plugin.rar

foreach Include: https://falcon-host.org/uploads/foreach.rar

a_samp Include: https://falcon-host.org/uploads/a_samp.rar

zcmd Include: https://falcon-host.org/uploads/zcmd.rar


Please Rep me if you like this filterscript


I'll upload a video in the future to let you see what it looks like.
KevTheJoker is offline   Reply With Quote
Old 06/01/2020, 02:56 PM   #2
KensPTV
Big Clucker
 
KensPTV's Avatar
 
Join Date: Oct 2019
Location: Vietnamese
Posts: 110
Reputation: 1
Default Re: Chaotic's Custom Emergency Siren

where demo?
__________________
Kens.P TV @ Youtuber
Scripting @ Samp
Adminstrator @ Designer @ [KG:RP]
KensPTV is offline   Reply With Quote
Old 06/01/2020, 03:00 PM   #3
KevTheJoker
Big Clucker
 
KevTheJoker's Avatar
 
Join Date: Dec 2018
Location: South America
Posts: 80
Reputation: 7
Default Re: Chaotic's Custom Emergency Siren

Quote:
where demo?
Working on it, but you can try it out in your server if you want to. Be sure to leave a rep if it's handy in your projects. You can also use it to play other audios from URLs, instead of the siren only. Good Luck!
KevTheJoker is offline   Reply With Quote
Old 06/01/2020, 03:04 PM   #4
Z3nx31L
Little Clucker
 
Join Date: Aug 2019
Posts: 34
Reputation: 0
Default Re: Chaotic's Custom Emergency Siren

Good job..
__________________

Z3nx31L Is Here
Z3nx31L is offline   Reply With Quote
Old 06/01/2020, 03:04 PM   #5
Huzaif
Little Clucker
 
Join Date: Mar 2018
Posts: 10
Reputation: 0
Default Re: Chaotic's Custom Emergency Siren

Niceone.
Huzaif is offline   Reply With Quote
Old 06/01/2020, 03:09 PM   #6
AjaxM
Big Clucker
 
AjaxM's Avatar
 
Join Date: May 2016
Posts: 180
Reputation: 29
Default Re: Chaotic's Custom Emergency Siren

I like how your release is beautifully detailed and presented.
__________________
Website | Forums| IP: 51.255.215.208:7817
AjaxM is offline   Reply With Quote
Old 06/01/2020, 03:40 PM   #7
Hazon
Huge Clucker
 
Hazon's Avatar
 
Join Date: May 2018
Location: Who cares ?
Posts: 206
Reputation: 37
Default Re: Chaotic's Custom Emergency Siren

Yes, presentation is good, can't say the same for the code.
Hazon is online now   Reply With Quote
Old 07/01/2020, 12:11 AM   #8
TheDiego
Little Clucker
 
Join Date: Sep 2019
Location: Join Date: 00/00/2006
Posts: 14
Reputation: 2
Default Re: Chaotic's Custom Emergency Siren

Looks amazing, well done!
TheDiego is offline   Reply With Quote
Old 11/01/2020, 05:01 PM   #9
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,885
Reputation: 1351
Default Re: Chaotic's Custom Emergency Siren

1.)
Code:
#define MAX_DYNAMIC_CARS 500 // If this isn't already in your script, add it
There are 2000 vehicles max this should be MAX_VEHICLES.

2.)
Code:
 enum VehicleSirenInfo
{
	EmergencyCopSiren
}
No need for an enum here at all.

Code:
stock InAreaWithCopSiren(playerid) // This is to check if a player is in the area with the siren audio
{
	new Float:x, Float:y, Float:z;
	for(new i = 0; i < MAX_DYNAMIC_CARS; i ++)
	{
		GetVehiclePos(i, x, y, z);
		if(IsPlayerInRangeOfPoint(playerid, 100.0, x, y, z))
		{
			if(VehicleInfo[i][EmergencyCopSiren] != 0)
			{
				SetPVarFloat(playerid, "CopSirenX", x);
				SetPVarFloat(playerid, "CopSirenY", y);
				SetPVarFloat(playerid, "CopSirenZ", z);
				return 1;
			}
		}
	}
	return false;
}
Code:
https://wiki.sa-mp.com/wiki/IsVehicleStreamedIn
Wouldn't checking if the vehicle is actually streamed in first be a good idea before doing anything?
Use of pvars is never recommended and should not be used here.

Code:
public OnPlayerUpdate(playerid)
This system is NOT a use case for OnPlayerUpdate() WHY? you ask. Instead of having the players check let the vehicles with sirens on do the checking! It boils down to if you have 100 players and 3 vehicles with sirens on you are having all 100 players check all vehicles each update. It makes a heck of a lot more sense to have 3 vehicles check 100 players every second since 100 meters is such a relatively wide distance +/- 20 meters when it comes to activation should give unnoticeable differentiation when it comes to performance. Even in the best case scenario that all players are standing still so OPU is only called once a second.

Assume 2000 vehicles
Assume 100 players
Assume 3 vehicles activated

Current method - 2000 x 100 = 200,000 iterations
Revised method - 3 x 100 = 300 iterations

That is a massive difference so if you are going to use OPU make sure it is absolutely necessary.

Code:
format(link, 128, "https://falcon-host.org/uploads/siren.mp3"); // This is the siren which I made and merged, but you can change it.
I really don't like hardcoded links in FS you have to assume that any kind of link has expired before the script is even released. Yes this can be changed but if you are going to have hardcoded links define them at the top of the script so the user knows right away this is a configurable option.
Pottus is offline   Reply With Quote
Old 19/08/2020, 11:50 PM   #10
realdiegopoptart
Little Clucker
 
Join Date: Jul 2020
Location: USA
Posts: 3
Reputation: 0
Default Re: Chaotic's Custom Emergency Siren

@KevTheJoker I am getting a Error when I compiled
realdiegopoptart is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Emergency help ThatFag Scripting Help 2 03/09/2016 06:05 AM
Ambulance Siren Sound for the new siren update dionisak0s Scripting Help 13 23/04/2015 06:46 PM
Need Help (emergency) Please! iOmar Server Support 19 13/04/2012 02:30 PM
[FilterScript] [FS] Chaotic Objects - Spice up your GM a bit with this addition. chaosnz Filterscripts 11 27/05/2010 07:56 PM
Emergency Help! Smiths Help Archive 5 14/02/2010 06:07 PM


All times are GMT. The time now is 09:02 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.