ID:177478
 
ive looked at some demos and ive tried writing an attack sequence myself but I keep getting hung up in the same spot I can not make my enemies walk over and attack a character could someone help please
//attack trial start

mob/romulan

icon = 'person.dmi'
icon_state = "romulan"
cl = -1
hp = 5




//for testing purposes only
verb/check_health()
set src in oview(5)
usr << "[src.hp]"
usr << "[usr.hp]"
//delete after engine is done


proc/isDead()
if (hp <=0)
icon_state = "deadrom"
density = 0
sleep(1000)
icon_state = "romulan"
src.hp += 5
return 1
return 0





Move()
if(isDead())

return 0
return ..()




New()
walk_rand(src,50)

return ..()

this is what I have now ive tried a number of ways to do this what I wanted was the romulan to fire a projectile towards the player and the player to be able to fire back
please help
ok so first things first my projectile is not working I thought this would draw a phaserbeam and move it in the direction that im faceing but it just puts the beam in my inventory. why?
obj
phaser
icon = 'phaser.dmi'
icon_state = "phaser"
verb/fire_phaser()
new /obj/phaserbeam(src.x,src.y,src.z)
walk(/obj/phaserbeam,src.dir,10)
obj/phaserbeam

icon = 'projectile.dmi'
icon_state = "phaser"
name = "phaserbeam"
density = 1
In response to Treasurecat
Treasurecat wrote:

verb/fire_phaser()
new /obj/phaserbeam(src.x,src.y,src.z)
walk(/obj/phaserbeam,src.dir,10)

This is your problem. First of all, you should use src.loc, or locate(src.x, src.y, src.z). Second, src is the object, you want usr, which is the mob who activated the verb. Third, you gotta define a var. So, var/obj/phaserbeam/P = new(usr.loc), then you can refer to the phaserbeam as P.
In response to Garthor
Garthor wrote:
Treasurecat wrote:

verb/fire_phaser()
new /obj/phaserbeam(src.x,src.y,src.z)
walk(/obj/phaserbeam,src.dir,10)

This is your problem. First of all, you should use src.loc, or locate(src.x, src.y, src.z). Second, src is the object, you want usr, which is the mob who activated the verb. Third, you gotta define a var. So, var/obj/phaserbeam/P = new(usr.loc), then you can refer to the phaserbeam as P.

ok I dont know what you mean with the last sugestion I tried adding that under the obj/phaserbeam but it gave me an error about the new(usr.loc) being incorrect also I changed all the src. to usr. and it stopped putting the beam in my inventory however its not drawing the beam next to the usr like I want
so this is what my code looks like so far
obj
phaser

icon = 'phaser.dmi'
icon_state = "phaser"
verb/fire_phaser()
new /obj/phaserbeam(usr.x,usr.y,usr.z)
walk(/obj/phaserbeam,usr.dir,10)
obj/phaserbeam

icon = 'projectile.dmi'
icon_state = "phaser"
name = "phaserbeam"
density = 1

how am I supposed to use this
var/obj/phaserbeam/P = new(usr.loc)
and where am I supposed to put it?

thanks
In response to Treasurecat
If you're after a projectile system, then give my War_Demo a whirl. It sounds like that's what you're after, so feel free to rip/tear/shred out the code from my demo and plop it in your game. ;)
In response to Treasurecat
Just do var/obj/phaserbeam/P = new(locate(usr.x,usr.y,usr.z)

Then, whenever you use P, it's referring to the new /obj you created.
In response to Malver
thanks guys
my phaser is firing now but I dont know how to have it cause damage when it hits a romulan ive looked through the war demo and I cant find that part of the code I guess im still to new to recognize it.

//phaser trial
obj
phaser
icon = 'phaser.dmi'
icon_state = "phaser"
verb/fire_phaser()
var/obj/phaserbeam/P = new(locate(usr.x,usr.y,usr.z))

walk(P,usr.dir,1)
obj/phaserbeam

icon = 'projectile.dmi'
icon_state = "phaser"
name = "phaserbeam"
density = 1



mob/romulan

icon = 'person.dmi'
icon_state = "romulan"
cl = -1
hp = 5




//for testing purposes only
verb/check_health()
set src in oview(5)
usr << "[src.hp]"
usr << "[usr.hp]"
//delete after engine is done


proc/isDead()
if (hp <=0)
icon_state = "deadrom"
density = 0
sleep(1000)
icon_state = "romulan"
src.hp += 5
return 1
return 0





Move()
if(isDead())

return 0
return ..()




New()
walk_rand(src,50)

return ..()

how can I damage the romulan when the beam hits him?
again thanks for your help.

also if you see something in my code that I should add or change please let me know
In response to Treasurecat
I would recommend searching each turf that the phaser enters for mobs.

turf/Enter(obj/Phaser/P)
if(!istype(P, /obj/Phaser))
return ..()
var/mob/M = locate(M) in src
if(!M)
return TRUE
M.hp -= 50 // Or whatever value
del(P) // Destroy the projectile

In response to Malver
That'd work, except it should be phaserbeam, not Phaser.
In response to Malver
turf/Enter(obj/phaserbeam/P)


if(!istype(P, /obj/phaserbeam))
return ..()
var/mob/M = locate(M) in src
if(!M)
return TRUE
M.hp -= 5 // Or whatever value
del(P) // Destroy the projectile

ok im getting the error that M is undefined var I tried making a var but it wont recognize it as obj/romulan is there a certain class im supposed to link the var to and what should the var say? var /obj/romulan = M

thank you
In response to Treasurecat
Try just locate() in src, or locate(mob) in src.
In response to Treasurecat
Treasurecat wrote:
turf/Enter(obj/phaserbeam/P)


if(!istype(P, /obj/phaserbeam))
return ..()
var/mob/M = locate(M) in src
if(!M)
return TRUE
M.hp -= 5 // Or whatever value
del(P) // Destroy the projectile

ok im getting the error that M is undefined var I tried making a var but it wont recognize it as obj/romulan is there a certain class im supposed to link the var to and what should the var say? var /obj/romulan = M

thank you

My mistake on that part. I was taking a gamble on using locate() there, which I shouldn't of. Let's try replacing what I gave you with this revised snippet:

turf/Enter(obj/phaserbeam/P)
if(!istype(P, /obj/phaserbeam))
return ..()
var/mob/romulan/M
for(M in src)
M.hp -= 5
del(P)
return FALSE

Sorry for the troubles with that. I hope that that code works out for you.
In response to Treasurecat
ok here is what Ive got so far
obj
phaser
icon = 'phaser.dmi'
icon_state = "phaser"
verb/fire_phaser()
var/obj/phaserbeam/P = new(locate(usr.x,usr.y,usr.z))

walk(P,usr.dir,1)


turf/Enter(obj/phaserbeam/P)
if(!istype(P, /obj/phaserbeam))
return ..()
var/mob/romulan/M
for(M in src)
M.hp -= 5
del(P)
return FALSE

now the prblem is that the del command is deleting my phaserbeam befor it gets a chance to hit anyone how can I fix this? the code seems to also negate the walk command making the phaserbeam just sit there. I dont know what part of the code does this.
In response to Treasurecat
The...


if(!istype(P, /obj/phaserbeam))
return ..()

shouldn't be there,

Basically, the whole proc should be...

turf/Enter(obj/phaserbeam/P)
if(istype(P,obj/phaserbeam)
for(var/mob/romulan/M in src)
if(istype(M,/mob/romulan)
M.hp -= 5
del(P)
return FALSE
return ..()

[edit] oops.
In response to Malver
Wouldnt it be better to have it use Bump() to check if the phaserbeam is bumping into a mob.
Something like:
obj
Bump(O)
if(istype(src, /obj/phaserbeam) && istype(O, /mob) //This checks to see if the obj calling Bump() is a phaserbeam and (&&) the thing its bumping into is a mob.
//Insert your damge code.
return //End the Proc
else //If it hit something that was dense, but not a mob (Ie, a wall) it will delete the phaserbeam.
del(src)
return //End the proc
The Bump() proc is very useful when used with istype(), you should read up on them in the help files.
-DogMan
In response to Dog Man
I am aware of the Bump() procedure, but I just never really liked it for projectile systems. One of my biggest gripes about it is that it removes the ability (or at least makes it more difficult) to create dense surfaces that the projectile can pass through, such as water.

Feel free to make use of my code, or wave it off if you want. Whatever suits you.
In response to Garthor
Garthor wrote:
The...


if(!istype(P, /obj/phaserbeam))
return ..()

shouldn't be there,

Basically, the whole proc should be...

turf/Enter(obj/phaserbeam/P)
for(var/mob/romulan/M in src)
if(istype(M,/mob/romulan)
M.hp -= 5
del(P)
return FALSE
return ..()

Uhm.

Actually, it should be. Just because you specified 'obj/phaserbeam' doesn't mean that it only calls the Enter() proc if that type of object enters. Such a istype() check is needed to avoid nasty errors if other objects happen to enter.
In response to Treasurecat
Treasurecat wrote:
now the prblem is that the del command is deleting my phaserbeam befor it gets a chance to hit anyone how can I fix this? the code seems to also negate the walk command making the phaserbeam just sit there. I dont know what part of the code does this.

The code for a moving projectile (and deleting it upon striking a mob) is all in the demo that I supplied you with. Just look through it, or even just copy the firing portion of it. It may take a few moments to clearly identify what's what, but I think you're smart enough to figure it out. :)
In response to Malver
turf
Water
Enter(O)
if(O.CanCrossWater) return 1
else return 0
Page: 1 2