ID:153826
 
could someone tell me how to make this shorter? It just seems there's a more elegant way to do this.
world
mob = /mob/player
turf = /turf/floor/grass
client
North()
South()
East()
West()
Northwest()
Northeast()
Southwest()
Southeast()

atom
Click()
switch(type)
if(/mob)
set src in oview(1)
if (usr:attack == 1)
damage = usr:str - src.def
src.health -= damage
usr << "You damage [src] for [damage] health!"
src.DeathCheck()
usr:attack = 0
usr.client.mouse_pointer_icon = null
else
usr.client.mouse_pointer_icon = null

mob
player
var
move = 0
attack = 0
str = 5
def = 2
damage
health = 10
icon = 'player.dmi'
proc
DeathCheck()
if(src.health <= 0)
world << "[src] was killed!"
del(src)

obj
hud
layer = MOB_LAYER + 1
icon = 'hud.dmi'
move
icon_state = "walk_to"
Click()
usr.client.mouse_pointer_icon = icon('mouse.dmi',"move_to")
usr:move = 1
New(client/C)
screen_loc = "1,1"
C.screen += src
attack
icon_state = "attack"
Click()
usr.client.mouse_pointer_icon = icon('mouse.dmi',"attack")
usr:attack = 1
New(client/C)
screen_loc = "2,1"
C.screen += src

client/New()
..()
new/obj/hud/move(src)
new/obj/hud/attack(src)


P.S. I get these errors with the switch statement up top:
Legacy of Lukai, The Secrets Within.dm:21:error:damage:undefined var
Legacy of Lukai, The Secrets Within.dm:22:error:damage:undefined var
Legacy of Lukai, The Secrets Within.dm:23:error:damage:undefined var
Legacy of Lukai, The Secrets Within.dm:21:error:src.def:undefined var
Legacy of Lukai, The Secrets Within.dm:22:error:src.health:undefined var
Legacy of Lukai, The Secrets Within.dm:24:error:src.DeathCheck:undefined proc
The errors were due to the fact that you were referencing mob variables under atom, where they do not exist.

This is the problem:
atom
Click()
switch(type)
if(/mob)


Move the Click() proc under mob, and take out the switch an if statements, restructuring accordingly. Also "set src" is meaningless under Click(), as it is for verbs. Furthermore, you can not set it condtionally (under an "if" statement).

There may be more problems... I only had time to skim through.
Delita12345 wrote:
could someone tell me how to make this shorter? It just seems there's a more elegant way to do this.
client
North()
South()
East()
West()
Northwest()
Northeast()
Southwest()
Southeast()

You should be able to just override client.Move() for the same effect with 7 less lines.

client
Move()

atom
Click()

I get these errors with the switch statement up top:
Legacy of Lukai, The Secrets Within.dm:21:error:damage:undefined var
Legacy of Lukai, The Secrets Within.dm:22:error:damage:undefined var
Legacy of Lukai, The Secrets Within.dm:23:error:damage:undefined var
Legacy of Lukai, The Secrets Within.dm:21:error:src.def:undefined var
Legacy of Lukai, The Secrets Within.dm:22:error:src.health:undefined var
Legacy of Lukai, The Secrets Within.dm:24:error:src.DeathCheck:undefined proc

Overide mob.Click() instead of atom.Click()
mob
Click()
/* the : operator will get you in trouble, use this to
avoid the colon and to make sure usr is a player */

var/mob/player/P = usr
if(!istype(P)) // if P isn't really a /mob/player
return

// set src has no effect in Click()
if(get_dist(usr,src)<=1) // use this to check range
if (P.attack == 1)
var/damage = P.str - src.def
src.health -= damage
P << "You damage [src] for [damage] health!"
src.DeathCheck()
P.attack = 0
/* you have this next statement in both parts of the if,
since it happens either way, just take it outside the if branches */

P.client.mouse_pointer_icon = null


Since you are using def, health and DeathCheck() with a bse mob type, they should be defined for all mobs, not just /mob/player. (You may want to move other vars to the parent mob type also. I'm just fixing the code I see, not guessing your intent.)
mob
var
def = 2
health = 10
proc
DeathCheck()
if(src.health <= 0)
world << "[src] was killed!"
del(src)

player
var
str = 5
move = 0
attack = 0
icon = 'player.dmi'

obj
hud
layer = MOB_LAYER + 1
icon = 'hud.dmi'

// brought these to /obj/hud since they are shared behavoir
Click()
usr.client.mouse_pointer_icon = icon('mouse.dmi',icon_state)

New(client/C)
C.screen += src

move
icon_state = "walk_to"
screen_loc = "1,1" // I moved this out of New()
Click()
..() // do the /obj/hud Click() stuff
/* this colon is troublesome, either make move a basic
mob var or check to make absolutely sure that usr
is a /mob/player */

usr:move = 1

attack
// see my notes for /obj/hud/move above
icon_state = "attack"
screen_loc = "2,1"
Click()
..()
usr:attack = 1

client/New()
..()
new/obj/hud/move(src)
new/obj/hud/attack(src)