[Share] Bazaar System

General assistance and guidelines for editing the server side of Soma.

[Share] Bazaar System

Postby Ramy » Wed Apr 24, 2013 4:44 am

This will be a quick and rough guide on how to make your own bazaar system (works with server files 3.0**)

**Note: there is a 1p1 edit required for this which is already in 3.0 files so be aware this is why you'd need that version

What is it?
This is like an auction system which will never close unless you want it to.
It's open to everyone to put items up for sale and buy them.
This uses guild store and auction functions to implement and therefore the limit for each instance is 20 items.
You may make as many instances as you wish however.

Installation

-First you will need to alter/add(if they don't exist) the following procs and views:


Code: Select all
CREATE VIEW dbo.view_unt_items
AS
SELECT     sNum
FROM         dbo.BASICITEM
WHERE     (sNum >= 1836) AND (sNum <= 1865) OR
                      (sSpecial = 67) OR
                      (sSpecial = 32) OR
                      (bType = 15) OR
                      (sNum >= 3985) AND (sNum <= 3999)

The above is for checking untradable items item nums provided by finito.

Replace the below procs with the updated version here.
Code: Select all
/****** ??: ?? ???? dbo.AUCTION_GET_MONEY    ???? ??: 2002-06-29 ?? 11:49:41 ******/
/****** ??: ?? ???? dbo.AUCTION_GET_MONEY    ???? ??: 2002-06-12 ?? 12:55:01 ******/
/****** ??: ?? ???? dbo.AUCTION_GET_MONEY    ???? ??: 2002-06-05 ?? 9:50:22 ******/
/****** Object:  Stored Procedure dbo.AUCTION_DRAW_SELL_ITEM    Script Date: 00-11-01 ?? 12:55:40 ******/
CREATE PROCEDURE AUCTION_GET_MONEY
@auctionnum smallint,
@struserid varchar(20)
AS
declare @money  int

SELECT @money  =  SUM(iCurMoney)  FROM AUCTION_TEMP WHERE sAuctionNum = @auctionnum AND strUserId = @struserid AND sState = 1
if @money > 0
begin
update AUCTION_TEMP set sState = 2 WHERE sAuctionNum = @auctionnum AND strUserId = @struserid AND sState = 1
select @money
end

if @money < 0
begin
select null
end
GO


Code: Select all
/****** ??: ?? ???? dbo.GUILD_TOWN_STORE_BUY_ITEM    ???? ??: 2002-06-29 ?? 11:49:53 ******/
/****** ??: ?? ???? dbo.GUILD_TOWN_STORE_BUY_ITEM    ???? ??: 2002-06-12 ?? 12:55:04 ******/
/****** ??: ?? ???? dbo.GUILD_TOWN_STORE_BUY_ITEM    ???? ??: 2002-06-05 ?? 9:50:23 ******/
CREATE PROCEDURE GUILD_TOWN_STORE_BUY_ITEM
@townnum smallint,
@index int,
@num smallint
AS
DECLARE @userid VARCHAR(20)
DECLARE @itemdat CHAR(100)
DECLARE @imoney int

SELECT iIndex, strUserId, iCost, ItemData, sNum FROM guild_town_store WHERE iIndex = @index and sState = 1 and sNum >= @num
if( @@rowcount > 0 )
begin
   update guild_town_store set sNum = sNum - @num where iIndex = @index
   update guild_town_store set sState = 0 where iIndex = @index and sState = 1 and sNum < 1

if (@townnum = 13)
begin
SELECT @userid = strUserId, @itemdat = ItemData, @imoney =( @num * iCost) FROM guild_town_store WHERE iIndex=@index
INSERT INTO AUCTION_TEMP
                      (iIndex, sAuctionNum, strUserId, iMinMoney, ItemData, iCurMoney, strBuyId,
                      sState)
VALUES         (@index, 6, @userid,@num, @itemdat, @imoney, 'buyer', 1)


end

if (@townnum > 15)
begin
SELECT @userid = strUserId, @itemdat = ItemData, @imoney =( @num * iCost) FROM guild_town_store WHERE iIndex=@index
INSERT INTO AUCTION_TEMP
                      (iIndex, sAuctionNum, strUserId, iMinMoney, ItemData, iCurMoney, strBuyId,
                      sState)
VALUES         (@index, 6, @userid,@num, @itemdat, @imoney, 'buyer', 1)


end

end
GO


Code: Select all
/****** ??: ?? ???? dbo.GUILD_TOWN_STORE_REG_ITEM    ???? ??: 2002-06-29 ?? 11:49:54 ******/
/****** ??: ?? ???? dbo.GUILD_TOWN_STORE_REG_ITEM    ???? ??: 2002-06-12 ?? 12:55:05 ******/
/****** ??: ?? ???? dbo.GUILD_TOWN_STORE_REG_ITEM    ???? ??: 2002-06-05 ?? 9:50:23 ******/
CREATE PROCEDURE GUILD_TOWN_STORE_REG_ITEM
@OutParam int OUTPUT,
@townnum smallint,
@struserid varchar(20),
@money int,
@itemdata char(100),
@num smallint
AS
declare @count smallint
declare @itemid smallint
--declare @cmpitemdata binary
--select @cmpitemdata = @itemdata
select @itemid = CAST((SUBSTRING(CAST(@itemdata as binary(2)),2,1) + SUBSTRING(CAST(@itemdata as binary(2)),1,1)) AS smallint)
-- check if it's not tradeable
select sNum from view_unt_items where sNum = @itemid
if (@@rowcount = 0)
BEGIN
select @count = count(*) from guild_town_store where sGuildTownNum = @townnum and sState = 1
if( @count < 20 )
begin
   INSERT INTO guild_town_store VALUES ( @townnum, @struserid, @money, @itemdata, @num, 1 )
   select @OutParam = 1
END
end
-- if the id is in the untradables return 0
--select sNum from view_unt_items where sNum = @itemid
--if (@@rowcount > 0)
--BEGIN
--select @OutParam = 0
--END

if( @count >= 20 )
begin
   select @OutParam = 0
end
GO


Add Rows to GUILD_TOWN table
Each row you add will represent a bazaar instance, the procs are coded to service sTownnum 13 , and stownnum above 15.

Fill in a row for townnum: 13 as follows:
dtTime: 2001/11/11 /* doesn't matter the date/time just put anything in dt format */
sType: 1 /* must be 1 */
sTownNum 13 /* must be either 13 or greater than 15 */
sGuildNum 1 /* MUST BE your gm guild's id very important!! all the money goes here */
strGuildName Bazaar Manager /* the thing that displays above npc's head if you like */
sLevel 1 /* doesn't matter leave it as 1 */
sTaxRate 1 /* doesn't matter but you can make your own tax if you want */
ally1 -1 /* allies don't matter either */
ally2 -1
ally3 -1

Events:
Code: Select all
;;;
;; anzan bazaar manager nasrin
EVENT 151
;E RUN_EVENT 20 ; <- you don't need this part
E SELECT_MSG 3896 3897 152 3898 153 3899 154 265 -1
; this is the main menu select message make up your own npcchats
E RETURN
END

; put items for sale
EVENT 152
E OPEN_GUILDTOWN_STORE_REG 13
; notice 13 corrisponds to the entry you did in guild_town if you added a different one say 16 that's what you'd put here
E RETURN
END

; buying items
EVENT 153
E OPEN_GUILDTOWN_STORE 13
; notice 13 corrisponds to the entry you did in guild_town if you added a different one say 16 that's what you'd put here
E RETURN
END

;pick up money for sold items
EVENT 154
E AUCTION_GET_MONEY 6
; this is to get all the money from sold items the 6 is just an instance of auction that is not used in esoma you may use this for all of your bazaar instances
E RETURN
END


That's it! enjoy... I won't go through the details of linking evts with npcs you should look to other guides for that, if you want to make more instances just add a new entry in guild_town with any stownnum above 15 (make sure they're unique) and copy/paste the evt code above changing only the guild store numbers from 13 to w/e stownnum entry you made, and obviously the event numbers.

EDIT: Please test this out before putting it live, although it has been tested on ShinRa with mssql 2000 , I may have forgotten to include something so if there are issues / bugs let me know.
User avatar
Ramy
SD Four Star
SD Four Star
 
Posts: 213
Joined: Fri Feb 29, 2008 1:20 pm

Re: [Share] Bazaar System

Postby waily » Fri Apr 26, 2013 2:24 am

cool!!!
waily
SD Four Star
SD Four Star
 
Posts: 152
Joined: Thu May 10, 2012 7:14 pm


Return to Server Development

Who is online

Users browsing this forum: No registered users and 6 guests

cron