How to use new Merchant Handlers?
Moderator: POL Developer
How to use new Merchant Handlers?
Hi all, i upgrade my svn to 346 and compiled new pol version with this handlers by Austin.
So i followed core-changes and inserted line ScriptedMerchantHandlers=1 on servspecopt.cfg and then bought something from a npc, but, nothing was changed, the item goes to my bag and ev.shoppinglist are <unitillized object>.
May i made something worng?
So i followed core-changes and inserted line ScriptedMerchantHandlers=1 on servspecopt.cfg and then bought something from a npc, but, nothing was changed, the item goes to my bag and ev.shoppinglist are <unitillized object>.
May i made something worng?
Re: How to use new Merchant Handlers?
Try an SVN update.. and recompile...
Re: How to use new Merchant Handlers?
Thanks for the fast answer Austin, is working now.
SYSEVENT_MERCHANT_BOUGHT is passing nothing into shoppinglist.
SYSEVENT_MERCHANT_SOLD is fine.
The only point to note, inside npc backpack items are into stacks even if item.stackable = 0 and item.splitstackinto not check this and create stack of non stackable item.
To solve this i used:
SYSEVENT_MERCHANT_BOUGHT is passing nothing into shoppinglist.
SYSEVENT_MERCHANT_SOLD is fine.
The only point to note, inside npc backpack items are into stacks even if item.stackable = 0 and item.splitstackinto not check this and create stack of non stackable item.
To solve this i used:
Code: Select all
if (item.stackable)
if (amt == item.amount)
moveitemtocontainer (item, who.backpack);
else
item.splitstackinto (who.backpack, amt);
endif
else
if (amt == 1)
moveitemtocontainer (item, who.backpack);
else
for i := 1 to amt
item.splitstackinto (who.backpack, 1);
endfor
endif
endif
Re: How to use new Merchant Handlers?
Groovy...
That is correct and why I had to put in item.SplitStack()
Off the top of my head the scripted handler could work something like this (no promises itll compile, its more an idea)
This is if the player bought something from the merchant:
That is correct and why I had to put in item.SplitStack()
Off the top of my head the scripted handler could work something like this (no promises itll compile, its more an idea)
This is if the player bought something from the merchant:
Code: Select all
foreach entry in ( event.shoppinglist )
if ( entry.item.stackable )
if ( entry.amount >= entry.item.amount ) // Player bought the whole thing
MoveItemToContainer(entry.item, player.backpack);
else
var sold_item := entry.item.SplitStackInto(player.backpack, entry.amount);
if ( sold_item.errortext )
SendSysMessage(player, "Error placing item in pack ->"+sold_item.errortext);
endif
endif
else
var i := entry.amount;
for ( i; i > 0; i-=1 )
var sold_item := entry.item.SplitStackInto(player.backpack, 1);
if ( sold_item.errortext )
SendSysMessage(player, "Error placing item in pack ->"+sold_item.errortext);
endif
Sleepms(2);
endfor
endif
Sleepms(20);
endforeach
Re: How to use new Merchant Handlers?
Overall, mine and yours script is pretty similar.
Can you see if MERCHANT_BOUGHT event is working properly for you? as i said, here pass no value in shoppinglist array.
Can you see if MERCHANT_BOUGHT event is working properly for you? as i said, here pass no value in shoppinglist array.
Re: How to use new Merchant Handlers?
Hahaha! I forgot to add one important line. Hold on.
Re: How to use new Merchant Handlers?
@348 solve the shoppinglist array problem.
A point to note is if npc have a stack with 5 items and i buy all stack at once, script bellow will give to me only 4 because last one return a error "Amount must be less than stack amount." So, to avoid put extra IFs and ELSEs into script, this could be if item.amount == SplitStackInto request amount -> the item is just moved to new container.
Another thing i feel is missing a way to stack up itens non stackable because when npc buys items from player, those items will spread out into npc "items to sell" container.
A point to note is if npc have a stack with 5 items and i buy all stack at once, script bellow will give to me only 4 because last one return a error "Amount must be less than stack amount." So, to avoid put extra IFs and ELSEs into script, this could be if item.amount == SplitStackInto request amount -> the item is just moved to new container.
Code: Select all
var i := entry.amount;
for ( i; i > 0; i-=1 )
var sold_item := entry.item.SplitStackInto(player.backpack, 1);
endfor
Re: How to use new Merchant Handlers?
Okay. Ill work on this tomorrow a bit.
If amount = stack amount - Return the original item as the new stack.
If amount > stack amount - Return an error
If amount = stack amount - Return the original item as the new stack.
If amount > stack amount - Return an error
Re: How to use new Merchant Handlers?
Thanks, quality in @350 is the same as item.quality?
Re: How to use new Merchant Handlers?
Yeap. Im working on a new crafting system ill release shortly - Really nifty stuff. I've been working on rewriting Mytharria.
351 will have your stack changes. I didn't test them though
351 will have your stack changes. I didn't test them though
Re: How to use new Merchant Handlers?
Crafting system? Share it with me if you have any chances, I'd be glad to introduce it to the Distro as soon I get a chance, if you're not already doing it.
Re: How to use new Merchant Handlers?
Ill start a new thread for the craft stuff here.
http://forums.polserver.com/viewtopic.p ... 196#p17196
Ive only been building this for about 3 days so far, its preliminary still.
http://forums.polserver.com/viewtopic.p ... 196#p17196
Ive only been building this for about 3 days so far, its preliminary still.
Re: How to use new Merchant Handlers?
I've tested @351 and the object of original stack return correctly if amt == stack amt, but the stack is not moved to new container or to xyz.351 will have your stack changes. I didn't test them though
Re: How to use new Merchant Handlers?
352: Fixes further issues identified by TercioB on forums with splitting stacks.
Here is the script I just put together to test it.
Here is the script I just put together to test it.
Code: Select all
// $Id$
//
//
use uo;
use os;
Unload_Scripts("stacktests");
program TextCommand(user)
SendSysMessage(user, "Starting with XYZ tests.");
Sleep(1);
XYZTests(user);
Sleep(4);
SendSysMessage(user, "Starting container tests.");
Sleep(1);
ContainerTests(user);
return 1;
endprogram
function XYZTests(user)
SendSysMessage(user, "Adding 100 gold to backpack.");
var stack_a := CreateItemInContainer(user.backpack, "GoldCoin", 100);
SendSysMessage(user, "Stack_A ->"+stack_a);
SendSysMessage(user, "Sending 20 to a nearby position.");
var stack_b := stack_a.SplitStackAt(user.x-1, user.y+1, user.z, user.realm, 20);
SendSysMessage(user, "Stack_B ->"+stack_b);
PrintTextAbove(stack_a, "Stack A");
PrintTextAbove(stack_b, "Stack B");
Sleep(2);
SendSysMessage(user, "Moving remaining gold to another position.");
var stack_c := stack_a.SplitStackAt(user.x+1, user.y-1, user.z, user.realm, stack_a.amount);
SendSysMessage(user, "Stack_C ->"+stack_c);
PrintTextAbove(stack_c, "Stack C");
Sleep(4);
SendSysMessage(user, "Cleaning up stacks.");
DestroyItem(stack_a);
DestroyItem(stack_b);
DestroyItem(stack_c);
return 1;
endfunction
function ContainerTests(user)
SendSysMessage(user, "Creating 100 gold at feet.");
var stack_a := CreateItemAtLocation(user.x, user.y, user.z, "GoldCoin", 100, user.realm);
SendSysMessage(user, "Stack_A ->"+stack_a);
SendSysMessage(user, "Sending 20 to your backpack.");
var stack_b := stack_a.SplitStackInto(user.backpack, 20);
SendSysMessage(user, "Stack_B ->"+stack_b);
PrintTextAbove(stack_a, "Stack A");
PrintTextAbove(stack_b, "Stack B");
Sleep(2);
SendSysMessage(user, "Moving remaining gold to backpack.");
var stack_c := stack_a.SplitStackInto(user.backpack, stack_a.amount);
SendSysMessage(user, "Stack_C ->"+stack_c);
PrintTextAbove(stack_c, "Stack C");
Sleep(4);
SendSysMessage(user, "Cleaning up stacks.");
DestroyItem(stack_a);
DestroyItem(stack_b);
DestroyItem(stack_c);
return 1;
endfunction
Re: How to use new Merchant Handlers?
just reporting, @352 solved the problem .