ID:264284
 
Code:
obj
Training_Log
icon = 'Turfs.dmi'
icon_state = "Log"
density = 1

obj
Needle
icon = 'Needle.dmi'
Price = 500
var/Material
Bump(atom/A)
var/mob/Owner
if(ismob(A))
var/mob/M = A
var/dmg = round(Owner.NeedleSkill + Owner.Taijutsu)
switch(Material)
if("Bronze") dmg=dmg*1
if("Iron") dmg=dmg*1.5
if("Steel") dmg=dmg*2
M.Health -= dmg
view(M)<<"[M] was hit by \a [src] for [dmg]"
M.Death(Owner)
if(istype(A,/obj/Training/Training_Log))
Owner.NeedleEXP += 25
Owner.NeedleLvlUp()
del(src)


Problem description:
I think I messed up in the typecasting or whatever, but when the Knife obj bumps into the Training_Log obj, it doesn't give any experience to whatever mob "O" is.
You have no var O in your snippet. You do have var/mob/Owner, but that var should belong to the obj itself and should be set when the projectile is created; it should not be part of the Bump() proc because at that point it's too late to find out who the owner is if you don't already know.

Lummox JR
In response to Lummox JR
Errors:
loading Interface.dmf
Objects.dm:79:error:Owner:invalid variable
Objects.dm:79:error:= :expected a constant expression

Line 79 - var/mob/O = Owner

obj/var/Owner = ""
obj/Weaponry
density = 1
layer = MOB_LAYER
Kunai
icon = 'Kunai.dmi'
Price = 1500
var/Material
var/mob/O = Owner
Bump(atom/A)
if(ismob(A))
var/mob/M = A
var/dmg = round(O.KunaiSkill*2 + O.Taijutsu)
switch(Material)
if("Bronze") dmg=dmg*1
if("Iron") dmg=dmg*1.5
if("Steel") dmg=dmg*2
M.Health -= dmg
view(A)<<"[M] was hit by \a [src] for [dmg]"
O.KunaiEXP += M.Level
O.KunaiLvlUp()
M.Death(Owner)
if(istype(A,/obj/Training/Training_Log))
O.KunaiEXP += 25
O.KunaiLvlUp()
del(src)
In response to Mizukouken Ketsu
Fixed it. Anyway to improve it?
obj
Knife
icon = 'Knife.dmi'
Price = 500
var/Material
Bump(atom/A)
var/mob/O = Owner
if(ismob(A))
var/mob/M = A
var/dmg = round(O.NeedleSkill*2 + O.Taijutsu)
switch(Material)
if("Bronze") dmg=dmg*1
if("Iron") dmg=dmg*1.5
if("Steel") dmg=dmg*2
M.Health -= dmg
view(M)<<"[M] was hit by \a [src] for [dmg]"
O.NeedleEXP += M.Level
O.NeedleLvlUp()
M.Death(O)
if(istype(A,/obj/Training/Training_Log))
O.NeedleEXP += 25
O.NeedleLvlUp()
O<<output("You gained 25 Needle experience","Crap")
del(src)
In response to Mizukouken Ketsu
                switch(Material)
if("Bronze") dmg=dmg*1
if("Iron") dmg=dmg*1.5
if("Steel") dmg=dmg*2


There are a few things with that:
  • Text is a limited resource, and you're wasting it. This might not be major, unless your objects will exist for a while (more than a minute or so)
  • You shouldn't have to define the damage multiplier like that. It should already be a var given to the object
  • Multiplying anything by one is a waste of CPU >_>
  • Use shorthand operators. var = var*another var/constant can be written shorthand as var *= another var/constant (like += or -=). This saves valuable time.


  • Also, if this is repetitive code, you might want to change your approach (ex. define /obj/projectile with a damage var etc. and then, if you need to perform some special task, create another subtype and override things as necessary).