diff options
Diffstat (limited to 'src/emap/script_buildins.c')
-rw-r--r-- | src/emap/script_buildins.c | 423 |
1 files changed, 419 insertions, 4 deletions
diff --git a/src/emap/script_buildins.c b/src/emap/script_buildins.c index 34d8f54..9430eb7 100644 --- a/src/emap/script_buildins.c +++ b/src/emap/script_buildins.c @@ -14,7 +14,10 @@ #include "map/achievement.h" #include "map/chat.h" #include "map/chrif.h" +#include "map/guild.h" +#include "map/homunculus.h" #include "map/instance.h" +#include "map/mapreg.h" #include "map/npc.h" #include "map/pc.h" #include "map/refine.h" @@ -185,7 +188,8 @@ BUILDIN(npcTalk3) BUILDIN(closeDialog) { getSD(); - send_npccommand(sd, st->oid, 5); + //send_npccommand(sd, st->oid, 5); + send_npccommand(sd, st->oid, 14); return true; } @@ -196,6 +200,32 @@ BUILDIN(closeClientDialog) return true; } +// npcshopattach(npc) will tell the scripts to run an event +// Enabling OnBuyItem and OnSellItem events of npc +BUILDIN(npcshopattach) +{ + const char* npcname = script_getstr(st,2); + struct npc_data* nd = npc->name2id(npcname); + int flag = 1; + + if( script_hasdata(st,3) ) + flag = script_getnum(st,3); + + if( !nd ) { + //Not found. + script_pushint(st,0); + return true; + } + + if (flag) + nd->master_nd = map->id2nd(st->oid); + else + nd->master_nd = NULL; + + script_pushint(st,1); + return true; +} + BUILDIN(shop) { getSD(); @@ -207,8 +237,14 @@ BUILDIN(shop) return false; } + // TMW2 Shops + /* + Move this to a new function, and comment the autoclose + Skip the forced check of SHOP type because I don't like it. + st->state = sd->state.dialog == 1 ? CLOSE : END; clif->scriptclose(sd, st->oid); + */ clif->npcbuysell (sd, nd->bl.id); return true; @@ -999,9 +1035,13 @@ BUILDIN(isPcDead) if (sd == NULL) { - ShowWarning("player not attached\n"); - script->reportsrc(st); - return false; + sd = script->nick2sd(st, script_getstr(st, 2)); + if (sd == NULL) + { + ShowWarning("player not attached\n"); + script->reportsrc(st); + return false; + } } script_pushint(st, pc_isdead(sd) ? 1 : 0); @@ -2342,3 +2382,378 @@ BUILDIN(isInstance) script_pushint(st, instance->valid(instance_id) ? 1 : 0); return true; } + +/////////////////////////////////////////////////////////////////////////////// +// TMW2 Custom Commands +/////////////////////////////////////////////////////////////////////////////// + +/*========================================== + * Return the data of the @guild_id + * null if not found + *------------------------------------------*/ +BUILDIN(getguildinfo) +{ + int guild_id; + struct guild* g; + + guild_id = script_getnum(st,2); + + if( ( g = guild->search(guild_id) ) != NULL ) + { + mapreg->setreg(reference_uid(script->add_variable("$@guildinfo_lvl"), guild_id),g->guild_lv); + mapreg->setreg(reference_uid(script->add_variable("$@guildinfo_avg"), guild_id),g->average_lv); + mapreg->setreg(reference_uid(script->add_variable("$@guildinfo_exp"), guild_id),g->exp); + mapreg->setreg(reference_uid(script->add_variable("$@guildinfo_nxp"), guild_id),g->next_exp); + } + else + { + //script_pushconststr(st,"null"); + script_pushint(st,0); + } + return true; +} + +/*========================================== + * Return the level of the @guild_id + * -1 if not found + *------------------------------------------*/ +BUILDIN(getguildlvl) +{ + int guild_id; + struct guild* g; + + guild_id = script_getnum(st,2); + + if( ( g = guild->search(guild_id) ) != NULL ) + { + script_pushint(st,g->guild_lv); + } + else + { + script_pushint(st,-1); + } + return true; +} + + +/*========================================== + * Return the average player level of the @guild_id + * -1 if not found + *------------------------------------------*/ +BUILDIN(getguildavg) +{ + int guild_id; + struct guild* g; + + guild_id = script_getnum(st,2); + + if( ( g = guild->search(guild_id) ) != NULL ) + { + script_pushint(st,g->average_lv); + } + else + { + script_pushint(st,-1); + } + return true; +} + + +/*========================================== + * Return the experience of the @guild_id + * -1 if not found + *------------------------------------------*/ +BUILDIN(getguildexp) +{ + int guild_id; + struct guild* g; + + guild_id = script_getnum(st,2); + + if( ( g = guild->search(guild_id) ) != NULL ) + { + script_pushint(st,g->exp); + } + else + { + script_pushint(st,-1); + } + return true; +} + + +/*========================================== + * Return the experience to level up for the @guild_id + * -1 if not found + *------------------------------------------*/ +BUILDIN(getguildnxp) +{ + int guild_id; + struct guild* g; + + guild_id = script_getnum(st,2); + + if( ( g = guild->search(guild_id) ) != NULL ) + { + script_pushint(st,g->next_exp); + } + else + { + script_pushint(st,-1); + } + return true; +} + + +/*========================================== + * Change a position for the @guild_id + * -1 if not found + * This will be superseed by ManaPlus eventually + * and is only a quick fix until 4144 can work with GUI. + * Everyone knows C is easier than C++ >.> + * WARNING Not sanitized + *------------------------------------------*/ +BUILDIN(setguildrole) +{ + int guild_id; + int idx; + int mode; + int exp_mode; + const char *name; + struct guild* g; + + guild_id = script_getnum(st,2); + idx = script_getnum(st,3); + mode = script_getnum(st,4); + exp_mode = script_getnum(st,5); + name = script_getstr(st,6); + + if( ( g = guild->search(guild_id) ) != NULL ) + { + script_pushint(st, guild->change_position(guild_id, idx, mode, exp_mode, name)); + } + else + { + script_pushint(st,-1); + } + return true; +} + +/*========================================== + * Get the information of the members of a guild by type. + * getguildmember <guild_id>{,<type>}; + * @param guild_id: ID of guild + * @param type: + * 0 : name (default) + * 1 : character ID + * 2 : account ID + *------------------------------------------*/ +BUILDIN(getguildmember) +{ + struct guild *g = NULL; + int j = 0; + + g = guild->search(script_getnum(st,2)); + + if (g) { + int i, type = 0; + + if (script_hasdata(st,3)) + type = script_getnum(st,3); + + for ( i = 0; i < MAX_GUILD; i++ ) { + if ( g->member[i].account_id ) { + switch (type) { + case 2: + mapreg->setreg(reference_uid(script->add_variable("$@guildmemberaid"), j),g->member[i].account_id); + break; + case 1: + mapreg->setreg(reference_uid(script->add_variable("$@guildmembercid"), j), g->member[i].char_id); + break; + default: + mapreg->setregstr(reference_uid(script->add_variable("$@guildmembername$"), j), g->member[i].name); + break; + } + mapreg->setreg(reference_uid(script->add_variable("$@guildmemberpos"), j),g->member[i].position); + j++; + } + } + } + mapreg->setreg(script->add_variable("$@guildmembercount"), j); + return true; +} + +/*========================================== + * Give homunculus exp + *------------------------------------------*/ +BUILDIN(gethomunexp) +{ + int base=0; + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL || sd->hd == NULL) + return true; + + base = script_getnum(st,2); + if (base < 0) + return true; + + // Cannot give EXP to inactive or dead homunculus + if (!homun_alive(sd->hd)) + return true; + + homun->gainexp(sd->hd, base); + return true; +} + +/*========================================== + * Send resting homunculus in a mission + * Homun must be resting. Returns true on success. + *------------------------------------------*/ +BUILDIN(deployhomunculus) +{ + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL || sd->hd == NULL) + return true; + + /* + // Homunculus must be resting + if (sd->hd->homunculus.vaporize != HOM_ST_REST) + return true; + + // Add morph state. + //sd->hd->homunculus.vaporize=HOM_ST_MORPH; + */ + + // Using the function, I don't need it resting + homun->vaporize(sd, HOM_ST_MORPH); + + // Return true + script_pushint(st,true); + return true; +} + +/*========================================== + * Returns the Homunculus from a mission + * Homun must be morph. Returns true on success. + *------------------------------------------*/ +BUILDIN(recallhomunculus) +{ + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL || sd->hd == NULL) + return true; + + // Homunculus must be vapor + if (sd->hd->homunculus.vaporize != HOM_ST_MORPH) + return true; + + // Remove morph state. + sd->hd->homunculus.vaporize=HOM_ST_REST; + homun->call(sd); // Respawn homunculus. + + // Return true + script_pushint(st,true); + return true; +} + + +/*========================================== + * Returns the Homunculus sleep status + *------------------------------------------*/ +BUILDIN(homstatus) +{ + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL || sd->hd == NULL) + return true; + + // Return the status (0 - active; 1 - resting ; 2 - mission) + script_pushint(st,sd->hd->homunculus.vaporize); + return true; +} + + +/*========================================== + * return the updated stats of sd (use bonus constants) + * Supported values: bStr~bLuk, bMaxHP, bMaxSP, bDef, bMdef, bAtk + *------------------------------------------*/ +BUILDIN(readparam2) +{ + struct map_session_data *sd; + int data = script_getnum(st,2); + + // Account ID/Player Name is also supported + if (script_hasdata(st, 3)) { + if (script_isstringtype(st, 3)) { + sd = script->nick2sd(st, script_getstr(st, 3)); + } else { + sd = script->id2sd(st, script_getnum(st, 3)); + } + } else { + sd = script->rid2sd(st); + } + + // Error + if (sd == NULL) { + script_pushint(st, -1); + return true; + } + + switch (data) { + case 13: + script_pushint(st, sd->battle_status.str); + break; + case 14: + script_pushint(st, sd->battle_status.agi); + break; + case 15: + script_pushint(st, sd->battle_status.vit); + break; + case 16: + script_pushint(st, sd->battle_status.int_); + break; + case 17: + script_pushint(st, sd->battle_status.dex); + break; + case 18: + script_pushint(st, sd->battle_status.luk); + break; + case 6: + script_pushint(st, sd->battle_status.max_hp); + break; + case 8: + script_pushint(st, sd->battle_status.max_sp); + break; + case 45: + script_pushint(st, sd->battle_status.def); + break; + case 41: + script_pushint(st, sd->battle_status.batk+sd->battle_status.rhw.atk); + break; + default: + ShowError("Wrong paramType in readparam2\nAre you sure you used bonus constants?\nSupported values: bMaxHP, bMaxSP, bStr, bAgi, bVit, bInt, bDex, bLuk, bAtk, bDef\n"); + script_pushint(st, -1); + break; + } + + return true; +} + +/*========================================== + * + *------------------------------------------*/ +static BUILDIN(debugmes) +{ + struct StringBuf buf; + StrBuf->Init(&buf); + + if (!script->sprintf_helper(st, 2, &buf)) { + StrBuf->Destroy(&buf); + script_pushint(st, 0); + return false; + } + + ShowDebug("script debug : %d %d : %s\n", st->rid, st->oid, StrBuf->Value(&buf)); + StrBuf->Destroy(&buf); + script_pushint(st, 1); + return true; +} + |