ID:164357
 
ok, i need to make a door, that makes its own 7 diget ID, now heres the thing i want the door to know if another door in the whole world has the same ID if so it will randomate another and check again, anyways once it finds a ID that it will share with no other door, i want it to create a Key (door key) that will have the same ID as the door, thus being able to lock/unlock it, now every doors ID will be 0 and once the world starts any door with that 0 as its ID it will start its ID making.

The door will also carry the var Owner and if it does not have a Owner it will carry a verb, if the door is to a house it will say "Buy_House" to a shop it will be "Buy_Shop" to a mansion it will be "Buy_Mansion" and when someone clicks that i want it to check their gold and if its enough they get the Deed to the house and the doors Key.

Any Questions?
My question is... what is your question?
Shouldn't this go under Creations. I don't see a problem or a question here.
In response to Mikau
I was asking how would i go about doing it..
In response to VolksBlade
The only question you asked, was if we had any questions.
In response to Mikau
well i thought maybe you would see that this is the Dev-How-To and know that it was questions i was saying
In response to VolksBlade
ok, i need know how to make a door, that makes its own 7 diget ID, now heres the thing i want the door to know if another door in the whole world has the same ID if so it will randomate another and check again, anyways once it finds a ID that it will share with no other door, i want it to create a Key (door key) that will have the same ID as the door, thus being able to lock/unlock it, now every doors ID will be 0 and once the world starts any door with that 0 as its ID it will start its ID making.

The door will also carry the var Owner and if it does not have a Owner it will carry a verb, if the door is to a house it will say "Buy_House" to a shop it will be "Buy_Shop" to a mansion it will be "Buy_Mansion" and when someone clicks that i want it to check their gold and if its enough they get the Deed to the house and the doors Key.

HOW would i go about doing that?

that is my re-made version
In response to VolksBlade
First, you'd scrap the whole "7-digit ID" crap. That's pointless. Give each door a unique tag (that's a built-in variable) starting at "Door_0" and going up to whatever. Then, give the keys a variable, which will be the same as the door that they'll unlock.

So, you'll need a global counter for the number of doors (this will need to be saved, by the way). In the New() proc for the door, if(!tag) (tag will be null by default), then tag = "Door_[doornum]". Then, increment global number of doors by 1.

In turf/door/Enter(mob/M), loop through the keys in M's contents. If a key whose unlock variable (or whatever you call it) is equal to src.tag, then return 1 (or return ..(), if you wish to obey normal rules of entering turfs). Outside the for() loop, we can assume no keys were found (otherwise, the proc would've already returned), and we can give M an error message and return 0.

As for buying doors (because we're not really buying a house, just the key to it), it's trivial. We can define a proc like this:

turf/door/proc/Buy()
set src in oview(usr,1)
if(usr can buy this door)
var/obj/item/Key/Master/K = new() //create a new master key
K.unlock = src.tag //set the master key to unlock this door
Move(K, usr) //give the master key to usr
bought = 1 //set this door as bought
verbs -= /turf/door/proc/Buy() //remove the ability to buy this door


Then, in turf/door/New(), you'll want to do verbs += /turf/door/proc/Buy(), provided it hasn't been bought yet. Notice that the Key in this instance is of type /obj/item/Key/Master. The Master subtype should work the same as a normal key, EXCEPT you'll be able to create copies, and if you fiddle around a bit, delete those copies as well. I'll show you how in a minute.

One benefit of using tags instead of another variable is that you can use locate() to immediately find an object that has been tagged. So, for example, we can easily make a key teleport us to the door it unlocks:

obj/item/Key/verb/teleport()
set src in usr
var/turf/door/D = locate(unlock) //find the key this door unlocks
if(D) usr.Move(D) //if it exists (and it should), move us to it


Now, for Master keys. Creating a copy is simple:

obj/item/Key/Master/verb/copy()
set src in usr
var/obj/item/Key/K = new(usr) //create a new Key in usr
K.unlock = src.unlock //set it to unlock the same door


Deleting copies is fairly difficult, however. Hopefully you'll put some effort into understanding this, because the line of reasoning behind it isn't exactly clear and mainly comes from experience. We'll also need to change copy() a bit from what I showed above (the indentation will also be different, because I'm opening up DM to write this one).

var/list/KeysToDelete = list()  //list of keys that should be deleted when they are created again

obj/item
Key
var/unlock
New()
if(tag in KeysToDelete) //if we were scheduled for deletion while offline
KeysToDelete -= tag //remove this key from the keys to be deleted
del(src) //delete us now
else ..()
Master
var/numCopies = 0
var/list/deletedCopies = list() //list of key copies we've already deleted
proc
num2copyTag(var/N) //turns a number into the tag of that # key copy
return "[unlock]_copy[N]"
verb
copy() //create a non-Master copy of this key
set src in usr
var/obj/item/Key/K = new(usr) //give usr a new key
K.unlock = src.unlock //set it to unlock the same door as src
K.tag = num2copyTag(numCopies) //set its tag to something we can use to find it again
numCopies++ //increment numCopies
view_copies() //list the copies of this key we've made and who has them (if they're online)
for(var/v = 0, v < numCopies, v++)
if(v in deletedCopies)
continue //skip keys we've deleted
usr << "Key #[v]\t\..." //tell us which key # this is
var/keyTag = num2copyTag(v) //get the tag of the vth key we've created
var/obj/item/Key/K = locate(keyTag) //find it
if(K) //if we've found it
if(ismob(K.loc)) //if a mob is holding it
usr << "posessed by [K.loc]" //tell us who's holding it
else //if it's somewhere else
usr << "lying around in [K.loc]" //tell us where it is
else
usr << "offline" //if we can't find it, then it's offline
delete_copy() //delete a previously created copy of this key
set src in usr
view_copies() //call the view_copies() verb, so we know which is which
var/N = input(usr,"Delete which copy?","Delete Copy") as num|null //get which one to delete
if(!N) return //if they cancelled, don't do anything
if(N in deletedCopies) //if we've already deleted this one
usr << "That key has already been deleted." //tell us so
return //then don't do anything
if(N >= numCopies) //if it's greater than our number of copies
usr << "You have not created that many copies"
return
if(N < 0) //if it's negative
usr << "Nonnegative numbers only"
return
var/keyTag = num2copyTag(N) //get the tag of the copy
var/obj/item/Key/K = locate(keyTag) //find the key
if(K) //if the key was found (and is thus online)
del(K) //delete it
//and tell the person holding it why their key suddenly disappeared:
K.loc << "Your key was deleted by the owner of the master key."
usr << "Key deleted successfully"
else //if the key wasn't found (and is thus offline)
KeysToDelete += keyTag //add it to the keys to be deleted
usr << "Key will be deleted when it next logs in"
deletedCopies += N //add this key to the list of deleted keys


That's not quite perfect, of course, but it should work. If you have any questions, feel free to ask.

And if the question is "can you write that code for me?" the answer is no. I wrote that last big chunk because it was too complicated to describe (to a newbie, at least). The rest is stuff you should be able to figure out from my descriptions.