Omg, i feel like an idiot. Help me with this, i forgot the basics ahh
Anyways i need help with an npc that checks if the person has 2 obj/MiningStuff/ore/copper in his inventory.
Then makes a new/obj/weapon/thing in his inventory and deletes the 2 ores. (obj/MiningStuff/ore/copper)
I am so sad, i have to post in newbie central ahh i feel sad, i forgot the basics =( Any help well appreciated lol
RaeKwon
ID:177725
![]() Aug 4 2002, 6:51 pm
|
|
for(var/obj/pieceofcrap/crap in src) del(crap) new /obj/dirtytoiletpaper(src) Is that what you mean? |
mob Are you mentioning this code? Because I tested it out and it works fine... |
That code would delete two ores. The while() creates a loop till the value of ores is equal to two. After adding one ore to the number it deletes the ore as well.
|
Thief jack wrote:
mob Are you mentioning this code? Because I tested it out and it works fine... And this deleted 2 ores from your inventory? RaeKwon |
Darkness wrote:
That code would delete two ores. The while() creates a loop till the value of ores is equal to two. After adding one ore to the number it deletes the ore as well. o.0 okay, Thanks. RaeKwon |
Sariat wrote:
Thanks would be not stealing splash screens and graphics from him. What exactly is that suppose to mean RaeKwon |
Thief jack wrote:
mob/verb/Melt() Two problems with this: You're deleting the ores even if there's only one in the inventory, and no matter what, the /obj/weapon/thing is always created even if there are no ores. mob/verb/Melt() Lummox JR |
Yeah. Also, supposedly, if you didn't have 2 ores it'd catch in an infinite loop, thanks to the while(). Two for() loops is somewhat bad form though, but oh well.
|
Garthor wrote:
Yeah. Also, supposedly, if you didn't have 2 ores it'd catch in an infinite loop, thanks to the while(). Two for() loops is somewhat bad form though, but oh well. Sheesh, I didn't even catch that. Good call. You're right; the double loop would really have caused a big problem. Lummox JR |
I was going to post my own method of doing this, but it got a little messy, and I was tired and gave up.
|
Sariat wrote:
for(var/obj/pieceofcrap/crap in src) He only wants it to delete 2 of the object, not all of them. var/a = 1 |
How about,
var/num = 0 for(var/obj/ore/O in usr) num ++ if(num >= 2) usr.contents.Remove(/obj/ore,/obj/ore) return 1 else usr << "You have [num] ores. You need [2-num] more." return 0 |
set category = "Commands"
var/Ores = 0
while(Ores < 2)
for(var/obj/MiningStuff/ore/copper/A in src)
Ores += 1
del(A)
new /obj/weapon/thing(src)
Thiefy