viewing paste rathena_setmobdata | Diff

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
 src/custom/script.inc     | 115 ++++++++++++++++++++++++++++++++++++++++++++++
 src/custom/script_def.inc |   3 ++
 src/map/script.c          |  57 +++++++++++++++++++++++
 src/map/script.h          |  32 +++++++++++++
 4 files changed, 207 insertions(+)
 
diff --git a/src/custom/script.inc b/src/custom/script.inc
index 1e01c88..84a11e6 100644
--- a/src/custom/script.inc
+++ b/src/custom/script.inc
@@ -17,3 +17,118 @@
 //     script_pushint(st,1);
 //     return 0;
 //}
+
+/*==========================================
+ * Modify the value of GID monster
+ * setmobdata <GID>, <parameter>, <new value>;
+ *------------------------------------------*/
+BUILDIN_FUNC(setmobdata) {
+       int mob_gid = script_getnum(st,2),
+               parameter = script_getnum(st,3),
+               value = script_getnum(st,4);
+       struct block_list *bl = map_id2bl( mob_gid );
+       if ( bl == NULL ) {
+               ShowError( "buildin_setmobdata: Attempted to modify a non-existed GID %d.\n", mob_gid );
+               return SCRIPT_CMD_FAILURE;
+       }
+       if ( bl->type != BL_MOB ) {
+               ShowError( "buildin_setmobdata: Attempted to modify not a monster. GID %d.\n", mob_gid );
+               return SCRIPT_CMD_FAILURE;
+       }
+       {
+               TBL_MOB *md = (TBL_MOB*)bl;
+               switch( parameter ) {
+               case MOBDATA_MOBID:
+                       ShowWarning( "buildin_setmobdata: Attempted to change MobID with type MOBDATA_MOBID.\n" );
+                       break;
+               case MOBDATA_LEVEL: md->level = cap_value(value, 1, SINT16_MAX); break;
+               case MOBDATA_HP: md->status.hp = cap_value(value, 1, SINT32_MAX); break;
+               case MOBDATA_MAXHP: md->status.max_hp = cap_value(value, 1, SINT32_MAX); break;
+               case MOBDATA_ATK_MIN: md->status.rhw.atk = cap_value(value, 1, md->status.rhw.atk2); break;
+               case MOBDATA_ATK_MAX: md->status.rhw.atk2 = cap_value(value, md->status.rhw.atk, SINT16_MAX); break;
+               case MOBDATA_MATK_MIN: md->status.matk_min = cap_value(value, 1, md->status.matk_max); break;
+               case MOBDATA_MATK_MAX: md->status.matk_max = cap_value(value, md->status.matk_min, SINT16_MAX); break;
+               case MOBDATA_DEF: md->status.def = cap_value(value, 0, SINT16_MAX); break;
+               case MOBDATA_MDEF: md->status.mdef = cap_value(value, 0, SINT16_MAX); break;
+               case MOBDATA_HIT: md->status.hit = cap_value(value, 0, SINT16_MAX); break;
+               case MOBDATA_FLEE: md->status.flee = cap_value(value, 0, SINT16_MAX); break;
+               case MOBDATA_CRITICAL: md->status.cri = cap_value(value, 0, SINT16_MAX); break;
+               case MOBDATA_PERFECT_DODGE: md->status.flee2 = cap_value(value, 0, SINT16_MAX); break;
+               case MOBDATA_STR: md->status.str = cap_value(value, 1, SINT16_MAX); break;
+               case MOBDATA_AGI: md->status.agi = cap_value(value, 1, SINT16_MAX); break;
+               case MOBDATA_VIT: md->status.vit = cap_value(value, 1, SINT16_MAX); break;
+               case MOBDATA_INT: md->status.int_ = cap_value(value, 1, SINT16_MAX); break;
+               case MOBDATA_DEX: md->status.dex = cap_value(value, 1, SINT16_MAX); break;
+               case MOBDATA_LUK: md->status.luk = cap_value(value, 1, SINT16_MAX); break;
+               case MOBDATA_ATTACK_RANGE: md->status.rhw.range = cap_value(value, 1, battle_config.area_size); break;
+               case MOBDATA_RACE: md->status.race = cap_value(value, 1, RC_MAX - 1); break;
+               case MOBDATA_ELEMENT_TYPE: md->status.def_ele = cap_value(value, 1, ELE_MAX-1); break;
+               case MOBDATA_ELEMENT_LEVEL: md->status.ele_lv = cap_value(value, 1, 4); break;
+               case MOBDATA_MODE: md->status.mode = cap_value(value, 1, SINT32_MAX); break;
+               case MOBDATA_MOVESPEED: md->status.speed = cap_value(value, MIN_WALK_SPEED, MAX_WALK_SPEED); break;
+               case MOBDATA_ATTACK_DELAY: md->status.adelay = cap_value(value, 1, SINT16_MAX); break;
+               case MOBDATA_ATTACK_MOTION: md->status.amotion = cap_value(value, 1, md->status.adelay); break;
+               case MOBDATA_DAMAGE_MOTION: md->status.dmotion = cap_value(value, 1, SINT16_MAX); break;
+               default:
+                       ShowError( "buildin_setmobdata: Attempted to use non-existing parameter %d.\n", parameter );
+                       return SCRIPT_CMD_FAILURE;
+               }
+       }
+       return SCRIPT_CMD_SUCCESS;
+}
+
+/*==========================================
+ * Retrieve the value of GID monster
+ * getmobdata <GID>, <parameter>;
+ *------------------------------------------*/
+BUILDIN_FUNC(getmobdata) {
+       int mob_gid = script_getnum(st,2),
+               parameter = script_getnum(st,3);
+       struct block_list *bl = map_id2bl( mob_gid );
+       if ( bl == NULL ) {
+               ShowError( "buildin_getmobdata: Attempted to retrieve a non-existed GID %d.\n", mob_gid );
+               return SCRIPT_CMD_FAILURE;
+       }
+       if ( bl->type != BL_MOB ) {
+               ShowError( "buildin_getmobdata: Attempted to retrieve not a monster. GID %d.\n", mob_gid );
+               return SCRIPT_CMD_FAILURE;
+       }
+       {
+               TBL_MOB *md = (TBL_MOB*)bl;
+               switch( parameter ) {
+                       case MOBDATA_MOBID: script_pushint( st, md->mob_id ); break;
+                       case MOBDATA_LEVEL: script_pushint( st, md->level ); break;
+                       case MOBDATA_HP: script_pushint( st, md->status.hp ); break;
+                       case MOBDATA_MAXHP: script_pushint( st, md->status.max_hp ); break;
+                       case MOBDATA_ATK_MIN: script_pushint( st, md->status.rhw.atk ); break;
+                       case MOBDATA_ATK_MAX: script_pushint( st, md->status.rhw.atk2 ); break;
+                       case MOBDATA_MATK_MIN: script_pushint( st, md->status.matk_min ); break;
+                       case MOBDATA_MATK_MAX: script_pushint( st, md->status.matk_max ); break;
+                       case MOBDATA_DEF: script_pushint( st, md->status.def ); break;
+                       case MOBDATA_MDEF: script_pushint( st, md->status.mdef ); break;
+                       case MOBDATA_HIT: script_pushint( st, md->status.hit ); break;
+                       case MOBDATA_FLEE: script_pushint( st, md->status.flee ); break;
+                       case MOBDATA_CRITICAL: script_pushint( st, md->status.cri ); break;
+                       case MOBDATA_PERFECT_DODGE: script_pushint( st, md->status.flee2 ); break;
+                       case MOBDATA_STR: script_pushint( st, md->status.str ); break;
+                       case MOBDATA_AGI: script_pushint( st, md->status.agi ); break;
+                       case MOBDATA_VIT: script_pushint( st, md->status.vit ); break;
+                       case MOBDATA_INT: script_pushint( st, md->status.int_ ); break;
+                       case MOBDATA_DEX: script_pushint( st, md->status.dex ); break;
+                       case MOBDATA_LUK: script_pushint( st, md->status.luk ); break;
+                       case MOBDATA_ATTACK_RANGE: script_pushint( st, md->status.rhw.range ); break;
+                       case MOBDATA_RACE: script_pushint( st, md->status.race ); break;
+                       case MOBDATA_ELEMENT_TYPE: script_pushint( st, md->status.def_ele ); break;
+                       case MOBDATA_ELEMENT_LEVEL: script_pushint( st, md->status.ele_lv ); break;
+                       case MOBDATA_MODE: script_pushint( st, md->status.mode ); break;
+                       case MOBDATA_MOVESPEED: script_pushint( st, md->status.speed ); break;
+                       case MOBDATA_ATTACK_DELAY: script_pushint( st, md->status.adelay ); break;
+                       case MOBDATA_ATTACK_MOTION: script_pushint( st, md->status.amotion ); break;
+                       case MOBDATA_DAMAGE_MOTION: script_pushint( st, md->status.dmotion ); break;
+                       default :
+                               ShowError( "buildin_getmobdata: Attempted to use non-existing parameter %d.\n", parameter );
+                               return SCRIPT_CMD_FAILURE;
+               }
+       }
+       return SCRIPT_CMD_SUCCESS;
+}
\ No newline at end of file
diff --git a/src/custom/script_def.inc b/src/custom/script_def.inc
index 3319eea..161ce8b 100644
--- a/src/custom/script_def.inc
+++ b/src/custom/script_def.inc
@@ -9,3 +9,6 @@
  **/
 
 //BUILDIN_DEF(example,""),
+
+       BUILDIN_DEF(setmobdata,"iii"),
+       BUILDIN_DEF(getmobdata,"ii"),
\ No newline at end of file
diff --git a/src/map/script.c b/src/map/script.c
index 326f3c0..797bb27 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -2291,6 +2291,63 @@ void script_hardcoded_constants(void) {
        script_set_constant("SCSTART_LOADED",SCSTART_LOADED,false);
        script_set_constant("SCSTART_NORATEDEF",SCSTART_NORATEDEF,false);
        script_set_constant("SCSTART_NOICON",SCSTART_NOICON,false);
+
+       /* setmobdata */
+       script_set_constant("MOBDATA_MOBID",MOBDATA_MOBID,false);
+       script_set_constant("MOBDATA_LEVEL",MOBDATA_LEVEL,false);
+       script_set_constant("MOBDATA_HP",MOBDATA_HP,false);
+       script_set_constant("MOBDATA_MAXHP",MOBDATA_MAXHP,false);
+       script_set_constant("MOBDATA_ATK_MIN",MOBDATA_ATK_MIN,false);
+       script_set_constant("MOBDATA_ATK_MAX",MOBDATA_ATK_MAX,false);
+       script_set_constant("MOBDATA_MATK_MIN",MOBDATA_MATK_MIN,false);
+       script_set_constant("MOBDATA_MATK_MAX",MOBDATA_MATK_MAX,false);
+       script_set_constant("MOBDATA_DEF",MOBDATA_DEF,false);
+       script_set_constant("MOBDATA_MDEF",MOBDATA_MDEF,false);
+       script_set_constant("MOBDATA_HIT",MOBDATA_HIT,false);
+       script_set_constant("MOBDATA_FLEE",MOBDATA_FLEE,false);
+       script_set_constant("MOBDATA_CRITICAL",MOBDATA_CRITICAL,false);
+       script_set_constant("MOBDATA_PERFECT_DODGE",MOBDATA_PERFECT_DODGE,false);
+       script_set_constant("MOBDATA_STR",MOBDATA_STR,false);
+       script_set_constant("MOBDATA_AGI",MOBDATA_AGI,false);
+       script_set_constant("MOBDATA_VIT",MOBDATA_VIT,false);
+       script_set_constant("MOBDATA_INT",MOBDATA_INT,false);
+       script_set_constant("MOBDATA_DEX",MOBDATA_DEX,false);
+       script_set_constant("MOBDATA_LUK",MOBDATA_LUK,false);
+       script_set_constant("MOBDATA_ATTACK_RANGE",MOBDATA_ATTACK_RANGE,false);
+       script_set_constant("MOBDATA_RACE",MOBDATA_RACE,false);
+       script_set_constant("MOBDATA_ELEMENT_TYPE",MOBDATA_ELEMENT_TYPE,false);
+       script_set_constant("MOBDATA_ELEMENT_LEVEL",MOBDATA_ELEMENT_LEVEL,false);
+       script_set_constant("MOBDATA_MODE",MOBDATA_MODE,false);
+       script_set_constant("MOBDATA_MOVESPEED",MOBDATA_MOVESPEED,false);
+       script_set_constant("MOBDATA_ATTACK_DELAY",MOBDATA_ATTACK_DELAY,false);
+       script_set_constant("MOBDATA_ATTACK_MOTION",MOBDATA_ATTACK_MOTION,false);
+       script_set_constant("MOBDATA_DAMAGE_MOTION",MOBDATA_DAMAGE_MOTION,false);
+
+       /* e_mode */
+       script_set_constant("MD_CANMOVE",MD_CANMOVE,false);
+       script_set_constant("MD_LOOTER",MD_LOOTER,false);
+       script_set_constant("MD_AGGRESSIVE",MD_AGGRESSIVE,false);
+       script_set_constant("MD_ASSIST",MD_ASSIST,false);
+       script_set_constant("MD_CASTSENSOR_IDLE",MD_CASTSENSOR_IDLE,false);
+       script_set_constant("MD_BOSS",MD_BOSS,false);
+       script_set_constant("MD_PLANT",MD_PLANT,false);
+       script_set_constant("MD_CANATTACK",MD_CANATTACK,false);
+       script_set_constant("MD_DETECTOR",MD_DETECTOR,false);
+       script_set_constant("MD_CASTSENSOR_CHASE",MD_CASTSENSOR_CHASE,false);
+       script_set_constant("MD_CHANGECHASE",MD_CHANGECHASE,false);
+       script_set_constant("MD_ANGRY",MD_ANGRY,false);
+       script_set_constant("MD_CHANGETARGET_MELEE",MD_CHANGETARGET_MELEE,false);
+       script_set_constant("MD_CHANGETARGET_CHASE",MD_CHANGETARGET_CHASE,false);
+       script_set_constant("MD_TARGETWEAK",MD_TARGETWEAK,false);
+       script_set_constant("MD_RANDOMTARGET",MD_RANDOMTARGET,false);
+       script_set_constant("MD_IGNOREMELEE",MD_IGNOREMELEE,false);
+       script_set_constant("MD_IGNOREMAGIC",MD_IGNOREMAGIC,false);
+       script_set_constant("MD_IGNORERANGED",MD_IGNORERANGED,false);
+       script_set_constant("MD_MVP",MD_MVP,false);
+       script_set_constant("MD_IGNOREMISC",MD_IGNOREMISC,false);
+       script_set_constant("MD_KNOCKBACK_IMMUNE",MD_KNOCKBACK_IMMUNE,false);
+       script_set_constant("MD_NORANDOM_WALK",MD_NORANDOM_WALK,false);
+       script_set_constant("MD_NOCAST_SKILL",MD_NOCAST_SKILL,false);
 }
 
 /*==========================================
diff --git a/src/map/script.h b/src/map/script.h
index 87dc604..abe1a06 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -297,6 +297,38 @@ enum script_parse_options {
        SCRIPT_RETURN_EMPTY_SCRIPT = 0x4// returns the script object instead of NULL for empty scripts
 };
 
+enum mobdata_type {
+       MOBDATA_MOBID = 1,
+       MOBDATA_LEVEL,
+       MOBDATA_HP,
+       MOBDATA_MAXHP,
+       MOBDATA_ATK_MIN,
+       MOBDATA_ATK_MAX,
+       MOBDATA_MATK_MIN,
+       MOBDATA_MATK_MAX,
+       MOBDATA_DEF,
+       MOBDATA_MDEF,
+       MOBDATA_HIT,
+       MOBDATA_FLEE,
+       MOBDATA_CRITICAL,
+       MOBDATA_PERFECT_DODGE,
+       MOBDATA_STR,
+       MOBDATA_AGI,
+       MOBDATA_VIT,
+       MOBDATA_INT,
+       MOBDATA_DEX,
+       MOBDATA_LUK,
+       MOBDATA_ATTACK_RANGE,
+       MOBDATA_RACE,
+       MOBDATA_ELEMENT_TYPE,
+       MOBDATA_ELEMENT_LEVEL,
+       MOBDATA_MODE,
+       MOBDATA_MOVESPEED,
+       MOBDATA_ATTACK_DELAY,
+       MOBDATA_ATTACK_MOTION,
+       MOBDATA_DAMAGE_MOTION,
+};
+
 /**
  * used to generate quick script_array entries
  **/
 
Viewed 975 times, submitted by AnnieRuru.