summaryrefslogtreecommitdiff
path: root/src/map/script.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/script.c')
-rw-r--r--src/map/script.c59
1 files changed, 56 insertions, 3 deletions
diff --git a/src/map/script.c b/src/map/script.c
index 4c669bf20..23c6af0f8 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -4035,7 +4035,7 @@ int run_func(struct script_state *st)
/*==========================================
* script execution
*------------------------------------------*/
-void run_script(struct script_code *rootscript,int pos,int rid,int oid) {
+void run_script(struct script_code *rootscript, int pos, int rid, int oid) {
struct script_state *st;
if( rootscript == NULL || pos < 0 )
@@ -10453,7 +10453,7 @@ BUILDIN(itemeffect) {
}
}
- script->run( item_data->script, 0, sd->bl.id, nd->bl.id );
+ script->run_use_script(sd, item_data, nd->bl.id);
return true;
}
@@ -19834,6 +19834,54 @@ bool script_hp_add(char *name, char *args, bool (*func)(struct script_state *st)
return script->add_builtin(&buildin, true);
}
+void script_run_use_script(struct map_session_data *sd, struct item_data *data, int oid) __attribute__((nonnull (1)));
+
+/**
+ * Run use script for item.
+ *
+ * @param sd player session data. Must be correct and checked before.
+ * @param n item index in inventory. Must be correct and checked before.
+ * @param oid npc id. Can be also 0 or fake npc id.
+ */
+void script_run_use_script(struct map_session_data *sd, struct item_data *data, int oid)
+{
+ script->current_item_id = data->nameid;
+ script->run(data->script, 0, sd->bl.id, oid);
+ script->current_item_id = 0;
+}
+
+void script_run_item_equip_script(struct map_session_data *sd, struct item_data *data, int oid) __attribute__((nonnull (1, 2)));
+
+/**
+ * Run item equip script for item.
+ *
+ * @param sd player session data. Must be correct and checked before.
+ * @param data equipped item data. Must be correct and checked before.
+ * @param oid npc id. Can be also 0 or fake npc id.
+ */
+void script_run_item_equip_script(struct map_session_data *sd, struct item_data *data, int oid)
+{
+ script->current_item_id = data->nameid;
+ script->run(data->equip_script, 0, sd->bl.id, oid);
+ script->current_item_id = 0;
+}
+
+void script_run_item_unequip_script(struct map_session_data *sd, struct item_data *data, int oid) __attribute__((nonnull (1, 2)));
+
+/**
+ * Run item unequip script for item.
+ *
+ * @param sd player session data. Must be correct and checked before.
+ * @param data unequipped item data. Must be correct and checked before.
+ * @param oid npc id. Can be also 0 or fake npc id.
+ */
+void script_run_item_unequip_script(struct map_session_data *sd, struct item_data *data, int oid)
+{
+ script->current_item_id = data->nameid;
+ script->run(data->unequip_script, 0, sd->bl.id, oid);
+ script->current_item_id = 0;
+}
+
#define BUILDIN_DEF(x,args) { buildin_ ## x , #x , args, false }
#define BUILDIN_DEF2(x,x2,args) { buildin_ ## x , x2 , args, false }
#define BUILDIN_DEF_DEPRECATED(x,args) { buildin_ ## x , #x , args, true }
@@ -20613,6 +20661,8 @@ void script_defaults(void) {
script->get_constant = script_get_constant;
script->label_add = script_label_add;
script->run = run_script;
+ script->run_npc = run_script;
+ script->run_pet = run_script;
script->run_main = run_script_main;
script->run_timer = run_script_timer;
script->set_var = set_var;
@@ -20778,5 +20828,8 @@ void script_defaults(void) {
script->add_language = script_add_language;
script->get_translation_file_name = script_get_translation_file_name;
script->parser_clean_leftovers = script_parser_clean_leftovers;
-
+
+ script->run_use_script = script_run_use_script;
+ script->run_item_equip_script = script_run_item_equip_script;
+ script->run_item_unequip_script = script_run_item_unequip_script;
}