06.01.2020, 14:50
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.