ID:152485
 
Ok so I made a clicking system for my game. Well kind of not everything works with clicks,but almost everything here is a small sample its what happens when you click on a mob. This works exactly like I want it to, but since I haven't been coding very long(a couple years) I wanted some proffesional advice and or opions about this code. I also wanted to know if I made any major mistakes. Also tell me what you think of the attack system.

mob
Click()
if(istype(src,/mob/shopkeeper))return //check if it's a shopkeeper
else if(istype(src,/mob))//make sure it is a mob
if(usr==src)//if it is and its you
if(src.veh)//and your in a vehicle
if(usr.car)//thats a car
var/obj/v=text2path("/obj/vehicles/cars/[usr.veh]")
var/obj/C=new v
C.dir=usr.dir
C.loc=usr.loc
C.icon_state=usr.vehi
usr.icon='pc.dmi'
usr.icon_state=""
usr.veh=null
usr.vehi=null
usr.car=0
else if(usr.boat)//if not a car than a boat
var/obj/v=text2path("/obj/vehicles/boats/[usr.veh]")
var/obj/C=new v
C.dir=usr.dir
C.loc=usr.loc
C.icon_state=usr.vehi
usr.icon='pc.dmi'
usr.icon_state=""
usr.veh=null
usr.vehi=null
usr.boat=0
else//if you arn't in a vehicle
return
else//if its not you
if(!src.veh)//and they arn't in a vehicle
if(usr.wept=="Gun")//if your weapon is a gun
if(src in oview(1))//if they are next to you bash them in the head(Woo hoo!)
var/dmg = round((usr.att+usr.weppwr)-(src.aura))
if(dmg<=0)
s_damage(src,0,"red")
src << "[usr] bashes you in the head with his [usr.weapon] for 0!!"
usr<<"You bash [src] in the head with your [usr.weapon] for 0!!"
else
src.hp -= dmg
s_damage(src,dmg,"red")
src << "[usr] bashes you in the head with his [usr.weapon] for[dmg]!!"
usr<<"You bash [src] in the head with your [usr.weapon] for [dmg]!!"
dcheck(src,usr)
else//if they arn't next to you shoot them
if(!usr.fired)
if(usr.ammo)
var/obj/H=text2path("/obj/wep/gun/Bullet/[usr.weapon]")
fire(usr,src,H)
usr.ammo-=1
usr.fired=1
sleep("[usr.frate]")
usr.fired=0
else
usr<<"Your Out Of Ammo......"
else//if you are not carrying a gun hit them
if(src in oview(1))
var/dmg = round((usr.att+usr.weppwr)-(src.aura))
if(dmg<=0)
s_damage(src,0,"red")
src << "[usr] attacks you for 0!!"
usr<<"You attack [src] for 0!!"
else
src.hp -= dmg
s_damage(src,dmg,"red")
src << "[usr] attacks you for[dmg]!!"
usr<<"You attack [src] for [dmg]!!"
dcheck(src,usr)


PS.I'm not sure if this is the right forum so if it isn't don't say anything.
Pretty sure it belongs in Design Philosophy. :P If we didn't say anything then people would be getting confused all the time and it'd be annoying for everyone else, so sorry! I am too tired to look at the programming right now, too.

-Exophus
Yep, Exophus is right, this belonged in DP. Moved.

One thing I can determine right off the bat is that your equipment system is set up wrong. Your vars like weapon and veh are only keeping track of the name of the object in use, but not the object itself. For that matter, if you do this correctly then the car var should belong to the vehicle itself, not the mob. E.g.:
if(usr.veh) usr.ExitVehicle()  // a separate proc should handle this

// then later:
mob/proc/EnterVehicle(obj/V)
if(!V || !(V in range(1,src))) return
if(veh) ExitVehicle()
var/am = animate_movement
animate_movement = 0
loc = V.loc
dir = V.dir
V.loc = null
icon = IconInVehicle(src, V) // define this proc on your own
veh = V
animate_movement = am

mob/proc/ExitVehicle()
if(!veh) return // sanity check
if(veh.iscar)
veh.dir = dir
veh.loc = loc
icon = initial(icon) // or you can store the old icon in a var
icon_state = ""
veh = null

Similarly with the gun you need to keep track of the object itself, not the name of it.

Lummox JR