From fc1684c82d92de81e5688e33a8386cde3c2407db Mon Sep 17 00:00:00 2001 From: Murilo Pereti Tavares Date: Thu, 25 Jan 2018 01:15:08 -0200 Subject: Implementation of Official Clan System All official features work including the autokick for inactive members And the system is completely customizable. --- src/map/script.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 127 insertions(+), 18 deletions(-) (limited to 'src/map/script.c') diff --git a/src/map/script.c b/src/map/script.c index fc304d4ff..36f37abb9 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -29,6 +29,7 @@ #include "map/channel.h" #include "map/chat.h" #include "map/chrif.h" +#include "map/clan.h" #include "map/clif.h" #include "map/date.h" #include "map/elemental.h" @@ -5593,6 +5594,8 @@ int script_reload(void) itemdb->name_constants(); + clan->set_constants(); + sysinfo->vcsrevision_reload(); return 0; @@ -8627,32 +8630,45 @@ BUILDIN(readparam) { * 2 : guild_id * 3 : account_id * 4 : bg_id + * 5 : clan_id *------------------------------------------*/ BUILDIN(getcharid) { - int num; + int num = script_getnum(st, 2); struct map_session_data *sd; - - num = script_getnum(st,2); - if( script_hasdata(st,3) ) - sd=map->nick2sd(script_getstr(st,3)); + + if (script_hasdata(st, 3)) + sd = map->nick2sd(script_getstr(st, 3)); else - sd=script->rid2sd(st); + sd = script->rid2sd(st); - if(sd==NULL) { - script_pushint(st,0); //return 0, according docs + if (sd == NULL) { + script_pushint(st, 0); //return 0, according docs return true; } - switch( num ) { - case 0: script_pushint(st,sd->status.char_id); break; - case 1: script_pushint(st,sd->status.party_id); break; - case 2: script_pushint(st,sd->status.guild_id); break; - case 3: script_pushint(st,sd->status.account_id); break; - case 4: script_pushint(st,sd->bg_id); break; - default: - ShowError("buildin_getcharid: invalid parameter (%d).\n", num); - script_pushint(st,0); - break; + switch (num) { + case 0: + script_pushint(st, sd->status.char_id); + break; + case 1: + script_pushint(st, sd->status.party_id); + break; + case 2: + script_pushint(st, sd->status.guild_id); + break; + case 3: + script_pushint(st, sd->status.account_id); + break; + case 4: + script_pushint(st, sd->bg_id); + break; + case 5: + script_pushint(st, sd->status.clan_id); + break; + default: + ShowError("buildin_getcharid: invalid parameter (%d).\n", num); + script_pushint(st, 0); + break; } return true; @@ -8900,10 +8916,12 @@ BUILDIN(getguildmember) * 1 : party_name or "" * 2 : guild_name or "" * 3 : map_name + * 4 : clan_name or "" * - : "" *------------------------------------------*/ BUILDIN(strcharinfo) { + struct clan *c; struct guild* g; struct party_data* p; struct map_session_data *sd; @@ -8943,6 +8961,13 @@ BUILDIN(strcharinfo) case 3: script_pushconststr(st, map->list[sd->bl.m].name); break; + case 4: + if ((c = sd->clan) != NULL) { + script_pushstrcopy(st, c->name); + } else { + script_pushconststr(st, ""); + } + break; default: ShowWarning("script:strcharinfo: unknown parameter.\n"); script_pushconststr(st, ""); @@ -23860,6 +23885,85 @@ BUILDIN(rodex_sendmail2) return true; } +/** + * Clan System: Add a player to a clan + */ +BUILDIN(clan_join) +{ + struct map_session_data *sd = NULL; + int clan_id = script_getnum(st, 2); + + if (script_hasdata(st, 3)) + sd = map->id2sd(script_getnum(st, 3)); + else + sd = map->id2sd(st->rid); + + if (sd == NULL) { + script_pushint(st, false); + return false; + } + + if (clan->join(sd, clan_id)) + script_pushint(st, true); + else + script_pushint(st, false); + + return true; +} + +/** + * Clan System: Remove a player from clan + */ +BUILDIN(clan_leave) +{ + struct map_session_data *sd = NULL; + + if (script_hasdata(st, 2)) + sd = map->id2sd(script_getnum(st, 2)); + else + sd = map->id2sd(st->rid); + + if (sd == NULL) { + script_pushint(st, false); + return false; + } + + if (clan->leave(sd, false)) + script_pushint(st, true); + else + script_pushint(st, false); + + return true; +} + +/** + * Clan System: Show clan emblem next to npc name + */ +BUILDIN(clan_master) +{ + struct npc_data *nd = map->id2nd(st->oid); + int clan_id = script_getnum(st, 2); + + if (nd == NULL) { + script_pushint(st, false); + return false; + } else if (clan_id <= 0) { + script_pushint(st, false); + ShowError("buildin_clan_master: Received Invalid Clan ID %d\n", clan_id); + return false; + } else if (clan->search(clan_id) == NULL) { + script_pushint(st, false); + ShowError("buildin_clan_master: Received Id of a nonexistent Clan. Id: %d\n", clan_id); + return false; + } + + nd->clan_id = clan_id; + clif->sc_load(&nd->bl, nd->bl.id, AREA, status->dbs->IconChangeTable[SC_CLAN_INFO], 0, clan_id, 0); + + script_pushint(st, true); + return true; +} + /** * Adds a built-in script function. * @@ -24556,6 +24660,11 @@ void script_parse_builtin(void) { /* Navigation */ BUILDIN_DEF(navigateto, "s??????"), + /* Clan System */ + BUILDIN_DEF(clan_join,"i?"), + BUILDIN_DEF(clan_leave,"?"), + BUILDIN_DEF(clan_master,"i"), + BUILDIN_DEF(channelmes, "ss"), BUILDIN_DEF(addchannelhandler, "ss"), BUILDIN_DEF(removechannelhandler, "ss"), -- cgit v1.2.3-60-g2f50