Jump to content
  • 0

Adquire a BGM Id from the Name of the map


Question

Posted

Hi,
I would like to know if it's possible to get the
ID of the BGM with the Map Name in source codes. I know that it can be done by creating a table in MySql or with a huge Array variable with all the BGM from All Maps of the Server (more than 1,000 without the custom maps =/) but cost a lot of time.

 

Thank you for your time =)

7 answers to this question

Recommended Posts

  • 0
Posted (edited)

Yep, I know that. What I'm thinking is to get the ID of the BGM with a custom command created in 'src\map\script.c' (Creating a command in source. Something like getBGMid("Prontera").)

What I don't know is: How can I get the information from the player. Is it a packet information? Is there another way to access this information?

 

If not, I'll start create a table to catalog the IDs

Edited by Fratini
  • 0
Posted

Why not make a script command that parses your mp3nametable.txt?

 

Nice! With your tip secret, I think I'm on the right track:

BUILDIN_FUNC(getbgmid){
	struct map_session_data* sd;
	FILE *bgm;
	const char* mcheck="";
	const char* m="";
	int id=0,r=0;
	char output[150];
	
	if(script_getstr(st,2))
		m = script_getstr(st,2);
	else{
		if(!sd){
			ShowDebug("getbgmid: No Player Attached");
			return SCRIPT_CMD_FAILURE;
		}
		m = map_mapid2mapname(sd->bl.m);
	}
	
	if(!(bgm=fopen("db/data/mp3nametable.txt", "r"))){
		ShowDebug("getbgmid: Can't find file 'mp3nametable.txt'");
		sprintf(output, "getbgmid: Can't find file 'mp3nametable.txt'");
		return SCRIPT_CMD_FAILURE;
	}
	
	while(fscanf(bgm,"%s.rsw#bgm\\%d.mp3#\n",mcheck,id)!=EOF && !r){
		if(m==mcheck)
			r=id;
	}
	
	if(r){
		script_pushint(st,id);
		return SCRIPT_CMD_SUCCESS;
	} else {
		sprintf(output, "Couldn't found the BGM ID from %s", m);
		return SCRIPT_CMD_FAILURE;
	}
	
}

I tried to made by writing the name of the Map that you want to know the ID or if you omit the script_getstr(st,2), the script will get the name of the map from the character.

But the map-server keeps crashing...

 

I think it's something about the 'fscanf'. I don't know much about C by the way.

 

PS: I add the BUILDIN_DEF =)

	BUILDIN_DEF(getbgmid,"?"),
  • 0
Posted

Don't parse the file every time you call the script command. Parse it on startup and make the script command grab the name from (maybe) a DBMap.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...