ID:174969
 
I need help modifying my Bump proc so that it gives the object's shooter +10 Experience. Here is all the code that has relevance.

proc
fireprojectile(Type, mob/Who)
/*
Type = the type of projectile
Who = who fired/threw the projectile
*/

var/obj/projectile/S = new Type(Who.loc) // make a new projectile where the mob is
if(!istype(S,/obj/projectile)) // make sure they are
world.log << "Invalid projectile:[Type]"
return
S.dir = Who.dir // projectile faces same dir as the mob
S.who = Who
S.shooter = S.who
S.missileloop()



obj
projectile
density = 1
layer = FLY_LAYER
var
mob/who // the mob that fires the projectile
damage = 1 // how much damage the projectile causes
mrange = 10 // how far the projectile can go
delay = 0 // number of ticks between movements




proc
missileloop()
walk(src,dir, 0) // T = space the
if(--mrange > 0) // decriment range
spawn(delay) missileloop()
else
endmissile()

endmissile()
/* This proc is called when the missile stops moving.
Override it for missiles that have special effects
like explosions or leaving items where they land.
*/

del(src)


Bump(O)
if(ismob(O))
// damage proc
O:HP -= src.damage
O:DeathCheck()
endmissile() // we hit something, so the missile stops

obj
var
shooter
What you need to do is give DeathCheck() an argument that says who the (potential) killer is, and use that information to add the experience from there. Your Bump() proc should then pass along the owner of the projectile as an argument to DeathCheck().

Lummox JR
In response to Lummox JR
Is this what you meant, Lummox?

Bump(O)
if(ismob(O))
// damage proc
O:HP -= src.damage
O:DeathCheck(src)
endmissile() // we hit something, so the missile stops

mob/proc/DeathCheck(P)
if(src.HP<=0)
if(!key)
del src
else

var/X=rand(1,world.maxx)
var/Y=rand(1,world.maxy)
var/Z=rand(1,world.maxz)
usr.Move(locate(X,Y,Z))
world << "[src] was killed!"
src.HP = 100
Ammunition = rand(1,300)
Grenades = rand(1,3)
LAWs = rand(1,2)
P:Experience += 10
In response to Drafonis
Bump(mob/O)//Wasn't defined correctly
if(ismob(O))
// damage proc
O.HP -= src.damage //EVIL COLONS!
O.DeathCheck(src)
endmissile() // we hit something, so the missile stops

mob/proc/DeathCheck(P) //Not defined correctly!
if(src.HP<=0)
if(!key)
del src
else

var/X=rand(1,world.maxx)
var/Y=rand(1,world.maxy)
var/Z=rand(1,world.maxz)
usr.Move(locate(X,Y,Z))
world << "[src] was killed!"
src.HP = 100
Ammunition = rand(1,300)
Grenades = rand(1,3)
LAWs = rand(1,2)
P:Experience += 10//Colons!


Agghhh! Evil colons choking me!

Worlds: Looks like a job for Superworlds!

I've done the code as it should be (roughly).
In response to Drafonis
Drafonis wrote:
Is this what you meant, Lummox?
Bump(O)
if(ismob(O))
// damage proc
O:HP -= src.damage
O:DeathCheck(src)
endmissile() // we hit something, so the missile stops

mob/proc/DeathCheck(P)
if(src.HP<=0)
if(!key)
del src
else
var/X=rand(1,world.maxx)
var/Y=rand(1,world.maxy)
var/Z=rand(1,world.maxz)
usr.Move(locate(X,Y,Z))
world << "[src] was killed!"
src.HP = 100
Ammunition = rand(1,300)
Grenades = rand(1,3)
LAWs = rand(1,2)
P:Experience += 10

No, because you did several things wrong.

First, you're still using usr in DeathCheck(). Totally wrong. Never ever ever do that.

Second, you called DeathCheck() with src, which is the projectile, not the porjectile's owner.

Third: Give P a type like mob/P, so you don't have to use a colon.

Lummox JR
In response to Lummox JR
I'm not 100% sure what you meant about the second problem (src is the projectile, not the projectile's owner.) I think the projectile's owner (using the system I set up) would, in this case, be src.owner, which I have pointing to src.shooter. How can I make that a bit less cumbersome?
In response to Drafonis
Drafonis wrote:
I'm not 100% sure what you meant about the second problem (src is the projectile, not the projectile's owner.) I think the projectile's owner (using the system I set up) would, in this case, be src.owner, which I have pointing to src.shooter.

You're correct. The correct thing to call DeathCheck() with would be src.shooter.

How can I make that a bit less cumbersome?

The best way to handle projectiles is to handle all initialization of the projectile in New(), not in the verb where you fire it. Pass a second argument to new() saying who fired, and then rewrite New() like this:
obj/projectile
var/mob/owner // or shooter, in your case
var/range = world.view

New(newloc, mob/M)
owner = M
if(M) walk(src, M.dir, 0) // start moving
spawn(range) del(src) // limited range

Lummox JR
In response to Lummox JR
I am not sure exactly how this is. However, here's how I did this. I made DeathCheck accept 2 arguments. One is mob/P, one is mob/S. On Bump, mob/P is defined as src.shooter, mob/S is O. The rest is the same.
In response to Drafonis
Drafonis wrote:
I am not sure exactly how this is. However, here's how I did this. I made DeathCheck accept 2 arguments. One is mob/P, one is mob/S. On Bump, mob/P is defined as src.shooter, mob/S is O. The rest is the same.

The mob/S bit is useless. The O in your Bump() is the thing that was bumped into, which is the mob whose DeathCheck() proc is called, so S==src in DeathCheck(). Therefore you don't need it; get rid of it.

It may be useful however to also tell DeathCheck() something about the weapon, so passing src (from Bump()) as a second argument (but not the first) might not be a bad idea.

Lummox JR