Trading an item and triggering a function

kairu

New member
Messages
23
Points
0
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?

 
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.
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.

 
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.

 
Is there any workaround in this? or atleast a guide on how to call a function on src

 
Last edited by a moderator:
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

 
Last edited by a moderator:
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

 
Last edited by a moderator:
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:

Code:
-	script	TradeTest	FAKE_NPC,{

OnTradeEvent:
	mes "Hello, world!";
	close;
}
 
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?

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


Code:
	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);
Code:
-	script	TradeTest	FAKE_NPC,{

OnTradeEvent:
	mes "Has exchanged with the player "+rid2name(@trader);
	close;
}
 
According to npc.c, this is how array values for OnBuyItem/OnSellItem are genereated. Maybe you can work something out from it.

Code:
 
	//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;
}
 
Back
Top