//Main.dm
world
turf = /turf/grass
mob
Login()
src.LoadPlayer()
..()
var
Hp = 0
Damage = 0
Wealth = 0
ExpGive = 0
Exp = 0
ExpNext=0
Level = 1
Str = 1
Def = 1
critRank = 1
proc
LoadPlayer()
var/mob/Player/P = new()
P.client = src.client
P.Move(locate(/turf/grassStart))
DeathCheck(mob/Killer)
if(src.Hp < 1)
LevelUp(Killer)
del(src)
..()
LevelUp(mob/M as mob)
if(usr.Exp >= usr.ExpNext)
usr.Level += 1
world<<"Level Up, Level: [usr.Level]"
usr.Exp = usr.Exp - usr.ExpNext
if(Level == 5)
critRank+=1
if(Level == 10)
critRank+=1
usr.Statgain()
Statgain(S,D)
world << "You have gained [S] Str and [D] Defense!"
TakeDamage(Dmg,mob/Source)
Source.Hp -= Dmg
Source.DeathCheck(Source)
//EnemyMain.dm
mob/Enemy/Weak
icon = 'Enemy.dmi'
icon_state = "Weak"
Hp = 10
ExpGive = 25
Def = 3
DeathCheck(mob/Enemy/Weak/M)
usr.Exp += ExpGive/2
var/obj/Ohms/G = new(loc)
G.value = 1
..()
mob/Enemy/Elite
icon='Enemy.dmi'
icon_state="Elite"
Hp= 150
Def = 15
ExpGive = 100
DeathCheck(mob/Enemy/Elite/M)
usr.Exp += ExpGive /2
var/obj/Ohms/G = new(loc)
G.value = rand(10,500)
..()
//PlayerMain.dm
mob/Player
Hp = 100
Level = 1
ExpNext = 100
Str = 5
Def = 10
critRank = 1
var
strGain=1
defGain=1
Statgain(S,D)
S = strGain
D = defGain
Str += strGain
Def += defGain
strGain += round(1.05 *rand(1,5))
defGain += round(1.05 *rand(1,5))
..()
verb
say(msg as text in view())
set category = "Social"
view() <<"[usr] says: [msg]"
OOC(msg as text)
set category = "Social"
world << "[usr]: [msg]"
Attack(mob/M in oview(1))
set category = "Combat"
Damage = Str - M.Def + rand(critRank*-10,critRank*10)
if(Damage < 0)
Damage = 0
if (M.Hp > 0)
view() << "[usr] hit [M] for [Damage] Damage!"
TakeDamage(Damage,M)
else if (M.Hp <= 0)
view() << "[M] Is Already Dead"
ScanMob(mob/M in oview(3))
set category = "Combat"
usr << "[M.name] : Hp: [M.Hp], Exp Gain: [M.ExpGive]"
CheckStats()
world << "Ohms: [usr.Wealth], Exp: [usr.Exp], Level: [Level], Strength: [Str], Defense: [Def]"
icon = 'player.dmi'
Problem description: Alright I've been racking my brain trying to figure this out. I've ran the code multiple times with different items commented out so I know that the DeathCheck() of the Mob is what is making this happen. Or atleast I hope.
When the mob dies it drops up to 7 different gold items. I had it at a random value between 1 and 50 but to see if it would change I made the drop value one.
I can't figure out for the life of me what's making it drop multiple gold.
Also my gold is called Ohms.
I've included the Player Script, the Enemy Script, and the Main script that all might be adding to the problem but from what I can tell, the problem stems from the mob/Enemy DeathCheck()s
So you're triggering the code that spawns the gold object every time you attack them, and not just when you kill them. You likely want to utilize the return value of the parent to make sure the child proc should execute.
But you're gonna run into an issue with that due to your del(src) line, which is going to cease the object's existence, and that'll stop any running procs. So you don't want that bit to be done until the end, which means either throwing it into the child's DeathCheck(), or not using del() at all, but reusing the mob. So instead of deleting it, you'd just hide it from the world for a period of time, then move it back to its original location with all of its stats restored, this'll let you keep using the mob without the overhead of creating or destroying it. If you still want to delete it, you'd just do so after the code that spawns the reward.
More ideally, you'd have a separate proc that handles special things to do before getting rid of the mob, that gets called right before you delete/hide it, then you'd use that proc to do things like drop loot and the sort.