ID:177462
 
proc/firePhaser()
if (usr in view(5))

wouldnt this be the correct way to have a npc to do something if within view of A usr?
Treasurecat wrote:
proc/firePhaser()
if (usr in view(5))

wouldnt this be the correct way to have a npc to do something if within view of A usr?

Close: You should use oview(5,src). view() will center itself on usr unless you specify otherwise.

Also, since you're in a proc, I'd avoid usr here, even if this is being called from a verb. (And if it's not being called by a verb, then this is a bad, bad thing.) Instead, I'd do this:
proc/firePhaser(atom/target)
if(target in view(5,src))
...

And if you were calling it from a verb, just call it with firePhaser(usr). Overall this is a lot safer.

Lummox JR
In response to Lummox JR
mob/romulan

icon = 'person.dmi'
icon_state = "romulan"
cl = -1
hp = 5
var mob/romulan/M

proc/firePhaser(atom/target)
if (target in view(5,src))
usr << "your shot"

return 0

do me a favor and look at this code. for some reason this proc wont work
In response to Treasurecat
Treasurecat wrote:
proc/firePhaser(atom/target)
if (target in view(5,src))
usr << "your shot"

return 0

do me a favor and look at this code. for some reason this proc wont work

Well, you didn't change usr, which I assume is the target of the shot, to target. Aside from that, you didn't show how this is being called.

Lummox JR
In response to Lummox JR
mob/romulan

icon = 'person.dmi'
icon_state = "romulan"
cl = -1
hp = 5
var mob/romulan/M

proc/firePhaser(atom/target)
while(src)
for(var/mob/romulan/M in view(5,src))
if (target in view(5,src))
usr << ""

return 0`

im sorry I dont know what you mean by "change usr"
I thought the proc() would start the loop as soon as the usr was within view.
please help
thanks
In response to Treasurecat
Treasurecat wrote:
im sorry I dont know what you mean by "change usr"
I thought the proc() would start the loop as soon as the usr was within view.

A loop won't start unless you tell it to start. while(src) shouldn't do much of anything.

What I mean by changing usr is that usr isn't valid in a proc, as I told you, unless that proc is being called directly by a verb. I think you mean when the player comes into view, and that's not necessarily the same as usr.

Lummox JR
In response to Lummox JR
Lummox JR wrote:
Treasurecat wrote:
im sorry I dont know what you mean by "change usr"
I thought the proc() would start the loop as soon as the usr was within view.

A loop won't start unless you tell it to start. while(src) shouldn't do much of anything.

What I mean by changing usr is that usr isn't valid in a proc, as I told you, unless that proc is being called directly by a verb. I think you mean when the player comes into view, and that's not necessarily the same as usr.

Lummox JR

what do I need to do to start this loop then ? I thought that usr << would just type the text for that usr
I changed it to this
proc/firePhaser(atom/target)
if (target in view(5,src))
target << ""

return 0
but it still does not work as for the while. that was somethig I was trying from a demo I just miss applied it but it was worth a shot.
In response to Treasurecat
He's saying procs don't automatically run. You have to call them to make them run. Just because you make a proc doesn't mean it's automatically called.

usr isn't "the player", either. usr is only the player in verbs. You have to find some other way of referencing the player.
In response to WizDragon
WizDragon wrote:
He's saying procs don't automatically run. You have to call them to make them run. Just because you make a proc doesn't mean it's automatically called.

ok how do I call a proc()
im confused because this worked
proc/isDead()

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

return 1

usr isn't "the player", either. usr is only the player in verbs. You have to find some other way of referencing the player.

ok im strikeing usr from my vocabulary while writing this proc. I think I uderstand this
thanks
In response to Treasurecat
Think of it like this: a proc is a command you're giving DM. When you make new procs, you're making up new commands. Commands aren't any good, however, if you don't give them. What you were doing with the firePhaser() proc is making it up and then never using it. That would be like if you invented the word "sit" and expected people to sit down just because you invented it. Obviously, it doesn't work. Calling procs is like giving commands. If you don't call it, it won't happen.

The only way you're really going to accomplish this is with a loop of some sort. Many demos show how to handle AI loops. Look up some basic combat in the Demos section. I believe Deadron has a simple combat demo.
In response to WizDragon
mob/romulan

icon = 'person.dmi'
icon_state = "romulan"
cl = -1
hp = 5
var mob/target


proc/firePhaser(atom/target)
if (target in view(5,src))
target << ""

return 0



proc/isDead()

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

return 1
return 0

ok so this is some of my code for creating and calling a proc().
proc/isDead() is being called while proc/firePhaser() is not. ive looked at a few demos and what im missing is the point where proc() is called I thought that a proc() would be called with the if branch.
please help.
In response to Treasurecat
Treasurecat wrote:
mob/romulan

icon = 'person.dmi'
icon_state = "romulan"
cl = -1
hp = 5
var mob/target


proc/firePhaser(atom/target)
if (target in view(5,src))
target << ""

return 0



proc/isDead()

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

return 1
return 0

ok so this is some of my code for creating and calling a proc().
proc/isDead() is being called while proc/firePhaser() is not. ive looked at a few demos and what im missing is the point where proc() is called I thought that a proc() would be called with the if branch.
please help.

does anyone know why this code does not work?
In response to Treasurecat
Treasurecat wrote:
does anyone know why this code does not work?

It should at least be doing something, if it's being called; unfortunately you have yet to show us any of the code that calls those two procs.

The isDead() proc is deeply flawed, however; code that you should be spawning out you're instead delaying with sleep(); thus, the code that's waiting for a return value from the proc has to sit on hold while isDead() is sleeping. Yet I doubt you're seeing the effects from this, because judging by your other comments you haven't called either firePhaser() or isDead()--at least, you haven't shown the code that does so.

Lummox JR
In response to WizDragon
WizDragon wrote:
The only way you're really going to accomplish this is with a loop of some sort. Many demos show how to handle AI loops. Look up some basic combat in the Demos section. I believe Deadron has a simple combat demo.

byond://Deadron.CombatSystem
In response to Lummox JR
//attack trial start

mob/romulan

icon = 'person.dmi'
icon_state = "romulan"
cl = -1
hp = 5
////////////////////this is my problem
proc/firePhaser(mob/M as mob)

if (M in view(src,5))
M << ""
return 1
return 0
///////////////////////////////////////////////
proc/isDead()

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

return 1
return 0

Move()
if(isDead())

return 0
return ..()

New()
walk_rand(src,40)

return ..()

//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)


phaserbeam
var
cl=-1

icon = 'person.dmi'
icon_state = "deadrom"
Bump(atom/A)

if(ismob(A))
var/mob/romulan/M = A

M.hp -= 5
del(src)
if(!ismob(A))
del(src)
else return 0


obj/phaserbeam

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

//attack trial end


if I where to use these proc() over and over I should make them global then just call them when I need them however im not that far along yet. im looking at the demo's they along with the help here has gotten me this far.
as for the inefficientcy of my code im aware of this and my priority is to code in ways that I can comprehend I will get better at this as I go along.

In response to Lummox JR
Lummox JR wrote:
It should at least be doing something, if it's being called; unfortunately you have yet to show us any of the code that calls those two procs.

thats what im saying but it does nothig. :(
In response to Treasurecat
Treasurecat wrote:
Lummox JR wrote:
It should at least be doing something, if it's being called; unfortunately you have yet to show us any of the code that calls those two procs.

thats what im saying but it does nothig. :(

Now that I've seen some of the code, I can honestly tell you I don't have a clue what you think it's supposed to be doing, or when, or how.
No offense, here, but the basic code is pretty well and truly frelled. Your best shot here is to put aside the old code--but keep it for a reference--and start new code from scratch. Build it up slowly, a piece at a time. When you ask for help on the procs you put in, explain exactly the sequence of things you want to happen. I think your only shot at saving this project is to clear to the foundation and rebuild.

Lummox JR
In response to Lummox JR
I'll admit this being my first project the code is a bit sloppy however up to this last thing the code is doing exactly what I want it to do. as for your advice on getting help and building this one piece at a time thats my strategy right now. the code I supplied earlier is simply supposed to do this.

move the romulan

fire a phaser beam at the romulan

kill the romulan if the beam hits him

my problem only begins when I want the romulan to fire a phaser at the player if he gets within a certain range.

proc/firePhaser()
while(src)
for(var/mob/M in range(src, 5))
world << ""
this is what I have right now I picked this up from a battle demo however it is not working either.

be advised this project is in no danger of failing

thanks for your help if you have any sugestions on how to get this done please let me know