ID:875863
 
Keywords: objects, turf, turfspawn
(See the best response by Albro1.)
Code:
proc/Death(mob/M)
if(M)
if(istype(M,/turf/rock/))
// M:opacity=0
// M:density=0
// M:icon_state="dirt"
// M:hp=5
var/dropgem = rand(1,256)
if(dropgem==1)
new/obj/pickup/Diamond(M.loc)
view()<<"<font color=white>A Diamond has fallen to the ground!</font>"
if(dropgem>=2 && dropgem<=3)
new/obj/pickup/Onyx(M.loc)
view()<<"<font color=white>A Diamond has fallen to the ground!</font>"
if(dropgem>=4 && dropgem<=7)
new/obj/pickup/Pearl(M.loc)
view()<<"<font color=white>A Pearl has fallen to the ground!</font>"
if(dropgem>=8 && dropgem<=16)
new/obj/pickup/Ruby(M.loc)
view()<<"<font color=red>A Ruby has fallen to the ground!</font>"
if(dropgem>=17 && dropgem<=33)
new/obj/pickup/Sapphire(M.loc)
view()<<"<font color=blue>A Sapphire has fallen to the ground!</font>"
if(dropgem>=34 && dropgem<=65)
new/obj/pickup/Amethyst(M.loc)
view()<<"<font color=#9900cc>A Amethyst has fallen to the ground!</font>"
if(dropgem>=66 && dropgem<=130)
new/obj/pickup/Topaz(M.loc)
view()<<"<font color=yellow>A Topaz has fallen to the ground!</font>"
if(dropgem>=131 && dropgem<=256)
new/obj/pickup/Emerald(M.loc)
view()<<"<font color=green>A Emerald has fallen to the ground!</font>"
M:opacity=0
M:density=0
M:icon_state="dirt"
Spawngem(M.loc)
return
if(istype(M,/obj/tree)||istype(M,/obj/tree))
var/drop = rand(1,10)
if(drop <= 2)
new/obj/pickup/Wood(M.loc)
if(drop >= 3)
new/turf/grass(M.loc)
del M
return
if(istype(M,/obj/wallm)||istype(M,/obj/wall)||istype(M,/obj/wallu)||istype(M,/obj/underwall)||istype(M,/obj/underwallu)||istype(M,/obj/underwallm)||istype(M,/obj/woodwall)||istype(M,/obj/woodwallu)||istype(M,/obj/woodwallm))
var/drop = rand(1,10)
if(drop <= 5)
new/obj/pickup/Brick(M.loc)
if(drop >= 1)
new/turf/woodfloor(M.loc)
del M
return



Problem description: So as you can see by my code, this is what happens when Death() procs. The problem is, the first part of the code involves turfs, which is where my question is. The second part of the code involves obj. The second part that involves obj works just fine, and I have no problems, however, the first part of the code, with the turfs, it tells me the "view()<<" string along with what dropped, but it does not ever drop an the gem item.

These are coded exactly the same, except for ones a obj, and ones a turf, and I already had to deal with obj and turfs interacting with the player. I decided to make turfs clickable, and just changing the icon state when the turf "dies". Now it seems that items do not want to drop if its related to a turf. Any help would be appreciated! Thanks!


Edit:Sorry A.T.H.K, I'm not familiar with forums all so much and I have alot on my mind with work + overtime and my finace and life's crazyness and this game so I appoligize if I formatted it wrong. Thanks for letting me know B).
You should put your code between the DM tags, so it is easier for everyone to read :)

<DM>
Code here
</DM>
I don't think turfs have any location as turf itself is a location. Try using
new/obj/pickup/Diamond(M)

instead of
new/obj/pickup/Diamond(M.loc)
Thanks Zaoshi, that worked perfect!
I would suggest using a different proc for drops altogther.
proc/Death(mob/M)

Suggests you are expecting a mob to be passed as M, yet no where in the proc is a mob even referenced, it doesn't really make sense. I would also suggest that if you want stuff you can destroy on the map make them objs, You don't want to go around destroying actual turf that will just leave black spaces on your map.

Here is a quick way I can think for it to be done:
obj
destroyable
icon = 'destroable.dmi'
var/list/drops = list("common", "medium", "rare")//you can add more divisons in here e.g. very common
rock
name = "rock"//this name needs to be set for something in the destroy proc, this must be the same as the icon state for this obj
icon_state = "rock"

drops = list("common" = /obj/pickup/pebble, "medium" = /obj/pickup/apple, "rare" = /obj/pickup/diamond)
//drops is a list of what this obj can drop each division has a /ocj/pickup assigned to it

proc
Destroy()
src.icon_state = "[src.name] destroyed"//sets the icon state to destroyed
src.density = 0//this is optional
var/obj/pickup/P
//this part decides the drop if any
if(prob(5))//a 5% chance for a rare drop
var/obj/pickup/p = src.drops["rare"]
P = new p
goto drop

if(prob(15))//15% chance for a medium drop
var/obj/pickup/p = src.drops["medium"]
P = new p
goto drop

if(prob(25))//25% chance for a common drop
var/obj/pickup/p = src.drops["common"]
P = new p
goto drop

drop//just a label
if(P)//if P exists, so if a drop was set
P.loc=locate(src)//locate p on the obj
view() << "A [P.name] was dropped when [src.name] was dstroyed."//tell people about it
return

pickup
icon = 'pickups.dmi'
diamond
//diamond stuff

apple
//apple stuff

pebble
//pebble stuff

There's an example, just something quick I gave small notes, nt to sure if it actually works didn't test is properly but it gives you an idea. I know a lot of people also don't like to use goto as it references ahead or something like that, but I saw it as appropriate here .
In response to GreatFisher
Best response
GreatFisher wrote:
> obj
> destroyable
> icon = 'destroable.dmi'
> var/list/drops = list("common", "medium", "rare")//you can add more divisons in here e.g. very common
> rock
> name = "rock"//this name needs to be set for something in the destroy proc, this must be the same as the icon state for this obj
> icon_state = "rock"
>
> drops = list("common" = /obj/pickup/pebble, "medium" = /obj/pickup/apple, "rare" = /obj/pickup/diamond)
> //drops is a list of what this obj can drop each division has a /ocj/pickup assigned to it
>
> proc
> Destroy()
> src.icon_state = "[src.name] destroyed"//sets the icon state to destroyed
> src.density = 0//this is optional
> var/obj/pickup/P
> //this part decides the drop if any
> if(prob(5))//a 5% chance for a rare drop
> var/obj/pickup/p = src.drops["rare"]
> P = new p
>
> else if(prob(15))//15% chance for a medium drop
> var/obj/pickup/p = src.drops["medium"]
> P = new p
>
> else if(prob(25))//25% chance for a common drop
> var/obj/pickup/p = src.drops["common"]
> P = new p
>
> if(P)//if P exists, so if a drop was set
> P.loc=locate(src)//locate p on the obj
> view() << "A [P.name] was dropped when [src.name] was dstroyed."//tell people about it
> return
>
> pickup
> icon = 'pickups.dmi'
> diamond
> //diamond stuff
>
> apple
> //apple stuff
>
> pebble
> //pebble stuff
>


Fixed your bad little gotos.
Haha thanks fella, I did it really quick and couldn't be asked to figure out a better way.
The reason I cannot use objects to destroy is due to the map not loading with that many objects. I had to settle for "destroying" turfs, when really the icon state is just changing and losing density to appear as if the player just mined the rock.

I am still getting used to this coding, as I am a graphic designer taking on a whole game for the most part. If you have any suggestions on how I can load the objects in game after the map loads, then I'd be more then happy to change them to objects and go that route. B)
I have a suggestion all be it an odd one. I think for creating all the objects at runtime you could:
turf
var
obj/destroyable/Object

mine_rock
Object = /obj/destroyable/rock

New()
..()
if(Object)
var/obj/O = new Object
O.loc = locate(src)

Something like that should work, just make specific turfs for objects to be made on and set the Object var to the path of the destroyable object.