ID:168866
 
I'm creating a new RPG, but I can't seem to figure out how to make an auction system much like the one used in Seika.

What I'm wanting to do is have 3 verbs. 1 is to start an auction which will ask for an item out of the user's inventory to auction, and then add it into a (list?) that can only hold 1 item. After that, it will ask a price to start the bidding at. After awhile, if the item is not bid on, it should return to the user's inventory.

The second one is to stop an auction, therefore returning the object in the (list?) to the users inventory and cancels all bids out.

The third one is a bid verb. This should not be less or equal to the object in the (list?)'s saleprice, and this will update the object in the (list?)'s saleprice to the new amount. Once the object has had a bid on it for so long, it should be given to the highest bidder, and the saleprice should be added to the person who started the auction's gold.

A push in the right direction or something like that would be very helpful.
I tried to make this as simple as I could possibly manage. Don't get mad if it's a little long, at least I produced one right? It's looks easily customizeable to me anyway. I've only commented parts that are not self explanatory with text output, i.e. "src<<"Process cancelled because of no input for the highest bid.""

var/highbid
var/highbidder
var/ownbidder
var/biditem
var/time=0
var/auctstop
var/auctstop2


mob/verb/Start_Auction()
if(biditem) {src<<"There is currently an auction in place.";return}
//If there is a biditem in place, cancel. We don't want two auctions at once.
var/obj/O=input("What item would you like to auction?","Auction Item")as null|obj in src
if(!O) return
//If there is no input for the object, cancel
var/startbid=input("What number would you like to start the bidding at?","Bidding Price")as null|num
if(!startbid) return
if(startbid<=0) {src<<"The starting bid must be higher than 0 gold.";return}
//No starting bid price? Cancel verb
highbid=startbid //State the starting bid price
biditem="\ref[O]" //Reference the object, it's easier to access later
ownbidder="\ref[src]"
src.verbs+=/mob/Auction/verb/Stop_Auction
src.verbs+=/mob/Auction/verb/Stop_Auction2
//Gice the auction starter a way to stop the auction
O.loc = locate(12,12,1)
//We don't want to get rid of the item incase it's a custom one\
Place the item somewhere that can't be accessed by users, a vacant part of the map?

world<<"[src] has started an auction for their [O.name]. Starting bid is [startbid]."
time=10//Set time to 10. Allows 10 seconds before someone places bid.
while(time)
if(auctstop) {world<<"[src] has stopped the auction.";auctstop=null;return}
if(auctstop2) {world<<"[src] has stopped the auction.";time=0;auctstop2=null;break}
sleep(10)
if(time==1)//Make sure you
time--//time it for precisely
sleep(10)//ten seconds
else time--
//Take Away from the time after 1 second has passed
if(!time&&!highbidder)
world<<"The auction has ended. The item goes to the owner."
var/obj/Item = locate(biditem) //Find the referenced item
Item.loc=src //Add the item to the Auction starter
if(!time&&highbidder)
var/mob/M = locate(highbidder)
world<<"[M] has won the auction with a bid of [highbid] gold."
var/obj/Item = locate(biditem) //Find the referenced item
Item.loc=M //Add the item to the Auction bidder
//M.gold-=highbid
//src.gold+=highbid
//Transfer Gold
highbid=null
highbidder=null
biditem=null
auctstop=null
auctstop2=null
ownbidder=null
src.verbs -= /mob/Auction/verb/Stop_Auction
src.verbs -= /mob/Auction/verb/Stop_Auction2

mob/Auction/verb/Stop_Auction()
//This verb will stop all functions of the aution currently\
in place. No functions will be carried out further. This \
eliminated purpose of the [auctstop2] veriable.

if(alert("Are you sure you want to stop the auction?\n\
This will completely erase the data as if \n\
no auction has even taken place."
,"Stop Auction","Yes","No")=="Yes")
auctstop=1
highbid=null
highbidder=null
biditem=null
ownbidder=null
src.verbs -= /mob/Auction/verb/Stop_Auction
src.verbs -= /mob/Auction/verb/Stop_Auction2
//Clear out all of the varibles and stop the time check procedure\
all the way up there in the Start_Auction verb.



mob/Auction/verb/Stop_Auction2()
//This verb will stop the auction for you. However\
instead of clearing all of the bids, it carries everything\
out. so, the highest bidder gets the item and so forth. \
Using this eliminates the purpose for the [auctstop] variable.

if(alert("Are you sure you want to stop the auction?\n\
You will still leave the auction to carry \n\
it's function, such as transferring the \n\
item and gold."
,"Stop Auction","Yes","No")=="Yes")
auctstop2=1
//The Start_Auction procdure takes care of the rest of it.

mob/verb/Auction_Bid()
if(!biditem) {src<<"There is no auction currently taking place.";return}
//Cancel process if there is no auction
var/i=input("How much would you like to bid for the item?","Bid Gold")as null|num
if(!i) return
//Cancel process if the person has not entered value to bid.
if(i<=highbid) {src<<"The bid is not high enough. It must be above [highbid].";return}
if(!biditem) {src<<"There is no auction currently taking place.";return}
//Make sure auction is still available after input
var/obj/O = locate(biditem)
//de-reference the biditem
highbidder="\ref[src]"
highbid=i
time=6
var/mob/M
while(time&&M==src&&biditem)
//Check to see if the timer is still set, M is the user of this verb, \
and the auction is still taking place.

M=locate(highbidder)
//Make sure there hasn't been another bidder
if(time==6)
world<<"[src] has bid [i] on the [O.name] currently at auction. Going once."
if(time==3) world<<"Going twice to [src] for [O.name]."
//All of the other functions are carried out when time hits 0 on the\
Start_Auction verb


client/Del()
if(biditem)
if(src.mob==locate(ownbidder))
auctstop=1
highbid=null
highbidder=null
biditem=null
ownbidder=null
src.verbs -= /mob/Auction/verb/Stop_Auction
src.verbs -= /mob/Auction/verb/Stop_Auction2
//Bring Auction to abrupt stop if the action owner has \
logged out. REMEMBER, the mob has to exist to access it.

//Delete the mob upon client/Del(), not on the exectution \
of mob/Logout() or a verb.

del(src.mob)
//Like here, delete the mob here, after it is done checking to see \
if it is the auction starter that has logged out.

..() //Carry out original functions. Make sure you have client/Del()\
nowhere else, otherwise you'll have to deal with the other proc bieng\
called first, and then deleteing the mob.


If there are any flaws, you should be able to notice them right away, I hope.

[EDIT] I never took the verbs away from the person when the auction was stopped.
In response to CaptFalcon33035
Every time anyone starts an auction, the game locks up.
In response to Sinoflife
I never made a delay to the while proc. That's a vital mistake on my part. Anyway, I'll just make a link to the file so you don't have to indent a bunch of crap.

Auction.zip

I wouldn't have zipped it, but HostUltra doesn't allow unknown file extensions for free account users. I'm broke.

[Edit] It also doesn't allow remote linking of files. You have to go to the download page and get it yourself.

Download Page

I should really update that page.
In response to CaptFalcon33035
Thanks. However, if someone bids on an item twice, it displays 2 messages to world saying Going once or Going twice, and players can bid something such as 100.1.(Fixed with fintext())
Also, I don't want players to be able to bid on their own item.


ex:

Artemio has bid 10 on the Large Axe of Knowledge currently at auction. Going once.
Going twice to Artemio for Large Axe of Knowledge.
Shinryu has bid 11 on the Large Axe of Knowledge currently at auction. Going once.
Artemio has bid 10 on the Large Axe of Knowledge currently at auction. Going once.
Going twice to Shinryu for Large Axe of Knowledge.
Shinryu has won the auction with a bid of 11 gold.
In response to Sinoflife
Use the ownbidder variable to check if that person is the bidder. If so, return the proc so that nothing happens. As for the bidding twice thing, check to see if the highbidder variable is referenced to him. If it is, return that proc as well.

There is a while proc in the Auction_Bid verb. Use that to check to see if the user is still the highest bidder. And if he's not, return the proc.
In response to CaptFalcon33035
I tried if(O.ownbidder==usr) return, but it says that it's an undefined variable.