ID:141422
 
Code:
mob/proc

Initiate_Battle(level) //monster is the type of monster generated when entering turf
var/tmp/tm = rand(1,3)
var/list/order
var/list/monsters

usr<<"[tm]" //lets me know how many monsters are supposed to spawn
for(var/x = 1, x < tm, x++)
monsters += AssignMon(level) // level is the monster's level group, its defined when the turf is entered
Create_Order(monsters,order,src)



Create_Order(list/monsters,list/mob/order,mob/player)
var/mob/monster = monsters[1]
usr<<"[player.name]"
usr<<" [monster.name]"
if(player.haste > monster.haste) //if player has higher haste
order = monsters.Copy(1,0)
order.Insert(1,player)
if(player.haste == monster.haste) //if equal haste
if(prob(50)) //50/50 who goes first
order = monsters.Copy(1,0)
order.Insert(1,player)
else
order = monsters.Copy(1,0)
order += player
else
order = monsters.Copy(1,0)
order += player


AssignMon(level)
switch(level)
if("level1")
var/choice = rand(1,3)
if(choice >= 1 && choice <= 4)
var/mob/y = new /mob/Monsters/Level1/Red_Slime
return y
else if(choice >=5 && choice <= 8)
var/mob/y = new /mob/Monsters/Level1/Goblin
y.loc = locate(23,21-x,4)
return y
else
var/mob/y = new /mob/Monsters/Level1/White_Tiger
y.loc = locate(23,21-x,4)
return y


Problem description:I'm trying to make a random multiple monster spawn (like in a final fantasy game) This is what i came up with. Monsters is the list of monsters (to be used for players ie: var/choice = input(...) in list monsters. order is the order of the turns. who goes first is based off of the mob's haste. I figured out that the list is full of nulls. I'm not sure how to correct this. The error i get in case it helps is:

runtime error: type mismatch: Red Slime (/mob/Monsters/Level1/Red_Slime) += Red Slime (/mob/Monsters/Level1/Red_Slime)
proc name: Initiate Battle (/mob/proc/Initiate_Battle)
source file: BattlePrep.dm,10
usr: the test (/mob)
src: the test (/mob)
call stack:
the test (/mob): Initiate Battle("level1")
Level1 (276,253,1) (/turf/CombatGrass/Level1): Entered(the test (/mob), Level1 (275,253,1) (/turf/CombatGrass/Level1))

please help! thanks in advance. (yes i know i'm a blond)
So far as I can tell, your AssignMon proc is returning null. Also, what is the level variable, and where does it come from. I have a feeling that it may be why AssignMon is returning null.



I will show you an example of some code that is fairly flexible from a game I am creating right now that might help you re-code your system, or help you spot something wrong in yours.

area
Monster_Area_1 // This just sets the potential monsters you can fight in the area
// you are entering as soon as you enter it. You would create one
// for every place the monsters change and lay it out accordingly.
// It only need be on the outside perimiter of the area.
Enter(mob/M)
.=..()
if(M.client && ismob(M))
M.Mon1 = /mob/Monsters/Slime
M.Mon2 = /mob/Monsters/Kaskos_Hopper
M.Mon3 = /mob/Monsters/Stag_Beetle
M.Mon4 = /mob/Monsters/Prank_Gopher

turf
Battles
Entered(mob/M)
..()
if(M.client && ismob(M))
var/encounter = rand(1,100)
var/list/_side2 = new() // This is my monster list.
var/i // Random var used to count the number of
// monsters being created.
if(encounter <= 2) // Lowest chance
for(i = 0, i < 4, i++) // creates 4 monsters
_side2 += pick( // randomly from the previously chosen monsters.
new M.Mon1,
prob(60)
new M.Mon2,
prob(40)
new M.Mon3,
prob(15)
new M.Mon4
)
else if(encounter <= 6) // Same as above, but slightly higher chance
for(i = 0, i < 3, i++) // only creates three monsters
_side2 += pick(
new M.Mon1,
prob(60)
new M.Mon2,
prob(40)
new M.Mon3,
prob(15)
new M.Mon4
)
else if(encounter <= 10) // Same again, with higher chance
for(i = 0, i < 2, i++) // Creates only 2 monsters this time.
_side2 += pick(
new M.Mon1,
prob(60)
new M.Mon2,
prob(40)
new M.Mon3,
prob(15)
new M.Mon4
)
else if(encounter <= 15) // Highest chance
for(i = 0, i < 1, i++)// creates 1 monster
_side2 += pick(
new M.Mon1,
prob(60)
new M.Mon2,
prob(40)
new M.Mon3,
prob(15)
new M.Mon4
)
if(encounter <= 15) // If there is something to fight
var/list/_side1 = M.client.party // make the first side the players
M.client.battle.Initiate_Battle(_side1, _side2) // and pit them against
// the monsters in combat.


This won't work as a straight up copy paste into your system for various reasons, I only posted it to maybe give you a new way to create your monsters, or help you some other way.