From cdae404e6a81f9ea26f43337b747ce1b2195f45b Mon Sep 17 00:00:00 2001 From: Atemo Date: Tue, 10 Apr 2018 00:23:22 +0200 Subject: [PATCH] Updated getunitdata / setunitdata (#3029) Added the possibility to retrieve / change the current target id of a Mob, Homunculus, Mercenary and Elemental through getunitdata / setunitdata --- doc/script_commands.txt | 4 ++++ src/map/script.cpp | 41 ++++++++++++++++++++++++++++++++++++ src/map/script.hpp | 4 ++++ src/map/script_constants.hpp | 4 ++++ 4 files changed, 53 insertions(+) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 932351d1d4..644cc8e802 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -7647,6 +7647,7 @@ Parameters (indexes) for monsters are: UMOB_AMOTION UMOB_ADELAY UMOB_DMOTION + UMOB_TARGETID ----- @@ -7690,6 +7691,7 @@ Parameter (indexes) for homunculi are: UHOM_AMOTION UHOM_ADELAY UHOM_DMOTION + UHOM_TARGETID ----- @@ -7771,6 +7773,7 @@ Parameter (indexes) for mercenaries are: UMER_AMOTION UMER_ADELAY UMER_DMOTION + UMER_TARGETID ----- @@ -7813,6 +7816,7 @@ Parameter (indexes) for elementals are: UELE_AMOTION UELE_ADELAY UELE_DMOTION + UELE_TARGETID ----- diff --git a/src/map/script.cpp b/src/map/script.cpp index 57a861903c..0d2d1923d0 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -17571,6 +17571,7 @@ BUILDIN_FUNC(getunitdata) getunitdata_sub(UMOB_AMOTION, md->status.amotion); getunitdata_sub(UMOB_ADELAY, md->status.adelay); getunitdata_sub(UMOB_DMOTION, md->status.dmotion); + getunitdata_sub(UMOB_TARGETID, md->target_id); break; case BL_HOM: @@ -17617,6 +17618,7 @@ BUILDIN_FUNC(getunitdata) getunitdata_sub(UHOM_AMOTION, hd->battle_status.amotion); getunitdata_sub(UHOM_ADELAY, hd->battle_status.adelay); getunitdata_sub(UHOM_DMOTION, hd->battle_status.dmotion); + getunitdata_sub(UHOM_TARGETID, hd->ud.target); break; case BL_PET: @@ -17704,6 +17706,7 @@ BUILDIN_FUNC(getunitdata) getunitdata_sub(UMER_AMOTION, mc->base_status.amotion); getunitdata_sub(UMER_ADELAY, mc->base_status.adelay); getunitdata_sub(UMER_DMOTION, mc->base_status.dmotion); + getunitdata_sub(UMER_TARGETID, mc->ud.target); break; case BL_ELEM: @@ -17749,6 +17752,7 @@ BUILDIN_FUNC(getunitdata) getunitdata_sub(UELE_AMOTION, ed->base_status.amotion); getunitdata_sub(UELE_ADELAY, ed->base_status.adelay); getunitdata_sub(UELE_DMOTION, ed->base_status.dmotion); + getunitdata_sub(UELE_TARGETID, ed->ud.target); break; case BL_NPC: @@ -17944,6 +17948,15 @@ BUILDIN_FUNC(setunitdata) case UMOB_AMOTION: md->base_status->amotion = (short)value; calc_status = true; break; case UMOB_ADELAY: md->base_status->adelay = (short)value; calc_status = true; break; case UMOB_DMOTION: md->base_status->dmotion = (short)value; calc_status = true; break; + case UMOB_TARGETID: { + struct block_list* target = map_id2bl(value); + if (!target) { + ShowWarning("buildin_setunitdata: Error in finding target for BL_MOB!\n"); + return SCRIPT_CMD_FAILURE; + } + mob_target(md,target,0); + break; + } default: ShowError("buildin_setunitdata: Unknown data identifier %d for BL_MOB.\n", type); return SCRIPT_CMD_FAILURE; @@ -17997,6 +18010,15 @@ BUILDIN_FUNC(setunitdata) case UHOM_AMOTION: hd->base_status.amotion = (short)value; calc_status = true; break; case UHOM_ADELAY: hd->base_status.adelay = (short)value; calc_status = true; break; case UHOM_DMOTION: hd->base_status.dmotion = (short)value; calc_status = true; break; + case UHOM_TARGETID: { + struct block_list* target = map_id2bl(value); + if (!target) { + ShowWarning("buildin_setunitdata: Error in finding target for BL_HOM!\n"); + return SCRIPT_CMD_FAILURE; + } + unit_attack(&hd->bl, target->id, 1); + break; + } default: ShowError("buildin_setunitdata: Unknown data identifier %d for BL_HOM.\n", type); return SCRIPT_CMD_FAILURE; @@ -18096,6 +18118,15 @@ BUILDIN_FUNC(setunitdata) case UMER_AMOTION: mc->base_status.amotion = (short)value; calc_status = true; break; case UMER_ADELAY: mc->base_status.adelay = (short)value; calc_status = true; break; case UMER_DMOTION: mc->base_status.dmotion = (short)value; calc_status = true; break; + case UMER_TARGETID: { + struct block_list* target = map_id2bl(value); + if (!target) { + ShowWarning("buildin_setunitdata: Error in finding target for BL_MER!\n"); + return SCRIPT_CMD_FAILURE; + } + unit_attack(&mc->bl, target->id, 1); + break; + } default: ShowError("buildin_setunitdata: Unknown data identifier %d for BL_MER.\n", type); return SCRIPT_CMD_FAILURE; @@ -18148,6 +18179,16 @@ BUILDIN_FUNC(setunitdata) case UELE_AMOTION: ed->base_status.amotion = (short)value; calc_status = true; break; case UELE_ADELAY: ed->base_status.adelay = (short)value; calc_status = true; break; case UELE_DMOTION: ed->base_status.dmotion = (short)value; calc_status = true; break; + case UELE_TARGETID: { + struct block_list* target = map_id2bl(value); + if (!target) { + ShowWarning("buildin_setunitdata: Error in finding target for BL_ELEM!\n"); + return SCRIPT_CMD_FAILURE; + } + elemental_change_mode(ed, static_cast(EL_MODE_AGGRESSIVE)); + unit_attack(&ed->bl, target->id, 1); + break; + } default: ShowError("buildin_setunitdata: Unknown data identifier %d for BL_ELEM.\n", type); return SCRIPT_CMD_FAILURE; diff --git a/src/map/script.hpp b/src/map/script.hpp index fa5f0e8c60..52aab1f873 100644 --- a/src/map/script.hpp +++ b/src/map/script.hpp @@ -470,6 +470,7 @@ enum unitdata_mobtypes { UMOB_AMOTION, UMOB_ADELAY, UMOB_DMOTION, + UMOB_TARGETID, }; enum unitdata_homuntypes { @@ -512,6 +513,7 @@ enum unitdata_homuntypes { UHOM_AMOTION, UHOM_ADELAY, UHOM_DMOTION, + UHOM_TARGETID, }; enum unitdata_pettypes { @@ -591,6 +593,7 @@ enum unitdata_merctypes { UMER_AMOTION, UMER_ADELAY, UMER_DMOTION, + UMER_TARGETID, }; enum unitdata_elemtypes { @@ -632,6 +635,7 @@ enum unitdata_elemtypes { UELE_AMOTION, UELE_ADELAY, UELE_DMOTION, + UELE_TARGETID, }; enum unitdata_npctypes { diff --git a/src/map/script_constants.hpp b/src/map/script_constants.hpp index 2f7f44d3b1..cb492dcf26 100644 --- a/src/map/script_constants.hpp +++ b/src/map/script_constants.hpp @@ -3095,6 +3095,7 @@ export_constant(UMOB_AMOTION); export_constant(UMOB_ADELAY); export_constant(UMOB_DMOTION); + export_constant(UMOB_TARGETID); /* unit control - homunculus */ export_constant(UHOM_SIZE); @@ -3136,6 +3137,7 @@ export_constant(UHOM_AMOTION); export_constant(UHOM_ADELAY); export_constant(UHOM_DMOTION); + export_constant(UHOM_TARGETID); /* unit control - pet */ export_constant(UPET_SIZE); @@ -3213,6 +3215,7 @@ export_constant(UMER_AMOTION); export_constant(UMER_ADELAY); export_constant(UMER_DMOTION); + export_constant(UMER_TARGETID); /* unit control - elemental */ export_constant(UELE_SIZE); @@ -3253,6 +3256,7 @@ export_constant(UELE_AMOTION); export_constant(UELE_ADELAY); export_constant(UELE_DMOTION); + export_constant(UELE_TARGETID); /* unit control - NPC */ export_constant(UNPC_DISPLAY);