ID:1938372
 
(See the best response by PJB3005.)
Code:
                    else if(usr.secondary == "Landmines")
usr.cooldown2 = 1
var/mob/M = new/atom/Landmines2
for(M)
M.Move(locate(usr))
spawn(15) usr.cooldown2 = 0
spawn(15) usr.middleclick = 0
return

atom
Landmines2
icon = 'objects.dmi'
icon_state = "Landmines"
layer = 5
density = 0
Enter(usr)
usr << "Landmine."
if(usr.maxHP > 0 && usr.layer == 5 && usr.icon != 'CharSprites.dmi')
usr.Damage = usr.Damage + rand(5,10)
usr.HP = usr.maxHP - usr.Damage
usr << "HP: [usr.HP]"
del(Landmines2)
if(usr.HP <= 0)
var/mob/M = usr
CheckDeathM(M)


Problem description:loading CodeGeass.dme
loading macro.dms
Combat\Combat.dm:982:error: usr.maxHP: undefined var
Combat\Combat.dm:982:error: usr.layer: undefined var
Combat\Combat.dm:982:error: usr.icon: undefined var
Combat\Combat.dm:983:error: usr.Damage: undefined var
Combat\Combat.dm:983:error: usr.Damage: undefined var
Combat\Combat.dm:984:error: usr.HP: undefined var
Combat\Combat.dm:984:error: usr.maxHP: undefined var
Combat\Combat.dm:984:error: usr.Damage: undefined var
Combat\Combat.dm:985:error: usr.HP: undefined var
Combat\Combat.dm:986:error: Landmines2: undefined var
Combat\Combat.dm:987:error: usr.HP: undefined var
CodeGeass.dmb - 11 errors, 0 warnings (9/19/15 12:47 pm)

I've already defined these in var and the landmine doesn't seem to be placing.

You need to typecast usr. Notice how when you do var/mob/M = usr at the very end it doesn't say CheckDeathM(M) is an undefined proc? By default Enter()'s first argument takes in atom/movable/O, not mob/.

Simply change Enter(usr) to Enter(mob/M), then change all of the usr's to M's.
Why am I getting bad loc on

var/mob/M = new/atom/Landmines2
M.loc = locate(usr.x,usr.y,usr.z)
Best response
Can you post the full code? because all of the things you're doing seem very weird.

First section of code:

var/mob/M = new/atom/Landmines2

Why are you typecasting this to a mob when it's a whole different type?

for(M)

This is not how for works at all, for is used for loops, however in this section of code it's not a loop and the syntax is incorrect, so I don't know what this is for at all.

M.Move(locate(usr))

First of all, that's not how you use locate(), unless you changed usr to something like a tag or text ref earlier.

Assuming you did do that, you're moving the landmine to the usr (you're putting it INSIDE the usr), instead of on the usr's loc (whereever the usr is standing).

Also, you're spawning a /atom, which isn't movable (you need /atom/movable for that), so this code probably throws a runtime.

This section of code can also be accomplished by passing the atom to put the mine in as parameter to new like so:
new/atom/Landmines2(usr.loc)


Second section of code:
The compilation errors are all because you're failing to typecast/you typo'd somewhere.
In response to BlackKingX
On the base /atom, the loc is a readonly var, you cannot move a /atom directly.
atom/var/middleclick = 0

/atom
Click(location,control,params)
var/list/p=params2list(params)
if(text2num(p["left"]))
if(src.enemytype && src.attacktarget != usr)
usr.incombat = 0
if(src == usr && usr.frozen != 1 && !src.Dead && src.icon != 'CharSprites.dmi')
if(usr.icon_state == "MR-1DriveOn")
usr.speed = 5
usr.icon_state = "MR-1On"
usr << "Changed to combat mode."
else if(usr.icon_state == "MR-1On")
usr.speed = 1
usr.icon_state = "MR-1DriveOn"
usr << "Changed to drive mode."
if(usr.weaponequipped)
usr.overlays -= usr.overlays
weaponequipped = 0
usr.cooldown = 0
if(src != usr && usr.frozen != 1 && !src.Dead && src.icon != 'CharSprites.dmi' && !src.immune)
if(usr.x > src.x && usr.dir == WEST || usr.x < src.x && usr.dir == EAST || usr.y < src.y && usr.dir == NORTH || usr.y > src.y && usr.dir == SOUTH)
if(usr.weaponequipped == 2 && !usr.cooldown)
usr.cooldown = 1
usr.overlays += /obj/overlay/assaultrifle
var/obj/S = new/obj/assaultriflespread(locate(src.x,src.y,src.z))
S.pixel_y += src.pixel_y
if(istype(src,/mob/))
usr << "Shot [src]."
src.Damage = src.Damage + rand(1,10)
src.HP = src.maxHP - src.Damage
usr << "Enemy HP: [src.HP]"
src << "HP: [src.HP]"
spawn(4) usr.overlays -= /obj/overlay/assaultrifle
CheckDeathRifle()
else
spawn(4) usr.overlays -= /obj/overlay/assaultrifle
sleep(15)
usr.cooldown = 0
else if(usr.weaponequipped == 4 && !usr.cooldown)
src = locate(x,y,z)
usr.cooldown = 1
usr.overlays += /obj/overlay/GiantCannonShoot
for(var/X in -1 to 1)
for(var/Y in -1 to 1)
spawn(rand(1,5)) new/obj/CannonExplode(locate(src.x+X,src.y+Y,src.z))
var/mob/M
for(M in view(1,src))
if(M.maxHP > 0 && M.icon != 'CharSprites.dmi')
usr << "Shot [M.name]."
M.Damage = M.Damage + rand(4,12)
M.HP = M.maxHP - M.Damage
usr << "Enemy HP: [M.HP]"
M << "HP: [M.HP]"
if(M.HP <= 0 && M in view(1,src))
CheckDeathM(M)
spawn(4) usr.overlays -= /obj/overlay/GiantCannonShoot
sleep(30)
usr.cooldown = 0
if(usr.weaponequipped == 1 && !usr.cooldown)
usr.cooldown = 1
var/obj/S = new/obj/Slash
S.dir = usr.dir
S.layer = usr.layer+1
S.pixel_y = usr.pixel_y
var/mob/M
if(usr.dir == NORTH)
S.loc = locate(usr.x,usr.y+1,usr.z)
S.pixel_y -= 37
S.pixel_x -= 10
S.layer = usr.layer-1
for(M in view(1,usr))
if(M.maxHP > 0 && M.layer == usr.layer && M.icon != 'CharSprites.dmi')
if(usr.y < M.y)
usr << "Slashed [M.name]."
if(M.enemytype && M.attacktarget != usr)
usr.incombat = 0
M.Damage = M.Damage + rand(1,5)
M.HP = M.maxHP - M.Damage
usr << "Enemy HP: [M.HP]"
M << "HP: [M.HP]"
if(M.HP <= 0)
CheckDeathM(M)
if(usr.dir == SOUTH)
S.loc = locate(usr.x,usr.y-1,usr.z)
S.pixel_x -= 27
S.layer = usr.layer-1
for(M in view(1,usr))
if(M.maxHP > 0 && M.layer == usr.layer && M.icon != 'CharSprites.dmi')
if(usr.y > M.y)
usr << "Slashed [M.name]."
if(M.enemytype && M.attacktarget != usr)
usr.incombat = 0
M.Damage = M.Damage + rand(1,5)
M.HP = M.maxHP - M.Damage
usr << "Enemy HP: [M.HP]"
M << "HP: [M.HP]"
if(M.HP <= 0)
CheckDeathM(M)
if(usr.dir == EAST)
S.loc = locate(usr.x+1,usr.y,usr.z)
S.pixel_x -= 20
S.layer = usr.layer-1
for(M in view(1,usr))
if(M.maxHP > 0 && M.layer == usr.layer && M.icon != 'CharSprites.dmi')
if(usr.x < M.x)
usr << "Slashed [M.name]."
if(M.enemytype && M.attacktarget != usr)
usr.incombat = 0
M.Damage = M.Damage + rand(1,5)
M.HP = M.maxHP - M.Damage
usr << "Enemy HP: [M.HP]"
M << "HP: [M.HP]"
if(M.HP <= 0)
CheckDeathM(M)
if(usr.dir == WEST)
S.loc = locate(usr.x-1,usr.y,usr.z)
S.pixel_x -= 17
S.layer = usr.layer-1
for(M in view(1,usr))
if(M.maxHP > 0 && M.layer == usr.layer && M.icon != 'CharSprites.dmi')
if(usr.x > M.x)
usr << "Slashed [M.name]."
if(M.enemytype && M.attacktarget != usr)
usr.incombat = 0
M.Damage = M.Damage + rand(1,5)
M.HP = M.maxHP - M.Damage
usr << "Enemy HP: [M.HP]"
M << "HP: [M.HP]"
if(M.HP <= 0)
CheckDeathM(M)
sleep(16)
usr.cooldown = 0
if(usr.weaponequipped == 3 && !usr.cooldown)
usr.cooldown = 1
var/obj/S = new/obj/Slash
S.dir = usr.dir
S.layer = usr.layer+1
S.pixel_y = usr.pixel_y
var/mob/M
if(usr.dir == NORTH)
S.loc = locate(usr.x,usr.y+1,usr.z)
S.pixel_y -= 37
S.pixel_x -= 10
S.layer = usr.layer-1
for(M in view(1,usr))
if(M.maxHP > 0 && M.layer == usr.layer && M.icon != 'CharSprites.dmi')
if(usr.y < M.y)
usr << "Slashed [M.name]."
if(M.enemytype && M.attacktarget != usr)
usr.incombat = 0
M.Damage = M.Damage + rand(2,7)
M.HP = M.maxHP - M.Damage
usr << "Enemy HP: [M.HP]"
M << "HP: [M.HP]"
if(M.HP <= 0)
CheckDeathM(M)
if(usr.dir == SOUTH)
S.loc = locate(usr.x,usr.y-1,usr.z)
S.pixel_x -= 27
S.layer = usr.layer-1
for(M in view(1,usr))
if(M.maxHP > 0 && M.layer == usr.layer && M.icon != 'CharSprites.dmi')
if(usr.y > M.y)
usr << "Slashed [M.name]."
if(M.enemytype && M.attacktarget != usr)
usr.incombat = 0
M.Damage = M.Damage + rand(2,7)
M.HP = M.maxHP - M.Damage
usr << "Enemy HP: [M.HP]"
M << "HP: [M.HP]"
if(M.HP <= 0)
CheckDeathM(M)
if(usr.dir == EAST)
S.loc = locate(usr.x+1,usr.y,usr.z)
S.pixel_x -= 20
S.layer = usr.layer-1
for(M in view(1,usr))
if(M.maxHP > 0 && M.layer == usr.layer && M.icon != 'CharSprites.dmi')
if(usr.x < M.x)
usr << "Slashed [M.name]."
if(M.enemytype && M.attacktarget != usr)
usr.incombat = 0
M.Damage = M.Damage + rand(2,7)
M.HP = M.maxHP - M.Damage
usr << "Enemy HP: [M.HP]"
M << "HP: [M.HP]"
if(M.HP <= 0)
CheckDeathM(M)
if(usr.dir == WEST)
S.loc = locate(usr.x-1,usr.y,usr.z)
S.pixel_x -= 17
S.layer = usr.layer-1
for(M in view(1,usr))
if(M.maxHP > 0 && M.layer == usr.layer && M.icon != 'CharSprites.dmi')
if(usr.x > M.x)
usr << "Slashed [M.name]."
if(M.enemytype && M.attacktarget != usr)
usr.incombat = 0
M.Damage = M.Damage + rand(2,7)
M.HP = M.maxHP - M.Damage
usr << "Enemy HP: [M.HP]"
M << "HP: [M.HP]"
if(M.HP <= 0)
CheckDeathM(M)
sleep(10)
usr.cooldown = 0
if(usr.weaponequipped == 5 && !usr.cooldown)
usr.cooldown = 1
var/obj/S = new/obj/SlashTwin
S.dir = usr.dir
S.layer = usr.layer+1
S.pixel_y = usr.pixel_y
var/mob/M
if(usr.dir == NORTH)
S.loc = locate(usr.x,usr.y+1,usr.z)
S.pixel_y -= 37
S.pixel_x -= 22
S.layer = usr.layer-1
for(M in view(1,usr))
if(M.maxHP > 0 && M.layer == usr.layer && M.icon != 'CharSprites.dmi')
if(usr.y < M.y)
usr << "Slashed [M.name]."
if(M.enemytype && M.attacktarget != usr)
usr.incombat = 0
M.Damage = M.Damage + rand(2,15)
M.HP = M.maxHP - M.Damage
usr << "Enemy HP: [M.HP]"
M << "HP: [M.HP]"
if(M.HP <= 0)
CheckDeathM(M)
if(usr.dir == SOUTH)
S.loc = locate(usr.x,usr.y-1,usr.z)
S.pixel_x -= 22
S.layer = usr.layer-1
for(M in view(1,usr))
if(M.maxHP > 0 && M.layer == usr.layer && M.icon != 'CharSprites.dmi')
if(usr.y > M.y)
usr << "Slashed [M.name]."
if(M.enemytype && M.attacktarget != usr)
usr.incombat = 0
M.Damage = M.Damage + rand(2,15)
M.HP = M.maxHP - M.Damage
usr << "Enemy HP: [M.HP]"
M << "HP: [M.HP]"
if(M.HP <= 0)
CheckDeathM(M)
if(usr.dir == EAST)
S.loc = locate(usr.x+1,usr.y,usr.z)
S.pixel_x -= 20
S.layer = usr.layer-1
for(M in view(1,usr))
if(M.maxHP > 0 && M.layer == usr.layer && M.icon != 'CharSprites.dmi')
if(usr.x < M.x)
usr << "Slashed [M.name]."
if(M.enemytype && M.attacktarget != usr)
usr.incombat = 0
M.Damage = M.Damage + rand(2,15)
M.HP = M.maxHP - M.Damage
usr << "Enemy HP: [M.HP]"
M << "HP: [M.HP]"
if(M.HP <= 0)
CheckDeathM(M)
if(usr.dir == WEST)
S.loc = locate(usr.x-1,usr.y,usr.z)
S.pixel_x -= 17
S.layer = usr.layer-1
for(M in view(1,usr))
if(M.maxHP > 0 && M.layer == usr.layer && M.icon != 'CharSprites.dmi')
if(usr.x > M.x)
usr << "Slashed [M.name]."
if(M.enemytype && M.attacktarget != usr)
usr.incombat = 0
M.Damage = M.Damage + rand(2,15)
M.HP = M.maxHP - M.Damage
usr << "Enemy HP: [M.HP]"
M << "HP: [M.HP]"
if(M.HP <= 0)
CheckDeathM(M)
sleep(10)
usr.cooldown = 0
if(usr.weaponequipped == 6)
usr.checkvar = input("Which variable to check?")
for(var/Vars in src.vars)
if(Vars == usr.checkvar)
world << "[src] [usr.checkvar] = [src.vars[Vars]]"




if(text2num(p["middle"]))
Midclick()



proc
Midclick()
if(!usr.middleclick)
usr.middleclick = 1
if(usr.icon == 'Knightmares.dmi' && usr.cooldown2 == 0)
if(usr.secondary == "Slash Harkens" && usr.icon_state == "LancelotOn")
usr.cooldown2 = 1
usr.overlays += /obj/overlay/LancelotSlashHarkens
for(var/mob/M in view(2,usr))
if(M.grapplepoint == 1 && get_dir(usr,M) == NORTH && usr.dir == NORTH)
spawn(10) usr.loc = locate(M.x,M.y+1,M.z)
else if(M != usr && M.name != "")
var/E = M.Damage
M.Damage = M.Damage + rand(0,2)
if(M.Damage > E)
M << "Hit with Slash Harkens."
usr << "Your Slash Harkens hit [M]."
var/S = M.speed
var/J = usr.speed
M.speed = M.speed + 2
usr.speed = usr.speed - 1
spawn(9) M.speed = S
spawn(5) usr.speed = J
else
..()
sleep(10)
usr.overlays -= /obj/overlay/LancelotSlashHarkens
usr.cooldown2 = 0
usr.middleclick = 0
return
else if(usr.secondary == "Slash Harkens" && usr.icon_state != "LancelotOn" && usr.icon_state != "MR-1DriveOn" && !usr.floatequipped)
usr.cooldown2 = 1
usr.overlays += /obj/overlay/grapple
usr.overlays += /obj/overlay/grapple2
usr.overlays += /obj/overlay/grapple3
usr.overlays += /obj/overlay/grapple4
for(var/mob/M in view(5,usr))
if(M.grapplepoint == 1 && get_dir(usr,M) == NORTH && usr.dir == NORTH)
spawn(10) usr.loc = locate(M.x,M.y+1,M.z)
else if(M != usr && get_dir(usr,M) == usr.dir && M.name != "")
var/E = M.Damage
M.Damage = M.Damage + rand(0,1)
if(M.Damage > E)
M << "Hit with a Slash Harken."
usr << "Your Slash Harken hit [M]."
var/S = M.speed
var/J = usr.speed
M.speed = M.speed + 2
usr.speed = usr.speed - 1
spawn(9) M.speed = S
spawn(5) usr.speed = J
else
..()
sleep(10)
usr.overlays -= /obj/overlay/grapple
usr.overlays -= /obj/overlay/grapple2
usr.overlays -= /obj/overlay/grapple3
usr.overlays -= /obj/overlay/grapple4
usr.cooldown2 = 0
usr.middleclick = 0
return
else if(usr.secondary == "Geass Push")
usr.cooldown2 = 1
usr.overlays += /obj/overlay/GeassPush
spawn(4) usr.overlays -= /obj/overlay/GeassPush
for(var/mob/M in oview(3,usr))
if(M.icon == 'Knightmares.dmi' || M.icon == 'Vehicles.dmi')
step_away(M,usr,3)
sleep(30)
usr.overlays -= /obj/overlay/GeassPush
usr.cooldown2 = 0
usr.middleclick = 0
return
else if(usr.secondary == "Geass Time Suspend")
usr.cooldown2 = 1
usr.overlays += /obj/overlay/GeassTimeSuspend
spawn(6) usr.overlays -= /obj/overlay/GeassTimeSuspend
for(var/mob/M in oview(2,usr))
if(M.icon == 'Knightmares.dmi' || M.icon == 'Vehicles.dmi')
M.northdir = 1
M.southdir = 1
M.westdir = 1
M.eastdir = 1
M.southwestdir = 1
M.southeastdir = 1
M.northwestdir = 1
M.northeastdir = 1
M.cooldown = 1
M.cooldown2 = 1
M.frozen = 1
spawn(40) M.northdir = 0
spawn(40) M.southdir = 0
spawn(40) M.westdir = 0
spawn(40) M.eastdir = 0
spawn(40) M.southwestdir = 0
spawn(40) M.southeastdir = 0
spawn(40) M.northwestdir = 0
spawn(40) M.northeastdir = 0
spawn(40) M.cooldown = 0
spawn(40) M.cooldown2 = 0
spawn(40) M.frozen = 0
sleep(50)
usr.overlays -= /obj/overlay/GeassTimeSuspend
usr.cooldown2 = 0
usr.middleclick = 0
return
else if(usr.secondary == "Factsphere Sensor")
usr.cooldown2 = 1
for(var/mob/M in oview(8,usr))
if(M.icon == 'Knightmares.dmi' || M.icon == 'Vehicles.dmi')
var/image/I = image(/obj/overlay/FactsphereKnightmare,M)
usr << I
spawn(10) del(I)
else if(M.icon == 'CharSprites.dmi')
var/image/I = image(/obj/overlay/Factsphere,M)
usr << I
spawn(10) del(I)
sleep(10)
usr.cooldown2 = 0
usr.middleclick = 0
return
else if(usr.secondary == "Teleport")
usr.cooldown2 = 1
usr.overlays += /obj/overlay/GeassTeleport
spawn(6) usr.overlays -= /obj/overlay/GeassTeleport
usr.Move(locate(src.x,src.y,src.z))
usr.cooldown2 = 0
usr.middleclick = 0
return
else if(usr.secondary == "Landmines")
usr.cooldown2 = 1
var/mob/M = new/atom/movable/Landmines2
M.loc = locate(usr.x,usr.y,usr.z)
spawn(15) usr.cooldown2 = 0
spawn(15) usr.middleclick = 0
return
usr.middleclick = 0


/atom/movable
Landmines2
icon = 'objects.dmi'
icon_state = "Landmines"
layer = 5
density = 0
Enter(mob/M)
M << "Landmine."
if(M.maxHP > 0 && M.layer == 5 && M.icon != 'CharSprites.dmi')
M.Damage = M.Damage + rand(5,10)
M.HP = M.maxHP - M.Damage
M << "HP: [M.HP]"
if(M.HP <= 0)
CheckDeathM(M)
del()




Now it places the mines but they don't explode or damage.
Instead of Enter() for your mines, you should use Crossed()
It works!
Instead of those why didn't you use Bump() ?
In response to Hebrons
That would require making the landmine dense, which makes no sense.

It explodes when you walk onto it.
In response to BlackKingX
Oh man. I didn't even read the code, I'd just like to inform you there's this thing called a switch statement. Use it.
In response to Konlet
Konlet wrote:
Oh man. I didn't even read the code, I'd just like to inform you there's this thing called a switch statement. Use it.

Not like it would help much it would still be a huge mess.

In response to Gokussj99
I was going to say that too. I believe that's what they call polishing a turd.
In response to Hebrons
Hebrons wrote:
Instead of those why didn't you use Bump() ?

This is one way of doing it, but I'd say it'd only be preferred if it was using modified boundaries (bound_x, bound_y, bound_width, bound_height)

Boundaries are neat. Try them out if it's a last resort.