ID:269749
 
I have created my own sell verb. Here it is:

mob/ShopKeepers/verb/Sell()
set category = "ShopKeeper"
set src = oview(1)
pay = 0
maxamount = 0
amountto = 0
var/ite = input("Select the item you wish to sell","Select") in usr.contents
var/it = ite:type
for(var/obj/O as obj in view(-1))
if(istype(O,it))
maxamount += 1
var/amount = input("How many [it] do you want(Max is [maxamount])") as num
if(amount > maxamount)
usr << "You dont have that many"
return
for(var/obj/P as obj in view(-1))
if(istype(P,it))
if(amountto >= amount)
usr.gold += pay
return
else
pay += P.cost
del(P)
amountto += 1
else
if(amountto >= amount)
usr.gold += pay
return
mob/ShopKeepers
var
pay = 0
maxamount = 0
amountto = 0

Ok now it always deletes the items though if I want to sell all of the same object it deletes them all and doesnt give me any gold. Could someone please help me!

(Please I know Ive put a : in there but please dont mention it as it gets annoying after a while)
For your : problem, you have to define the variable as an obj.

    var/obj/ite = input("Select the item you wish to sell","Select") in usr.contents
var/it = ite.type


~~> Dragon Lord
mob/ShopKeepers/verb/Sell()
set category = "ShopKeeper"
set src in oview(1)
var/pay = 0
var/maxamount = 0
var/amountto = 0
var/obj/ite = input(usr,"Select the item you wish to sell","Select") in usr
for(var/obj/O in view(1)) if(istype(O,ite.type)) maxamount ++
var/amount
while(!amount)
amount=input("How many [it] do you want to sell? Max is [maxamount])")as num
if(amount>maxamount) {usr<<"You don't have that many.";amount=null}
if(amount<0) {usr<<"You cannot sellnegative numbers of items.";amount=null}
if(amount==0) return //Obviously doesn't want to sell anything.
for(var/i=1,i<=amount,i++)
var/obj/O=locate(ite.type) in view(1)
pay += O.cost
del(O)
usr.gold+=pay
return


Something like that should work, but I don't get why you are using view() in there. Are you trying to sell bjects of the same type around the floor?

As for those variables that belong to the shopkeeper, don't do it, because more than two people may be using that shopkeeper at the same time, everything will get all mixed up.
In response to CaptFalcon33035
Ok it almost works. I had to add something to make it work so ill post my improved version for anyone else who wants to use it.

mob/ShopKeepers/verb/Sell()
set category = "ShopKeeper"
set src in oview(1)
var/pay = 0
var/maxamount = 0
var/obj/ite = input(usr,"Select the item you wish to sell","Select") in usr
var/obj/it = ite.type
for(var/obj/O in view(1)) if(istype(O,it)) maxamount ++
var/amount
while(!amount)
amount=input("How many [it] do you want to sell? Max is [maxamount])")as num
if(amount>maxamount) {usr<<"You don't have that many.";amount=null}
if(amount<0) {usr<<"You cannot sell negative numbers of items.";amount=null}
if(amount==0) return //Obviously doesn't want to sell anything.
for(var/i=1,i<=amount,i++)
var/obj/O=locate(it) in view(1)
pay += O.cost
del(O)
usr.gold+=pay
return

If I dont define another varible that stores the type of the object you want to sell later on in the code it will get deleted and come up with the error <font color=red>cannot read null.cost</font>

<font color=red><font size=5>ADT_CLONE</font></font>