SphereCommunity

Full Version: NPC buy limit
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Sometimes a player sell a lot of items to the same vendor, without any problem or wait for something.
This script "lock" the vendor for some time, so he can't buy anything from players while locked and the player will have to find another NPC to sell his things.

Code:
////////////// Script by: Stanic - Daniel Barbosa Maranhão - Email: pikulinhu@hotmail.com | Skype: daniel.bmaranhao
/// To install open your sphere.ini and add e_PlayerSell to EventsPlayer

[DEFNAME VendorsEconomy]
SellStockDelay    "3600"    //Delay in seconds to "restock" the vendor.

[EVENTS e_PlayerSell]
ON=@ItemSell
LOCAL.MaxAmount=<eval <SERV.VendorMaxSell>-<ARGO.TAG0.SellStock>>
IF (<ARGN1> > <LOCAL.MaxAmount>)
  IF (<LOCAL.MaxAmount>==<SERV.VendorMaxSell>)
   ARGO.SAY Sorry <NAME>, I don't want to buy all these items. Give me <SERV.VendorMaxSell> and we both will be satisfied!
  ELIF (<LOCAL.MaxAmount> > 0)
   ARGO.SAY Sorry <NAME>, my stock of items is almost full and I can only carry with me more <dLOCAL.MaxAmount> items.
  ELSE
   ARGO.SAY Sorry <NAME>, my stock of items is full and I can't take more anything with me.
  ENDIF
  return 1
ENDIF
ARGO.TAG0.SellStock +=<ARGN1>
ARGO.TIMERF <dDEF.SellStockDelay>, SellReStock <ARGN1>

[FUNCTION SellReStock]
TAG.SellStock -=<ARGS>

[EOF]
http://forum.spherecommunity.net/sshare/...ccarry.scp
Thanks!
Kinda usefull for RP shards, good job Smile
Code:
[DEFNAME VendorsEconomy]
VendorMaxSell              50 // Missing value

Funny, everyone congratulated you on your script but didn't notice it is missing a key element. *smh*

Code:
tag0.sellstock

What is the relevance of this tag on the vendor for every purchase but not the one item type in general?

If argn1 > <VendorMaxSell> which you check for.. why are you testing if they are equal?

Also... your tag relies on the sale of any item and doesn't record that item being sold; just a total in general. So he/she will only buy 'x' of ANY item and that is it. Was this desired?

Plus I am finding your script contradictory. I am working on a rework now.

Here is the rework:

Code:
[defname vendorseconomy]
sellstockdelay            3600    //delay in seconds to "restock" the vendor.
vendormaxsell            500    // Max Items

[events e_playersell]
on=@ItemSell
local.maxamount=<eval (<serv.vendormaxsell> - <argo.tag0.sellstock>)>

// vendor cannot hold anymore items. we shall not buy the items and exit from code.
if (<argn1> > <local.maxamount>) && (<local.maxamount> == 0)
argo.say Sorry <name>, my stock of items is full and I can't take anything more with me.
return 1
endif

// vendor can hold more items, but the players is selling more than the vendor can hold.
if (<local.maxamount> != 0) && (<argn1> > <local.maxamount>)
argo.say Sorry <name>, I don't want to buy all of these items. Give me <local.maxamount> and we both will be satisfied!
return 1
endif

argo.tag0.sellstock += <argn1>
argo.timerf <ddef.sellstockdelay>, sellrestock <argn1>

[function sellrestock]
tag.sellstock -= <argn>

Now in the above script I am sticking to your vendor only buying "x" items. I see where you are coming from with that to a point. I fixed all of your redundancies and contradictions as well. ARGS wasn't needed in the function; just ARGN since it was storing a #. I chose to use two different IF statements to try and exit the code as fast as possible without parsing the extras. If the purchase goes through it will add to the tag0.sellstock.

Before you argue you tested this... there is no way you tested the (==) parsing you did above. If the player was selling wares == to what the vendor could hold, then the sale would be successful. Also there was no reason to check what the max items the vendor can hold from the def. That is pointless if he was only able to carry say 50 from the local. Telling the player they could for instance sell 500 from the def would have left them confused and complaining about a bug.

Also I'd like to note this is firing on EVERY item sold. Not just the entire lot at once. ACT is the item in question. Just so you know how often this is actually firing.
(11-28-2013 04:31 PM)Khaos Wrote: [ -> ]If argn1 > <VendorMaxSell> which you check for.. why are you testing if they are equal?
If <ARGN1> is > then <LOCAL.MaxAmount> this mean that the player is trying to buy more that the npc can sell.

The script have 3 situations (Consider "SERV.VendorMaxSell = 50", for example):
1. The player try to buy more than 50 items when the NPC is "restocked":
Code:
Sorry <NAME>, I don't want to buy all these items. Give me <SERV.VendorMaxSell> and we both will be satisfied!
2. The player try to buy more items then the npc can sell for him:
Code:
Sorry <NAME>, my stock of items is almost full and I can only carry with me more <dLOCAL.MaxAmount> items.
3. The npc can't sell more anything:
Code:
Sorry <NAME>, my stock of items is full and I can't take more anything with me.

The script simulates that the Vendor is heavy and can't hold more anything, so the tag relies on the sale of any item because this was the prupose of this script.

Tongue
Just test what I sent through. Trust me. It fixed it. Calling for the ddef was not even logical if your max limit was set by 100 in a local and serv was 5000.

The == line was also odd and unneeded. Several of us looked at the code and agreed something was off.

Your script is still missing the def for maxitems in the ddef.

I upgraded it even more on my end. I literally just about rewrote the entire thing, cut out that == check (which was a bad check) and added in checks for stolen items, new markup tags (custom mathematics to be a bit more accurate). removed nested IF's (which I showed above and is better to do in most cases).

Quote:@ItemSell
Description

This trigger fires when a character sells an item to a vendor. The trigger fires for each item that is sold in the transaction.

Has nothing to do with a vendor selling anything to a player. It works as the player is selling things to the vendor. Again... TRY my script. It will fix the issues which I laid out that you aren't understanding it seems.
Here is an updated and improved version of this script without the need of the redundancies. Stanic's NPC BUY LIMIT REWORKED AND IMPROVED.
Gr8 work Stanic and Khaos! I'm going to use this.. ;]
hey guys, i was checking this script and i have a doubt
whats the tag.markup for??? never read of it, only for tag.vendormarkup ...

thanks.

// If the vendor has a markup price; this will reduce the pricing accurately.
if (<argo.tag.markup> > 0) && (<argo.tag.vendormarkup> == 0)
argn2=(<argn2> - <muldiv <argn2>,<argo.tag.markup>,100>)
endif
Pages: 1 2
Reference URL's