ID:882117
 
(See the best response by Robertbanks2.)
I've been using a beam code from the BYOND resources, the laser one, and im having some trouble with it.



obj
beam
icon = 'Alphabet.dmi'
icon_state = "B"
layer = 100
density = 0
Bump(A)
if(istype(A,/turf/))
var/turf/T = A
if(T.density)
del(src)
if(istype(A,/obj/))
del(src)
Move()
for(var/mob/M in src.loc)
var/damage = src.Str
M.HP -= damage
if(M.HP <= 0)
world << "[M] has been slain"
del(M)
else
world <<"[M] got hit for [damage] damage!"

var/K = new/obj/Tail(src.loc)

K:dir = src.dir
..()



I am just starting to learn and would appreciate the help, the var/damage with a digit is fine, works perfect but im trying to get the damage to be the strength of the player. var/damage = 20 works but var/damage = src.Str does not. Can anybody help me please I think it is an easy fix but I dont understand enough yet maybe somebody could explain. Thank you
well first most likely you would want to use the persons strenght who is casting the beam. Src in this case is the beam and well most likely the beam doesnt have a strenght variable. When the beam is cast I would make a variable named owner and make it equal usr. Basically then you can write damage = owner.str.

Hope that helps any.

EDIT :
Which library are you using ? It shouldnt be using : sign. instead it should be a dot. It might give an error since K doesnt have a defined type.
ok so an obj var called owner linking it to the usr? Is that what you mean?

EDIT:
Also, could you maybe show me what you mean? im a little confused

No. A mob type variable linking to the usr.

like :

var/mob/owner = usr

I used var/mob instead of mob/var because my way specifies the type of the variable which will hold a mob and the other way just specifies a variable which will hold things related to mobs. Also my way it a global variable which can be accessed easy
In response to Dj dovis
Dj dovis wrote:
No. A mob type variable linking to the usr.

like :

> var/mob/owner = usr
>


This is generally bad practice. You would be better off just saving whatever value you want it to use or the user's key and going from there. I don't think it really presents an issue in this situation, but it's a bad habit to get into. Saving direct references to a player's mob can cause all sorts of rollback issues, and it's best to err on the side of caution.
oh i see. after adding that I still get this:

runtime error: Cannot read 0.Str
proc name: Move (/obj/beam/Move)
source file: Skill System.dm,30
usr: 0
src: Guest-3082693870 (/obj/beam)
call stack:
Guest-3082693870 (/obj/beam): Move(Grass (17,17,1) (/turf/General/Grass), 1)



obj
beam
icon = 'Alphabet.dmi'
icon_state = "B"
layer = 100
density = 0
Bump(A)
if(istype(A,/turf/))
var/turf/T = A
if(T.density)
del(src)
if(istype(A,/obj/))
del(src)
Move()
for(var/mob/M in src.loc)
var/mob/owner = usr
var/damage = owner.Str
M.HP -= damage
M.DamageShow(damage,200,0,0) //flashes the damage on the screen
if(M.HP <= 0)
world << "[M] has been slain"
del(M)
else
world <<"[M] got hit for [damage] damage!"

var/K = new/obj/Tail(src.loc)

K:dir = src.dir
..()


mob
verb
Shoot_Peircing_Beam()
var/obj/beam/K = new /obj/beam
if(src.dir == NORTH)
K.loc = locate(usr.x,usr.y+1,usr.z)
if(src.dir == SOUTH)
K.loc = locate(usr.x,usr.y-1,usr.z)
if(src.dir == EAST)
K.loc = locate(usr.x+1,usr.y,usr.z)
if(src.dir == WEST)
K.loc = locate(usr.x-1,usr.y,usr.z)
K.dir = usr.dir
K.name=usr.name

walk(K,usr.dir,2)
spawn(16)
del(K)


try logging into the pager
In response to N64izzle
An obj's Move() proc doesn't have a usr, you have to set the variables at the time of creation.
same thing

runtime error: Cannot read 0.Str
proc name: Move (/obj/beam/Move)
source file: Skill System.dm,32
usr: 0
src: N64izzle (/obj/beam)
call stack:
N64izzle (/obj/beam): Move(Grass (17,16,1) (/turf/General/Grass), 1)
im using lasor source not DBZ
well for one thing you shouldnt initiate the var inside the move proc since it has no user lol . Sorry I didnt tell you before since I didnt look at your code before I posted that.
Best response
I very seriously doubt that. Regardless, see the "usr: 0"? You're reference a usr that doesn't exist because a usr is a client's mob, and an obj doesn't have that. You have to pass the user into the beam's New() proc and set things there. If you can't handle that, go do some proper tutorials instead of screwing around with the worst sources you can find.
In response to Robertbanks2
+1 on that