ID:159458
 
I cant seem to get my piece of coding to work so i deleted it.

If somebody would be so kind and to code it for me or show me a easy trick i would appreciate it.

Ok. I want it to create a new mob at random when u walk over the turf, my real problem is the random part i can not seem to get it 2 work and the creating a new mob. Should i code a proc for it or not? or just code what i want it to do under the turf?
You need a far better description of what you want.
So when you walk over a cetain turf you want a random mob to appear? You could use this if I understand you correctly:

turf
Mob_Creater
Entered()
var/A=rand(1,3)
if(A==1)
new/mob/Bob
if(A==2)
new/mob/George
if(A==3)
new/mob/Jim

something along those lines? You'll need to tweek that of course so it knows where to put the mobs and such, but the idea around the random part is the rand() proc there. The 1,3 I put is that it chooses between setting the value between 1 and 3. You can make it anything you want though.

I think that's what you're looking for.

In response to Fugsnarf
thanx a lot that's exactly what i needed. I guess i was just forgetting the Entered() proc.
In response to Fugsnarf
A more effecient way to do the random mobs part is this, just so you don't have to write 20 lines of code for 10 mobs, only 2.

var/t = pick(mob/bob,/mob/george,mob/jim)//Put all mobs here
var/mob/A = new t
In response to Bakasensei
Bakasensei wrote:
var/t = pick(mob/bob,/mob/george,mob/jim)//Put all mobs here
var/mob/A = new t


You could even use typesof, if you have all if the possibilities defined under a node.

var/p = pick(typesof(/mob/random_enemy)-"/mob/random_enemy")
new p(src) // Sorry, wasn't considering that you're using a turf
In response to Schnitzelnagler
thanx for all the help and siggestions but im getting a runtime error everytime the mob walks over the turf.

runtime error: Cannot read 0.loc
proc name: Entered (/turf/pokegrass/Entered)
usr: 0
src: the pokegrass (1,10,1) (/turf/pokegrass)
call stack:
the pokegrass (1,10,1) (/turf/pokegrass): Entered(the charmander (/obj/enemy/charmander), the pokegrass (1,11,1) (/turf/pokegrass))
the charmander (/obj/enemy/charmander): look()
the charmander (/obj/enemy/charmander): New(the pokegrass (1,11,1) (/turf/pokegrass))
the pokegrass (1,11,1) (/turf/pokegrass): Entered(the asdfsadf (/mob), the pokegrass (1,12,1) (/turf/pokegrass))

got any suggestions?
In response to Blip182
Could you post the related snippet of your code, please?
In response to Schnitzelnagler
turf
pokegrass
icon='pokegrass.dmi'
Entered()
var/A=rand(1,4)
if(A==1)
new/obj/enemy/charmander(usr.loc)
if(A==2)
new/obj/enemy/bulba(usr.loc)
if(A==3)
new/obj/enemy/squirtle(usr.loc)
if(A==4)
return
In response to Blip182
turf
pokegrass
icon='pokegrass.dmi'
Entered()
var/A=rand(1,4)
if(A==1)
new/obj/enemy/charmander(src)
if(A==2)
new/obj/enemy/bulba(src)
if(A==3)
new/obj/enemy/squirtle(src)
if(A==4)
return


Using usr in proc(edures) isn't save.

Edit: You(r code) might profit from looking up switch.
In response to Schnitzelnagler
thanx so much for the help i dont get the runtime error anymore

Heres my code.

turf
pokegrass
icon='pokegrass.dmi'
Entered()
var/M = usr
var/A=rand(1,4)
if(A==1 && ismob(M))
new/obj/enemy/charmander(usr.loc)
if(A==2 && ismob(M))
new/obj/enemy/bulba(usr.loc)
if(A==3 && ismob(M))
new/obj/enemy/squirtle(usr.loc)
if(A==4 && ismob(M))
return
In response to Blip182
You didn't really improve the code one bit, and you're still using usr. Copying usr into another var has no effect, as both vars are then identical, and if usr was wrong/invalid, your new var is as well. So it's still usr-abuse. Essentially you don't have to try accessing what entered the turf (which would be appropriate to do by Entered() argument, not usr. You need to look all of these up, as well as src.) to begin with here, since you're only wanting to use the turf, which is already available seeing as the proc is defined on it, so it's the source of the proc.
In response to Schnitzelnagler
Why do you subtract a text string like that? I don't see how it helps :\ Please explain?
In response to Spunky_Girl
I was actually going to comment on that, but didn't deem it worthy of an extra post. The text string is indeed a mistake; it shouldn't have been one, and just the type path (so, no quotes). Incidentally, a text string would've been fine inside the parentheses there.
The reason this is often needed is because the list typesof(Type) includes Type itself (or, the base parent type you've used), and such types are often not meant to be directly used but exist for inheritance purposes. For example, you could have types such as /obj/item or /mob/monster that aren't actual full prototypes with icons and all, in contrast to /obj/item/apple or /mob/monster/rat. Schnitzel presented a similar thing with the "mob/random_enemy" ancestor type.
In response to Kaioken
I'm afraid I still don't fully understand it... So he adds everything that's got the parent type of "/mob/random_enemy", but each iteration will remove the parent type, leaving only the child? So if you have...
mob/random_enemy
rat
mole
wurm

...you'll only be adding "rat", "mole", and "wurm" to the list?
In response to Spunky_Girl
Pretty much, though I don't know what iteration you're talking about, as there is none here. It's pretty simple like you've said though - removing Type from the result of typesof(Type) leaves you with only the descendants of Type in the list (so without Type itself).
In response to Kaioken
Sorry, Schnitzel used pick() while I used a for() loop on my end xD

So what would be the benefit of only adding descendants of the typepath to a list? When you go to reference it, how would it know to reference that specific mob? Or are you just removing the textual representation of the typepath, so the full pth is still there, but it only shows the child? Kind of like an associative list... "rat" = /mob/radom_enemy/rat
In response to Spunky_Girl
There's nothing special or any special benefit here, and note it's not text or associative list related either. You simply may not want the main type to be included in the list, in which case you remove it, so it isn't.
mob/monster
rat
rabbit
...
verb/CreateRandomMonster()
//store all the monster types in the list
var/list/type_paths = typesof(/mob/monster)
//list is now equivalent to one made with \
list(/mob/monster,/mob/monster/rat,/mob/monster/rabbit)

type_paths -= /mob/monster //we remove a single type from it
//list is now equivalent to list(/mob/monster/rat,/mob/monster/rabbit)
//simple stuff. >_>
var/p = pick(type_paths)
new p(loc)
In response to Kaioken
Oh! I see! I was thinking of it differently! xD
var/list/type_paths = list()
mob/verb/Random_Monsters()
type_paths = list(typesof(/mob/montser)-/mob/enemy)
//I thought it would make the list look like...
(rat,rabbit)
//not take out the entry in the list that literally was just the parent type path xD