ID:147434
 
here is my code
turf
paulie


verb
Sell()
set category="Gun shop"
set src in oview(2)
var/list/A=new()
var/obj/B
for(var/obj/O in usr.contents)
A+=O
A+="Cancel"
B=input(" What do you wish to sell?","Paulie's Gun Shop","Cancel") in A
if(B=="Cancel")
return 0
else
switch(alert(" Are you sure you wish to sell the [B] for [B.sellprice] dollars?","Paulie's Gun Shop","Yes","No"))
if("Yes")
usr.money+=B.sellprice
del(B)
usr<<"Transaction completed!"
usr<<"Thank you, come again!"
return 0
obj/var/sellprice
obj/Magnum
sellprice=50
obj/Sawedoff_Shotgun
sellprice=250
obj/Pump_Shotgun
sellprice=750
obj/Tommy_Gun
sellprice=5000

my question is how do i make it so that you can sell a equiped weapon?
i tryed one ver for all weapons but that made it so i could not sell any weapons at all.
Coolz wrote:
my question is how do i make it so that you can sell a equiped weapon?

obj
var
equipped

mob/verb/equip()
var/obj/item = input("Which item do you want to equip?","Equip") in usr.contents
if(item.equipped)
return
item.equipped = 1

mob
sellguy
icon='sss.dmi'
Click()
var/obj/c=input("What would you like to sell?")in usr.contents
if(!c.equipped)
usr<<"Sale Guy:The item has to be equipped."
else
usr.contents-=c
usr.money+=10//whatever amount here
usr<<"Sale Guy:Sold"


Untested though.
In response to SSJ4_Gohan_Majin
SSJ4_Gohan_Majin wrote:
Coolz wrote:
my question is how do i make it so that you can sell a equiped weapon?

> obj
> var
> equipped
>
> mob/verb/equip()
> var/obj/item = input("Which item do you want to equip?","Equip") in usr.contents
> if(item.equipped)
> return
> item.equipped = 1
>
> mob
> sellguy
> icon='sss.dmi'
> Click()
> var/obj/c=input("What would you like to sell?")in usr.contents
> if(<b><u>!c(</b></u>)
> usr<<"Sale Guy:The item has to be equipped."
> else
> usr.contents-=c
> usr.money+=10//whatever amount here
> usr<<"Sale Guy:Sold"
>
>

Untested though.


Don't you mean "c.equipped" instead of "!c". And then another "else if(!c) return"

~Ease~
In response to Ease
Ease wrote:
SSJ4_Gohan_Majin wrote:
Coolz wrote:
my question is how do i make it so that you can sell a equiped weapon?

> > obj
> > var
> > equipped
> >
> > mob/verb/equip()
> > var/obj/item = input("Which item do you want to equip?","Equip") in usr.contents
> > if(item.equipped)
> > return
> > item.equipped = 1
> >
> > mob
> > sellguy
> > icon='sss.dmi'
> > Click()
> > var/obj/c=input("What would you like to sell?")in usr.contents
> > if([b][u]!c([/b][/u])
> > usr<<"Sale Guy:The item has to be equipped."
> > else
> > usr.contents-=c
> > usr.money+=10//whatever amount here
> > usr<<"Sale Guy:Sold"
> >
> >

Untested though.


Don't you mean "c.equipped" instead of "!c". And then another "else if(!c) return"

Oh, sorry! Thanks for pointing that out!
~Ease~
In response to SSJ4_Gohan_Majin
Oh, my! I just realised how offensive my last reply sounded! Sorry about that, I was just trying to be factual. Sorry!

~Ease~
In response to Ease
nevermind i got it
In response to SSJ4_Gohan_Majin
Stop providin bad advice.
In response to Garthor
Garthor wrote:
Stop providin bad advice.

Maybe you can stop providing commentary without constructive feedback or corrections to the problem in the first place? People learn a lot better when you can back up your babble with something useful.
In response to SSJ4_Gohan_Majin
SSJ4_Gohan_Majin wrote:
obj
var
equipped


No no no NO. That is the wrong way to do an equipment system. This is the right way:
mob
var/obj/item/weapon/weapon
var/obj/item/armor/armor
...
I've said it a million times, but just to review, the reasons there should not be an obj.equipped var are many.

  • The mob has no way of knowing, without looping through each item in its contents, which item is equipped. A simple Equip() verb has to perform this loop, for no good reason, just to make sure nothing else is already in use.
  • In the event of a bug, such as one that duplicates an item in your inventory (not uncommon as bugs go) or changes its loc without resetting the equip var first, the item will think it's equipped when it's really not.

    The correct system uses a var belonging to the mob holding the item. The var is null by default, meaning no item is equipped for that slot, or else it points to the item equipped. The item doesn't need an equipped var, and shouldn't have one, because all it needs to do is 1) check if its loc is a mob, and 2) check the mob's equipment var to see if it matches the item. Most of the time it's much more useful to know which item is equipped than to know about a particular one; and the latter you can learn without a loop. In the case of a sell verb, usr is that mob, which simplifies things.
if(item == usr.weapon) item.Unequip()
else if(item == usr.armor) item.Unequip()
...

Lummox JR
In response to digitalmouse
digitalmouse wrote:
Garthor wrote:
Stop providin bad advice.

Maybe you can stop providing commentary without constructive feedback or corrections to the problem in the first place? People learn a lot better when you can back up your babble with something useful.

That seems like a great amount of effort to cover up someone else's mistake of not using the search button.