1
2
ID:149815
Feb 14 2002, 3:48 am
|
|
What is the code to transfer an obj from one mob's (NPC) to another mob's (PC) contents list?
|
In response to Rcet
|
|
Looking good. I'm going to be changing over to a system where the Shop keepers hold everything in their contents list. If they don't have it, they don't make a new one out of air. It has be made and sold to them. The only thing that will be created new will be resources.
Thanks LJR |
In response to LordJR
|
|
in that case, do something like this:
mob hope i helped -Rcet |
In response to Rcet
|
|
In response to Super16
|
|
Well also I'm going to use this for my Rent a room code. Will your code pop up a dialog box of everything the mob/npc is carrying??? If so then if the Inn Keeper has a key in his inventory then u can rent that room. If someone else already has the key then no room. This will really simplify my code alot for checking if the key is out or not. Also I've got code to get the key back if they leave the Inn area, or log out of the game.
LJR |
In response to LordJR
|
|
Since I'm bored.
mob/InnKeeper |
In response to Nadrew
|
|
Wow coolio dude.. domoarigato!!
LJR |
In response to Nadrew
|
|
Nadrew wrote:
Since I'm bored. > mob/InnKeeper This did not work :P |
In response to LordJR
|
|
Well I get a list here.. but when I select an item, it doesn't give me the key or take gold or do anything.
LJR verb/Rent_a_room() set src in oview(2) if(!istype(usr,/mob/pc)) return else var/mob/pc/M = usr var/obj/itemlist = input ("Pick a room key to rent, 1-2(5gp) 3-4(10gp).") in src.contents for(var/obj/innkeys/O in src) if(O == itemlist && M:gold > 4) M:gold -= 5 O.Move(usr) if(itemlist == "Tanis Inn Key Room-2" && M:gold > 4) M:gold -= 5 itemlist.Move(usr) if(itemlist == "Tanis Inn Key Room-3" && M:gold > 9) M:gold -= 10 itemlist.Move(usr) if(itemlist == "Tanis Inn Key Room-4" && M:gold > 9) M:gold -= 10 itemlist.Move(usr) if(itemlist == "Nevermind") return |
In response to LordJR
|
|
LordJR wrote:
Well I get a list here.. but when I select an item, it doesn't give me the key or take gold or do anything. You're comparing itemlist to a string, when you should be using itemlist.name for that. Your code is correctly determining that the object you select doesn't equal a text string, and since it's not told to do anything in that case, it doesn't. My BYONDscape article on associative lists has some shopkeeper code that I think you can modify nicely to fit your innkeeper. It should allow you to present a better interface; for example the room price could be included with the items in the input() list instead of in the prompt text. Lummox JR |
In response to Nadrew
|
|
This also helped me, so thanks, it works great.
|
In response to Lummox JR
|
|
yeah but in order to see that article I will have to subscribe to byondscape. do you know how much of a hassle it is for me to put dimes in my account? can't you just tell me? all I really want to know is how to get the fricking shovel out of the shed? please.
|
In response to Canar
|
|
Canar wrote:
yeah but in order to see that article I will have to subscribe to byondscape. do you know how much of a hassle it is for me to put dimes in my account? can't you just tell me? all I really want to know is how to get the fricking shovel out of the shed? please. Actually my associative lists article is non-subscription content. Anyone can access it. Lummox JR |
In response to Lummox JR
|
|
oh...ok. thanks a bunch. I've been messing around with bits of code trying to get it where you can take a shovel out of a shed and put it back. It's a little more difficult than i thought it would be. I keep getting the same runtime error with everything i try...
cannot append to that list or something like that. I hope i can find that article. |
In response to LordJR
|
|
Ok a few people have offered various ways to code this, but I still can't get anything to work. Can someone look at the following code and see a flaw or what I can do to make it work? Here are the conditions the code must meet:
1) There is only 1 obj/key at a time in the world. 2) If you have enough gold, then the inn keeper transfers the key from his contents-list, to your contents-list. LJR ps. Upon re-reading the List section of the Blue Book which is obviously what I'm dealing with. I think M.contents-= contents[O] will work for me? EDIT: I've updated my code to reflect the following. Will this work? var/mob/pc/M = usr var/obj/itemlist = input ("Pick a room key to rent, 1-2(5gp) 3-4(10gp).") in src.contents for(var/obj/innkeys/O in src) if(itemlist == "Tanis Inn Key Room-1" && M:gold > 4) M.gold -= 5 M.contents += src.contents[O] if(itemlist == "Tanis Inn Key Room-2" && M:gold > 4) M.gold -= 5 M.contents += src.contents[O] if(itemlist == "Tanis Inn Key Room-3" && M:gold > 9) M.gold -= 10 M.contents += src.contents[O] if(itemlist == "Tanis Inn Key Room-4" && M:gold > 9) M.gold -= 10 M.contents += src.contents[O] if(itemlist == "Nevermind") return |
In response to LordJR
|
|
Because you're looping for(O in src), O is already in src.contents (since src is an atom, not a list, BYOND understands you mean src.contents), so you could just say +=O. src.contents[O] is asking for an associated item, since O is not a numerical index but a unique object key. I'm not sure if the contents list supports association or not, but I'm quite sure this isn't what you intended anyway.
Lummox JR |
In response to Lummox JR
|
|
Any ideals on this?? I really need to get this code to work because bigger things to come depend upon it working. The code I posted does this when I test it.
1) The Rent verb works ok. 2) I get a list of all the keys by their name also the Cancel object I created works fine. 3) When I select a key from the list, it closes out, no gold is taken, no message of getting a key, and no key is given to my inventory. 4) Upon check the innkeeper the key I just tried to get is still showing by name in his inventory. Just need to move that key from his contents to my contents. I could just do a delete and new item, but to keep from having a chance of introducing a bug I want to keep only 1 instance of the item in the world. LJR |
In response to LordJR
|
|
LordJR wrote:
Any ideals on this?? I really need to get this code to work because bigger things to come depend upon it working. The code I posted does this when I test it. The reason nothing is happening is that you're assigning the result of input() to var/obj/itemlist, and then you're comparing itemlist to a string: if(itemlist == " ... ") What you need to be comparing is itemlist.name or something else with a string as a value. Also, contents[O] still won't work, because O is not a numerical index into the list; it's an object already in the list. contents[O] means "the value associated with O in src.contents". I don't know if atom.contents even supports list association, but at any rate that's not what you want; you would just want to use O. Even if that were to subtract O from M.contents, that wouldn't help anyway; it's not in M's contents list. To transfer the key to the player's inventory, use: O.loc=M The contents lists are updated automatically when loc changes. 4) Upon check the innkeeper the key I just tried to get is still showing by name in his inventory. This makes sense; since all of the if() tests are failing, the key is never rented. However, even if the if() checks were correct, the key wouldn't move anyway because the existing code doesn't do that. Lummox JR |
1
2
there ya go :]
hope i helped
-Rcet