ID:157768
 
How can I make it to where if someone picks up an obj, shortly later another one will spawn where the old one was?
//global proc:
proc
replace_object(var/atom/location, var/type, var/time)
spawn(time)
new type(location)


Call this with the appropriate arguments (where the object was, its type, and how long to wait before creating a new one) when you pick up the object.

It's important that this is a global proc, separate from the object being picked up. Otherwise the object being deleted before replacement would prevent it from being replaced.
In response to Garthor
I was working on an example and I ended up converting it to use Garthors suggestion because it reduced my own code by a couple of lines. :)

ObjectSpawnExample

ts
In response to Tsfreaks
Thanks so much. I think that should work, but of course I'll have to go try it. Looking at that resource also should be good, so I can know how to adjust it to my needs.

I am new to DM... ok I'm not but never really did much with it. I am working on my currently biggest project.

Before this I had tried many things. First of all i thought the World Repop was the problem, but then I realized that until it was deleted completetly without anyone having it, it wouldnt respawn. So what i did was change the Get verb to the individual objects and had them make a copy of themselves to your inventory and delete the old one, so the Repop would create it again. But it caused them to not be able to be equipped (which i still dunno why). Now I got to remember to put it back the way it was so I can try this. Thanks for the help.

I will get back to you if this doesn't work for some reason.
In response to KSDT
Thanx!It works fine! Just a small delay with it being added to your inventory but thats no problem.
In response to Tsfreaks
Make a hub for those things, it's a pain to download, save as, extract, and then run D:
In response to Ruben7
lol... sorry to put you through so much work.
In response to Tsfreaks
Uh oh didn't work! (Im same guy different acc)

Its not letting me equip the stuff still!
In response to Garthor
obj
items //Define a subtype so we can organize our items better than having to loop through looking for special properties
verb
Drop()
set src in usr.contents
set category=null
if(src.Move(usr.loc))
usr<<"<font color=white><b>You dropped [src.name]!</b>"
Get()
set src in oview(1,usr)
set category=null
if(src.Move(usr))
usr<<"<font color=white><b>You picked up [src.name]!</b>"
Proc_SpawnObject(loc, src.type, spawnTime)
del(src)
var
{
spawnTime;
}
proc
Use() //Here I'm defining a proc that's inherited by all obj/items, the parent proc is blank, so we can over ride it for other objects
DblClick()
if((src in usr.inventory))
src.Use()
weapons //another subtype to designate between regular items and clothing that can be equipped
Use() //This is where we over ride the main Use() proc that we defined earlier to suit the special needs of clothes
var/mob/User=src.loc //If this piece of clothing is in a mobs inventory, the loc of it should equal its carrier
if(User) //Make sure it's not null
if(ismob(User)) //Just a safety check to make sure it is infact a mob
if((src in User.equipped)) //If it's equipped, unequip it and remove the overlay
src.suffix=""
User<<"<font color=white><b>You remove the [src.name].</b>"
User.equipped.Remove(src,null)
else //If it's not equipped, equip it and add the overlays
src.suffix="<Equipped>"
User<<"<font color=white><b>You equip the [src.name].</b>"
User.equipped.Add(src)
weapon //This is an example of how you'd want to do different stuff for different types of clothes
var
attack=1
spirit=1
defense=1
spidefense=1
LongSword
icon='weapontest.dmi'
attack=30
spirit=10
Use() //We're over riding our Use() proc again, except this time we're using the same properties from the last time we redefined, except we'll be adding armor to the player armor defense
..() //call the parent proc so it adds the overlays and such
var/mob/User=src.loc
if(User)
if(ismob(User))
if((src in User.equipped))
User.str+=src.attack
User.spi+=src.spirit
else
User.str-=src.attack
User.spi-=src.spirit
New()
{
spawnTime = rand(50,100)
}
WoodenStaff
icon='weapontest.dmi'
icon_state="staff"
attack=15
spirit=30
Use() //We're over riding our Use() proc again, except this time we're using the same properties from the last time we redefined, except we'll be adding armor to the player armor defense
..() //call the parent proc so it adds the overlays and such
var/mob/User=src.loc
if(User)
if(ismob(User))
if((src in User.equipped))
User.str+=src.attack
User.spi+=src.spirit
else
User.str-=src.attack
User.spi-=src.spirit
New()
{
spawnTime = rand(50,100)
}
LeatherBreastplate
icon='weapontest.dmi'
icon_state="leatherbreastplate"
spidefense=15
defense=30
Use() //We're over riding our Use() proc again, except this time we're using the same properties from the last time we redefined, except we'll be adding armor to the player armor defense
..() //call the parent proc so it adds the overlays and such
var/mob/User=src.loc
if(User)
if(ismob(User))
if((src in User.equipped))
User.def+=src.defense
User.spidef+=src.spidefense
else
User.def-=src.defense
User.spidef-=src.spidefense
New()
{
spawnTime = rand(50,100)
}
Tunic
icon='weapontest.dmi'
icon_state="Tunic"
spidefense=30
defense=15
Use() //We're over riding our Use() proc again, except this time we're using the same properties from the last time we redefined, except we'll be adding armor to the player armor defense
..() //call the parent proc so it adds the overlays and such
var/mob/User=src.loc
if(User)
if(ismob(User))
if((src in User.equipped))
User.def+=src.defense
User.spidef+=src.spidefense
else
User.def-=src.defense
User.spidef-=src.spidefense
New()
{
spawnTime = rand(50,100)
}
SteelToe
icon='weapontest.dmi'
icon_state="steeltoe"
spidefense=5
defense=10
Use() //We're over riding our Use() proc again, except this time we're using the same properties from the last time we redefined, except we'll be adding armor to the player armor defense
..() //call the parent proc so it adds the overlays and such
var/mob/User=src.loc
if(User)
if(ismob(User))
if((src in User.equipped))
User.def+=src.defense
User.spidef+=src.spidefense
else
User.def-=src.defense
User.spidef-=src.spidefense
New()
{
spawnTime = rand(50,100)
}
LeatherGloves
icon='weapontest.dmi'
icon_state="Leather gloves"
spidefense=5
defense=10
Use() //We're over riding our Use() proc again, except this time we're using the same properties from the last time we redefined, except we'll be adding armor to the player armor defense
..() //call the parent proc so it adds the overlays and such
var/mob/User=src.loc
if(User)
if(ismob(User))
if((src in User.equipped))
User.def+=src.defense
User.spidef+=src.spidefense
else
User.def-=src.defense
User.spidef-=src.spidefense
New()
{
spawnTime = rand(50,100)
}
IronCap
icon='weapontest.dmi'
icon_state="Iron Cap"
spidefense=5
defense=10
Use() //We're over riding our Use() proc again, except this time we're using the same properties from the last time we redefined, except we'll be adding armor to the player armor defense
..() //call the parent proc so it adds the overlays and such
var/mob/User=src.loc
if(User)
if(ismob(User))
if((src in User.equipped))
User.def+=src.defense
User.spidef+=src.spidefense
else
User.def-=src.defense
User.spidef-=src.spidefense
New()
{
spawnTime = rand(50,100)
}
VitalityNecklace
icon='weapontest.dmi'
icon_state="Vitality Necklace"
spidefense=50
defense=0
Use() //We're over riding our Use() proc again, except this time we're using the same properties from the last time we redefined, except we'll be adding armor to the player armor defense
..() //call the parent proc so it adds the overlays and such
var/mob/User=src.loc
if(User)
if(ismob(User))
if((src in User.equipped))
User.def+=src.defense
User.maxhp+=src.spidefense
else
User.def-=src.defense
User.maxhp-=src.spidefense
New()
{
spawnTime = rand(50,100)
}
ClothShoes
icon='weapontest.dmi'
icon_state="Cloth shoes"
spidefense=10
defense=5
Use() //We're over riding our Use() proc again, except this time we're using the same properties from the last time we redefined, except we'll be adding armor to the player armor defense
..() //call the parent proc so it adds the overlays and such
var/mob/User=src.loc
if(User)
if(ismob(User))
if((src in User.equipped))
User.def+=src.defense
User.spidef+=src.spidefense
else
User.def-=src.defense
User.spidef-=src.spidefense
New()
{
spawnTime = rand(50,100)
}
ClothGloves
icon='weapontest.dmi'
icon_state="Cloth gloves"
spidefense=10
defense=5
Use() //We're over riding our Use() proc again, except this time we're using the same properties from the last time we redefined, except we'll be adding armor to the player armor defense
..() //call the parent proc so it adds the overlays and such
var/mob/User=src.loc
if(User)
if(ismob(User))
if((src in User.equipped))
User.def+=src.defense
User.spidef+=src.spidefense
else
User.def-=src.defense
User.spidef-=src.spidefense
New()
{
spawnTime = rand(50,100)
}
Circlet
icon='weapontest.dmi'
icon_state="Circlet"
spidefense=10
defense=5
Use() //We're over riding our Use() proc again, except this time we're using the same properties from the last time we redefined, except we'll be adding armor to the player armor defense
..() //call the parent proc so it adds the overlays and such
var/mob/User=src.loc
if(User)
if(ismob(User))
if((src in User.equipped))
User.def+=src.defense
User.spidef+=src.spidefense
else
User.def-=src.defense
User.spidef-=src.spidefense
New()
{
spawnTime = rand(50,100)
}
Raizan
icon='weapontest.dmi'
icon_state="Raizan"
attack=300
spirit=300
Use() //We're over riding our Use() proc again, except this time we're using the same properties from the last time we redefined, except we'll be adding armor to the player armor defense
..() //call the parent proc so it adds the overlays and such
var/mob/User=src.loc
if(User)
if(ismob(User))
if((src in User.equipped))
User.str+=src.attack
User.spi+=src.spirit
User.verbs += typesof(/mob/Raizan/verb)
else
User.str-=src.attack
User.spi-=src.spirit
User.verbs -= typesof(/mob/Raizan/verb)
New()
{
spawnTime = rand(50,100)
}
Enryuu
icon='weapontest.dmi'
icon_state="Enryuu"
attack=300
spirit=300
Use() //We're over riding our Use() proc again, except this time we're using the same properties from the last time we redefined, except we'll be adding armor to the player armor defense
..() //call the parent proc so it adds the overlays and such
var/mob/User=src.loc
if(User)
if(ismob(User))
if((src in User.equipped))
User.str+=src.attack
User.spi+=src.spirit
User.verbs += typesof(/mob/Enryuu/verb)
else
User.str-=src.attack
User.spi-=src.spirit
User.verbs -= typesof(/mob/Enryuu/verb)
New()
{
spawnTime = rand(50,100)
}
Shippuu
icon='weapontest.dmi'
icon_state="Shippuu"
attack=300
spirit=300
Use() //We're over riding our Use() proc again, except this time we're using the same properties from the last time we redefined, except we'll be adding armor to the player armor defense
..() //call the parent proc so it adds the overlays and such
var/mob/User=src.loc
if(User)
if(ismob(User))
if((src in User.equipped))
User.str+=src.attack
User.spi+=src.spirit
User.verbs += typesof(/mob/Shippuu/verb)
else
User.str-=src.attack
User.spi-=src.spirit
User.verbs -= typesof(/mob/Shippuu/verb)
New()
{
spawnTime = rand(50,100)
}
SoulStealer
icon='weapontest.dmi'
icon_state="Soul Stealer"
attack=600
spirit=300
Use() //We're over riding our Use() proc again, except this time we're using the same properties from the last time we redefined, except we'll be adding armor to the player armor defense
..() //call the parent proc so it adds the overlays and such
var/mob/User=src.loc
if(User)
if(ismob(User))
if((src in User.equipped))
User.str+=src.attack
User.spi+=src.spirit
User.soulsuck=1
else
User.str-=src.attack
User.spi-=src.spirit
User.soulsuck=0
New()
{
spawnTime = rand(50,100)
}
SoulJudgement
icon='weapontest.dmi'
icon_state="Soul's Judgement"
name="Soul's Judgement"
spidefense=400
defense=500
Use() //We're over riding our Use() proc again, except this time we're using the same properties from the last time we redefined, except we'll be adding armor to the player armor defense
..() //call the parent proc so it adds the overlays and such
var/mob/User=src.loc
if(User)
if(ismob(User))
if((src in User.equipped))
User.def+=src.defense
User.spidef+=src.spidefense
User.soulsuck=0
else
User.def-=src.defense
User.spidef-=src.spidefense
New()
{
spawnTime = rand(50,100)
}
EnchantedRing
icon='weapontest.dmi'
icon_state="Enchanted Ring"
spidefense=50
defense=0
Use() //We're over riding our Use() proc again, except this time we're using the same properties from the last time we redefined, except we'll be adding armor to the player armor defense
..() //call the parent proc so it adds the overlays and such
var/mob/User=src.loc
if(User)
if(ismob(User))
if((src in User.equipped))
User.def+=src.defense
User.maxmp+=src.spidefense
else
User.def-=src.defense
User.maxmp-=src.spidefense
New()
{
spawnTime = rand(50,100)
}
BloodfangNecklace
icon='weapontest.dmi'
icon_state="BloodFang Necklace"
spidefense=50
defense=0
Use() //We're over riding our Use() proc again, except this time we're using the same properties from the last time we redefined, except we'll be adding armor to the player armor defense
..() //call the parent proc so it adds the overlays and such
var/mob/User=src.loc
if(User)
if(ismob(User))
if((src in User.equipped))
User.def+=src.defense
User.str+=src.spidefense
else
User.def-=src.defense
User.str-=src.spidefense
New()
{
spawnTime = rand(50,100)
}
Gemstone
icon='weapontest.dmi'
icon_state="Gemstone"
spidefense=50
defense=0
Use() //We're over riding our Use() proc again, except this time we're using the same properties from the last time we redefined, except we'll be adding armor to the player armor defense
..() //call the parent proc so it adds the overlays and such
var/mob/User=src.loc
if(User)
if(ismob(User))
if((src in User.equipped))
User.def+=src.defense
User.spi+=src.spidefense
else
User.def-=src.defense
User.spi-=src.spidefense
New()
{
spawnTime = rand(50,100)
}


That's what I'm doing, and of course I have the stuff you gave me... Is there a problem in that? (Yes, the notes are from an object rescource I built off of.)

obj
BBWall1
icon='turf.dmi'
icon_state="Wall Bottom1B"
density = 1
verb
Break()
set src in oview(1,usr)
set category=null
del(src)
BTWall1
icon='turf.dmi'
icon_state="wall top1B"
density = 1
verb
Break()
set src in oview(1,usr)
set category=null
del(src)







proc
{
//
// Spawns various objects
//
Proc_SpawnObject(var/atom/location, var/type, var/spawntime)
{
spawn()
{
sleep(spawntime)
new type(location)
}
}
}


Uh oh, I think this is turning into a coding problem :(
In response to ZKR
You really shouldn't need to be copy-pasting Use() over and over again. They're almost all exactly the same, so just provide that functionality in the base obj/items/Use().

Anyway, one issue is that you are deleting src in Get(), which you shouldn't be. After all, src is what you just moved to the player's contents. Speaking of which, the other issue is that loc is going to be the player now, after you've moved it, so store the current location in some variable, attempt to move it to the player, and if the move succeeds then call Proc_SpawnObject() for the old location.

Also note that a player can pick up and drop the same item multiple times to essentially clone it. You might want to have some variable which says whether or not it's been picked up or not, and only create a replacement if it hasn't been.
In response to Garthor
Garthor wrote:
You really shouldn't need to be copy-pasting Use() over and over again. They're almost all exactly the same, so just provide that functionality in the base obj/items/Use().

Anyway, one issue is that you are deleting src in Get(), which you shouldn't be. After all, src is what you just moved to the player's contents. Speaking of which, the other issue is that loc is going to be the player now, after you've moved it, so store the current location in some variable, attempt to move it to the player, and if the move succeeds then call Proc_SpawnObject() for the old location.

Also note that a player can pick up and drop the same item multiple times to essentially clone it. You might want to have some variable which says whether or not it's been picked up or not, and only create a replacement if it hasn't been.

ok as you can tell I'm horrible with code so let me try to figure this out...

Ok, so I shouldnt del the src... done.

Store the current location in some variable... OH! I think I get it...
obj
items //Define a subtype so we can organize our items better than having to loop through looking for special properties
verb
Drop()
set src in usr.contents
set category=null
if(src.Move(usr.loc))
usr<<"<font color=white><b>You dropped [src.name]!</b>"
Get()
set src in oview(1,usr)
set category=null
var/turf/X = src.loc
if(src.Move(usr))
usr<<"<font color=white><b>You picked up [src.name]!</b>"
Proc_SpawnObject(X, src.type, spawnTime)


That's that... test it so far...

Done, and it worked! I kinda guessed on the coding >_>

Now I can see what you meant on cloning it... but then I noticed it didnt clone after I fixed it... Wait, lemme check something...

AH, I see... you drop it then after a while it comes back...

obj
items //Define a subtype so we can organize our items better than having to loop through looking for special properties
var/Q=0
verb
Drop()
set src in usr.contents
set category=null
if(src.Move(usr.loc))
usr<<"<font color=white><b>You dropped [src.name]!</b>"
Get()
set src in oview(1,usr)
set category=null
var/turf/X = src.loc
if(src.Move(usr))
usr<<"<font color=white><b>You picked up [src.name]!</b>"
if(src.Q == 0)
Proc_SpawnObject(X, src.type, spawnTime)
src.Q=1


Kinda like that?
Testing...


HAHA it worked! ^^ Actually that was the third revision up there o.O I kept messing up! I dunno if thats what you meant but hey it works. It started working with the last advice but stopped all of a sudden so I'll come back to you all if it starts screwing up again. You've been all great help!

P.S. Is that what you meant? Cause I basically took knoledge and examinations from other things I have done or other sources I have seen to put the puzzle together XD
In response to ZKR
That's exactly what I meant. You may wish to name the variable something more informative than "Q", though.
In response to Garthor
Ok, I got another problem stringing from this.

Yeah, I know it's a late reply, I didn't really work on the game lately.


mob
RegaliusShopkeeper
icon = 'mobs.dmi'
icon_state = "Shopkeeper"
verb
Talk()
set src in oview(1,usr)
set category=null
switch(input("What can I get you?","Shop")in list("Vitality Necklace (350 GP)","Enchanted Ring (350 GP)","BloodFang Necklace (400 GP)","Gemstone (400 GP)","Raizan (30000 GP)","Enryuu (30000 GP)","Shippuu (30000 GP)","Soul Stealer (50000 GP)","Soul's Judgement (50000 GP)","Cancel"))
if("Vitality Necklace (350 GP)")
if(usr.gold >= 350)
usr.gold -= 350
new/obj/items/weapons/weapon/VitalityNecklace(usr)
else
alert("Oh, I'm sorry, you don't have enough for that!")
return
if("Enchanted Ring (350 GP)")
if(usr.gold >= 350)
usr.gold -= 350
new/obj/items/weapons/weapon/EnchantedRing(usr)
else
alert("Oh, I'm sorry, you don't have enough for that!")
return
if("BloodFang Necklace (400 GP)")
if(usr.gold >= 400)
usr.gold -= 400
new/obj/items/weapons/weapon/BloodfangNecklace(usr)
else
alert("Oh, I'm sorry, you don't have enough for that!")
return
if("Gemstone (400 GP)")
if(usr.gold >= 400)
usr.gold -= 400
new/obj/items/weapons/weapon/Gemstone(usr)
else
alert("Oh, I'm sorry, you don't have enough for that!")
return
if("Raizan (30000 GP)")
if(usr.gold >= 30000)
usr.gold -= 30000
new/obj/items/weapons/weapon/Raizan(usr)
else
alert("Oh, I'm sorry, you don't have enough for that!")
return
if("Enryuu (30000 GP)")
if(usr.gold >= 30000)
usr.gold -= 30000
new/obj/items/weapons/weapon/Enryuu(usr)
else
alert("Oh, I'm sorry, you don't have enough for that!")
return
if("Shippuu (30000 GP)")
if(usr.gold >= 30000)
usr.gold -= 30000
new/obj/items/weapons/weapon/Shippuu(usr)
else
alert("Oh, I'm sorry, you don't have enough for that!")
return
if("Soul Stealer (50000 GP)")
if(usr.gold >= 50000)
usr.gold -= 50000
new/obj/items/weapons/weapon/SoulStealer(usr)
else
alert("Oh, I'm sorry, you don't have enough for that!")
return
if("Soul's Judgement (50000 GP)")
if(usr.gold >= 50000)
usr.gold -= 50000
new/obj/items/weapons/weapon/SoulJudgement(usr)
else
alert("Oh, I'm sorry, you don't have enough for that!")
return
if("Cancel")
return

The item goes into the inventory completely fine, but it isn't able to be equipped. I am still using the same coding string as from the post above. Can anyone help?
In response to KSDT
That has nothing to do with this thread.