summaryrefslogtreecommitdiff
path: root/src/map/script-fun.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/script-fun.cpp')
-rw-r--r--src/map/script-fun.cpp215
1 files changed, 126 insertions, 89 deletions
diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp
index e51a692..2c09ba6 100644
--- a/src/map/script-fun.cpp
+++ b/src/map/script-fun.cpp
@@ -80,14 +80,14 @@ namespace map
if (st->oid) { \
dumb_ptr<npc_data> nullpo_nd = map_id_is_npc(st->oid); \
if (nullpo_nd && nullpo_nd->name) { \
- PRINTF("script:%s: " #error " @ %s\n"_fmt, BUILTIN_NAME(), nullpo_nd->name); \
+ PRINTF("script:%s: %s @ %s\n"_fmt, BUILTIN_NAME(), error, nullpo_nd->name); \
} else if (nullpo_nd) { \
- PRINTF("script:%s: " #error " (unnamed npc)\n"_fmt, BUILTIN_NAME()); \
+ PRINTF("script:%s: %s (unnamed npc)\n"_fmt, BUILTIN_NAME(), error); \
} else { \
- PRINTF("script:%s: " #error " (no npc)\n"_fmt, BUILTIN_NAME()); \
+ PRINTF("script:%s: %s (no npc)\n"_fmt, BUILTIN_NAME(), error); \
} \
} else { \
- PRINTF("script:%s: " #error " (no npc)\n"_fmt, BUILTIN_NAME()); \
+ PRINTF("script:%s: %s (no npc)\n"_fmt, BUILTIN_NAME(), error); \
} \
st->state = ScriptEndState::END; \
return; \
@@ -111,7 +111,7 @@ static
void builtin_mes(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
sd->state.npc_dialog_mes = 1;
RString mes = HARG(0) ? conv_str(st, &AARG(0)) : ""_s;
clif_scriptmes(sd, st->oid, mes);
@@ -125,7 +125,7 @@ static
void builtin_mesq(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
sd->state.npc_dialog_mes = 1;
RString mes = HARG(0) ? conv_str(st, &AARG(0)) : ""_s;
MString mesq;
@@ -145,8 +145,8 @@ void builtin_mesn(ScriptState *st)
dumb_ptr<map_session_data> sd = script_rid2sd(st);
dumb_ptr<npc_data> nd;
nd = map_id_is_npc(st->oid);
- script_nullpo_end(nd, "npc not found");
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(nd, "npc not found"_s);
+ script_nullpo_end(sd, "player not found"_s);
sd->state.npc_dialog_mes = 1;
RString mes = HARG(0) ? conv_str(st, &AARG(0)) : RString(nd->name.xislice_h(std::find(nd->name.begin(), nd->name.end(), '#'))); // strnpcinf
MString mesq;
@@ -164,7 +164,7 @@ static
void builtin_clear(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
clif_npc_action(sd, st->oid, 9, 0, 0, 0);
}
@@ -389,7 +389,7 @@ static
void builtin_next(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
st->state = ScriptEndState::STOP;
clif_scriptnext(sd, st->oid);
}
@@ -411,7 +411,7 @@ void builtin_close(ScriptState *st)
}
st->state = ScriptEndState::END;
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
if (sd->state.npc_dialog_mes)
clif_scriptclose(sd, st->oid);
@@ -428,7 +428,7 @@ void builtin_close2(ScriptState *st)
{
st->state = ScriptEndState::STOP;
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
if (sd->state.npc_dialog_mes)
clif_scriptclose(sd, st->oid);
else
@@ -443,7 +443,7 @@ static
void builtin_menu(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
if (sd->state.menu_or_input == 0)
{
@@ -676,7 +676,7 @@ void builtin_isat(ScriptState *st)
x = conv_num(st, &AARG(1));
y = conv_num(st, &AARG(2));
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
push_int<ScriptDataInt>(st->stack,
(x == sd->bl_x) && (y == sd->bl_y)
@@ -695,7 +695,7 @@ void builtin_warp(ScriptState *st)
MapName str = stringish<MapName>(ZString(conv_str(st, &AARG(0))));
x = conv_num(st, &AARG(1));
y = conv_num(st, &AARG(2));
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
pc_setpos(sd, str, x, y, BeingRemoveWhy::GONE);
}
@@ -748,7 +748,7 @@ void builtin_heal(ScriptState *st)
hp = conv_num(st, &AARG(0));
sp = conv_num(st, &AARG(1));
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
if(sd != nullptr && (sd->status.hp < 1 && hp > 0)){
pc_setstand(sd);
@@ -901,7 +901,7 @@ void builtin_input(ScriptState *st)
char postfix = name.back();
sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
if (sd->state.menu_or_input)
{
// Second time (rerun)
@@ -962,7 +962,7 @@ void builtin_requestitem(ScriptState *st)
}
sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
if (sd->state.menu_or_input)
{
// Second time (rerunline)
@@ -1055,7 +1055,7 @@ void builtin_requestlang(ScriptState *st)
ZString name = variable_names.outtern(reg.base());
char postfix = name.back();
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
if (postfix != '$')
{
@@ -1247,7 +1247,7 @@ void builtin_foreach(ScriptState *st)
else if (st->rid)
sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
map_foreachinarea(std::bind(builtin_foreach_sub, ph::_1, event, sd->bl_id),
m,
@@ -1279,12 +1279,23 @@ void builtin_destroy(ScriptState *st)
/* Not safe to call destroy if others may also be paused on this NPC! */
if (st->rid) {
sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
npc_event_dequeue(sd);
}
+ // Cancel all existing timers on the NPC.
+ // They "would" never fire, and we don't want race conditions here.
+ for (int i = 0; i < MAX_EVENTTIMER; i++)
+ {
+ nd->eventtimer[i].cancel();
+ }
+ // Schedule the NPC to be freed on the next available tick.
+ // Scripts can be invoked under iteration of the ev_db global event
+ // database, and we don't want to invalidate active iterators.
+ nd->deletion_pending = npc_data::DELETION_QUEUED;
+ nd->eventtimer[0] = Timer(gettick(), std::bind(npc_free, nd));
+
nd = nd->is_script();
- npc_free(nd);
st->oid = BlockId();
if (!HARG(0))
@@ -1350,7 +1361,7 @@ void builtin_puppet(ScriptState *st)
nd->npc_subtype = NpcSubtype::SCRIPT;
npc_script++;
- nd->deletion_pending = false;
+ nd->deletion_pending = npc_data::NOT_DELETING;
nd->n = map_addnpc(nd->bl_m, nd);
@@ -1453,7 +1464,7 @@ void builtin_set(ScriptState *st)
else
{
bl = script_rid2sd(st);
- script_nullpo_end(bl, "player not found");
+ script_nullpo_end(bl, "player not found"_s);
}
int val = conv_num(st, &AARG(1));
@@ -1628,14 +1639,14 @@ void builtin_setarray(ScriptState *st)
else
bl = map_id_is_npc(wrap<BlockId>(tid));
}
- script_nullpo_end(bl, "npc not found");
+ script_nullpo_end(bl, "npc not found"_s);
if (st->oid && bl->bl_id != st->oid)
j = getarraysize2(reg, bl);
}
else if (prefix != '$' && !name.startswith(".@"_s))
{
bl = map_id_is_player(st->rid);
- script_nullpo_end(bl, "player not found");
+ script_nullpo_end(bl, "player not found"_s);
}
for (; i < st->end - st->start - 2 && j < 256; i++, j++)
@@ -1674,7 +1685,7 @@ void builtin_cleararray(ScriptState *st)
else if (prefix != '$' && !name.startswith(".@"_s))
{
bl = map_id_is_player(st->rid);
- script_nullpo_end(bl, "player not found");
+ script_nullpo_end(bl, "player not found"_s);
}
for (int i = 0; i < sz; i++)
@@ -1847,7 +1858,7 @@ void builtin_gmlog(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
ZString message = ZString(conv_str(st, &AARG(0)));
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
log_atcommand(sd, STRPRINTF("{SCRIPT} %s"_fmt, message));
}
@@ -1861,7 +1872,7 @@ void builtin_setlook(ScriptState *st)
dumb_ptr<map_session_data> sd = script_rid2sd(st);
LOOK type = LOOK(conv_num(st, &AARG(0)));
int val = conv_num(st, &AARG(1));
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
pc_changelook(sd, type, val);
@@ -1881,7 +1892,7 @@ void builtin_countitem(ScriptState *st)
struct script_data *data;
sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
data = &AARG(0);
get_val(st, data);
@@ -1929,7 +1940,7 @@ void builtin_checkweight(ScriptState *st)
struct script_data *data;
sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
data = &AARG(0);
get_val(st, data);
@@ -1978,7 +1989,7 @@ void builtin_getitem(ScriptState *st)
struct script_data *data;
sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
data = &AARG(0);
get_val(st, data);
@@ -2082,7 +2093,7 @@ void builtin_delitem(ScriptState *st)
struct script_data *data;
sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
data = &AARG(0);
get_val(st, data);
@@ -2133,7 +2144,7 @@ static
void builtin_getversion(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
push_int<ScriptDataInt>(st->stack, unwrap<ClientVersion>(sd->client_version));
}
@@ -2220,7 +2231,7 @@ void builtin_strcharinfo(ScriptState *st)
else
sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
num = conv_num(st, &AARG(0));
if (num == 0)
@@ -2277,7 +2288,7 @@ void builtin_getequipid(ScriptState *st)
else
sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
num = conv_num(st, &AARG(0));
IOff0 i = pc_checkequip(sd, equip[num - 1]);
if (i.ok())
@@ -2336,7 +2347,7 @@ void builtin_bonus(ScriptState *st)
type = SP(conv_num(st, &AARG(0)));
int val = conv_num(st, &AARG(1));
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
pc_bonus(sd, type, val);
}
@@ -2357,7 +2368,7 @@ void builtin_bonus2(ScriptState *st)
int type2 = conv_num(st, &AARG(1));
int val = conv_num(st, &AARG(2));
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
pc_bonus2(sd, type, type2, val);
}
@@ -2378,7 +2389,7 @@ void builtin_skill(ScriptState *st)
if (HARG(2))
flag = conv_num(st, &AARG(2));
sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
pc_skill(sd, id, level, flag);
clif_skillinfoblock(sd);
@@ -2397,7 +2408,7 @@ void builtin_setskill(ScriptState *st)
SkillID id = static_cast<SkillID>(conv_num(st, &AARG(0)));
level = conv_num(st, &AARG(1));
sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
level = std::min(level, MAX_SKILL_LEVEL);
level = std::max(level, 0);
@@ -2415,7 +2426,7 @@ void builtin_getskilllv(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
SkillID id = SkillID(conv_num(st, &AARG(0)));
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
push_int<ScriptDataInt>(st->stack, pc_checkskill(sd, id));
}
@@ -2427,7 +2438,7 @@ static
void builtin_overrideattack(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
//PRINTF("inside override attack!!\n"_fmt);
if (HARG(0))
@@ -2477,7 +2488,7 @@ static
void builtin_getgmlevel(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
push_int<ScriptDataInt>(st->stack, pc_isGM(sd).get_all_bits());
}
@@ -2510,7 +2521,7 @@ void builtin_getopt2(ScriptState *st)
dumb_ptr<map_session_data> sd;
sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
push_int<ScriptDataInt>(st->stack, static_cast<uint16_t>(sd->opt2));
@@ -2527,7 +2538,7 @@ void builtin_setopt2(ScriptState *st)
Opt2 new_opt2 = Opt2(conv_num(st, &AARG(0)));
sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
if (new_opt2 == sd->opt2)
return;
@@ -2548,7 +2559,7 @@ void builtin_savepoint(ScriptState *st)
dumb_ptr<map_session_data> sd = script_rid2sd(st);
int x, y;
MapName str = stringish<MapName>(ZString(conv_str(st, &AARG(0))));
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
x = conv_num(st, &AARG(1));
y = conv_num(st, &AARG(2));
@@ -2648,7 +2659,7 @@ void builtin_openstorage(ScriptState *st)
// int sync = 0;
// if (st->end >= 3) sync = conv_num(st,& (st->stack->stack_data[st->start+2]));
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
// if (sync) {
st->state = ScriptEndState::STOP;
@@ -2668,7 +2679,7 @@ void builtin_getexp(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
int base = 0, job = 0;
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
base = conv_num(st, &AARG(0));
job = conv_num(st, &AARG(1));
@@ -2981,7 +2992,7 @@ void builtin_mobinfo_droparrays(ScriptState *st)
else if (prefix != '$' && !name.startswith(".@"_s))
{
bl = map_id_is_player(st->rid);
- script_nullpo_end(bl, "player not found");
+ script_nullpo_end(bl, "player not found"_s);
}
switch (request)
@@ -3334,7 +3345,7 @@ void builtin_addtimer(ScriptState *st)
else if (st->rid)
sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
pc_addeventtimer(sd, tick, event);
}
@@ -3367,7 +3378,7 @@ void builtin_initnpctimer(ScriptState *st)
nd_ = npc_name2id(stringish<NpcName>(ZString(conv_str(st, &AARG(0)))));
else
nd_ = map_id_is_npc(st->oid);
- script_nullpo_end(nd_, "no npc");
+ script_nullpo_end(nd_, "no npc"_s);
assert (nd_ && nd_->npc_subtype == NpcSubtype::SCRIPT);
dumb_ptr<npc_data_script> nd = nd_->is_script();
@@ -3388,7 +3399,7 @@ void builtin_startnpctimer(ScriptState *st)
nd_ = npc_name2id(stringish<NpcName>(ZString(conv_str(st, &AARG(0)))));
else
nd_ = map_id_is_npc(st->oid);
- script_nullpo_end(nd_, "no npc");
+ script_nullpo_end(nd_, "no npc"_s);
assert (nd_ && nd_->npc_subtype == NpcSubtype::SCRIPT);
dumb_ptr<npc_data_script> nd = nd_->is_script();
@@ -3408,7 +3419,7 @@ void builtin_stopnpctimer(ScriptState *st)
nd_ = npc_name2id(stringish<NpcName>(ZString(conv_str(st, &AARG(0)))));
else
nd_ = map_id_is_npc(st->oid);
- script_nullpo_end(nd_, "no npc");
+ script_nullpo_end(nd_, "no npc"_s);
assert (nd_ && nd_->npc_subtype == NpcSubtype::SCRIPT);
dumb_ptr<npc_data_script> nd = nd_->is_script();
@@ -3430,7 +3441,7 @@ void builtin_getnpctimer(ScriptState *st)
nd_ = npc_name2id(stringish<NpcName>(ZString(conv_str(st, &AARG(1)))));
else
nd_ = map_id_is_npc(st->oid);
- script_nullpo_end(nd_, "no npc");
+ script_nullpo_end(nd_, "no npc"_s);
assert (nd_ && nd_->npc_subtype == NpcSubtype::SCRIPT);
dumb_ptr<npc_data_script> nd = nd_->is_script();
@@ -3463,7 +3474,7 @@ void builtin_setnpctimer(ScriptState *st)
nd_ = npc_name2id(stringish<NpcName>(ZString(conv_str(st, &AARG(1)))));
else
nd_ = map_id_is_npc(st->oid);
- script_nullpo_end(nd_, "no npc");
+ script_nullpo_end(nd_, "no npc"_s);
assert (nd_ && nd_->npc_subtype == NpcSubtype::SCRIPT);
dumb_ptr<npc_data_script> nd = nd_->is_script();
@@ -3482,7 +3493,7 @@ void builtin_npcaction(ScriptState *st)
int id = 0;
short x = HARG(2) ? conv_num(st, &AARG(2)) : 0;
short y = HARG(3) ? conv_num(st, &AARG(3)) : 0;
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
if(HARG(1))
{
@@ -3507,7 +3518,7 @@ static
void builtin_camera(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
if (HARG(0))
{
@@ -3564,7 +3575,7 @@ void builtin_setnpcdirection(ScriptState *st)
else
nd_ = map_id_is_npc(st->oid);
- script_nullpo_end(nd_, "no npc");
+ script_nullpo_end(nd_, "no npc"_s);
if (bool(conv_num(st, &AARG(1))))
action = DamageType::SIT;
@@ -3580,7 +3591,7 @@ void builtin_setnpcdirection(ScriptState *st)
if (st->rid)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
clif_sitnpc_towards(sd, nd_, action);
clif_setnpcdirection_towards(sd, nd_, dir);
}
@@ -3610,7 +3621,7 @@ void builtin_announce(ScriptState *st)
bl = map_id2bl(st->oid);
else
bl = script_rid2sd(st);
- script_nullpo_end(bl, "player not found");
+ script_nullpo_end(bl, "player not found"_s);
clif_GMmessage(bl, str, flag);
}
else
@@ -3992,7 +4003,7 @@ void builtin_resetstatus(ScriptState *st)
{
dumb_ptr<map_session_data> sd;
sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
pc_resetstate(sd);
}
@@ -4174,7 +4185,7 @@ void builtin_setpvpchannel(ScriptState *st)
if (flag < 1)
flag = 0;
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
sd->state.pvpchannel = flag;
}
@@ -4191,7 +4202,7 @@ void builtin_getpvpflag(ScriptState *st)
else
sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
int num = conv_num(st, &AARG(0));
int flag = 0;
@@ -4373,7 +4384,7 @@ static
void builtin_getpartnerid2(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
push_int<ScriptDataInt>(st->stack, unwrap<CharId>(sd->status.partner_id));
}
@@ -4438,7 +4449,7 @@ void builtin_explode(ScriptState *st)
else if (prefix != '$' && prefix != '.')
{
bl = map_id2bl(st->rid)->is_player();
- script_nullpo_end(bl, "target player not found");
+ script_nullpo_end(bl, "target player not found"_s);
}
@@ -4489,7 +4500,7 @@ void builtin_getinventorylist(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
int j = 0;
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
for (IOff0 i : IOff0::iter())
{
@@ -4520,7 +4531,7 @@ void builtin_getactivatedpoolskilllist(ScriptState *st)
int skill_pool_size = skill_pool(sd, pool_skills);
int i, count = 0;
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
for (i = 0; i < skill_pool_size; i++)
{
@@ -4553,7 +4564,7 @@ void builtin_getunactivatedpoolskilllist(ScriptState *st)
dumb_ptr<map_session_data> sd = script_rid2sd(st);
int i, count = 0;
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
for (i = 0; i < skill_pool_skills.size(); i++)
{
@@ -4585,7 +4596,7 @@ void builtin_poolskill(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
SkillID skill_id = SkillID(conv_num(st, &AARG(0)));
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
skill_pool_activate(sd, skill_id);
clif_skillinfoblock(sd);
@@ -4600,7 +4611,7 @@ void builtin_unpoolskill(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
SkillID skill_id = SkillID(conv_num(st, &AARG(0)));
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
skill_pool_deactivate(sd, skill_id);
clif_skillinfoblock(sd);
@@ -4844,7 +4855,7 @@ void builtin_nude(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
for (EQUIP i : EQUIPs)
{
@@ -4864,7 +4875,7 @@ static
void builtin_unequipbyid(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
EQUIP slot_id = EQUIP(conv_num(st, &AARG(0)));
@@ -5005,7 +5016,7 @@ void builtin_title(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
ZString msg = ZString(conv_str(st, &AARG(0)));
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
clif_npc_send_title(sd->sess, st->oid, msg);
}
@@ -5026,7 +5037,7 @@ void builtin_smsg(ScriptState *st)
int type = HARG(1) ? conv_num(st, &AARG(0)) : 0;
ZString msg = ZString(conv_str(st, (HARG(1) ? &AARG(1) : &AARG(0))));
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
if (type < 0 || type > 0xFF)
type = 0;
@@ -5041,7 +5052,7 @@ static
void builtin_remotecmd(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
if (HARG(1))
{
@@ -5068,7 +5079,7 @@ void builtin_sendcollision(ScriptState *st)
short x1, y1, x2, y2;
x1 = x2 = conv_num(st, &AARG(2));
y1 = y2 = conv_num(st, &AARG(3));
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
if (HARG(5))
{
@@ -5101,7 +5112,7 @@ void builtin_music(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
ZString msg = ZString(conv_str(st, &AARG(0)));
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
clif_change_music(sd, msg);
}
@@ -5126,7 +5137,7 @@ void builtin_mapmask(ScriptState *st)
else if(HARG(1) && nd)
nd->bl_m->mask = map_mask;
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
clif_send_mask(sd, map_mask);
}
@@ -5208,7 +5219,7 @@ void builtin_getlook(ScriptState *st)
dumb_ptr<map_session_data> sd = script_rid2sd(st);
LOOK type = LOOK(conv_num(st, &AARG(0)));
int val = -1;
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
switch (type)
{
@@ -5252,7 +5263,7 @@ void builtin_getsavepoint(ScriptState *st)
{
int x, y, type;
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
type = conv_num(st, &AARG(0));
@@ -5346,7 +5357,7 @@ void builtin_isin(ScriptState *st)
x2 = conv_num(st, &AARG(3));
y2 = conv_num(st, &AARG(4));
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
push_int<ScriptDataInt>(st->stack,
(sd->bl_x >= x1 && sd->bl_x <= x2)
@@ -5382,7 +5393,7 @@ void builtin_shop(ScriptState *st)
dumb_ptr<map_session_data> sd = script_rid2sd(st);
dumb_ptr<npc_data> nd;
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
NpcName name = stringish<NpcName>(ZString(conv_str(st, &AARG(0))));
nd = npc_name2id(name);
@@ -5400,7 +5411,7 @@ static
void builtin_isdead(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
push_int<ScriptDataInt>(st->stack, pc_isdead(sd));
}
@@ -5434,7 +5445,7 @@ static
void builtin_getx(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
push_int<ScriptDataInt>(st->stack, sd->bl_x);
}
@@ -5446,7 +5457,7 @@ static
void builtin_gety(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
push_int<ScriptDataInt>(st->stack, sd->bl_y);
}
@@ -5458,7 +5469,7 @@ static
void builtin_getdir(ScriptState *st)
{
dumb_ptr<map_session_data> sd = script_rid2sd(st);
- script_nullpo_end(sd, "player not found");
+ script_nullpo_end(sd, "player not found"_s);
push_int<ScriptDataInt>(st->stack, static_cast<uint8_t>(sd->dir));
}
@@ -5485,6 +5496,30 @@ void builtin_getmap(ScriptState *st)
}
/*==========================================
+ * Get the maximum x coordinate of a map
+ *------------------------------------------
+ */
+static
+void builtin_getmapmaxx(ScriptState *st)
+{
+ MapName mapname = stringish<MapName>(ZString(conv_str(st, &AARG(0))));
+ P<map_local> m = TRY_UNWRAP(map_mapname2mapid(mapname), return);
+ push_int<ScriptDataInt>(st->stack, m->xs-1);
+}
+
+/*==========================================
+ * Get the maximum y coordinate of a map
+ *------------------------------------------
+ */
+static
+void builtin_getmapmaxy(ScriptState *st)
+{
+ MapName mapname = stringish<MapName>(ZString(conv_str(st, &AARG(0))));
+ P<map_local> m = TRY_UNWRAP(map_mapname2mapid(mapname), return);
+ push_int<ScriptDataInt>(st->stack, m->ys-1);
+}
+
+/*==========================================
* Get the NPC's info
*------------------------------------------
*/
@@ -5513,7 +5548,7 @@ void builtin_strnpcinfo(ScriptState *st)
nd = map_id_is_npc(st->oid);
}
- script_nullpo_end(nd, "npc not found");
+ script_nullpo_end(nd, "npc not found"_s);
switch(num)
{
@@ -5551,7 +5586,7 @@ void builtin_getnpcx(ScriptState *st)
nd = map_id_is_npc(st->oid);
}
- script_nullpo_end(nd, "no npc");
+ script_nullpo_end(nd, "no npc"_s);
push_int<ScriptDataInt>(st->stack, nd->bl_x);
}
@@ -5573,7 +5608,7 @@ void builtin_getnpcy(ScriptState *st)
nd = map_id_is_npc(st->oid);
}
- script_nullpo_end(nd, "no npc");
+ script_nullpo_end(nd, "no npc"_s);
push_int<ScriptDataInt>(st->stack, nd->bl_y);
}
@@ -5745,6 +5780,8 @@ BuiltinFunction builtin_functions[] =
BUILTIN(getnpcy, "?"_s, 'i'),
BUILTIN(strnpcinfo, "i?"_s, 's'),
BUILTIN(getmap, "?"_s, 's'),
+ BUILTIN(getmapmaxx, "M"_s, 'i'),
+ BUILTIN(getmapmaxy, "M"_s, 'i'),
BUILTIN(mapexit, ""_s, '\0'),
BUILTIN(freeloop, "i"_s, '\0'),
BUILTIN(if_then_else, "iii"_s, 'v'),