ID:177725
 
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
mob/verb/Melt()
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

for(var/obj/pieceofcrap/crap in src)
del(crap)
new /obj/dirtytoiletpaper(src)


Is that what you mean?
In response to Thief Jack
I know how to do what you 2 did, But, i need it so it deletes 2 ores, not just 1.

RaeKwon
In response to RaeKwon
mob
verb/Melt()
set category = "Commands"
var/tmp/Ores = 0
while(Ores < 2)
for(var/obj/MiningStuff/ore/copper/A in src)
Ores += 1
del(A)
break
new /obj/weapon/thing(src)


Are you mentioning this code? Because I tested it out and it works fine...
In response to RaeKwon
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.
In response to Thief Jack
Thief jack wrote:
mob
> verb/Melt()
> set category = "Commands"
> var/tmp/Ores = 0
> while(Ores < 2)
> for(var/obj/MiningStuff/ore/copper/A in src)
> Ores += 1
> del(A)
> break
> new /obj/weapon/thing(src)

Are you mentioning this code? Because I tested it out and it works fine...

And this deleted 2 ores from your inventory?

RaeKwon
In response to Darkness
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
In response to RaeKwon
Wait was I right or a bit off the track, or fully wrong?
In response to RaeKwon
Thanks would be not stealing splash screens and graphics from him.

In response to Sariat
Sariat wrote:
Thanks would be not stealing splash screens and graphics from him.


What exactly is that suppose to mean

RaeKwon
In response to RaeKwon
Having problems understanding that? Click here.
In response to RaeKwon
I dunno, take a look at your game(s) and you tell me.
In response to Thief Jack
Thief jack wrote:
mob/verb/Melt()
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)

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()
set src=usr
var/obj/MiningStuff/ore/copper/A
var/Ores = 0
for(A in usr) ++Ores // just count; don't delete
if(Ores<2)
usr << "You need 2 units of copper ore to make a weapon."
return
Ores=0
for(A in usr)
++Ores
del(A)
if(Ores>=2) break
new /obj/weapon/thing(usr)

Lummox JR
In response to 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.
In response to Garthor
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
In response to 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.
In response to Sariat
Sariat wrote:
for(var/obj/pieceofcrap/crap in src)
del(crap)
new /obj/dirtytoiletpaper(src)


Is that what you mean?

He only wants it to delete 2 of the object, not all of them.

var/a = 1
for(var/obj/whatever/C in src)
del(C)
a++
if(a == 2)
new /obj/super_item(src)
In response to Malver
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
In response to RaeKwon
Here's another approach

var/num = 0
for(var/obj/ore/O in usr)
num ++
if(num >= 2)
var/A = 0
do
usr.contents.Remove(/obj/ore)
A ++
while(A < 2)
else return
Page: 1 2