Help With Boombox script
#1

Hello, well me and my friend are trying to script a boombox(music player) with RL radio stations.

But we got a problem, we scripted it like this:

-We saved like 8 positions IG and created music player objects in those coordinates(you can hear music from each one within the specific radius)

Well the problem is if we turn on some radio station for some reason it takes the coordinates of each boombox and by that it fucks up the streamed radio link and we cannot hear it, but if for example we will disable the radiuses for each boombox the radio starts to play.

Well We need to make it so that the music playing cmd wont touch every boombox coordinate but it should enable only the 1 that player is standing near.

here is half of the code that might be causing the problem

Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == CHANNEL_DIALOGID)
    {
  		GetObjectPos(gsf,box[0],box[1],box[2]);
  		GetObjectPos(sbf,box[0],box[1],box[2]);
  		GetObjectPos(tdf,box[0],box[1],box[2]);
  		GetObjectPos(fyb,box[0],box[1],box[2]);
  		GetObjectPos(rhb,box[0],box[1],box[2]);
  		GetObjectPos(ktb,box[0],box[1],box[2]);
  		GetObjectPos(tdb,box[0],box[1],box[2]);
  		GetObjectPos(v,box[0],box[1],box[2]);
  		GetObjectPos(vla,box[0],box[1],box[2]);
PS. The "gsf","sbf","tdf" etc.. parts are the created boomboxes:

Example:
Код:
CreateMusicBox(FUNBOX, 2489.7170,-1648.9633,13.5063 -1, 0.0,0.0,0.0,100);
Код:
stock CreateMusicBox(modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ, Float:DrawDistance)
{
	new musicbox = CreateObject(modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ, Float:DrawDistance);
	RadioObject[musicbox] = 1;
	return musicbox;
}
-Please someone help and thank you.
Reply
#2

Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == CHANNEL_DIALOGID)
    {
  		GetObjectPos(gsf,box[0],box[1],box[2]);
  		GetObjectPos(sbf,box[0],box[1],box[2]);
  		GetObjectPos(tdf,box[0],box[1],box[2]);
  		GetObjectPos(fyb,box[0],box[1],box[2]);
  		GetObjectPos(rhb,box[0],box[1],box[2]);
  		GetObjectPos(ktb,box[0],box[1],box[2]);
  		GetObjectPos(tdb,box[0],box[1],box[2]);
  		GetObjectPos(v,box[0],box[1],box[2]);
  		GetObjectPos(vla,box[0],box[1],box[2]);
I'm assuming you're using box[0], box[1], box[2] to play the stream. That being the case this would only play the stream at the coordinates of 'vla' (hence why it works if you disable the radius, because this one is actually playing). Each call is overwriting the coordinates currently saved. You will need to make a separate variable for each boombox.
E.G:
Код:
new box1[2],
    box2[2];

GetObjectPos(gsf,box1[0],box1[1],box1[2]);
GetObjectPos(sbf,box2[0],box2[1],box2[2]);
etc..
Reply
#3

I'm not sure what you mean, but SA. is probably right at what you've done wrong. However, there is an easier way and you won't have to edit the whole script when you add a new boombox. We use a method to count how many (static) objects were created, loop through them, check if any of the object reensambles a boombox and process it:

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == CHANNEL_DIALOGID)
    {
        // CreateObject returns the ID of the new object
        new object_count = CreateObject(1337, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0)+1;
        new Float:box[3];
        for(new i = 0; i != object_count; i++ )
        {
            if(RadioObject[i] != 0)
            {
                GetObjectPos(i, box[0], box[1], box[2]);
                {
                    // do something
                }
            }
        }
        DestroyObject(object_count); // We need to destroy the useless object.
    }
}
I hope it works for you.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)