hey im using the shop keeper from RPG Tutorial 2, but if i add more items to buy, and i try to buy it it doesnt show up in my invetory heres my code:
mob/var/weapon = 0
obj
var
equiped = 0
weapons
var //Set defaults...
MinDamage = 1
MaxDamage = 1
TheDelay = 0 //Setting this to 0 will let the usr's delay be 4. If this var was 1, it would add 1 to the usr's attack delay and make him/her slower.
verb
pick_up()
set src in oview(1)
Move(usr)
usr << "You pick up the [src]."
destroy()
set src in usr
switch(alert("Do you really want to destroy this?","Destroy [src]:","Yes","No"))
if("Yes")
if(src.equiped == 1)
unequip()
sleep(2)
usr << "You discarded the [src]."
del(src)
equip()
set src in usr
if(usr.weapon == 0)
usr << "You equip the [src]."
usr.Min_Damage += MinDamage
usr.Max_Damage += MaxDamage
usr.Attack_Delay += TheDelay //If this is a positive number, it will make the mob slower... If it is 0, it will do nothing to the mob's attack delay... But if it is negative, it will make the mob attack faster. This is because (for those of you not very good at math) a positive + a negative is the same as a positive - a positive. Example: 4 + (-5) = -1; 8 - (-7) = 15.
suffix = "(Wielded)"
usr.weapon = 1
src.equiped = 1
else
usr << "You may only have one weapon equiped!"
unequip()
set src in usr
if(src.equiped == 1)
usr << "You unequip the [src]."
usr.Min_Damage -= MinDamage
usr.Max_Damage -= MaxDamage
usr.Attack_Delay -= TheDelay
suffix = null
usr.weapon = 0
src.equiped = 0
else
usr << "That's not equiped yet!"
drop()
if(src.equiped == 1)
unequip()
sleep(2)
src.loc = usr.loc
usr << "You drop the [src]."
Giant_Sword //The first weapon... Since we defined the verbs above, we will not need to define anything more.
icon = 'Weapons.dmi'
icon_state = "Giant Sword"
MinDamage = 3
MaxDamage = 6
TheDelay = -1 //Setting this to -1 makes it so it will subtract making the player's attack delay less, which makes him/her faster.
obj/var/worth = 1 //Default.
mob/NPC/Shopkeeper
icon = 'shopkeeper_m2.dmi'
verb/buy()
set src in view(2)
var/selling = input("What do you want to buy?") in list("Potion","Giant_Sword","Nothing.") //Lets give the usr a selection to buy from.
var/cost //This time, lets define this before we set the var...
switch(selling)
if("Potion")
cost = 40 //If they selected to buy a potion, set the cost.
if("Nothing.")
return
if("Giant_Sword")
cost = 500
var/choice = input("That will be [cost] gold. You currently have [usr.Gold] gold") in list("Yes","No")
if(choice == "Yes")
if(usr.Gold >= cost)
usr.Gold -= cost
if(selling == "Potion")
new/obj/Potion(usr) //Make a new potion in the usr's inventory.
else
usr<<"You don't have enough Gold!"
spawn()
buy() //Repeat it so they can buy something else if they wish without needing to click the NPC again.
verb/sell()
set src in view(1)
var/objlist = list() //This list will contain all the objects in the usr's inventory, plus a "Nothing." option.
for(var/obj/O in usr.contents) //Here, we add each of the objects in the usr's contents (their inventory) to objlist.
objlist += O
objlist += "Nothing." //Then we add the option to get out of the menu.
var/buying = input("What would you like to sell?","Sell") in objlist
if(buying == "Nothing.")
return
switch(alert("I will buy [buying] from you for [buying:worth] gold.",,"Yes","No"))
if("Yes")
if(buying:equiped == 1) //Once again, we will check if it is equiped by looking at it's equiped var, then if it is, unequip it.
buying:unequip()
sleep(6)
usr << "\red You sold the [buying]."
var/buyingsworth = buying:worth //You will define worth on each item to let the player sell it for a nice price.
del(buying)
usr.Gold += buyingsworth
spawn()
sell()
obj/Potion
icon = 'Potion.dmi'
var/HP_Rise = 20
worth = 20 //Here we define worth.
verb/drink()
usr << "You drank the [src]!"
usr.HP += HP_Rise
if(usr.HP > usr.MAX_HP)
usr.HP = usr.MAX_HP
del(src) //Delete the potion (src)
1
2
ID:175291
May 12 2003, 2:41 pm
|
|
May 13 2003, 9:05 am
|
|
no way to fix this?
|
your code = confusing. Heres one i whipped up. not 100% sure it works, but i tjhink it should. chances are lummoxJR or Garthor are gunna critisize(spelling?) me anyway, even if it does help both od us become betters coders by yelling at us. anyway, heres the code:
mob/shopkeeper |
In response to Airjoe
|
|
had alot of errors but i got it down to 2 errors
the errors are............ loading The Adventures of Perspolis.dme loading Adventures of Perspolis.dmp Adventures of Perspolis.dmp:77:error: undefined type: /mob/NPC/Shopkeeper Adventures of Perspolis.dmp:77:error: unknown type The Adventures of Perspolis.dmb - 2 errors, 0 warnings (double-click on an error to jump to it) |
In response to Nave
|
|
you just need to define the /mob/NPC/shopkeeper. You don't have one in your code yet.
|
In response to Draks
|
|
yeah i did that no errors now, just when i buy it it doesnt show up in my invortory............
|
In response to Nave
|
|
are you using your origanal code?
|
In response to Nave
|
|
I beleive i posted the working code.
|
In response to Airjoe
|
|
no, because your code says:
new/obj/giantsword (usr.contents)
If you do this, it will make a new giant sword, but it doesn't know what to do with it. It doesn't know where the y and z locations are, and doesn't complain because it thinks its moving it to the players inventory. What it's do is like this: new/obj/giantsword You want something like this:
usr.contents += new /obj/giantsword
That should do it! |
In response to Draks
|
|
no im thinking about useing his code.......
|
In response to Nave
|
|
k. One MAJOR problem is that there is no such thing as /mob/NPC/shopkeeper. Take a look:
mob/shopkeeper /*<-- You have two choices: CHange that and indent everything, or change whatever is refering to /mob/NPC/shopkeeper.*/ name = "ShopKeeper" |
In response to Draks
|
|
Whoops, I also forgot to change another part of the code. For a reason why it works, look at one of my other posts here (I dont remember which). This is the working code:
mob/shopkeeper /*<-- You have two choices: Change that and indent everything, or change whatever is refering to /mob/NPC/shopkeeper.*/ name = "ShopKeeper" density = 1 icon = 'npc.dmi' icon_state = "shopkeeper" Click() var/itemstore = input("What Item do you want to buy?","Buy Items",) in list("Potion","Giant Sword","Nothing") switch(itemstore) if("Potion") if(usr.gold<40) usr << "Not enough gold." else usr.gold -= 40 usr.contents += new /obj/potion if("Giant Sword") if(usr.gold<500) usr << "Not enough gold" else usr.gold -= 500 usr.contents += new /obj/giantsword if("Nothing") return |
In response to Draks
|
|
ok it works, but i want it to be a verb to buy something from the shop keeper, instead of Clicking on the shop keeper.......
|
In response to Nave
|
|
Oh, thats easy. Just replace the click with the verb stuff, like
//The rest fo the stuff goes here Buy() //The rest fo the stuff goes here |
In response to Draks
|
|
/mob/NPC/Shopkeeper
mob/shopkeeper name = "ShopKeeper" density = 1 icon = 'shopkeeper_m2.dmi' verb Buy() var/itemstore = input("What Item do you want to buy?","Buy Items",) in list("Potion","Giant Sword","Nothing") switch(itemstore) if("Potion") if(usr.Gold<40) usr << "Not enough gold." else usr.Gold -= 40 usr.contents += new /obj/Potion if("Giant Sword") if(usr.Gold<500) usr << "Not enough gold" else usr.Gold -= 500 usr.contents += new /obj/weapons/Giant_Sword if("Nothing") return |
In response to Nave
|
|
*Chuckles* You forgot to change the /mob/shopkeeper to the /mob/NPC/shopkeeper, and indent everything in the shopkeepers path. Like, indent the icon and struff for the shopkeeper.
|
In response to Draks
|
|
ok now im confused.......
|
In response to Nave
|
|
This is the working code:
mob/NPC |
In response to Draks
|
|
Draks wrote:
no, because your code says:
new/obj/giantsword (usr.contents)
If you do this, it will make a new giant sword, but it doesn't know what to do with it. It doesn't know where the y and z locations are, and doesn't complain because it thinks its moving it to the players inventory. You're right that it won't work, but not for the reason you think. usr.contents is wrong there, but usr is not. y and z have nothing to do with it, nor does it think anything is moving into the player's inventory. The reason is that the first argument to New() for an atom should be its location. usr is a location; usr.contents is just a list. You can't set loc to usr.contents, because usr.contents is not an atom; you can set it to usr, because usr is an atom. You want something like this:
usr.contents += new /obj/giantsword
That should do it! That should work, but it's not as good a method as the other way. The key is just to get the other way right. Lummox JR |
In response to Draks
|
|
Draks wrote:
This is the working code: > mob/NPC Bo it doesnt work........... oh well |
1
2