Jump to content
  • 0
kairu

Trading an item and triggering a function

Question

So i was wondering if this is possible if you put in an item in the trade window a function will be called.

i tried looking at trade.c of trade_tradeadditem; but i dont know how to call the function if i put it in the source code. or is there like an "OnTradeAdd" command?

Share this post


Link to post
Share on other sites

11 answers to this question

Recommended Posts

  • 1
2 hours ago, kairu said:

Thanks! i will try this one when i get back... is there also a way to pass arguments/variables into the script?

 

	npc->event_doall_id( "OnTradeEvent", sd->bl.id );
	npc->event_doall_id( "OnTradeEvent", tsd->bl.id );

	// Save char RID of exchanger into @trader variable
	pc->setreg(sd,script->add_str("@trader"),tsd->status.account_id);
	pc->setreg(tsd,script->add_str("@trader"),sd->status.account_id);
-	script	TradeTest	FAKE_NPC,{

OnTradeEvent:
	mes "Has exchanged with the player "+rid2name(@trader);
	close;
}

 

Share this post


Link to post
Share on other sites
  • 0
25 minutes ago, meko said:

What exactly would that function be needed for?

does it matter? maybe they want to add a counter for each time player trades. or bring a mes() window.

Share this post


Link to post
Share on other sites
  • 0
Just now, Myriad said:

does it matter? maybe they want to add a counter for each time player trades. or bring a mes() window.

It's just that there's likely another way to accomplish what they try to do without modifying the source or making a plugin. But for that we need to know what the original intent is.

Share this post


Link to post
Share on other sites
  • 0
1 hour ago, meko said:

It's just that there's likely another way to accomplish what they try to do without modifying the source or making a plugin. But for that we need to know what the original intent is.

i basically have a randomized skill system where equipments give skills and/or stats etc.. so id like players to know what they got on it and if theyre going to trade it to another player it shows them. so if they put in the item on the trade window theres a dispbottom that shows the hidden attributes.

Share this post


Link to post
Share on other sites
  • 0
25 minutes ago, kairu said:

Bump

General Posting Guidelines

  • Posts may not contain SPAM. Spam is one word posts, posts with no meaning to the topic, or double/triple posts without reason.
  • Posts in the support sections may be bumped with more information no less than 24 hours after the last post; if you have new information within less than 24h, edit your previous post.

http://herc.ws/board/guidelines/

 

Sorry, I'm not able to help further as the engine does not support what you are trying to accomplish

Please fill an issue here if you would like a new feature to be added (ie trading events):
https://github.com/HerculesWS/Hercules/issues/new

Share this post


Link to post
Share on other sites
  • 0

This may probably be moved to the source support section.

Heres an update/work around of it for now:

i went in and inputted the items that will be having the hidden abilities in itemdb.h

ofcourse i have declared the missing ones and included sql and inter files.

nameid = sd->status.inventory[index].nameid;
	 if(itemdb_is_cweapon(nameid)){
		 unique_id = sd->status.inventory[index].unique_id;
		 if(SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `description` FROM `randombonus` WHERE `unique_id`='%s'", unique_id)){
			Sql_ShowDebug(inter->sql_handle);
		 }
		else{
			 char str[500];
			SQL->GetData(inter->sql_handle, 1, &data, NULL); str[0] = data;
			clif->disp_message(&(sd)->bl,str,CHAT);
			SQL->FreeResult(inter->sql_handle);
		 }
	 }

The problem now is im stuck of the error it gives and i dont know what to do with it next.

Capture.JPG

Edited by kairu

Share this post


Link to post
Share on other sites
  • 0

Open src/map/trade.c, find:

// save both player to avoid crash: they always have no advantage/disadvantage between the 2 players
	if (map->save_settings&1) {
		chrif->save(sd,0);
		chrif->save(tsd,0);
	}

Add below:

	npc->event_doall_id( "OnTradeEvent", sd->bl.id );
	npc->event_doall_id( "OnTradeEvent", tsd->bl.id );

 

Test NPC:

-	script	TradeTest	FAKE_NPC,{

OnTradeEvent:
	mes "Hello, world!";
	close;
}

 

Share this post


Link to post
Share on other sites
  • 0
On 6/16/2017 at 9:14 AM, Easycore said:

Open src/map/trade.c, find:


// save both player to avoid crash: they always have no advantage/disadvantage between the 2 players
	if (map->save_settings&1) {
		chrif->save(sd,0);
		chrif->save(tsd,0);
	}

Add below:


	npc->event_doall_id( "OnTradeEvent", sd->bl.id );
	npc->event_doall_id( "OnTradeEvent", tsd->bl.id );

 

Test NPC:


-	script	TradeTest	FAKE_NPC,{

OnTradeEvent:
	mes "Hello, world!";
	close;
}

 

Thanks! i will try this one when i get back... is there also a way to pass arguments/variables into the script?

Share this post


Link to post
Share on other sites
  • 0

According to npc.c, this is how array values for OnBuyItem/OnSellItem are genereated. Maybe you can work something out from it.

 
	//npc_buylist for script-controlled shops.
int npc_buylist_sub(struct map_session_data *sd, struct itemlist *item_list, struct npc_data *nd)
{
    char npc_ev[EVENT_NAME_LENGTH];
    int i;
    int key_nameid = 0;
    int key_amount = 0;
	    nullpo_ret(item_list);
    nullpo_ret(nd);
	    // discard old contents
    script->cleararray_pc(sd, "@bought_nameid", (void*)0);
    script->cleararray_pc(sd, "@bought_quantity", (void*)0);
	    // save list of bought items
    for (i = 0; i < VECTOR_LENGTH(*item_list); i++) {
        struct itemlist_entry *entry = &VECTOR_INDEX(*item_list, i);
        intptr_t nameid = entry->id;
        intptr_t amount = entry->amount;
        script->setarray_pc(sd, "@bought_nameid", i, (void *)nameid, &key_nameid);
        script->setarray_pc(sd, "@bought_quantity", i, (void *)amount, &key_amount);
    }
	    // invoke event
    snprintf(npc_ev, ARRAYLENGTH(npc_ev), "%s::OnBuyItem", nd->exname);
    npc->event(sd, npc_ev, 0);
    return 0;
}

Share this post


Link to post
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.   Restore formatting

  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.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.