Jump to content
  • 0

Jumptosell command


masterzeus

Question


  • Group:  Members
  • Topic Count:  17
  • Topics Per Day:  0.00
  • Content Count:  58
  • Reputation:   1
  • Joined:  08/18/13
  • Last Seen:  

Hello! Could this code be adapted to today's rAthena?
Generates an error with the line containing "itemdb_searchname"

https://github.com/coookie1010/Server-Patches/blob/main/rA-jumptosell.diff

 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  14
  • Topics Per Day:  0.00
  • Content Count:  402
  • Reputation:   89
  • Joined:  02/07/13
  • Last Seen:  

/*==========================================
* @jumptosell - warps to the cheapest shop.
* Made by Vengence
* Make it work for latest [Shakto]
*------------------------------------------*/
ACMD_FUNC(jumptosell)
{
	char item_name[100];
	int item_id = 0, j, count = 0, sat_num = 0;
	int s_type = 1; // search bitmask: 0-name,1-id, 2-card, 4-refine
	int refine = 0,card_id = 0;
	struct map_session_data* pl_sd;
	struct map_session_data* pl_sd2;
	struct s_mapiterator* iter;
	unsigned int MinPrice = battle_config.vending_max_value, MaxPrice = 0;
	nullpo_retr(-1, sd);

	if (!message || !*message) {
		clif_displaymessage(fd, "Use: @jumptosell (<+refine> )(<item_id>)(<[card_id]>) or @jumptosell <name>");
		return -1;
	}

	if (sscanf(message, "+%d %d[%d]", &refine, &item_id, &card_id) == 3){
		s_type = 1+2+4;
	} else if (sscanf(message, "+%d %d", &refine, &item_id) == 2){
		s_type = 1+4;
	} else if (sscanf(message, "+%d [%d]", &refine, &card_id) == 2){
		s_type = 2+4;
	} else if (sscanf(message, "%d[%d]", &item_id, &card_id) == 2){
		s_type = 1+2;
	} else if (sscanf(message, "[%d]", &card_id) == 1){
		s_type = 2;
	} else if (sscanf(message, "+%d", &refine) == 1){
		s_type = 4;
	} else if (sscanf(message, "%d", &item_id) == 1 && item_id == atoi(message)){
		s_type = 1;
	} else if (sscanf(message, "%99[^\n]", item_name) == 1){
		s_type = 1;
		std::shared_ptr<item_data> id = item_db.searchname( item_name );

		if( id == nullptr ){
			clif_displaymessage(fd, "No item found with this name");
			return -1;
		}

		item_id = id->nameid;
	} else {
		clif_displaymessage(fd, "Use: @jumptosell (<+refine> )(<item_id>)(<[card_id]>) or @jumptosell <name>");
		return -1;
	}
    
	struct item_data *item_data;

	//check card
	if(s_type & 2 && ((item_data = itemdb_exists(card_id)) == NULL || item_data->type != IT_CARD)){
		clif_displaymessage(fd, "Not found a card with than ID");
		return -1;
	}
	//check item
	if(s_type & 1 && (item_data = itemdb_exists(item_id)) == NULL){
		clif_displaymessage(fd, "Not found an item with than ID");
		return -1;
	}
	//check refine
	if(s_type & 4){
		if (refine<0 || refine>10){
			clif_displaymessage(fd, "Refine out of bounds: 0 - 10");
			return -1;
		}
		/*if(item_data->type != IT_WEAPON && item_data->type != IT_ARMOR){
			clif_displaymessage(fd, "Use refine only with weapon or armor");
			return -1;
		}*/
	}
	iter = mapit_getallusers();
	
	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
	{
		if( pl_sd->vender_id ) //check if player is vending
		{
			for (j = 0; j < pl_sd->vend_num; j++) 
			{
				if((item_data = itemdb_exists(pl_sd->cart.u.items_cart[pl_sd->vending[j].index].nameid)) == NULL)
					continue;
				if(s_type & 1 && pl_sd->cart.u.items_cart[pl_sd->vending[j].index].nameid != item_id)
					continue;
				if(s_type & 2 && ((item_data->type != IT_ARMOR && item_data->type != IT_WEAPON) ||
						(pl_sd->cart.u.items_cart[pl_sd->vending[j].index].card[0] != card_id &&
						pl_sd->cart.u.items_cart[pl_sd->vending[j].index].card[1] != card_id &&
						pl_sd->cart.u.items_cart[pl_sd->vending[j].index].card[2] != card_id &&
						pl_sd->cart.u.items_cart[pl_sd->vending[j].index].card[3] != card_id)))
					continue;
				if(s_type & 4 && ((item_data->type != IT_ARMOR && item_data->type != IT_WEAPON) || pl_sd->cart.u.items_cart[pl_sd->vending[j].index].refine != refine))
					continue;
				if(pl_sd->vending[j].value < MinPrice){ 
					MinPrice = pl_sd->vending[j].value;
					pl_sd2 = pl_sd;
				}
				count++;
			}
		}
	}
	mapit_free(iter);

	if(count > 0) {
		pc_setpos(sd, pl_sd2->mapindex, pl_sd2->bl.x, pl_sd2->bl.y, CLR_TELEPORT);
	} else
		clif_displaymessage(fd, "Nobody is selling it now.");

return 0;
}

 

  • Upvote 1
  • Love 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  17
  • Topics Per Day:  0.00
  • Content Count:  58
  • Reputation:   1
  • Joined:  08/18/13
  • Last Seen:  

On 2/19/2022 at 2:18 PM, Shakto said:
/*==========================================
* @jumptosell - warps to the cheapest shop.
* Made by Vengence
* Make it work for latest [Shakto]
*------------------------------------------*/
ACMD_FUNC(jumptosell)
{
	char item_name[100];
	int item_id = 0, j, count = 0, sat_num = 0;
	int s_type = 1; // search bitmask: 0-name,1-id, 2-card, 4-refine
	int refine = 0,card_id = 0;
	struct map_session_data* pl_sd;
	struct map_session_data* pl_sd2;
	struct s_mapiterator* iter;
	unsigned int MinPrice = battle_config.vending_max_value, MaxPrice = 0;
	nullpo_retr(-1, sd);

	if (!message || !*message) {
		clif_displaymessage(fd, "Use: @jumptosell (<+refine> )(<item_id>)(<[card_id]>) or @jumptosell <name>");
		return -1;
	}

	if (sscanf(message, "+%d %d[%d]", &refine, &item_id, &card_id) == 3){
		s_type = 1+2+4;
	} else if (sscanf(message, "+%d %d", &refine, &item_id) == 2){
		s_type = 1+4;
	} else if (sscanf(message, "+%d [%d]", &refine, &card_id) == 2){
		s_type = 2+4;
	} else if (sscanf(message, "%d[%d]", &item_id, &card_id) == 2){
		s_type = 1+2;
	} else if (sscanf(message, "[%d]", &card_id) == 1){
		s_type = 2;
	} else if (sscanf(message, "+%d", &refine) == 1){
		s_type = 4;
	} else if (sscanf(message, "%d", &item_id) == 1 && item_id == atoi(message)){
		s_type = 1;
	} else if (sscanf(message, "%99[^\n]", item_name) == 1){
		s_type = 1;
		std::shared_ptr<item_data> id = item_db.searchname( item_name );

		if( id == nullptr ){
			clif_displaymessage(fd, "No item found with this name");
			return -1;
		}

		item_id = id->nameid;
	} else {
		clif_displaymessage(fd, "Use: @jumptosell (<+refine> )(<item_id>)(<[card_id]>) or @jumptosell <name>");
		return -1;
	}
    
	struct item_data *item_data;

	//check card
	if(s_type & 2 && ((item_data = itemdb_exists(card_id)) == NULL || item_data->type != IT_CARD)){
		clif_displaymessage(fd, "Not found a card with than ID");
		return -1;
	}
	//check item
	if(s_type & 1 && (item_data = itemdb_exists(item_id)) == NULL){
		clif_displaymessage(fd, "Not found an item with than ID");
		return -1;
	}
	//check refine
	if(s_type & 4){
		if (refine<0 || refine>10){
			clif_displaymessage(fd, "Refine out of bounds: 0 - 10");
			return -1;
		}
		/*if(item_data->type != IT_WEAPON && item_data->type != IT_ARMOR){
			clif_displaymessage(fd, "Use refine only with weapon or armor");
			return -1;
		}*/
	}
	iter = mapit_getallusers();
	
	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
	{
		if( pl_sd->vender_id ) //check if player is vending
		{
			for (j = 0; j < pl_sd->vend_num; j++) 
			{
				if((item_data = itemdb_exists(pl_sd->cart.u.items_cart[pl_sd->vending[j].index].nameid)) == NULL)
					continue;
				if(s_type & 1 && pl_sd->cart.u.items_cart[pl_sd->vending[j].index].nameid != item_id)
					continue;
				if(s_type & 2 && ((item_data->type != IT_ARMOR && item_data->type != IT_WEAPON) ||
						(pl_sd->cart.u.items_cart[pl_sd->vending[j].index].card[0] != card_id &&
						pl_sd->cart.u.items_cart[pl_sd->vending[j].index].card[1] != card_id &&
						pl_sd->cart.u.items_cart[pl_sd->vending[j].index].card[2] != card_id &&
						pl_sd->cart.u.items_cart[pl_sd->vending[j].index].card[3] != card_id)))
					continue;
				if(s_type & 4 && ((item_data->type != IT_ARMOR && item_data->type != IT_WEAPON) || pl_sd->cart.u.items_cart[pl_sd->vending[j].index].refine != refine))
					continue;
				if(pl_sd->vending[j].value < MinPrice){ 
					MinPrice = pl_sd->vending[j].value;
					pl_sd2 = pl_sd;
				}
				count++;
			}
		}
	}
	mapit_free(iter);

	if(count > 0) {
		pc_setpos(sd, pl_sd2->mapindex, pl_sd2->bl.x, pl_sd2->bl.y, CLR_TELEPORT);
	} else
		clif_displaymessage(fd, "Nobody is selling it now.");

return 0;
}

 

Works fine ❤️
Thanks

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  9
  • Reputation:   0
  • Joined:  12/27/14
  • Last Seen:  

Crash mapserver when i do @jumptosell, y char is vending a item with cost of 1 Billon zeny

Edited by Melk3000
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...