The following warnings occurred:
Warning [2] Use of undefined constant SAPI_NAME - assumed 'SAPI_NAME' (this will throw an Error in a future version of PHP) - Line: 3388 - File: inc/functions.php PHP 7.4.33-nmm6 (Linux)
File Line Function
/inc/functions.php 3388 errorHandler->error
/showthread.php 116 build_archive_link
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm6 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/inc/functions.php 3324 build_forum_breadcrumb
/showthread.php 195 build_forum_breadcrumb
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm6 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/showthread.php 195 build_forum_breadcrumb






Post Reply 
 
Thread Rating:
  • 2 Votes - 4.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NPC buy limit
Author Message
Staff_Stanic
Journeyman
*

Posts: 96
Likes Given: 25
Likes Received: 14 in 8 posts
Joined: Nov 2012
Reputation: 1

Dimension Shard

Post: #1
NPC buy limit
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


Attached File(s)
.scp  npccarry.scp (Size: 1,016 bytes / Downloads: 17)
(This post was last modified: 11-28-2013 01:57 AM by Staff_Stanic.)
11-28-2013 01:27 AM
Visit this user's website Find all posts by this user Like Post Quote this message in a reply
[+] 2 users Like Staff_Stanic's post
amonvangrell
Banned

Posts: 337
Likes Given: 17
Likes Received: 32 in 20 posts
Joined: Aug 2012

britannia shard

Post: #2
RE: NPC buy limit
Thanks!
11-28-2013 05:22 AM
Visit this user's website Find all posts by this user Like Post Quote this message in a reply
XuN
Sphere Developer
*****

Posts: 852
Likes Given: 102
Likes Received: 156 in 119 posts
Joined: Jul 2013
Reputation: 30



Post: #3
RE: NPC buy limit
Kinda usefull for RP shards, good job Smile
11-28-2013 07:50 AM
Find all posts by this user Like Post Quote this message in a reply
[+] 1 user Likes XuN's post
Khaos
Master
**

Posts: 595
Likes Given: 166
Likes Received: 83 in 51 posts
Joined: Mar 2012
Reputation: 11



Post: #4
RE: NPC buy limit
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.
(This post was last modified: 11-28-2013 05:25 PM by Khaos.)
11-28-2013 04:31 PM
Find all posts by this user Like Post Quote this message in a reply
Staff_Stanic
Journeyman
*

Posts: 96
Likes Given: 25
Likes Received: 14 in 8 posts
Joined: Nov 2012
Reputation: 1

Dimension Shard

Post: #5
RE: NPC buy limit
(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
(This post was last modified: 11-29-2013 03:01 AM by Staff_Stanic.)
11-29-2013 03:01 AM
Visit this user's website Find all posts by this user Like Post Quote this message in a reply
Khaos
Master
**

Posts: 595
Likes Given: 166
Likes Received: 83 in 51 posts
Joined: Mar 2012
Reputation: 11



Post: #6
RE: NPC buy limit
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.
(This post was last modified: 11-29-2013 08:04 AM by Khaos.)
11-29-2013 07:56 AM
Find all posts by this user Like Post Quote this message in a reply
Khaos
Master
**

Posts: 595
Likes Given: 166
Likes Received: 83 in 51 posts
Joined: Mar 2012
Reputation: 11



Post: #7
RE: NPC buy limit
Here is an updated and improved version of this script without the need of the redundancies. Stanic's NPC BUY LIMIT REWORKED AND IMPROVED.
11-30-2013 12:26 PM
Find all posts by this user Like Post Quote this message in a reply
amonvangrell
Banned

Posts: 337
Likes Given: 17
Likes Received: 32 in 20 posts
Joined: Aug 2012

britannia shard

Post: #8
RE: NPC buy limit
Gr8 work Stanic and Khaos! I'm going to use this.. ;]
01-19-2014 10:23 AM
Visit this user's website Find all posts by this user Like Post Quote this message in a reply
kn4tseb
Master
**

Posts: 392
Likes Given: 45
Likes Received: 10 in 10 posts
Joined: May 2014
Reputation: 0



Post: #9
RE: NPC buy limit
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.

(This post was last modified: 09-19-2014 04:28 AM by kn4tseb.)
09-19-2014 04:27 AM
Find all posts by this user Like Post Quote this message in a reply
Extreme
Grandmaster Poster
***

Posts: 1,141
Likes Given: 217
Likes Received: 90 in 77 posts
Joined: May 2012
Reputation: 20

SphereCommunity

Post: #10
RE: NPC buy limit
// 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

STEPS BEFORE CREATE A THREAD
- Check the revisions log;
- Use the search button and use the keywords of your problem;
- Check the WIKI;
- Create a thread.
09-19-2014 06:34 AM
Find all posts by this user Like Post Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)