[FilterScript] Boombox Script [Simple]
#1

Boombox Script

Commands/Info

Note*: Plays music global to any player in range of it, don't think any more details needed, this is my first release so i hope it gets positive feedback

- /boombox [url] : Places/Destroys Boombox Object, Plays Music

- /boomboxnext [url] : Changes current song to new url

Pictures

- No Pictures, don't think its needed

Credits

- D_Malfoy

-Include Creators

- SA:MP team

Includes/Plugns (Required)

- SSCANF

- STREAMER

- ZCMD

- FOREACH

Change-log (v2)

- Uses OnPlayerEnterDynamicArea instead of Onplayerupdate (ryansheilds)

- Uses foreach (which i believe its meant to be better)

- Changed Variables to PVar system

Download

pawn Код:
// Includes
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#include <streamer>

// Defines
#define COLOR_WHITE 0xFFFFFFFF
#define COLOR_LIGHTBLUE 0x33CCFFFF
#define COLOR_GREY 0xAFAFAFFF

// Variables
new Boombox[MAX_PLAYERS];
new BoomboxObject[MAX_PLAYERS];
new BoomboxStream[MAX_PLAYERS];
new BoomboxPlayer[MAX_PLAYERS];
new BoomboxURL[MAX_PLAYERS][256];
new Float:bpos[MAX_PLAYERS][4];

// Clearing variables
public OnPlayerConnect(playerid)
{
    Boombox[playerid] = 0;
    BoomboxPlayer[playerid] = -1;
    BoomboxStream[playerid] = 0;
    bpos[playerid][0] = 0; bpos[playerid][1] = 0; bpos[playerid][2] = 0; bpos[playerid][3] = 0;
    format(BoomboxURL[playerid], 256, "");
    if(IsValidDynamicObject(BoomboxObject[playerid])) DestroyDynamicObject(BoomboxObject[playerid]);
    return 1;
}

// Clearing variables & Stopping boombox music on disconnect (Double check)
public OnPlayerDisconnect(playerid)
{
    Boombox[playerid] = 0;
    BoomboxPlayer[playerid] = -1;
    BoomboxStream[playerid] = 0;
    bpos[playerid][0] = 0; bpos[playerid][1] = 0; bpos[playerid][2] = 0; bpos[playerid][3] = 0;
    format(BoomboxURL[playerid], 256, "");
    if(IsValidDynamicObject(BoomboxObject[playerid])) DestroyDynamicObject(BoomboxObject[playerid]);
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(BoomboxPlayer[i] == playerid)
            {
                BoomboxStream[i] = 0;
                BoomboxPlayer[i] = -1;
                StopAudioStreamForPlayer(i);
                SendClientMessage(i, COLOR_GREY, " The boombox creator has disconnected from the server.");
            }
        }
    }
    return 1;
}


// Boombox command - Usage: /boombox [URL]
CMD:boombox(playerid, params[])
{
    new string[128];
    if(!Boombox[playerid])
    {
        if(sscanf(params, "s[256]", params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /boombox [music url]");
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                    if(Boombox[i])
                    {
                        if(IsPlayerInRangeOfPoint(playerid, 30, bpos[i][0], bpos[i][1], bpos[i][2]))
                        {
                            SendClientMessage(playerid, COLOR_GREY, " There is another boombox nearby, place yours somewhere else.");
                            return 1;
                        }
                    }
            }
        }
        Boombox[playerid] = 1;
        format(string, sizeof(string), " You have placed your boombox at your location.");
        SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
        GetPlayerPos(playerid, bpos[playerid][0], bpos[playerid][1], bpos[playerid][2]); bpos[playerid][2] = bpos[playerid][2] - 1;
        GetPlayerFacingAngle(playerid, bpos[playerid][3]); bpos[playerid][3] = bpos[playerid][3] +180;
        BoomboxObject[playerid] = CreateDynamicObject(2103, bpos[playerid][0], bpos[playerid][1], bpos[playerid][2], 0, 0, bpos[playerid][3]);
        format(BoomboxURL[playerid], 256, "%s", params);
    }
    else
    {
        Boombox[playerid] = 0;
        format(string, sizeof(string), " You have removed your boombox.");
        SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
        DestroyDynamicObject(BoomboxObject[playerid]);
        format(BoomboxURL[playerid], 256, "");
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                if(BoomboxPlayer[i] == playerid)
                {
                    BoomboxStream[i] = 0;
                    BoomboxPlayer[i] = -1;
                    StopAudioStreamForPlayer(i);
                    SendClientMessage(i, COLOR_GREY, " The boombox creator has removed his boombox.");
                }
            }
        }
    }
    return 1;
}

// Boombox editing - Usage: /boomboxnext [url]
CMD:boomboxnext(playerid, params[])
{
    if(!Boombox[playerid]) return SendClientMessage(playerid, COLOR_GREY, "You don't have a boombox placed.");
    if(sscanf(params, "s[256]", params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /boomboxnext [music url]");
    SendClientMessage(playerid, COLOR_GREY, " You have changed the music your boombox is playing.");
    format(BoomboxURL[playerid], 256, "%s", params);
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
                if(BoomboxPlayer[i] == playerid)
                {
                    PlayAudioStreamForPlayer(i, BoomboxURL[playerid], bpos[playerid][0], bpos[playerid][1], bpos[playerid][2], 30, 1);
                    SendClientMessage(i, COLOR_GREY, " The boombox music you're listening to has changed.");
                }
        }
    }
    return 1;
}


// Playing/Stopping boombox music for nearby players
public OnPlayerUpdate(playerid)
{
    if(!BoomboxStream[playerid])
    {
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                if(Boombox[i])
                {
                    if(IsPlayerInRangeOfPoint(playerid, 30, bpos[i][0], bpos[i][1], bpos[i][2]))
                    {
                        PlayAudioStreamForPlayer(playerid, BoomboxURL[i], bpos[i][0], bpos[i][1], bpos[i][2], 30, 1);
                        BoomboxPlayer[playerid] = i;
                        BoomboxStream[playerid] = 1;
                        SendClientMessage(playerid, COLOR_GREY, " You are listening to music coming out of a nearby boombox.");
                    }
                }
            }
        }
    }
    else
    {
        new i = BoomboxPlayer[playerid];
        if(!IsPlayerInRangeOfPoint(playerid, 30, bpos[i][0], bpos[i][1], bpos[i][2]))
        {
            BoomboxStream[playerid] = 0;
            BoomboxPlayer[playerid] = -1;
            StopAudioStreamForPlayer(playerid);
            SendClientMessage(playerid, COLOR_GREY, " You have went far away from the boombox.");
        }
    }
    return 1;
}
Download v2
pawn Код:
// Includes
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#include <streamer>
#include <foreach>

// Defines
#define COLOR_WHITE 0xFFFFFFFF
#define COLOR_LIGHTBLUE 0x33CCFFFF
#define COLOR_GREY 0xAFAFAFFF

// Clearing variables
public OnPlayerConnect(playerid)
{
    DeletePVar(playerid, "BoomboxObject"); DeletePVar(playerid, "BoomboxURL");
    DeletePVar(playerid, "bposX"); DeletePVar(playerid, "bposY"); DeletePVar(playerid, "bposZ"); DeletePVar(playerid, "bboxareaid");
    if(IsValidDynamicObject(GetPVarInt(playerid, "BoomboxObject"))) DestroyDynamicObject(GetPVarInt(playerid, "BoomboxObject"));
    return 1;
}

// Clearing variables & Stopping boombox music on disconnect (Double check)
public OnPlayerDisconnect(playerid)
{
    if(GetPVarType(playerid, "BoomboxObject"))
    {
        DestroyDynamicObject(GetPVarInt(playerid, "BoomboxObject"));
        if(GetPVarType(playerid, "bboxareaid"))
        {
            foreach(Player,i)
            {
                if(IsPlayerInDynamicArea(i, GetPVarInt(playerid, "bboxareaid")))
                {
                    StopAudioStreamForPlayer(i);
                     SendClientMessage(i, COLOR_GREY, " The boombox creator has disconnected from the server.");
                }
            }
        }
    }
    return 1;
}


// Boombox command - Usage: /boombox [URL]
CMD:boombox(playerid, params[])
{
    new string[128];
    if(!GetPVarType(playerid, "BoomboxObject"))
    {
        if(sscanf(params, "s[256]", params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /boombox [music url]");
        foreach(Player, i)
        {
            if(GetPVarType(i, "BoomboxObject"))
            {
                if(IsPlayerInRangeOfPoint(playerid, 30.0, GetPVarFloat(i, "bposX"), GetPVarFloat(i, "bposY"), GetPVarFloat(i, "bposZ")))
                {
                    SendClientMessage(playerid, COLOR_GREY, " There is another boombox nearby, place yours somewhere else.");
                    return 1;
                }
            }
        }
       
        new Float:x, Float:y, Float:z, Float:a;
        GetPlayerPos(playerid, x, y, z); GetPlayerFacingAngle(playerid, a);
        SetPVarInt(playerid, "BoomboxObject", CreateDynamicObject(2103, x, y, z, 0.0, 0.0, 0.0, .worldid = GetPlayerVirtualWorld(playerid), .interiorid = GetPlayerInterior(playerid)));
        SetPVarFloat(playerid, "bposX", x); SetPVarFloat(playerid, "bposY", y); SetPVarFloat(playerid, "bposZ", z);
        SetPVarInt(playerid, "bboxareaid", CreateDynamicSphere(x, y, z, 30.0, GetPlayerVirtualWorld(playerid), GetPlayerInterior(playerid)));
        format(string, sizeof(string), " You have placed your boombox at your location.");
        SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
        foreach(Player, i)
        {
            if(IsPlayerInDynamicArea(i, GetPVarInt(playerid, "bboxareaid")))
            {
                PlayAudioStreamForPlayer(i, params, GetPVarFloat(playerid, "bposX"), GetPVarFloat(playerid, "bposY"), GetPVarFloat(playerid, "bposZ"), 30.0, 1);
            }
        }
        SetPVarString(playerid, "BoomboxURL", params);
    }
    else
    {
        DestroyDynamicObject(GetPVarInt(playerid, "BoomboxObject"));
        DeletePVar(playerid, "BoomboxObject"); DeletePVar(playerid, "BoomboxURL");
        DeletePVar(playerid, "bposX"); DeletePVar(playerid, "bposY"); DeletePVar(playerid, "bposZ");
        if(GetPVarType(playerid, "bboxareaid"))
        {
            foreach(Player,i)
            {
                if(IsPlayerInDynamicArea(i, GetPVarInt(playerid, "bboxareaid")))
                {
                    StopAudioStreamForPlayer(i);
                    SendClientMessage(i, COLOR_GREY, " The boombox creator has removed his boombox.");
                }
            }
            DeletePVar(playerid, "bboxareaid");
        }
        SendClientMessage(playerid, COLOR_LIGHTBLUE, " You have removed your boombox.");
    }
    return 1;
}

// Boombox editing - Usage: /boomboxnext [url]
CMD:boomboxnext(playerid, params[])
{
    if(!Boombox[playerid]) return SendClientMessage(playerid, COLOR_GREY, "You don't have a boombox placed.");
    if(sscanf(params, "s[256]", params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /boomboxnext [music url]");
    SendClientMessage(playerid, COLOR_GREY, " You have changed the music your boombox is playing.");
    foreach(Player, i)
    {
        if(IsPlayerInDynamicArea(i, GetPVarInt(playerid, "bboxareaid")))
        {
            PlayAudioStreamForPlayer(i, params, GetPVarFloat(playerid, "bposX"), GetPVarFloat(playerid, "bposY"), GetPVarFloat(playerid, "bposZ"), 30.0, 1);
        }
    }
    SetPVarString(playerid, "BoomboxURL", params);
    return 1;
}

// Playing/Stopping boombox music for nearby players / Updated from Onplayerupdate
public OnPlayerEnterDynamicArea(playerid, areaid)
{
    foreach(Player, i)
    {
        if(GetPVarType(i, "bboxareaid"))
        {
            new station[256];
            GetPVarString(i, "BoomboxURL", station, sizeof(station));
            if(areaid == GetPVarInt(i, "bboxareaid"))
            {
                PlayAudioStreamForPlayer(playerid, station, GetPVarFloat(i, "bposX"), GetPVarFloat(i, "bposY"), GetPVarFloat(i, "bposZ"), 30.0, 1);
                SendClientMessage(playerid, COLOR_GREY, " You are listening to music coming out of a nearby boombox.");
                return 1;
            }
        }
    }
    return 1;
}

public OnPlayerLeaveDynamicArea(playerid, areaid)
{
    foreach(Player, i)
    {
        if(GetPVarType(i, "bboxareaid"))
        {
            if(areaid == GetPVarInt(i, "bboxareaid"))
            {
                StopAudioStreamForPlayer(playerid);
                SendClientMessage(playerid, COLOR_GREY, " You have went far away from the boombox.");
                return 1;
            }
        }
    }
    return 1;
}
Reply
#2

Good script + REP For You
Reply
#3

Quote:
Originally Posted by God'Z War
Посмотреть сообщение
Good script + REP For You
thx for the feedback
Reply
#4

Good 9/10
Reply
#5

Why do you include foreach and never use it? You could also make use of 'CreateDynamicSphere' then 'OnPlayerEnterDynamicArea' rather than 'OnPlayerUpdate'. However good work.
Reply
#6

Very Very Good I give it a 10/10!
Reply
#7

Nicely done. 9/10
Reply
#8

Very Nice, Now people can RP listening out of a boombox except for a bugged /setstation(veh)

REP!+
Reply
#9

Thanks man you rock!!!

This script is gold for me !!

+1 rep
Reply
#10

C:\Users\Suzi\Downloads\samp03e_svr_win32\pawno\bo ombox.pwn(49) : error 017: undefined symbol "StopAudioStreamForPlayer"
C:\Users\Suzi\Downloads\samp03e_svr_win32\pawno\bo ombox.pwn(102) : error 017: undefined symbol "StopAudioStreamForPlayer"
C:\Users\Suzi\Downloads\samp03e_svr_win32\pawno\bo ombox.pwn(124) : error 017: undefined symbol "PlayAudioStreamForPlayer"
C:\Users\Suzi\Downloads\samp03e_svr_win32\pawno\bo ombox.pwn(146) : error 017: undefined symbol "PlayAudioStreamForPlayer"
C:\Users\Suzi\Downloads\samp03e_svr_win32\pawno\bo ombox.pwn(162) : error 017: undefined symbol "StopAudioStreamForPlayer"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


5 Errors.
need h elp with this
Reply
#11

use new samp include
Reply
#12

Wheres the download link this is golden!
Reply
#13

pawn Код:
dcmd_boombox(playerid, params[])
{
    new string[128];
    if(PlayerInfo[playerid][pBoombox] == 1)
    {
        if(!Boombox[playerid])
        {
            if(sscanf(params, "s[128]", params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /boombox [music url]");
            for(new i=0; i<MAX_PLAYERS; i++)
            {
                if(IsPlayerConnected(i))
                {
                        if(Boombox[i])
                        {
                            if(IsPlayerInRangeOfPoint(playerid, 30, bpos[i][0], bpos[i][1], bpos[i][2]))
                            {
                                SendClientMessage(playerid, COLOR_GREY, " There is another boombox nearby, place yours somewhere else.");
                                return 1;
                            }
                        }
                }
            }
            Boombox[playerid] = 1;
            format(string, sizeof(string), " You have placed your boombox at your location.");
            SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
            GetPlayerPos(playerid, bpos[playerid][0], bpos[playerid][1], bpos[playerid][2]); bpos[playerid][2] = bpos[playerid][2] - 1;
            GetPlayerFacingAngle(playerid, bpos[playerid][3]); bpos[playerid][3] = bpos[playerid][3] +180;
            BoomboxObject[playerid] = CreateDynamicObject(2103, bpos[playerid][0], bpos[playerid][1], bpos[playerid][2], 0, 0, bpos[playerid][3]);
            format(BoomboxURL[playerid], 256, "%s", params);
        }
        else
        {
            Boombox[playerid] = 0;
            format(string, sizeof(string), " You have removed your boombox.");
            SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
            DestroyDynamicObject(BoomboxObject[playerid]);
            format(BoomboxURL[playerid], 256, "");
            for(new i=0; i<MAX_PLAYERS; i++)
            {
                if(IsPlayerConnected(i))
                {
                    if(BoomboxPlayer[i] == playerid)
                    {
                        BoomboxStream[i] = 0;
                        BoomboxPlayer[i] = -1;
                        StopAudioStreamForPlayer(i);
                        SendClientMessage(i, COLOR_GREY, " The boombox creator has removed his boombox.");
                    }
                }
            }
        }
    }
    else
    {
        SendClientMessage(playerid, COLOR_GREY, "You don't have a boombox, buy one at the 24/7 for $125.");
        return 1;
    }
    return 1;
}
Says unknown command, what's the bug here ?
Reply
#14

Quote:
Originally Posted by ryansheilds
Посмотреть сообщение
Why do you include foreach and never use it? You could also make use of 'CreateDynamicSphere' then 'OnPlayerEnterDynamicArea' rather than 'OnPlayerUpdate'. However good work.
I fully agree with you!
Reply
#15

Good job man, Rep+.
Reply
#16

Nvm.
Reply
#17

Quote:
Originally Posted by Shazwan
Посмотреть сообщение
C:\Users\Suzi\Downloads\samp03e_svr_win32\pawno\bo ombox.pwn(49) : error 017: undefined symbol "StopAudioStreamForPlayer"
C:\Users\Suzi\Downloads\samp03e_svr_win32\pawno\bo ombox.pwn(102) : error 017: undefined symbol "StopAudioStreamForPlayer"
C:\Users\Suzi\Downloads\samp03e_svr_win32\pawno\bo ombox.pwn(124) : error 017: undefined symbol "PlayAudioStreamForPlayer"
C:\Users\Suzi\Downloads\samp03e_svr_win32\pawno\bo ombox.pwn(146) : error 017: undefined symbol "PlayAudioStreamForPlayer"
C:\Users\Suzi\Downloads\samp03e_svr_win32\pawno\bo ombox.pwn(162) : error 017: undefined symbol "StopAudioStreamForPlayer"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


5 Errors.
need h elp with this
Anyone going to help him?
Reply
#18

Quote:
Originally Posted by Mark Shade
Посмотреть сообщение
Anyone going to help him?
If you review the audio plugin update. You could easily see the updates because those aren't the recalls anymore. ~

Here is a link for the thread : https://sampforum.blast.hk/showthread.php?tid=82162

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
Reply
#19

Nice job
Reply
#20

That's what I needed
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)