ID:170871
 
Is there a way to do this? Where a player can own something in the sense that no-one else can pick it up unless some kind of permission is given to them?
I'm not asking for code (though any would be appreciated :D) but just for a push in the right direction.
obj
var/list/speshul = list() //Note, I spelt special wrong!
asdf
Click()
if(src.speshul.Find(usr.key))
usr << "You're speshul!"

Try that

[edit]Fixed the problems that Lummox pointed out.
In response to Hell Ramen
Hell Ramen wrote:
var/list/speshul = list()//Note, I spelt special wrong!
obj
asdf
Click()
if(speshul.Find(usr.key)
usr << "You're speshul!"

Try that

Your code doesn't even begin to help answer the question at hand. The question was how to own an individual item and control access to it, not how to check on some generic special status unrelated to any item at all.

You're also missing a closing parenthesis. And you absolutely must put some spaces before the // so the comment stands out from the rest of the line. (It's not that it doesn't compile without space between, but that it's just totally wrong to jam them up against each other like that. Comments done that way are nigh unreadable.)

Lummox JR
In response to Lummox JR
thx for the suggestion, but this still (as Lummox said) answer my question. I need to make it where players can have exclusive rights to an item, or turf if that makes it any easier. Would it be a good idea to just make a verb that claims items/turf?
In response to Pakbaum
You'd have to record the owning player's name in a variable. Only the player with that name gets to pick up that item. As an alternative, rather than a name, you could record a unique identification number for each user.

I've actually done this in a project I'm working on... Just where the owner of an item can lock it down inside of their home, but if someone else tried to lock something down in someone else's home, it won't work. This is a bit more complex. I had to create an area (Since you wouldn't want to record the owner of every single turf.) and then record the name of the owner of that area, then when you tried to lock down the piece of furniture, it would check if you were the proper user.

The point is, it is possible, and there are MANY ways to do this. I wish you luck.
In response to Lummox JR
Lummox JR wrote:
Your code doesn't even begin to help answer the question at hand. The question was how to own an individual item and control access to it, not how to check on some generic special status unrelated to any item at all.
Lummox JR

If someone is within the owner list(special list), they could do special stuff with that item.
In response to Hell Ramen
Try:

obj
var
OwnerName = null //You can set this later on..

obj
Sword
verb
Get()
set src in view(1) //The src is within about 1 tile from the mob
if(!src.OwnerName)
src.OwnerName = usr.name
src.loc = usr.loc //This
//seemed..right.
return //Yeah..
else
usr << "This is not your item."
src.loc = usr.loc

That sets the owner name when it's picked up, and then we can add..

obj
Sword
verb
Use()
//Put anything needed here first.
if(src.OwnerName = usr.name)
//Go about your attack stuff
else
return //^_^



So they can't attack unless they OWN that item. That Should be what you want, but I am not sure. There shouldn't really be much wrong with it either, I mean, some of the code may be innaccurate for the Use() verb, don't know..

[EDIT]
GAH! Tried to push CTRL+K again.
In response to Lenox
Wouldn't a list be better?
In response to Hell Ramen
If the creator wants to allow for multiple players, then a list WOULD be better, but as of right now, he's never said anything about multiple owners. OOOO, I just thought of something wrong in my code, the Item's owner would be overriden, even if the owner already exists. Let me go fix that.
In response to Hell Ramen
Hell Ramen wrote:
Lummox JR wrote:
Your code doesn't even begin to help answer the question at hand. The question was how to own an individual item and control access to it, not how to check on some generic special status unrelated to any item at all.

If someone is within the owner list(special list), they could do special stuff with that item.

That's true, if your list was specific to that item; it isn't. You made a global list, which does nothing for item ownership. That sort of thing is good however for listing players in a game, admins and GMs, etc. If you had a GM-only weapon used for bug testing, a global list would be great for that.

But property being what it is, joint ownership is actually a rare thing. In most games a simple owner name/key var per object would do. (Note: Such a var shouldn't be set to the owner's mob itself, or a list thereof. Among other reasons, saving the item with such a var would cause a copy of the owner's mob to save, which can cause a "rollback" bug when a character holding somebody else's item loads up again.)

If the game requires the flexibility of a list, you can always have it both ways. An owner var can be a single value like a key, or it could be a list of keys. Just check the var's type against /list with istype() to determine that the item has multiple ownership.

Lummox JR
In response to Ter13
this might not be a good thing to ask, but could someone please explain with like maybe a small piece of coding? you dont have to do everything, just to get your ideas of what might work across
In response to Pakbaum
This method just records the owner of the item. The owner is the first person to pick it up. If it is dropped intentionally by the owner, it is no longer owned by them. If the player gives it willingly to another player, it is the other player's item.

obj
item
var/owner = null
verb
get()
set src in oview(1)
if(src.owner==null)
src.owner = usr.ckey
usr.contents += src
drop()
set src in usr.contents
if(src.owner==usr.ckey)
src.owner = null
src.loc = usr.loc
mob
verb
give()
set src in oview(1)
var/list/items = list()
for(var/obj/item/item in usr.contents)
items += item
if(items.len)
var/obj/item/item = input(usr,"What will you give to [src]?","Give?") as null|anything in items
if(item)
if(item.owner==usr.ckey)
item.owner = src.ckey
if(locate(src) in oview(1,usr))
src.contents += item
src << "[usr] gives you [item]!"


If you want to make it so that the player cannot use the item at all if they aren't the owner:

//implement the above code as well.
obj
item
special
get()
set src in oview(1)
if(src.owner==usr.ckey)
..()
else
usr << "You can't use this item! It isn't yours!"
drop()
set src in usr.contents
src.loc = usr.loc


And to make it so that the item cannot be given is a bit harder, you'd actually have to go and create an exception, but this should be what you were looking for if I didn't go off track and completely de-rail... haven't slept since about a day and a half ago.
In response to Ter13
thx again ter, and one more question on all of this owning and stuff. What about "owning" turf? is there a way to do this?
In response to Pakbaum
I very much prefer to do this with areas.

Let's say you own an orchard. Only you can plant things in this orchard, rather than waste all the memory on multiple text strings pointing to your player's ckey, we can just make a small, nice pointer to an area.

area
claimed
claimable
mob
var
area/owned
verb
claim(var/turf/T in oview(1,src))
var/area/a = T.loc
if(istype(a,/area/claimable))
if(src.owned==null)
src.owned = new/area/claimed(null)
src.owned.owner_ckey = src
a.contents += T
turf
orchard
verb
pick_fruit()
set src in oview(0)
if(istype(src.loc,/area/claimed))
var/area/claimed/a = src.loc
if(a==usr.area)
usr << "You pick some fruit!"
else
usr << "This isn't your orchard!"
else
usr << "You pick some fruit form an unowned orchard!"


Of course, this is a useless example, and kind of a boring one... But you can understand the concept.