ID:1587988
 
(See the best response by Ssj4justdale.)
Problem description:
My projectile system only recognizes the default Range(8). I can't get it to override (when no Range has been specified) the default range, and change it to the range of the actual obj being used. Can somebody tell me where I am going wrong about this?

Also, any other inefficiencies or ways to enhance the code down below would be appreciated.

Thanks

Projectile
parent_type = /obj

density = 1
layer = MOB_LAYER+2

var

Range = 8

Bump(atom/A)

if(A.density)
Null_Projectile(src)

if(ismob(A))
Null_Projectile(src)
A.overlays += image('Explosion.dmi',icon_state="",layer=EFFECTS_LAYER)
sleep(5)
A.overlays -= image('Explosion.dmi',icon_state="",layer=EFFECTS_LAYER)

proc

Null_Projectile(obj/A)
A.icon = null
A.loc = null

Skill(var/mob/M, _Skill, Range)
Range = src.Range
world<<Range
var/Path = text2path("/Projectile/[_Skill]")

if(!Path)return

var/obj/Skill = new Path(M.loc)

switch(M.dir)
if(NORTH)
Skill.dir = turn(Skill.dir,-180)
Skill.icon = turn(Skill.icon,-180)
if(SOUTH)
Skill.dir = turn(Skill.dir,0)
Skill.icon = turn(Skill.icon,0)
if(WEST)
Skill.dir = turn(Skill.dir,-90)
Skill.icon = turn(Skill.icon,-90)
if(EAST)
Skill.dir = turn(Skill.dir,90)
Skill.icon = turn(Skill.icon,90)

for(var/Travelled=0, Travelled<Range, Travelled++)
step(Skill,Skill.dir)
sleep(1)

Null_Projectile(Skill)

FireBall
icon='Fireball.dmi'
Range = 3

mob/proc
Skill(var/mob/M, _Skill, Range)
var/Projectile/projectile = new
projectile.Skill(M,_Skill,Range)

mob/verb
Fireball()
Skill(usr,"FireBall")
I'll comment everything I altered and explain it to you on why.
Projectile
parent_type = /obj

density = 1
layer = MOB_LAYER+2

var

Range = 8 //I'm assuming this will say what the range should be?

Bump(atom/A)

if(A.density)
Null_Projectile(src)

if(ismob(A))
Null_Projectile(src)
A.overlays += image('Explosion.dmi',icon_state="",layer=EFFECTS_LAYER)
sleep(5)
A.overlays -= image('Explosion.dmi',icon_state="",layer=EFFECTS_LAYER)

proc

Null_Projectile(obj/A)
A.icon = null
A.loc = null

Skill(var/mob/M, var/_Skill) //umm why have range defined up here if you are going to alter it below? (I prefer some vars)
//Range = src.Range //like right here? - no need to set the range if it is just going to make it the skills range.
//I belive you meant to do src.Range=Range, but idk, so i just removed it
world<<Range //tells the world the range
var/Path = text2path("/Projectile/[_Skill]")

if(!Path)return

var/obj/Skill = new Path(M.loc)

switch(M.dir)
if(NORTH)
Skill.dir = turn(Skill.dir,-180)
Skill.icon = turn(Skill.icon,-180)
if(SOUTH)
Skill.dir = turn(Skill.dir,0)
Skill.icon = turn(Skill.icon,0)
if(WEST)
Skill.dir = turn(Skill.dir,-90)
Skill.icon = turn(Skill.icon,-90)
if(EAST)
Skill.dir = turn(Skill.dir,90)
Skill.icon = turn(Skill.icon,90)

for(var/Travelled=0, Travelled<Range, Travelled++)
step(Skill,Skill.dir)
sleep(1)

Null_Projectile(Skill)

FireBall
icon='Fireball.dmi'
Range = 3

mob/proc
Skill(var/mob/M, var/_Skill) //the whole Range thing is redundant because it does nothing due to your code, i removed it.
var/Projectile/projectile = new
projectile.Skill(M,_Skill) //same as what I said above.

mob/verb
Fireball()
Skill(usr,"FireBall")
    var

Range = 8 //I'm assuming this will say what the range should be?


This is actually what the default Range would be for any projectile which doesn't already have it's range preset

I am trying to override the default Range for something like Fireball, which already has a preset Range of 3 and use that instead.
This is the code if you want to be able to override it.

Example:
Skill(src,_Skill,21) //to allow it to go 21 spaces


Here is the code
Projectile
parent_type = /obj

density = 1
layer = MOB_LAYER+2

var

Range = 8

Bump(atom/A)

if(A.density)
Null_Projectile(src)

if(ismob(A))
Null_Projectile(src)
A.overlays += image('Explosion.dmi',icon_state="",layer=EFFECTS_LAYER)
sleep(5)
A.overlays -= image('Explosion.dmi',icon_state="",layer=EFFECTS_LAYER)

proc

Null_Projectile(obj/A)
A.icon = null
A.loc = null

Skill(var/mob/M, var/_Skill, var/_Range)
//Range = src.Range //lets switch these
if(_Range>0)src.Range = _Range //I'm sure if the Range is 0, it should be set to the default.
world<<Range
var/Path = text2path("/Projectile/[_Skill]")

if(!Path)return

var/obj/Skill = new Path(M.loc)

switch(M.dir)
if(NORTH)
Skill.dir = turn(Skill.dir,-180)
Skill.icon = turn(Skill.icon,-180)
if(SOUTH)
Skill.dir = turn(Skill.dir,0)
Skill.icon = turn(Skill.icon,0)
if(WEST)
Skill.dir = turn(Skill.dir,-90)
Skill.icon = turn(Skill.icon,-90)
if(EAST)
Skill.dir = turn(Skill.dir,90)
Skill.icon = turn(Skill.icon,90)

for(var/Travelled=0, Travelled<Range, Travelled++)
step(Skill,Skill.dir)
sleep(1)

Null_Projectile(Skill)

FireBall
icon='Fireball.dmi'
Range = 3

mob/proc
Skill(var/mob/M, var/_Skill, var/_Range)
var/Projectile/projectile = new
projectile.Skill(M,_Skill,_Range)

mob/verb
Fireball()
Skill(usr,"FireBall")


Please broaden what you want so I can assist further.
Oh Okay, is ee what you mean. Well what you are doing is wrong. I'l correct it for you.
I'm going to alter the whole code because a lot of it is pointless. If you don't mind.
It's ok. I just want to be headed in the right direction.
Just out of curiousity, why do you have it set where a "Projectile" is created, just for that "projectile" to create another?

If you don't know, I'll just change a lot of stuff and document it all :)
You mean here?
mob/proc
Skill(var/mob/M, _Skill, Range)
var/Projectile/projectile = new
projectile.Skill(M,_Skill,Range)


If so, because I want to call the Skill() proc of the Projectile datum
It makes sense there, but then under the Skill proc for the projectile, it just creates another, I don't get the purpose.
THis one
Skill(var/mob/M, _Skill, Range)
Range = src.Range
world<<Range
var/Path = text2path("/Projectile/[_Skill]")

if(!Path)return

var/obj/Skill = new Path(M.loc)
I'm defining a obj and giving it the Path I previously found
I just find that process redundant since the original projectile was already created, you could just make that the original object created.

This will result in 1 object created for the skill and get the same process's done rather than 2 objects created per skill.
You could just do this:

mob/proc
Skill(var/mob/M, _Skill, Range)
var/Projectile/projectile = text2path("/Projectile/[_Skill]")
if(!ispath(projectile))return
projectile = new projectile
projectile.Skill(M)
Anyway, here is my altered code. It is untested and I will test it now.

Projectile
parent_type = /obj

density = 1
layer = MOB_LAYER+2

var

Range = 8

Bump(atom/A)

if(A.density)
Null_Projectile(A) //this will get rid of the projectile and do what it needs to with the thing it collided with

if(ismob(A))
Null_Projectile(A)
//A.overlays += image('Explosion.dmi',icon_state="",layer=EFFECTS_LAYER)
//sleep(5)
//A.overlays -= image('Explosion.dmi',icon_state="",layer=EFFECTS_LAYER) --moved to the projectiles Null_Projectile code.

proc

Null_Projectile(atom/A)//obj/A) -- if it's going to effect this object, why bother with the arguments in (), I changed it to be whoever it collided with so you can
//A.icon = null -- replaced with below
//A.loc = null -- replaced with below
src.icon = null
src.loc = null
if(A) //if 'A' was found.
A.overlays += image('Explosion.dmi',icon_state="",layer=EFFECTS_LAYER)
sleep(5)
A.overlays -= image('Explosion.dmi',icon_state="",layer=EFFECTS_LAYER)
del(src) //deletes it from existence to prevent stockpile of objects in the world.

Skill(var/mob/M)//, _Skill, Range) -- since we already created the object, we don't need to define _Skill and Range to create another, REDUNDANT
//Range = src.Range -- pointless if the range is going to be the the objects default range.
world<<Range
//var/Path = text2path("/Projectile/[_Skill]") -- pointless, the skill was created elsewere

//if(!Path)return -- pointless, the skill was created elsewhere.

//var/obj/Skill = new Path(M.loc) dont need this
var/obj/Skill = src //I'm too lazy to alter every Skill here.

switch(M.dir)
if(NORTH)
Skill.dir = turn(Skill.dir,-180)
Skill.icon = turn(Skill.icon,-180)
if(SOUTH)
Skill.dir = turn(Skill.dir,0)
Skill.icon = turn(Skill.icon,0)
if(WEST)
Skill.dir = turn(Skill.dir,-90)
Skill.icon = turn(Skill.icon,-90)
if(EAST)
Skill.dir = turn(Skill.dir,90)
Skill.icon = turn(Skill.icon,90)

for(var/Travelled=0, Travelled<Range, Travelled++)
step(Skill,Skill.dir)
sleep(1)

Null_Projectile()

FireBall
icon='Fireball.dmi'
Range = 3

mob/proc
Skill(var/mob/M, _Skill, Range)
var/Projectile/projectile = new
projectile.Skill(M,_Skill,Range)

mob/verb
Fireball()
Skill(usr,"FireBall")
Hm. Interesting
It appears that using this:
mob/proc
Skill(var/mob/M, _Skill, Range)
var/Projectile/projectile = text2path("/Projectile/[_Skill]")
if(!ispath(projectile))return
projectile = new projectile
projectile.Skill(M)

Returns the skill's actual range, instead of the default.

I am currently trying to see how I can put 2 and 2 together
Alright.

Thanks for the help! Ssj4justdale!

I've got it down with:
Projectile
parent_type = /obj

density = 1
layer = MOB_LAYER+2

var Range = 8

Bump(atom/A)

if(A.density)
Null_Projectile(src)

if(ismob(A))
Null_Projectile(src)

proc

Null_Projectile(atom/A)
src.icon = null
src.loc = null

if(A)
var/image/Explosion = image('Explosion.dmi',icon_state="",layer=EFFECTS_LAYER)
A.overlays += Explosion
sleep(5)
A.overlays -= Explosion

Skill(var/mob/M,src)

world<<Range
var/obj/Skill = src
switch(M.dir)

if(NORTH)
Skill.dir = turn(Skill.dir,-180)
Skill.icon = turn(Skill.icon,-180)
if(SOUTH)
Skill.dir = turn(Skill.dir,0)
Skill.icon = turn(Skill.icon,0)
if(WEST)
Skill.dir = turn(Skill.dir,-90)
Skill.icon = turn(Skill.icon,-90)
if(EAST)
Skill.dir = turn(Skill.dir,90)
Skill.icon = turn(Skill.icon,90)

for(var/Travelled=0, Travelled<Range, Travelled++)
step(Skill,Skill.dir)
sleep(1)

Null_Projectile(Skill)

FireBall
icon='Fireball.dmi'
Range = 10

mob/proc
Skill(var/mob/M, _Skill, Range)
var/Projectile/projectile = text2path("/Projectile/[_Skill]")
if(!ispath(projectile))return
projectile = new projectile(M.loc)
projectile.Skill(M,projectile)

mob/verb
Fireball()
Skill(usr,"FireBall")
Best response
Well I forgot something in there.

This one was tested and works 100%.

Projectile
parent_type = /obj

density = 1
layer = MOB_LAYER+2

var

Range = 8

Bump(atom/A)
if(ismob(A))
Null_Projectile(A)
else Null_Projectile()
proc
Null_Projectile(atom/A)//obj/A) -- if it's going to effect this object, why bother with the arguments in (), I changed it to be whoever it collided with so you can
//A.icon = null -- replaced with below
//A.loc = null -- replaced with below
src.icon=null
src.loc=null
if(A)
A.overlays += image('Explosion.dmi',icon_state="",layer=EFFECTS_LAYER)
sleep(5)
A.overlays -= image('Explosion.dmi',icon_state="",layer=EFFECTS_LAYER)
sleep(10)
del(src) //deletes it from existence to prevent stockpile of objects in the world.

Skill(var/mob/M)//, _Skill, Range) -- since we already created the object, we don't need to define _Skill and Range to create another, REDUNDANT
//Range = src.Range -- pointless if the range is going to be the the objects default range.
world<<Range
//var/Path = text2path("/Projectile/[_Skill]") -- pointless, the skill was created elsewere

//if(!Path)return -- pointless, the skill was created elsewhere.

//var/obj/Skill = new Path(M.loc) dont need this
var/obj/Skill = src //I'm too lazy to alter every Skill here.
Skill.loc=M.loc

switch(M.dir)
if(NORTH)
Skill.dir = turn(Skill.dir,-180)
Skill.icon = turn(Skill.icon,-180)
if(SOUTH)
Skill.dir = turn(Skill.dir,0)
Skill.icon = turn(Skill.icon,0)
if(WEST)
Skill.dir = turn(Skill.dir,-90)
Skill.icon = turn(Skill.icon,-90)
if(EAST)
Skill.dir = turn(Skill.dir,90)
Skill.icon = turn(Skill.icon,90)

for(var/Travelled=0, Travelled<Range, Travelled++)
step(Skill,Skill.dir)
sleep(1)

Null_Projectile()

FireBall
icon='Fireball.dmi'
Range = 3

mob/proc
Skill(var/mob/M,var/_Skill)
var/Projectile/projectile = text2path("/Projectile/[_Skill]")
if(!ispath(projectile))return
projectile = new projectile
projectile.Skill(M)

mob/verb
Fireball()
Skill(usr,"FireBall")
And alright, you can use mine or stick with yours but okay :)
Page: 1 2