Pārlūkot izejas kodu

* Follow up 2cee5b6ff1bf53c4ae53bc1278b09ae84b8a0a76: `gethominfo`, `getpetinfo`, and `getmercinfo` for type 0 were correct 'to get ID' from database/their unique ID, not as GID.
* Added type for `gethominfo`, `getpetinfo`, and `getmercinfo` to return GID.
* Added `geteleminfo`, to retrieve Elemental ID and GID. The otherinfo can be gained from `getunitdata`

Signed-off-by: Cydh Ramdh <cydh@pservero.com>

Cydh Ramdh 9 gadi atpakaļ
vecāks
revīzija
de40271000
2 mainītis faili ar 70 papildinājumiem un 19 dzēšanām
  1. 23 7
      doc/script_commands.txt
  2. 47 12
      src/map/script.c

+ 23 - 7
doc/script_commands.txt

@@ -374,8 +374,10 @@ But what about GID?
 
 GID stands for the Game ID of something, this can either be the GID obtained
 through mobspawn (mob control commands) or the account ID of a character.
-Another way would be to right click on a mob, 
-NPC or char as GM sprited char to view the GID.
+Another way would be to right click on a mob, NPC or char as GM sprited char
+to view the GID.
+
+See also 'getpetinfo', 'getmercinfo', 'gethominfo', and 'geteleminfo'.
 
 This is mostly used for the new version of skill and the mob control commands
 implemented.
@@ -7228,6 +7230,17 @@ Example:
 	// Set the max HP of the Poring to 1000 (current HP will also get updated to 1000).
 	setunitdata .GID,3,1000;
 
+---------------------------------------
+
+*geteleminfo <type>{,<char_id>};
+
+Get info of elemental of attached player or player by char_id.
+Other info can be obtained by 'getunitdata' command.
+
+Valid types are:
+   0: Elemental ID
+   1: Elemental Game ID
+
 ---------------------------------------
 \\
 6,1.- End of unit-related commands
@@ -8240,12 +8253,12 @@ server and the egg will disappear when anyone tries to hatch it.
 
 ---------------------------------------
 
-*getpetinfo(<type>)
+*getpetinfo(<type>{,<char_id>})
 
 This function will return pet information for the pet the invoking character 
 currently has active. Valid types are:
 
- 0 - Pet Game ID
+ 0 - Pet ID
  1 - Pet class number as per 'db/pet_db.txt' - will tell you what kind of a pet it 
      is.
  2 - Pet name. Will return "null" if there's no pet. 
@@ -8253,6 +8266,7 @@ currently has active. Valid types are:
  4 - Pet hungry level. 100 is completely full.
  5 - Pet rename flag. 0 means this pet has not been named yet.
  6 - Pet level
+ 7 - Pet Game ID
 
 ---------------------------------------
 
@@ -8408,20 +8422,21 @@ and will return the following values:
 
 ---------------------------------------
 
-*gethominfo(<type>)
+*gethominfo(<type>{,<char_id>})
 
 This function will return Homunculus information for the Homunculus of the
 invoking character, regardless of its vaporize state. It returns zero or
 "null" if the player does not own a Homunculus.
 
 Valid types are:
- 0 - Homunculus Game ID
+ 0 - Homunculus ID
  1 - Homunculus Class
  2 - Homunculus Name
  3 - Homunculus friendly level (intimacy score). 100000 is full loyalty.
  4 - Homunculus hungry level. 100 is completely full.
  5 - Homunculus rename flag. 0 means this homunculus has not been named yet.
  6 - Homunculus level
+ 7 - Homunculus Game ID
 
 ---------------------------------------
 
@@ -8491,7 +8506,7 @@ character. If char id is given, the information of that character is
 retrieved instead. Type specifies what information to retrieve and
 can be one of the following:
 
-    0 - Mercenary Game ID
+    0 - Mercenary ID
     1 - Mercenary Class
     2 - Mercenary Name
     3 - Mercenary faith value for this mercenary's guild, if any
@@ -8499,6 +8514,7 @@ can be one of the following:
     5 - Mercenary kill count
     6 - Mercenary remaining life time in msec
     7 - Mercenary level
+    8 - Mercenary Game ID
 
 If the character does not have a mercenary, the command returns ""
 for name and 0 for all other types.

+ 47 - 12
src/map/script.c

@@ -14063,24 +14063,25 @@ BUILDIN_FUNC(recovery)
 }
 
 /*==========================================
- * Get your pet info: getpetinfo(n)
+ * Get your pet info: getpetinfo <type>{,<char_id>}
  * n -> 0:pet_id 1:pet_class 2:pet_name
- * 3:friendly 4:hungry, 5: rename flag.6:level
+ * 3:friendly 4:hungry, 5: rename flag.6:level,
+ * 7:game id
  *------------------------------------------*/
 BUILDIN_FUNC(getpetinfo)
 {
 	TBL_PC *sd=script_rid2sd(st);
 	TBL_PET *pd;
-	int type=script_getnum(st,2);
+	int type = script_getnum(st,2);
 
-	if(!sd || !sd->pd) {
+	if (!script_charid2sd(3, sd) || !(pd = sd->pd)) {
 		if (type == 2)
 			script_pushconststr(st,"null");
 		else
 			script_pushint(st,0);
 		return SCRIPT_CMD_SUCCESS;
 	}
-	pd = sd->pd;
+
 	switch(type){
 		case 0: script_pushint(st,pd->pet.pet_id); break;
 		case 1: script_pushint(st,pd->pet.class_); break;
@@ -14089,6 +14090,7 @@ BUILDIN_FUNC(getpetinfo)
 		case 4: script_pushint(st,pd->pet.hungry); break;
 		case 5: script_pushint(st,pd->pet.rename_flag); break;
 		case 6: script_pushint(st,(int)pd->pet.level); break;
+		case 7: script_pushint(st,pd->bl.id); break;
 		default:
 			script_pushint(st,0);
 			break;
@@ -14097,10 +14099,10 @@ BUILDIN_FUNC(getpetinfo)
 }
 
 /*==========================================
- * Get your homunculus info: gethominfo(n)
- * n -> 0:hom_id 1:class 2:name
+ * Get your homunculus info: gethominfo <type>{,<char_id>};
+ * type -> 0:hom_id 1:class 2:name
  * 3:friendly 4:hungry, 5: rename flag.
- * 6: level
+ * 6: level, 7: game id
  *------------------------------------------*/
 BUILDIN_FUNC(gethominfo)
 {
@@ -14108,8 +14110,7 @@ BUILDIN_FUNC(gethominfo)
 	TBL_HOM *hd;
 	int type=script_getnum(st,2);
 
-	hd = sd?sd->hd:NULL;
-	if(!hd) {
+	if (!script_charid2sd(3, sd) || !(hd = sd->hd)) {
 		if (type == 2)
 			script_pushconststr(st,"null");
 		else
@@ -14125,6 +14126,7 @@ BUILDIN_FUNC(gethominfo)
 		case 4: script_pushint(st,hd->homunculus.hunger); break;
 		case 5: script_pushint(st,hd->homunculus.rename_flag); break;
 		case 6: script_pushint(st,hd->homunculus.level); break;
+		case 7: script_pushint(st,hd->bl.id); break;
 		default:
 			script_pushint(st,0);
 			break;
@@ -14179,6 +14181,7 @@ BUILDIN_FUNC(getmercinfo)
 		case 5: script_pushint(st,md ? md->mercenary.kill_count : 0); break;
 		case 6: script_pushint(st,md ? mercenary_get_lifetime(md) : 0); break;
 		case 7: script_pushint(st,md ? md->db->lv : 0); break;
+		case 8: script_pushint(st,md ? md->bl.id : 0); break;
 		default:
 			ShowError("buildin_getmercinfo: Invalid type %d (char_id=%d).\n", type, sd->status.char_id);
 			script_pushnil(st);
@@ -20670,6 +20673,37 @@ BUILDIN_FUNC(ignoretimeout)
 	return SCRIPT_CMD_SUCCESS;
 }
 
+/**
+ * geteleminfo <type>{,<char_id>};
+ **/
+BUILDIN_FUNC(geteleminfo) {
+	TBL_ELEM *ed = NULL;
+	TBL_PC *sd = NULL;
+	int type = script_getnum(st,2);
+
+	if (!script_charid2sd(3, sd)) {
+		script_pushint(st, 0);
+		return SCRIPT_CMD_SUCCESS;
+	}
+
+	if (!(ed = sd->ed)) {
+		//ShowDebug("buildin_geteleminfo: Player doesn't have Elemental.\n");
+		script_pushint(st, 0);
+		return SCRIPT_CMD_SUCCESS;
+	}
+
+	switch (type) {
+		case 0: script_pushint(st, ed->elemental.elemental_id); break;
+		case 1: script_pushint(st, ed->bl.id); break;
+		default:
+			ShowError("buildin_geteleminfo: Invalid type '%d'.\n", type);
+			script_pushint(st, 0);
+			return SCRIPT_CMD_FAILURE;
+	}
+
+	return SCRIPT_CMD_SUCCESS;
+}
+
 #include "../custom/script.inc"
 
 // declarations that were supposed to be exported from npc_chat.c
@@ -21005,8 +21039,8 @@ struct script_function buildin_func[] = {
 	BUILDIN_DEF(preg_match,"ss?"),
 	BUILDIN_DEF(dispbottom,"s??"), //added from jA [Lupus]
 	BUILDIN_DEF(recovery,"i???"),
-	BUILDIN_DEF(getpetinfo,"i"),
-	BUILDIN_DEF(gethominfo,"i"),
+	BUILDIN_DEF(getpetinfo,"i?"),
+	BUILDIN_DEF(gethominfo,"i?"),
 	BUILDIN_DEF(getmercinfo,"i?"),
 	BUILDIN_DEF(checkequipedcard,"i"),
 	BUILDIN_DEF(jump_zero,"il"), //for future jA script compatibility
@@ -21231,6 +21265,7 @@ struct script_function buildin_func[] = {
 	BUILDIN_DEF(getvar,"vi"),
 	BUILDIN_DEF(showscript,"s?"),
 	BUILDIN_DEF(ignoretimeout,"i?"),
+	BUILDIN_DEF(geteleminfo,"i?"),
 
 #include "../custom/script_def.inc"