Jump to content
  • 0

Question

3 answers to this question

Recommended Posts

  • 0
Posted
/*==========================================
* @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
  • 0
Posted
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

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...