Music Save and Load System
#1

Hello Guys,

I'm working on a boombox system I've found here: https://sampforum.blast.hk/showthread.php?tid=358790

I would like to make it save and load from an INI file but I don't know how to get it to work.

I've did this so far: (but I thing I'm doing some things completely wrong)

Could someone help me please??

Код:
// Includes
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#include <streamer>
#include <dini>
#include <SII>
#include <dcmd>




// Defines
#define COLOR_WHITE 0xFFFFFFFF
#define COLOR_LIGHTBLUE 0x33CCFFFF
#define COLOR_GREY 0xAFAFAFFF
#define MAX_BOOMBOX            	(600)
// 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];

enum dav
{
	boomplayerid,
	boomboxurl[192],
	Float:bposA,
	Float:bposB,
	Float:bposC
};
new BoomBoxInfo[MAX_BOOMBOX][dav];
new BoomBoxIDTaken[MAX_BOOMBOX];
new boomboxes;

LoadBoombox()
{
	for(new i = 1; i < MAX_BOOMBOX; i++)
	{
	    new file[100];
 		new boomboxurlname[192];
	    format(file, sizeof(file), "Boxes/%d.ini", i);
	    if(fexist(file) && INI_Open(file))
	    {
	        BoomBoxInfo[i][boomplayerid] = INI_ReadInt("boomplayerid");
  			INI_ReadString(boomboxurlname, "boomboxurl");
			strmid(BoomBoxInfo[i][boomboxurl], boomboxurlname, 0, strlen(boomboxurlname), 255);
			BoomBoxInfo[i][bposA] = INI_ReadFloat("bposA");
			BoomBoxInfo[i][bposB] = INI_ReadFloat("bposB");
			BoomBoxInfo[i][bposC] = INI_ReadFloat("bposC");
			PlayAudioStreamForPlayer(BoomBoxInfo[i][boomplayerid], BoomBoxInfo[i][boomboxurl], BoomBoxInfo[i][bposA], BoomBoxInfo[i][bposB], BoomBoxInfo[i][bposC], 30, 1);
            // BoomboxPlayer[playerid] = i;
            BoomboxStream[playerid] = 1;
            SendClientMessage(playerid, COLOR_GREY, "You are listening to music coming out of a nearby boombox.");
			BoomBoxIDTaken[i] = 1;
			boomboxes += 1;
			strdel(boomboxurlname, 0, 192);
			INI_Close();
		}
	}
	return 1;
}

SaveBoombox()
{
	for(new i = 1; i < MAX_BOOMBOX; i++)
	{
	    if(BoomBoxIDTaken[i] == 0) continue;
	    new file[100];
	    format(file, sizeof(file), "Boxes/%d.ini", i);
	    if(INI_Open(file))
	    {
	        INI_WriteInt("boomplayerid", BoomBoxInfo[i][boomplayerid]);
         	INI_WriteString("boomboxurl", BoomBoxInfo[i][boomboxurl]);
	        INI_WriteFloat("bposA", BoomBoxInfo[i][bposA]);
	        INI_WriteFloat("bposB", BoomBoxInfo[i][bposB]);
	        INI_WriteFloat("bposC", BoomBoxInfo[i][bposC]);
			INI_Save();
			INI_Close();
		}
	}
	return 1;
}

public OnFilterScriptInit()
{
	LoadBoombox();
	return 1;
}


// 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;
                        }
                    }
            }
        }
        

        
        
        				

				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;
				BoomBoxIDTaken[i] = 1;
				Boombox[playeri] = 1;

				
				BoomBoxInfo[i][bposA] = bpos[playerid][0];
				BoomBoxInfo[i][bposB] = bpos[playerid][1];
				BoomBoxInfo[i][bposC] = bpos[playerid][2];

				strmid(BoomBoxInfo[id][boomboxurl], BoomboxURL[playerid], 0, strlen(BoomboxURL[playerid]), 255);


    			format(string, sizeof(string), " You have placed your boombox at your location.");
        		SendClientMessage(playerid, COLOR_LIGHTBLUE, string);


        		BoomboxObject[playerid] = CreateDynamicObject(2103, bpos[playerid][0], bpos[playerid][1], bpos[playerid][2], 0, 0, bpos[playerid][3]);
        		format(BoomboxURL[playerid], 256, "%s", params);


				boomboxes += 1;
				SaveBoombox();
				return 1;
        
       
    }
    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;
}








// 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;
}
Reply
#2

0 replies so far... Could someone help me please??
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)