From 7991c7c91af27fdd65913695b285ee7c422d3665 Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Sat, 25 Jan 2020 13:24:04 -0300 Subject: ChangePlayerMusic() --- src/emap/init.c | 1 + src/emap/script_buildins.c | 27 +++++++++++++++++++++++++++ src/emap/script_buildins.h | 1 + src/emap/send.c | 22 ++++++++++++++++++++++ src/emap/send.h | 1 + 5 files changed, 52 insertions(+) (limited to 'src/emap') diff --git a/src/emap/init.c b/src/emap/init.c index b469281..dcb046b 100644 --- a/src/emap/init.c +++ b/src/emap/init.c @@ -167,6 +167,7 @@ HPExport void plugin_init (void) addScriptCommand("setavataraction", "i", setAvatarAction); addScriptCommand("clear", "", clear); addScriptCommand("changemusic", "ss", changeMusic); + addScriptCommand("changeplayermusic", "s", changePlayerMusic); addScriptCommand("setnpcdialogtitle", "s", setNpcDialogTitle); addScriptCommand("getmapname", "", getMapName); addScriptCommand("unequipbyid", "i", unequipById); diff --git a/src/emap/script_buildins.c b/src/emap/script_buildins.c index 297fb4e..65ac653 100644 --- a/src/emap/script_buildins.c +++ b/src/emap/script_buildins.c @@ -954,6 +954,33 @@ BUILDIN(changeMusic) return true; } +// changePlayerMusic(music) +BUILDIN(changePlayerMusic) +{ + const char *const music = script_getstr(st, 2); + //ShowWarning("ChangePlayerMusic called\n"); + if (!music) + { + ShowWarning("invalid music file\n"); + script->reportsrc(st); + return false; + } + //ShowWarning("Music defined as %s\n", (char*)(music)); + + struct map_session_data *sd = NULL; + sd = script->rid2sd(st); + if (sd == NULL) + { + ShowWarning("player not attached\n"); + script->reportsrc(st); + return false; + } + + //ShowWarning("Sending data\n"); + send_changemusic(sd->fd, music); + return true; +} + BUILDIN(setNpcDialogTitle) { const char *const name = script_getstr(st, 2); diff --git a/src/emap/script_buildins.h b/src/emap/script_buildins.h index e8fdcf7..53907bd 100644 --- a/src/emap/script_buildins.h +++ b/src/emap/script_buildins.h @@ -40,6 +40,7 @@ BUILDIN(setAvatarDir); BUILDIN(setAvatarAction); BUILDIN(clear); BUILDIN(changeMusic); +BUILDIN(changePlayerMusic); BUILDIN(setNpcDialogTitle); BUILDIN(getMapName); BUILDIN(unequipById); diff --git a/src/emap/send.c b/src/emap/send.c index 08c57b0..df60611 100644 --- a/src/emap/send.c +++ b/src/emap/send.c @@ -298,6 +298,28 @@ void send_advmoving(struct unit_data* ud, bool moving, struct block_list *tbl, e aFree(buf); } + +void send_changemusic(int fd, const char *music) +{ + if (!music) + return; + + const int sz = (int)strlen(music) + 5; + char *buf; + + // Setup the packet + CREATE(buf, char, sz); + WBUFW (buf, 0) = 0xb05 + evolPacketOffset; + WBUFW (buf, 2) = sz; + strcpy (WBUFP (buf, 4), music); + // Send the packet + WFIFOHEAD(fd,sz); + memcpy(WFIFOP(fd,0), buf, sz); + WFIFOSET(fd,sz); + // Free the buffer + aFree(buf); +} + void send_changemusic_brodcast(const int map, const char *music) { if (!music) diff --git a/src/emap/send.h b/src/emap/send.h index b89f1fc..880cdb7 100644 --- a/src/emap/send.h +++ b/src/emap/send.h @@ -22,6 +22,7 @@ void send_mapmask(int fd, int mask); void send_mapmask_brodcast(const int map, const int mask); void send_mob_info(struct block_list* bl1, struct block_list* bl2, enum send_target target); void send_advmoving(struct unit_data* ud, bool moving, struct block_list *tbl, enum send_target target); +void send_changemusic(int fd, const char *music); void send_changemusic_brodcast(const int map, const char *music); void send_changenpc_title (struct map_session_data *sd, const int npcId, const char *name); void send_join_ack(int fd, const char *const name, int flag); -- cgit v1.2.3-70-g09d2