Ver código fonte

* Added warning message when addtimer script is failed, as bugreport:8459 http://rathena.org/board/tracker/issue-8459-addtimer-command-should-report-an-error-if-it-hits-max-eventtimer/
* Follow up 0f7ecd0, 308ee6c, 1f29f50
* Little source documentation updated on script.c

Signed-off-by: Cydh Ramdh <house.bad@gmail.com>

Cydh Ramdh 11 anos atrás
pai
commit
f46a7920e2
5 arquivos alterados com 112 adições e 105 exclusões
  1. 1 1
      src/char/char.c
  2. 1 1
      src/map/battle.c
  3. 3 2
      src/map/pc.c
  4. 106 100
      src/map/script.c
  5. 1 1
      src/map/skill.c

+ 1 - 1
src/char/char.c

@@ -4766,7 +4766,7 @@ int parse_char(int fd)
 			if( RFIFOREST(fd) < 6 )
 				return 0;
 			if( pincode_enabled && RFIFOL(fd,2) == sd->account_id ){
-				if( strlen( sd->pincode ) <= 0 ){
+				if( sd->pincode[0] == '\0' ){
 					pincode_sendstate( fd, sd, PINCODE_NEW );
 				}else{
 					pincode_sendstate( fd, sd, PINCODE_ASK );

+ 1 - 1
src/map/battle.c

@@ -3378,7 +3378,7 @@ static int battle_calc_attack_skill_ratio(struct Damage wd, struct block_list *s
 		case LG_SHIELDSPELL:// [(Casters Base Level x 4) + (Shield DEF x 10) + (Casters VIT x 2)] %
 			if( sd ) {
 				int index = sd->equip_index[EQI_HAND_L];
-				struct item_data *shield_data;
+				struct item_data *shield_data = NULL;
 				if( index >= 0 && sd->inventory_data[index] && sd->inventory_data[index]->type == IT_ARMOR )
 					shield_data = sd->inventory_data[index];
 				skillratio = status_get_lv(src) * 4 + status_get_vit(src) * 2;

+ 3 - 2
src/map/pc.c

@@ -8534,7 +8534,8 @@ static int pc_checkcombo(struct map_session_data *sd, struct item_data *data) {
 		}
 
 		CREATE(combo_idx,int16,data->combos[i]->count);
-		memset(combo_idx,-1,sizeof(combo_idx));		
+		memset(combo_idx,-1,data->combos[i]->count * sizeof(int16));
+
 		for( j = 0; j < data->combos[i]->count; j++ ) {
 			uint16 id = data->combos[i]->nameid[j], k;
 			bool found = false;
@@ -10136,7 +10137,7 @@ static int pc_read_statsdb(const char *basedir, int last_s, bool silent){
 		fclose(fp);
 		ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s/%s"CL_RESET"'.\n", entries, basedir,"statpoint.txt");
 	}
-	return (i>1)?i:last_s; //If i == 1 means the file is empty.
+	return max(last_s,i);
 }
 
 /*==========================================

+ 106 - 100
src/map/script.c

@@ -9230,7 +9230,10 @@ BUILDIN_FUNC(addtimer)
 	if( sd == NULL )
 		return 0;
 
-	pc_addeventtimer(sd,tick,event);
+	if (!pc_addeventtimer(sd,tick,event)) {
+		ShowWarning("buildin_addtimer: Event timer is full, can't add new event timer. (cid:%d timer:%s)\n",sd->status.char_id,event);
+		return SCRIPT_CMD_FAILURE;
+	}
 	return SCRIPT_CMD_SUCCESS;
 }
 
@@ -17679,7 +17682,9 @@ BUILDIN_FUNC(npcskill)
 
 /* Consumes an item.
  * consumeitem <item id>;
- * consumeitem "<item name>"; */
+ * consumeitem "<item name>";
+ * @param item: Item ID or name
+ */
 BUILDIN_FUNC(consumeitem)
 {
 	TBL_NPC *nd;
@@ -17698,30 +17703,30 @@ BUILDIN_FUNC(consumeitem)
 
 		if( ( item_data = itemdb_searchname( name ) ) == NULL ){
 			ShowError( "buildin_consumeitem: Nonexistant item %s requested.\n", name );
-			return 1;
+			return SCRIPT_CMD_FAILURE;
 		}
 	}else if( data_isint( data ) ){
 		int nameid = conv_num( st, data );
 
 		if( ( item_data = itemdb_exists( nameid ) ) == NULL ){
 			ShowError("buildin_consumeitem: Nonexistant item %d requested.\n", nameid );
-			return 1;
+			return SCRIPT_CMD_FAILURE;
 		}
 	}else{
 		ShowError("buildin_consumeitem: invalid data type for argument #1 (%d).", data->type );
-		return 1;
+		return SCRIPT_CMD_FAILURE;
 	}
 
 	run_script( item_data->script, 0, sd->bl.id, nd->bl.id );
 	return SCRIPT_CMD_SUCCESS;
 }
 
-/*=======================================================
- * Make a player sit/stand.
+/** Makes a player sit/stand.
  * sit {"<character name>"};
  * stand {"<character name>"};
  * Note: Use readparam(Sitting) which returns 1 or 0 (sitting or standing).
- *-------------------------------------------------------*/
+ * @param name: Player name that will be invoked
+ */
 BUILDIN_FUNC(sit)
 {
 	TBL_PC *sd;
@@ -17732,7 +17737,7 @@ BUILDIN_FUNC(sit)
 		sd = script_rid2sd(st);
 
 	if( sd == NULL)
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 
 	if( !pc_issit(sd) ) {
 		unit_stop_walking(&sd->bl, 1|4);
@@ -17743,6 +17748,9 @@ BUILDIN_FUNC(sit)
 	return SCRIPT_CMD_SUCCESS;
 }
 
+/** Makes player to stand
+* @param name: Player name that will be set
+*/
 BUILDIN_FUNC(stand)
 {
 	TBL_PC *sd;
@@ -17753,7 +17761,7 @@ BUILDIN_FUNC(stand)
 		sd = script_rid2sd(st);
 
 	if( sd == NULL)
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 
 	if( pc_issit(sd) ) {
 		pc_setstand(sd);
@@ -17764,22 +17772,18 @@ BUILDIN_FUNC(stand)
 	return SCRIPT_CMD_SUCCESS;
 }
 
-/*==========================================
+/** Creates an array of bounded item IDs
  * countbound {<type>};
- * Creates an array of bounded item IDs
- * Returns amount of items found
- * Type:
- *	1 - Account Bound
- *	2 - Guild Bound
- *	3 - Party Bound
- *------------------------------------------*/
+ * @param type: 1 - Account Bound; 2 - Guild Bound; 3 - Party Bound
+ * @return amt: Amount of items found
+ */
 BUILDIN_FUNC(countbound)
 {
 	int i, type, j=0, k=0;
 	TBL_PC *sd;
 
 	if( (sd = script_rid2sd(st)) == NULL )
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 
 	type = script_hasdata(st,2)?script_getnum(st,2):0;
 
@@ -17798,17 +17802,19 @@ BUILDIN_FUNC(countbound)
 	return SCRIPT_CMD_SUCCESS;
 }
 
-/*==========================================
+/** Creates new party
  * party_create "<party name>"{,<char id>{,<item share>{,<item share type>}}};
- * <item share>: 0-Each Take. 1-Party Share
- * <item share type>: 0-Each Take. 1-Even Share
- * Return values:
+ * @param party_name: String of party name that will be created
+ * @param char_id: Chara that will be leader of this new party. If no char_id specified, the invoker will be party leader
+ * @param item_share: 0-Each Take. 1-Party Share
+ * @param item_share_type: 0-Each Take. 1-Even Share
+ * @return val: Result value
  *	-3	- party name is exist
  *	-2	- player is in party already
  *	-1	- player is not found
  *	0	- unknown error
  *	1	- success, will return party id $@party_create_id
- *------------------------------------------*/
+ */
 BUILDIN_FUNC(party_create)
 {
 	char party_name[NAME_LENGTH];
@@ -17817,19 +17823,19 @@ BUILDIN_FUNC(party_create)
 
 	if( (!script_hasdata(st,3) && !(sd = script_rid2sd(st))) || (script_hasdata(st,3) && !(sd = map_charid2sd(script_getnum(st,3)))) ) {
 		script_pushint(st,-1);
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 	}
 
 	if( sd->status.party_id ) {
 		script_pushint(st,-2);
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 	}
 
 	safestrncpy(party_name,script_getstr(st,2),NAME_LENGTH);
 	trim(party_name);
 	if( party_searchname(party_name) ) {
 		script_pushint(st,-3);
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 	}
 	if( script_getnum(st,4) )
 		item1 = 1;
@@ -17841,17 +17847,18 @@ BUILDIN_FUNC(party_create)
 	return SCRIPT_CMD_SUCCESS;
 }
 
-/*==========================================
+/** Adds player to specified party
  * party_addmember <party id>,<char id>;
- * Adds player to specified party
- * Return values:
+ * @param party_id: The party that will be entered by player
+ * @param char_id: Char id of player that will be joined to the party
+ * @return val: Result value
  *	-4	- party is full
  *	-3	- party is not found
  *	-2	- player is in party already
  *	-1	- player is not found
  *	0	- unknown error
  *	1	- success
- *------------------------------------------*/
+ */
 BUILDIN_FUNC(party_addmember)
 {
 	int party_id = script_getnum(st,2);
@@ -17860,46 +17867,46 @@ BUILDIN_FUNC(party_addmember)
 
 	if( !(sd = map_charid2sd(script_getnum(st,3))) ) {
 		script_pushint(st,-1);
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 	}
 
 	if( sd->status.party_id ) {
 		script_pushint(st,-2);
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 	}
 
 	if( !(party = party_search(party_id)) ) {
 		script_pushint(st,-3);
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 	}
 
 	if( party->party.count >= MAX_PARTY ) {
 		script_pushint(st,-4);
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 	}
 	sd->party_invite = party_id;
 	script_pushint(st,party_add_member(party_id,sd));
 	return SCRIPT_CMD_SUCCESS;
 }
 
-/*==========================================
+/** Removes player from his/her party. If party_id and char_id is empty remove the invoker from his/her party
  * party_delmember {<char id>,<party_id>};
- * Removes player from his/her party. If party_id and char_id is empty
- * remove the invoker from his/her party
- * Return values:
+ * @param: char_id
+ * @param: party_id
+ * @return val: Result value
  *	-3	- player is not in party
  *	-2	- party is not found
  *	-1	- player is not found
  *	0	- unknown error
  *	1	- success
- *------------------------------------------*/
+ */
 BUILDIN_FUNC(party_delmember)
 {
 	TBL_PC *sd = NULL;
 
 	if( !script_hasdata(st,2) && !script_hasdata(st,3) && !(sd = script_rid2sd(st)) ) {
 		script_pushint(st,-1);
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 	}
 	if( sd || (script_getnum(st,2) && (sd = map_charid2sd(script_getnum(st,2)))) )
 		script_pushint(st,party_removemember2(sd,0,0));
@@ -17908,17 +17915,17 @@ BUILDIN_FUNC(party_delmember)
 	return SCRIPT_CMD_SUCCESS;
 }
 
-/*==========================================
+/** Changes party leader of specified party (even the leader is offline)
  * party_changeleader <party id>,<char id>;
- * Can change party leader even the leader is not online
- * Return values:
+ * @param party_id: ID of party
+ * @param char_id: Char ID of new leader
+ * @return val: Result value
  *	-4	- player is party leader already
  *	-3	- player is not in this party
  *	-2	- player is not found
  *	-1	- party is not found
  *	0	- unknown error
- *	1	- success
- *------------------------------------------*/
+ *	1	- success */
 BUILDIN_FUNC(party_changeleader)
 {
 	int i, party_id = script_getnum(st,2);
@@ -17928,59 +17935,55 @@ BUILDIN_FUNC(party_changeleader)
 
 	if( !(party = party_search(party_id)) ) {
 		script_pushint(st,-1);
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 	}
 
 	if( !(tsd = map_charid2sd(script_getnum(st,3))) ) {
 		script_pushint(st,-2);
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 	}
 
 	if( tsd->status.party_id != party_id ) {
 		script_pushint(st,-3);
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 	}
 
 	ARR_FIND(0,MAX_PARTY,i,party->party.member[i].leader);
 	if( i >= MAX_PARTY ) {	//this is should impossible!
 		script_pushint(st,0);
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 	}
 	if( party->data[i].sd == tsd ) {
 		script_pushint(st,-4);
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 	}
 
 	script_pushint(st,party_changeleader(sd,tsd,party));
 	return SCRIPT_CMD_SUCCESS;
 }
 
-/*==========================================
+/** Changes party option
  * party_changeoption <party id>,<option>,<flag>;
- * Return values:
- *	-1	- party is not found
- *	0	- invalid option
- *	1	- success
- *------------------------------------------*/
+ * @param party_id: ID of party that will be changed
+ * @param option: Type of option
+ * @return val: -1 - party is not found, 0 - invalid option, 1 - success
+ */
 BUILDIN_FUNC(party_changeoption)
 {
 	struct party_data *party;
 
 	if( !(party = party_search(script_getnum(st,2))) ) {
 		script_pushint(st,-1);
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 	}
 	script_pushint(st,party_setoption(party,script_getnum(st,3),script_getnum(st,4)));
 	return SCRIPT_CMD_SUCCESS;
 }
 
-/*==========================================
+/** Destroys party with party id.
  * party_destroy <party id>;
- * Destroys party with party id.
- * Return values:
- *	0	- failed
- *	1	- success
- *------------------------------------------*/
+ * @param party_id: ID of party that will be destroyed
+ */
 BUILDIN_FUNC(party_destroy)
 {
 	int i;
@@ -17988,7 +17991,7 @@ BUILDIN_FUNC(party_destroy)
 
 	if( !(party = party_search(script_getnum(st,2))) ) {
 		script_pushint(st,0);
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 	}
 
 	ARR_FIND(0,MAX_PARTY,i,party->party.member[i].leader);
@@ -18009,13 +18012,10 @@ BUILDIN_FUNC(party_destroy)
 	return SCRIPT_CMD_SUCCESS;
 }
 
-/*==========================================
-* Checks if a player's client version meets a required version or date.
-* @type :
-*  0 - check by version number
-*  1 - check by date
-* @return true/false
- *------------------------------------------*/
+/** Checks if a player's client version meets a required version or date.
+* @param type: 0 - check by version number; 1 - check by date
+* @param data: Input
+*/
 BUILDIN_FUNC(is_clientver) {
 	TBL_PC *sd = NULL;
 	int type = script_getnum(st,2);
@@ -18028,7 +18028,7 @@ BUILDIN_FUNC(is_clientver) {
 		sd = script_rid2sd(st);
 	if (sd == NULL) {
 		script_pushint(st,0);
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 	}
 
 	switch(type){
@@ -18043,10 +18043,9 @@ BUILDIN_FUNC(is_clientver) {
 	return SCRIPT_CMD_SUCCESS;
 }
 
-/*==========================================
-* Retrieves server definitions.
-* (see @type in const.txt)
- *------------------------------------------*/
+/** Retrieves server definitions
+* @param type: See in const.txt
+*/
 BUILDIN_FUNC(getserverdef) {
 	int type = script_getnum(st,2);
 	switch(type){
@@ -18070,9 +18069,10 @@ BUILDIN_FUNC(getserverdef) {
 	return SCRIPT_CMD_SUCCESS;
 }
 
-/* Returns various information about a player's VIP status.
+/** Returns various information about a player's VIP status. Need to enable VIP system
  * vip_status <type>,{"<character name>"};
- * Note: VIP System needs to be enabled.
+ * @param type: Info type, 1: VIP status, 2: Expired date, 3: Remaining time
+ * @param name: Character name (Optional)
  */
 BUILDIN_FUNC(vip_status) {
 #ifdef VIP_ENABLE
@@ -18087,7 +18087,7 @@ BUILDIN_FUNC(vip_status) {
 		sd = script_rid2sd(st);
 
 	if (sd == NULL)
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 
 	switch(type) {
 		case 1: // Get VIP status.
@@ -18120,10 +18120,10 @@ BUILDIN_FUNC(vip_status) {
 }
 
 
-/* Adds or removes VIP time in minutes.
+/** Adds or removes VIP time in minutes. Need to enable VIP system
  * vip_time <time in mn>,{"<character name>"};
- * If time < 0 remove time, else add time.
- * Note: VIP System needs to be enabled. 
+ * @param time: VIP duration in minutes. If time < 0 remove time, else add time.
+ * @param name: Character name (optional)
  */
 BUILDIN_FUNC(vip_time) {
 #ifdef VIP_ENABLE //would be a pain for scripting npc otherwise
@@ -18136,7 +18136,7 @@ BUILDIN_FUNC(vip_time) {
 		sd = script_rid2sd(st);
 
 	if (sd == NULL)
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 
 	chrif_req_login_operation(sd->status.account_id, sd->status.name, 6, viptime, 7, 0); 
 #endif
@@ -18144,10 +18144,16 @@ BUILDIN_FUNC(vip_time) {
 }
 
 
-/*==========================================
- * Turns a player into a monster and grants SC attribute effect. [malufett/Hercules]
+/** Turns a player into a monster and grants SC attribute effect. [malufett/Hercules]
  * montransform <monster name/ID>, <duration>, <sc type>, <val1>, <val2>, <val3>, <val4>;
- *------------------------------------------*/
+ * @param monster: Monster ID or name
+ * @param duration: Transform duration in millisecond (ms)
+ * @param sc_type: Type of SC that will be affected during the transformation
+ * @param val1: Value for SC
+ * @param val2: Value for SC
+ * @param val3: Value for SC
+ * @param val4: Value for SC
+ */
 BUILDIN_FUNC(montransform) {
 
 	TBL_PC *sd;
@@ -18175,17 +18181,17 @@ BUILDIN_FUNC(montransform) {
 			ShowWarning("buildin_montransform: Attempted to use non-existing monster '%s'.\n", script_getstr(st, 2));
 		else
 			ShowWarning("buildin_montransform: Attempted to use non-existing monster of ID '%d'.\n", script_getnum(st, 2));
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 	}
 
 	if (mob_id == MOBID_EMPERIUM) {
 		ShowWarning("buildin_montransform: Monster 'Emperium' cannot be used.\n");
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 	}
 
 	if (!(type > SC_NONE && type < SC_MAX)) {
 		ShowWarning("buildin_montransform: Unsupported status change id %d\n", type);
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 	}
 
 	if (script_hasdata(st, 5))
@@ -18205,12 +18211,12 @@ BUILDIN_FUNC(montransform) {
 
 		if (battle_config.mon_trans_disable_in_gvg && map_flag_gvg2(sd->bl.m)) {
 			clif_displaymessage(sd->fd, msg_txt(sd,1500)); // Transforming into monster is not allowed in Guild Wars.
-			return 0;
+			return SCRIPT_CMD_FAILURE;
 		}
 
 		if (sd->disguise){
 			clif_displaymessage(sd->fd, msg_txt(sd,1498)); // Cannot transform into monster while in disguise.
-			return 0;
+			return SCRIPT_CMD_FAILURE;
 		}
 
 		sprintf(msg, msg_txt(sd,1497), monster->name); // Traaaansformation-!! %s form!!
@@ -18246,7 +18252,7 @@ BUILDIN_FUNC(bonus_script) {
 		sd = script_rid2sd(st);
 
 	if (sd == NULL)
-		return 0;
+		return SCRIPT_CMD_FAILURE;
 	
 	script_str = script_getstr(st,2);
 	dur = 1000 * abs(script_getnum(st,3));
@@ -18255,27 +18261,27 @@ BUILDIN_FUNC(bonus_script) {
 	FETCH(6,icon);
 
 	if (script_str[0] == '\0' || !dur) {
-		//ShowWarning("buildin_bonus_script: Invalid value(s). Skipping...\n");
-		return 0;
+		//ShowWarning("buildin_bonus_script: Invalid script. Skipping...\n");
+		return SCRIPT_CMD_FAILURE;
 	}
 
 	//Skip duplicate entry
 	ARR_FIND(0,MAX_PC_BONUS_SCRIPT,i,&sd->bonus_script[i] && sd->bonus_script[i].script_str && strcmp(sd->bonus_script[i].script_str,script_str) == 0);
 	if (i < MAX_PC_BONUS_SCRIPT) {
 		//ShowWarning("buildin_bonus_script: Duplicate entry with bonus '%d'. Skipping...\n",i);
-		return 0;
+		return SCRIPT_CMD_SUCCESS;
 	}
 
 	if (!(script = parse_script(script_str,"bonus_script",0,1))) {
-		//ShowWarning("buildin_bonus_script: Failed to parse script '%s'. Skipping...\n",script_str);
-		return 0;
+		ShowWarning("buildin_bonus_script: Failed to parse script '%s' (cid:%d). Skipping...\n",script_str,sd->status.char_id);
+		return SCRIPT_CMD_FAILURE;
 	}
 
 	//Find the empty slot
 	ARR_FIND(0,MAX_PC_BONUS_SCRIPT,i,!sd->bonus_script[i].script);
 	if (i >= MAX_PC_BONUS_SCRIPT) {
-		ShowWarning("buildin_itemscript: Maximum script_bonus is reached (max: %d). Skipping...\n",MAX_PC_BONUS_SCRIPT);
-		return 0;
+		ShowWarning("buildin_itemscript: Maximum script_bonus is reached (cid:%d max: %d). Skipping...\n",sd->status.char_id,MAX_PC_BONUS_SCRIPT);
+		return SCRIPT_CMD_SUCCESS;
 	}
 
 	//Add the script data

+ 1 - 1
src/map/skill.c

@@ -8914,7 +8914,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
 			int opt = rnd()%3 + 1;
 			int val = 0, splash = 0;
 			int index = sd->equip_index[EQI_HAND_L];
-			struct item_data *shield_data;
+			struct item_data *shield_data = NULL;
 			if( index >= 0 && sd->inventory_data[index] && sd->inventory_data[index]->type == IT_ARMOR )
 				shield_data = sd->inventory_data[index];
 			if( !shield_data || shield_data->type != IT_ARMOR ) {	// No shield?