I want to make a shop

ramtha
28 Jan 2006, 21:31
I'm trying to figure out how to create a shop where, oddly enough, you can buy items. I wanted to make a menu with the list of items so you could just select the one you wanted and get it, But when i did this, and you chose the item again, i would get an error message and the game would shut off. Any suggestions.
I would have just said if you have the item then dont give it, but for items you can have more than one of,such as potions, I'm having problems.

Elexxorine
30 Jan 2006, 09:10
i've created a working shop system for my game 'neverquest'. i'll prolly be able to make a demo version for you soon...

ramtha
30 Jan 2006, 18:53
sweet ^_^

Elexxorine
01 Feb 2006, 09:09
here's some codes grabbed from 'neverquest', but you can use them.
	command </shop list> {
if property <#quest.currentroom[userid]#; shop> then do <shop_list> else msg <This is not a shop.> }

command </buy #num# #shopitem#; buy #num# #shopitem#> do <shop_buy>

command <inventory; /inventory; inv; /inv; i; /i> {
msg <|cyYou have $objectproperty(#name[userid]#;gold)$ Gold.|cb>
set numeric <count1; 0>
set numeric <count2; 0>
for each object in <item_storage> {
inc <count1>
set numeric <own; $objectproperty(#name[userid]#; item_#quest.thing#)$>
if ( %own% > 0 ) then msg <|b$displayname(#quest.thing#)$:|xb %own%.> else inc <count2>
}
if ( %count2% = %count1% ) then msg <You aren't carrying anything.>
}

define variable <gold>
scope local
type numeric
value <o>
display <Gold: $objectproperty(#name[userid]#;gold)$.>
end define
These are global commands and should go in the game define block.
define room <shop room>
alias <Weapon smith's, Xelenq>
look <Bast is sitting by the counter, waiting for a customer. There's an anvil near the wall and many tools and bits of metal hanging on the walls.|n|nType '|cr/shop list|cb' to see what's for sale.>
out <town1, street2>
properties <shop; name=xel>

define object <bast>
alt <Bast; owner; shopowner; shop owner>
look <Bast is sitting by the counter, looking bored.>
properties <normal; living; person; not attackable>
displaytype <shop owner>
speak choose <shop_menu>
end define

define object <xelsi_knife>
alias <knife>
look <A basic weapon. There are $objectproperty(knife;number)$ for sale.>
properties <invisible; shopitem; number=5; m_price=15; s_price=0; b_price=0>
end define

define object <xelsi_staff>
alias <staff>
properties <invisible; shopitem; number=2; m_price=16; s_price=0; b_price=0>
end define

end define


define room <player_storage>


define object <Elexxorine>
look <Elexxorine is the creator of NeverQuest.>
displaytype <Admin>
properties <gold=30000; item_knife=0; item_staff=0; item_banesword=0; item_fclothtop=0; item_fclothleg=0; item_fleathboot=0; item_furcloak=0; item_mithpauld=0; item_mithcuirass=0; item_mithgreave=0>
end define

end define


define room <item_storage>

define object <knife>
properties <pos=equip_weapon; equipable; name=knife>
end define

define object <staff>
properties <pos=equip_weapon; equipable; name=staff>
end define

define object <banesword>
alias <bane sword>
properties <pos=equip_weapon; equipable; name=banesword>
end define
define object <fclothtop>
alias <fine cloth shirt>
properties <pos=wear_body; equipable; name=fclothtop>
end define
define object <fclothleg>
alias <fine cloth legs>
properties <pos=wear_legs; equipable; name=fclothleg>
end define
define object <fleathboot>
alias <fine leather boots>
properties <pos=wear_boots; equipable; name=fleathboot>
end define
define object <furcloak>
alias <fur cloak>
properties <pos=wear_back; equipable; name=furcloak>
end define
define object <mithpauld>
alias <mithrel pauldrons>
properties <pos=equip_shoulders; equipable; name=mithpauld>
end define
define object <mithcuirass>
alias <mithrel cuirass>
properties <pos=equip_weapon; equipable; name=mithcuirass>
end define
define object <mithgreave>
alias <mithrel greaves>
properties <pos=equip_legs; equipable; name=mithgreave>
end define

end define


define procedure <shop_list>
for each object in <#quest.currentroom[userid]#> {
if property <#quest.thing#; shopitem> then {
set numeric <number; $objectproperty(#quest.thing#;number)$>
set string <obname; $displayname(#quest.thing#)$>
if ( %number% > 0 ) then {
do <price_calc>
msg <|b|cr$capfirst(#obname#)$:|xb|n|cgBuy for: |cy$objectproperty(#quest.thing#;s_price)$|cb.|n|cgSell for: |cy$objectproperty(#quest.thing#;b_price)$|cb.>
}
else {
property <#quest.thing#; b_price=$objectproperty(#quest.thing#; m_price)$>
msg <|b|cr$capfirst(#obname#)$:|cy|xbSOLD OUT!|n|cgBuying for: |cy$objectproperty(#quest.thing#;b_price)$|cb.>
}
}
}
msg <|crTo buy something type '/buy NUMBER ITEM', eg: '/buy 4 staff'.|cb>

end define


define procedure <price_calc>
set numeric <maxprice; $objectproperty(#quest.thing#;m_price)$>
set numeric <sellprice; %maxprice% / %number%>
if ( %sellprice% = 0 ) then set numeric <sellprice; %maxprice%>
property <#quest.thing#; s_price=%sellprice%>
set numeric <buyprice; %number% * 2>
set numeric <buyprice; %maxprice% / %buyprice%>
if ( %buyprice% = 0 ) then set numeric <buyprice; %maxprice%>
property <#quest.thing#; b_price=%buyprice%>

end define


define procedure <shop_buy>
if property <#quest.currentroom[userid]#; shop> then {
set stirng <shopitem; $getobjectname(#shopitem#)$>
set string <alias; $displayname(#shopitem#)$>
set numeric <num; #num#>
if ( %num% = 0 ) then msg <"Fine..."> else {
if here <#shopitem#> then if property <#shopitem#; shopitem> then {
set numeric <num2; $objectproperty(#shopitem#; number)$>
if ( %num% > %num2% ) then msg <"We don't have that many..."> else {
set numeric <number; $objectproperty(#shopitem#;number)$>
set string <quest.thing; #shopitem#>
do <price_calc>
' set numeric <moneyi; $objectproperty(#shopitem#;s_price)$>
set numeric <moneyi; %sellprice% * %num%>
set numeric <moneys; $objectproperty(#name[userid]#; gold)$>
if ask <%num% $displayname(#shopitem#)$(s) cost %moneyi%, you have %moneys%. Are you sure you want to buy?> then {
if ( %moneyi% > %moneys% ) then {
msg <"I'm sorry, but you don't seem to have enough money ...">
}
else {
set numeric <pprice; %moneys% - %moneyi%>
property <#name[userid]#; gold=%pprice%>
set <num2; %num2% - %num%>
property <#shopitem#; number=%num2%>
' msg <You hand over %moneyi% |cygold|cb and receive %num% $displayname(#shopitem#)$(s).>
set numeric <ownitem; $objectproperty(#name[userid]#; item_#alias#)$>
inc <ownitem; %num%>
property <#name[userid]#; item_#alias#=%ownitem%>

set string <talker; #name[userid]#>
for each object in <#quest.currentroom[userid]#> {
set string <name; $displayname(#quest.thing#)$>
if property <#name#; real> then {
if ( $displayname(#quest.thing#)$ = #talker# ) then {
msgto <$objectproperty(#quest.thing#;userid)$; You hand over |b|cy%moneyi% gold|cb|xb and receive %num% $displayname(#shopitem#)$(s).>
}
else {
' if property <#quest.thing#; real> then {
msgto <$objectproperty(#quest.thing#;userid)$; |b|cy$capfirst(#talker#)$|xb buys %num% $displayname(#shopitem#)$(s) for %moneyi% gold.|cb>
}
}
}
}
}
else msg <"Fine...">
}
}
else msg <"I'm sorry, but we don't sell that here.">
}
}
else msg <This isn't a shop.>

end define
theses are the other stuff. read them over....

paul_one
01 Feb 2006, 13:40
Be careful of the wordwrap and that game (neverquest) is for the multiplayer version of Quest.. So if you need single player please say so.

I haven't had chance to read that Elex - formatting looks better than in the email I had.

ramtha
01 Feb 2006, 18:38
I do need a single player... hee hee...

Elexxorine
02 Feb 2006, 09:03
simple conversion.... just delete all the [userid]'s and change the properties to variables too...