ID:1501020
 
(See the best response by Pirion.)
Code:
turf        
Ore_Deposit
icon='ores.dmi'
density=1
icon_state=


proc
OreCheck()
if(turf icon='ores.dmi')//The icon holding the ore icons
icon_state= rand(1,2)//1,2,3 being the icon_states
if (icon_state=1)
usr << "Test 1)"
if (icon_state=2)
usr << "Test 2"


Problem description:
So, I've been having some creativity issues about how I'd like the ore system for this project I am doing to go. I've come upon the conclusion that an turf, or object, will be assigned a ore based off a percentage value. Not only am I having issues implementing such idea, it also seems like a poor way to run such a system. I'd greatly appreciate better ideas about how to set up an ore system, or about how to get mine to work.

Also, the OreCheck() proc would need to be called every two or so minutes.
Try something like

turf
Ore_Deposit
icon = 'ores.dmi'


New()
..()
icon_state = "[rand(1,2)]"


You only need to set the icon_state (and whatever other values are associated with that ore) once when it is created.

Is there a reason why you just don't have multiple types of ores defined?

turf
ore_deposit
icon = 'ores.dmi'

ore_type1
icon_state = "1"

ore_type2
icon_state = "2"
Hummm... Koshigia is 100% correct but what about this code? Would it work? Let's give it a try XD

turf/Ore_Deposit
icon='ores.dmi'
density=1

New()
..()
T()


turf/proc/T()
start
var/a = rand(1,2)
if(a==1)
src.icon_state="1"
else
src.icon_state="2"
sleep(10)
goto start





mob/verb/Create_Ore_Deposit()
new /turf/Ore_Deposit(usr.loc)


Once you click the verb that I included in my code you'll see the desired effect.
Please, any corrections or advices will be welcome :D

,MistY,
In response to Misticone
You're going to need to spawn() T(), or else New() isn't going to return. Also, although it isn't technically wrong, I would advise against using goto in that way, and instead use a while() loop.
Best response
By ore system, and the code you are writing, it looks like your intent is to implement mining? I wanted to show you what a well thought out system would do.

Let's think about this then. First we need to think about how this will work as a system. I'm going to walk you through how I would think about a system implementation for this.

*I need someone to be able to mine a rock.

*In order to prevent them from overmining a rock, I want to limit the amount they can get.

*I want to randomly spawn diffrent ores, depending on the rock they are mining.


Now, I have three basic requirements, how to we implement them? Well, lets get the most basic down, I need to allow them to mine a rock, right? Now, rocks aren't part of the turf, as a turf can have rocks and other things in it, so I would make it an obj/resource/ores. Now, in order to provide diffrent ores, I would create a varible, and overwrite this for each type of ores. Below, I will create a basic rock, and a legendary rock that gives mostly coal, but some amazing ores too. The resource class can be inherited by any other resouce too.

To limit the ores, I would create a new instance and add them to obj.contents.

obj/resource //resoruces, can be used for all resouces, not just ores.
var
list/resources = new() //a place to store what we want to gather
max_resources = 10 //maximum number of items
sleep_between_resources = 100 //delay between creating new items
tmp/generating = 0 //are we currently making anything

New()
..()
Generate() //on new, lets start creating

proc/Generate()
if(generating) return //prevent generating multiple times.
generating = !generating
while(src.contents.len < max_resources) //if src.contents has more than we need, no work to do.
sleep(sleep_between_resources)
var/type_to_generate = pick(resources)
if(type_to_generate) new type_to_generate(src.contents)
generating = !generating

proc/Gather(mob/m)
if(prob(10))
. = pick(src.contents) //10% chance of obtaining something
Generate() //start our generating again.

ores
icon = 'rock.dmi'
icon_state = "a_rock"
Click(o)
if(o && type(o,/mob))
if(o.action) return
o.action = !o.action
o << "You begin to mine."
sleep(10)
var/obj/i = Gather(o)
if(i)
o << "You found a [i] ore."
else
o << "You didn't find anything.
o.action = !o.action

basic
resources = list(/obj/ore/tin=10,/obj/ore/copper=10) // 10 + 10 = 20, so 50% tin, 50% copper

legendary
max_resources = 3
resources = list(/obj/ore/coal=88,/obj/ore/mithreil=11,/obj/ore/moondust=1) //88 + 11 + 1 = 100, so 88% coal, 11% mith, 1% moondust



Now, we can add some fun things to it. Say we have some ore icons, and want to show them sticking out of the rock. We can generate a new overlay or underlay and add this to the item, depending on the path selected.

obj/resource
proc/add_overlay(resource_name) //placeholder only

proc/Generate()
if(generating) return //prevent generating multiple times.
generating = !generating
while(src.contents.len < max_resources) //if src.contents has more than we need, no work to do.
sleep(sleep_between_resources)
var/type_to_generate = pick(resources)
if(type_to_generate)
var/obj/o = new type_to_generate(src.contents)
src.add_overlay(o.name) //add the overlay
generating = !generating

proc/Gather(mob/m)
if(prob(10))
var/obj/o = pick(src.contents) //10% chance of obtaining something
Generate() //start our generating again.
. = o
src.rem_overlay(o.name) //remove the overlay <<


obj/resource/var/list/_overlays = new()

obj/resource/ores/add_overlay(resource_type)
var/obj/overlay/o = new /obj/overlay/ore()
o.resource = resource_type
o.icon_state = "[resource_type][pick(1,2,3)]"
src._overlays += o
src.overlays += o

obj/resource/ores/rem_overlay(resource_type)
for(var/obj/overlay/ore in _overlays)
if(ore.resource == resource_type) //if correct resource
. = ore
break //stop looking
src.overlays -= .//remove from overlays

obj/overlay
var/resource
ore
icon = 'oreolay.dmi'
Thank you all. I really enjoy doing this, and when I have too much trouble to solve myself, I can come here, and get some pretty cool solutions that help me not only fix my code, but know what to do next time.
I'm afraid that I made a pretty big mistake.

Upon Gathering(), it needs to set waitfor = 0 or spawn(), otherwise you would be waiting for a long time to finish doing anything. Creating New or Harvesting. :)