ID:164682
 
Items
Dagger
name = "Dagger" //Give it a name of Sword.
icon = 'weapons.dmi' //The icon of the object(what it will look like)
icon_state = "Dagger" //The icon state of the object
text = "<font bgcolor=maroom>P"
suffix="Weapon"
cost=20
power=5
Description="A small dagger with an attack value of 5."
Click()
if(src in view(1))
var/Items/Dagger = locate(/Items/Dagger) in usr.contents
if(Dagger)
if(src.equipped==0)
if(usr.canshop==0)
if(usr.WeaponSlotUsed==0)
src.suffix="Weapon (Equipped)"
usr<<"You equip the [src.name]!"
usr.strength+=src.power
src.equipped=1
usr.WeaponSlotUsed=1
else
usr<<"You already have a weapon/tool equipped!"
else
usr << "[src.Description]"
switch(alert("Do you want to sell your weapon?",,"Yes","No"))
if("Yes")
usr.crowns+=src.cost
del(src)
usr << "You sell [src.name]."
return
if("No")
return
else
src.suffix="Weapon"
usr<<"You unequip the [src.name]!"
usr.strength-=src.power
src.equipped=0
usr.WeaponSlotUsed=0


This is my current Dagger code. The statpanel forshopping code, is here:

mob
Stat()
for(var/mob/I in oview(3))
if(I in oview(1))
if(I.isplayer==0)
statpanel("Shop")
// stat("[I.Description]")
stat(I.contents)
canshop=1
else
canshop=0


When you come within one space of the Weapons Guy, it'll bring up a shop statpanel and it will display the weapon. The only problem is, is purchasing that weapon. Currently, if you click on your weapon in your inventory when next to the Weapons Guy, it'll display the description for that item. How would I make it check to see if it is in the shopkeepers inventory, and if so, then display a different message like "Click twice to buy!" or something along those lines.

Would it be easier to simply make another object to put in the Weapons Guy's inventory that is specifically coded for shops, or just to modify my current weapons?


Please help,

Michael
I've tried working on this yet I can't seem to get it to work. Is there a way to check what statpanel an object is in?
Okay, here's a little bit of a hint:

People will completely ignore your question, if you put every line of code up, and ask for them to fix it. What you want to do, is cut down your code to only what's necessary to your problem/question. In your case, take away the Dagger's stats, descriptions, and equip/unequip verbs. Obviously, keep them in your game's code; just remove them from the code you're posting online. Only leave the sell verb on the dagger.

Simply because I have nothing better to do, I'll do this for you:

Items
Dagger
Click()
if(src in view(1))
var/Items/Dagger = locate(/Items/Dagger) in usr.contents
if(Dagger)
if(usr.canshop==0) return //if the user CAN'T shop, do nothing.
else //if the user CAN shop, do the following:
switch(alert("Do you want to sell your weapon?",,"Yes","No"))
if("Yes")
usr << "You sell [src.name] for [src.cost]."
del(src)
if("No") return


See, this will be much easier for others' to work with and help you with than what you originally posted. It's much shorter and much less cluttery. I'll admit, it's a bit painful to have to cut down your own code so much so that people can understand it better, and it may be confusing to piece back together again once it works properly, but it's certainly worth it; more people are willing to help with a code that's short, sweet, and to the point, than they are to troubleshoot an entire game's worth of code.

Here's a couple small edits in the other piece of code:

mob
Stat()
for(var/mob/I in oview(1)) //instead of having to check for 3 spaces, then 1, just put 1 here.
if(I.isplayer==0)
statpanel("Shop")
stat(I.contents) //there was a "disabled" line of code above this; get rid of it.
canshop=1
else
canshop=0


Now, I might have been wrong in that first edit. I didn't test this code out myself, so I don't know if what you had was necessary. If so, my apologies, just put it back how it was. Regardless, we didn't need the "disabled" code; if it doesn't affect the code, and it doesn't comment the code, we don't need to see it.

As for actually helping you, I'm working on it; I just wanted to give you a few pointers as to how to actually get help around here.
In response to RIPyro
Items
Dagger
Click()
if(src in view(1))
var/Items/Dagger = locate(/Items/Dagger) in usr.contents
if(Dagger)
for(var/mob/I in oview(1))
if(I.isplayer==0)
switch(alert("Do you want to sell your weapon?",,"Yes","No"))
if("Yes")
usr << "You sell [src.name] for [src.cost]."
del(src)
if("No") return
else
for(var/mob/I in oview(1))
if(I.isplayer==0)
var/Items/I_Dagger = locate(/Items/Dagger) in I.contents
if(I_Dagger)
switch(alert("Do you want to buy a [src.name]?",,"Yes","No"))
if("Yes")
usr << "You buy [src.name] for [src.cost]."
usr.contents += src
if("No") return
mob
Stat()
for(var/mob/I in oview(1))
if(I.isplayer==0)
statpanel("Shop")
stat(I.contents)


As far as I'm concerned, this should work. Again, I haven't tested this code myself, nor do I plan to, as there are too many custom vars, objects, etc. that it would just be a waste of time for me to try to recreate myself (hah, as if my last reply wasn't a waste of time).

I believe the "canshop" var is completely unnecessary, and that it would be more efficient to simply re-check for a non-player mob one space away. Regardless, this looks like it'll work to me; let me know if otherwise, and I'll see what I can do.

Oh, also: with this code, it'll make it so that if there is NOT a dagger in your inventory, and you click on a dagger elsewhere, it'll ask if you want to buy one. I'm not sure if this would be useful (or why you would want to buy another dagger when there's one on the ground, or whatever the hell is going on at that point).
If what you meant was, allow the player to click on the Dagger in his inventory, and (if he's next to a shop that has a Dagger itself) ask if the player wants to buy ANOTHER dagger, use this:

Items
Dagger
Click()
if(src in view(1))
var/Items/Dagger = locate(/Items/Dagger) in usr.contents
if(Dagger)
for(var/mob/I in oview(1))
if(I.isplayer==0)
var/Items/I_Dagger = locate(/Items/Dagger) in I.contents
if(I_Dagger)
switch(alert("Do you want to buy a [src.name]?",,"Yes","No"))
if("Yes")
usr << "You buy [src.name] for [src.cost]."
usr.contents += src
if("No") return
switch(alert("Do you want to sell your weapon?",,"Yes","No"))
if("Yes")
usr << "You sell [src.name] for [src.cost]."
del(src)
if("No") return
else
for(var/mob/I in oview(1))
if(I.isplayer==0)
mob
Stat()
for(var/mob/I in oview(1))
if(I.isplayer==0)
statpanel("Shop")
stat(I.contents)


Now, with THIS code, the player will be able to buy as many Daggers as he or she likes; hopefully needless to say, you're going to need to edit the code to check if the player even has enough money (or "crowns," as it seems to be named in your game) to buy a Dagger (or anything, for that matter) before it makes the deal. Otherwise, the player could end up with negative amounts of money, and continue to spend it. Also, when you ask if the player wants to buy/sell a Dagger, you should also mention the Dagger's price. And, for the sake of being partially realistic, keep in mind that stores will sell goods for higher prices than they'll pay; if the player buys something then sells it back, he/she should still lose money in the deal. The buy price is normally higher than the sell price. Not that you necessarily need to follow this.

And yes, I realize that I spent far too much time and effort with this. It should be at least partially helpful, I hope.
In response to RIPyro
Wow, you really did type a mouthfull, but let me tell you, I really appreciated it! Thanks for all the help! =)

Problem solved!
In response to Michael3131
You can see where an atom was clicked, including in which statpanel; look up Click()...