Player Identification

Status
Not open for further replies.

Prisima

Member
I am making a Homing Missile that, when shot, executes A_HomingChase to follow any player other than yourself. Everything works except that the missile follows any nearby player, including you. I have the target being player.mo. Is it possible to make it distinguish between the firer and the target, and not chase after the firer?
 
I'm assuming you've set it to follow the object's tracer, which is set to a nearby player? The best thing you could do to set the tracer to a nearby player other than yourself is probably to use a Lua function that goes something like this: (I'm not sure if there's a non-Lua method to do this with)

Code:
-- Finds a player other than the object's target that's nearby, and sets it to the object's tracer
-- Var1 = distance limit
-- Var2 = if set, get the nearest player - if not, just take the first one in range
function A_FindOtherPlayer(mo, distlimit, nearest)
    local distcheck = distlimit
    for p in players.iterate do
        if not (p.mo and p.mo.valid and p.mo.health) then continue end
        if p.mo == mo.target then continue end
        local newdist = P_AproxDistance(P_AproxDistance(p.mo.x-mo.x, p.mo.y-mo.y), p.mo.z-mo.z)
        if newdist <= distcheck then
            mo.tracer = p.mo
            distcheck = newdist
            if not nearest then return end
        end
    end
end
 
Thank you RedEnchilada. "Distance limit" means the distance away from the firer that the other player (that is being set as the tracer) has to be, right?
 
It's the maximum distance the player can be from the missile, yes. If you want a minimum distance you can change line 10 to:

if newdist <= distcheck and newdist >= nearest then

and line 13 to

if not (nearest & 1) then return end

and the upper 16 bits of var2 will be said minimum. But for the purpose you've outlined (just finding a player that isn't your target) it shouldn't be necessary.
 
Last edited:
EuphoricKaleidoscopicAtlasmoth.gif

It might be that I have to set the tracer to MT_PLAYER instead of player.mo.
 
Last edited:
There has to be a reason why its only chasing me and no other player, as you saw in the gif. Just guessing here, it could be that player.mo would just identify you (the firer), and not every other player.
 
I didn't even notice there was a GIF in your last post since it didn't load on my end, lol. Could you post the script in question so I can see if it's really an issue with identification or if some other culprit may be the cause? 'Cus I can't think of anything wrong with the script I shared, but I also don't have a setup to quickly test it in.
 
Thanks, I fixed the GIF in the other post. Here's the LUA part:
Code:
freeslot("MT_SUPERMISSILE", "S_SUPERMISSILE", "S_SUPERMISSILE2", "S_SUPERMISSILE3", "S_SUPERMISSILE_EXPLODE", "S_SUPERMISSILE_EXPLODE2", "S_SUPERMISSILE_EXPLODE3")

// Finds a player other than the object's target that's nearby, and sets it to the object's tracer
// Var1 = distance limit
// Var2 = if set, get the nearest player - if not, just take the first one in range
function A_FindOtherPlayer(mo, distlimit, nearest)
    local distcheck = distlimit
    for p in players.iterate do
        if not (p.mo and p.mo.valid and p.mo.health) then continue end
        if p.mo == mo.target then continue end
        local newdist = P_AproxDistance(P_AproxDistance(p.mo.x-mo.x, p.mo.y-mo.y), p.mo.z-mo.z)
        if newdist <= distcheck then
            mo.tracer = p.mo
            distcheck = newdist
            if not nearest then return end
        end
    end
end

addHook("ThinkFrame", function()
	for player in players.iterate do
		
		if not player.supermissile then
			player.supermissile = 1
		end
		
		player.supermissile = $1 + 1
		
		if (player.cmd.buttons & BT_CUSTOM1)
		and player.supermissile > 32 then
			P_SpawnPlayerMissile(player.mo, MT_SUPERMISSILE, MF2_RAILRING)
			A_BunnyHop(player.mo, 7, -7)
			player.supermissile = 1
		end
end
end)

Here's the SOC part:
Code:
FREESLOT
MT_SUPERMISSILE
S_SUPERMISSILE
S_SUPERMISSILE2
S_SUPERMISSILE3
S_SUPERMISSILE_EXPLODE
S_SUPERMISSILE_EXPLODE2
S_SUPERMISSILE_EXPLODE3

Object MT_SUPERMISSILE
SpawnState = S_SUPERMISSILE
SpawnHealth = 1000
SeeState = S_NULL
SeeSound = sfx_brakrl
ReactionTime = 8
AttackSound = sfx_None
PainState = S_NULL
PainChance = 0
PainSound = sfx_None
MeleeState = S_NULL
MissileState = S_NULL
DeathState = S_SUPERMISSILE_EXPLODE
XDeathState = S_NULL
DeathSound = sfx_brakrx
Speed = 40*FRACUNIT
Radius = 11*FRACUNIT
Height = 8*FRACUNIT
DispOffset = 0
Mass = 100
Damage = 32*FRACUNIT
ActiveSound = sfx_None
Flags = MF_NOBLOCKMAP|MF_MISSILE|MF_NOGRAVITY
RaiseState = S_NULL

State S_SUPERMISSILE
SpriteName = RCKT
SpriteFrame = A
Duration = 16
Next = S_SUPERMISSILE2
Action = A_SetObjectFlags2
Var1 = MF2_RAILRING
Var2 = 2

State S_SUPERMISSILE2
SpriteName = RCKT
SpriteFrame = A
Duration = 1
Next = S_SUPERMISSILE3
Action = A_FindOtherPlayer
Var1 = 25*FRACUNIT
Var2 = 1

State S_SUPERMISSILE3
SpriteName = RCKT
SpriteFrame = A
Duration = 1
Next = S_SUPERMISSILE3
Action = A_HomingChase
Var1 = 40*FRACUNIT
Var2 = 1

State S_SUPERMISSILE_EXPLODE
SpriteName = RCKT
SpriteFrame = B
Duration = 8
Next = S_SUPERMISSILE_EXPLODE2
Action = A_Explode
Var1 = 0
Var2 = 0

State S_SUPERMISSILE_EXPLODE2
SpriteName = RCKT
SpriteFrame = C
Duration = 6
Next = S_SUPERMISSILE_EXPLODE3
Action = A_NapalmScatter
Var1 = MT_CYBRAKDEMON_NAPALM_FLAMES+(6<<16)
Var2 = 32+(16<<16)

State S_SUPERMISSILE_EXPLODE3
SpriteName = RCKT
SpriteFrame = D
Duration = 4
Next = S_NULL
 
That distance limit is way too low. 25*FRACUNIT is less distance than the missile and a player would be on collision, so if you want it to home in you need to bump that limit waaaaay up.
 
Even pushing it up to 250*FRACUNIT returns the same result. Also, my typo: S_SUPERMISSILE3's Var2 is supposed to be 0, not 1.
 
No, you want its Var2 to be 1. HomingChase should go after the tracer, not the target, because the target is whoever fired it. A_FindOtherPlayer is specifically made to set the object's tracer for this reason.
 
Status
Not open for further replies.

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top