How do i make an object have actions on touch?

Trying to make a boss that can chase a player though the map and kill on touch, also can go through walls like a ghost.
I'm using SOC, i tried using all the actions but i don't know how to do that.

Not sure if i should learn Lua, seems a little difficult to me.




Sonic Object Configuration (SOC):
Freeslot
S_MON11_STND
S_MON11_FLY1
S_MON11_FLY2
S_MON11_FLY3
S_MON11_FLY4
S_MON11_FLY5
S_MON11_FLY6
S_MON11_FLY7
S_MON11_FLY8
S_MON11_FLY9
S_MON11_FLY10
S_MON11_FLY11
S_MON11_FLY12
S_MON11_PAIN1
MT_MONSTER11
SPR_MO11


#FLYINGHOSTSPAWN:

State S_MON11_STND
SpriteName = MO11
SpriteFrame = A
Duration = 5
Next = S_MON11_FLY1
Action = A_Look
Var1 = 0
Var2 = 0

#FLYINGHOSTLOOKING:

State S_MON11_FLY1
SpriteName = MO11
SpriteFrame = A
Duration = 1
Next = S_MON11_FLY2
Action = A_FaceTarget
Var1 = 0
Var2 = 0

State S_MON11_FLY2
SpriteName = MO11
SpriteFrame = A
Duration = 2
Next = S_MON11_FLY3
Action = A_Chase
Var1 = 0
Var2 = 0

State S_MON11_FLY3
SpriteName = MO11
SpriteFrame = B
Duration = 1
Next = S_MON11_FLY4
Action = A_FaceTarget
Var1 = 0
Var2 = 0

State S_MON11_FLY4
SpriteName = MO11
SpriteFrame = B
Duration = 2
Next = S_MON11_FLY5
Action = A_Chase
Var1 = 0
Var2 = 0

State S_MON11_FLY5
SpriteName = MO11
SpriteFrame = C
Duration = 1
Next = S_MON11_FLY6
Action = A_FaceTarget
Var1 = 0
Var2 = 0

State S_MON11_FLY6
SpriteName = MO11
SpriteFrame = C
Duration = 2
Next = S_MON11_FLY7
Action = A_Chase
Var1 = 0
Var2 = 0

State S_MON11_FLY7
SpriteName = MO11
SpriteFrame = D
Duration = 1
Next = S_MON11_FLY8
Action = A_FaceTarget
Var1 = 0
Var2 = 0

State S_MON11_FLY8
SpriteName = MO11
SpriteFrame = D
Duration = 2
Next = S_MON11_FLY9
Action = A_Chase
Var1 = 0
Var2 = 0

State S_MON11_FLY9
SpriteName = MO11
SpriteFrame = E
Duration = 1
Next = S_MON11_FLY10
Action = A_FaceTarget
Var1 = 0
Var2 = 0

State S_MON11_FLY10
SpriteName = MO11
SpriteFrame = E
Duration = 2
Next = S_MON11_FLY11
Action = A_Chase
Var1 = 0
Var2 = 0

State S_MON11_FLY11
SpriteName = MO11
SpriteFrame = F
Duration = 1
Next = S_MON11_FLY12
Action = A_FaceTarget
Var1 = 0
Var2 = 0

State S_MON11_FLY12
SpriteName = MO11
SpriteFrame = F
Duration = 2
Next = S_MON11_STND
Action = A_Chase
Var1 = 0
Var2 = 0

#GHOSTGOESOUCH

State S_MON11_PAIN1
SpriteName = MO11
SpriteFrame = F
Duration = 7
Next = S_MON11_STND
Action = A_ForceStop
Var1 = 0
Var2 = 0


#$Name Monster 11SP
#$Sprite MO11
#$Category Custom Enemies
Object MT_MONSTER11
MapThingNum = 2858
SpawnState = S_MON11_STND
SpawnHealth = 15
SeeState = S_MON11_FLY1
SeeSound = sfx_None
ReactionTime = 32
AttackSound = sfx_none
PainState = S_MON11_PAIN1
PainChance = 200
PainSound = sfx_none
MeleeState = S_NULL
MissileState = S_NULL
DeathState = S_XPLD1
XDeathState = S_NULL
DeathSound = sfx_mon11d
Speed = 55
Radius = 30*FRACUNIT
Height = 60*FRACUNIT
DispOffset = 0
Mass = 100
Damage = 0
ActiveSound = sfx_None
Flags = MF_BOSS|MF_SPECIAL|MF_SHOOTABLE|MF_RUNSPAWNFUNC|MF_NOGRAVITY|MF_NOCLIP|MF_FLOAT|MF_NOCLIPHEIGHT
RaiseState = S_NULL

What should i add to make that action?
 
Lua seems like the way to go here. Firstly, you'll need a TouchSpecial hook that checks the following things:
  1. If one of the mobj types involved in the interaction is MT_PLAYER
  2. If the other mobj type is MT_MONSTER11
  3. If the player mobj isn't able to damage the boss (using not P_PlayerCanDamage())
If all of these conditions are met, Use P_DamageMobj(), with the target being the player mobj, the inflictor/source being the boss, damage being some arbitrary number (any number works, if you're concerned.), and damagetype being DMG_INSTAKILL.

If you're too lazy to try and interpret all that (which isn't recommended), here's some code you can use. thing and tmthing are just variables pointing to separate mobjs:
Lua:
addHook("TouchSpecial", function(thing, tmthing)
    if thing.type == MT_MONSTER11 and tmthing.type == MT_PLAYER then
        if not P_PlayerCanDamage(tmthing.player) then
            P_DamageMobj(tmthing, thing, thing, 1, DMG_INSTAKILL)
        end
    end
end)

imo this seems a little bit unfair, but I can't really control what you do with this. Hopefully this works, though.
 
Thank you, the code did work but didn't have the effect i expected and i got this when touching the object.

"bad argument #2 to 'P_PlayerCanDamage' (MOBJ_T* expected, got no value)
stack traceback:
"


so i edited the lua by removing the line 3
and it worked, now the custom object can do instakill on touch.
also i think i learned something about how "hooks", "if" and "then" works, now i understand how the lua thing works.

it looks like this now.

Lua:
addHook("TouchSpecial", function(thing, tmthing)
    if thing.type == MT_MONSTER11 and tmthing.type == MT_PLAYER then
            P_DamageMobj(tmthing, thing, thing, 1, DMG_INSTAKILL)
    end
end)

Again, thanks for the help :)
 
so i edited the lua by removing the line 3
That is not the solution. You should've just added this change:
Lua:
addHook("TouchSpecial", function(thing, tmthing)
    if thing.type == MT_MONSTER11 and tmthing.type == MT_PLAYER then
        if not P_PlayerCanDamage(tmthing.player, thing) then
            P_DamageMobj(tmthing, thing, thing, 1, DMG_INSTAKILL)
        end
    end
end)
 

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

Back
Top