ID:165996
 
How would I make a trade code were I can right-click a mob close to me, choose trade and make a alert sent to him/her saying I would like to trade. Then if she/he says yes, I can choose from my inventory an item and trade with him/her?
The right click thing can be achieved by a simple verb.

After which just use the switch(input()) on the mob clicked (which'll be src in the verb).

If s/he says yes, choosing from your inventory depends on what your inventory is. If it's a list, create an input() for usr with its options as things in the list.

Then just give the chosen item to src although I'd add a confirmation.
In response to DeathAwaitsU
Alright thanks. I'll see what I can do.

[EDIT]

I've tried to create it and haven't got very far at all. I don't know what to do.

mob/verb/Trade(M as mob)
set src in oview(6)
M<<alert("[src] would like to trade with you. Allow?","Yes","No")
if("Yes")
//I have no ide what to do here.
if("No")
return
In response to DarkD3vil666
What is your inventory?
In response to DeathAwaitsU
You mean src.contents?
In response to DarkD3vil666
Ok dont take my word for anything Im just trying to help, if I were you I'd wait for another person to confirm if this code is ok or if its "ugh" worthy before using it, but maybe this'll work;

mob 
verb
Trade(mob/M in oview(5))
var Request = alert(M,"[src] would like to trade with you, do you accept?","Trade Box","Yes","No")
if(Request == "Yes")
src << "[M] has accepted your trade request."
M << "(waiting for [src] to select item)"
var/itemA = input(src,"Please select the item you'd like to trade") in src.contents
var/itemB = input(M,"Please select the item you'd like to trade") in M.contents
var/agreeA = alert(M,"[src] is offering [itemA] for your [itemB], do you accept?","Trade Confirm","Yes","No")
var/agreeB = alert(src,"[M] is offering [itemB] for your [itemA], do you accept?","Trade Confirm","Yes","No")
if(agreeA == "Yes" && agreeB == "Yes")
M.contents -= itemA
src.contents -= itemB

M.contents += itemB
src.contents += itemA

src << "<b>Trade successfull! You recieved [itemA] for [itemB]!</b>"
M << "<b>Trade successfull! You recieved [itemB] for [itemA]!</b>"
else
src << "<b>[M]</b> declined your trade request."
M << "You declined <b>[src]</b>'s trade request."


I would've tested it with myself but its been so long since I've used BYOND that Im having trouble hosting a test game and joining the game through another client, and none of my old pager friends are too interested in testing it so, if you do test it tell me the results.

Maybe if it checks out ok with the oldbies Ill comment it and put up a demo.

- Conj'
In response to The Conjuror
You may want to add a nothing option as well in the state that a player just wants to give an item to someone...

Also, to add an item to one's inventory would you not have to create a new instance of it?

Like
var/obj/O = new itemA()
src.contents += O


Maybe not, I haven't been on byond in months...
In response to Spire8989
Normally yes but (atleast I think) in this case since the object already exists, you're merely changing it's position. If the code was switched to deleting the object from the person's contents then I think yeah you'd have to make the object with new.
In response to The Conjuror
You simply made a variable containing the response and thus name and address of the item selected. I still think a new would be needed however I can't really test it either so if someone can, it would be much appreciated...

Or possibly instead of just var/itemA it be made var/atom/movable/itemA out of pure conciousness.
In response to Spire8989
:P well Im assuming that the object has been created somewhere in the world. If an object is in the user's contents, it must have been created previously, either through buying it from a shop, picking it up from the ground, however it got into the user's contents the fact remains it must have been created for that to work. When I tested the code with myself (not over the internet, just by trading myself) it worked, because the objects were previously created.
In response to The Conjuror
Still kinda wondering if my code snippet works, could someone try testing it over a connection with someone else?
In response to The Conjuror
Your Code works nicely congrats on it :).
~Grand~