How do you make a state that attacks enemies/bosses/monitors/etc?

BarioBro1

Member
I'm trying to create a good custom character for the first time, and I've come across a problem I have every time I try this: I don't know how to make a state damage objects. I've searched on the internet, on the wiki, tried plagiarism, but never found an answer. I've tried RadiusAttack, but that doesn't do anything to monitors. I've tried looking through the blockmap and damaging everything there, but it doesn't feel right, and the player still takes damage sometimes.
 
Could you show how the state looks like? I think I may have an idea on what you could do. •3•
 
Could you show how the state looks like? I think I may have an idea on what you could do. •3•

Here it is:
State init:
states[S_JARED_HAMMER] = {
    sprite = SPR_PLAY,
    frame = SPR2_HAMR|A|FF_ANIMATE,
    tics = 40,
    nextstate = S_JARED_HAMMER
}
Every frame:
if ((player.cmd.buttons & BT_SPIN) and not ((player.mo.state == S_JARED_UPHAMMER) or ((player.cmd.buttons & BT_CUSTOM1) and (player.canupham)))) and not (player.pflags & PF_FULLSTASIS) then
    player.mo.state = S_JARED_HAMMER
    if not P_IsObjectOnGround(player.mo)
        P_SetObjectMomZ(player.mo, -32*FRACUNIT, false)
    end
    -- the next few lines are the not good looking placeholder damage code lines that dont work well
    P_RadiusAttack(player.mo,player.mo,160*FRACUNIT,DMG_SPIKE,0)
    searchBlockmap("objects",function(refmobj, foundmobj)
        if R_PointToDist2(refmobj.x, refmobj.y, foundmobj.x, foundmobj.y) < FRACUNIT*160 and abs(foundmobj.z-refmobj.z)<96*FRACUNIT and (foundmobj.flags | MF_SHOOTABLE)
            P_DamageMobj(foundmobj, refmobj, refmobj, 1, DMG_SPIKE)
        end
    end,player.mo)
end
highlighted lines in the second one are placeholders for dealing damage
 
Okay, so basically there's a really simple way of doing this that seemingly not that much people know about. ;v;

SRB2 has a power value, and the main power you need to focus on is pw_strong. It let's you set a variable of ways the player can attack stuff.

For example "player.powers[pw_strong] = STR_MELEE" Gives you the same attack stuff as Amy's hammer attack (Shatters walls, spikes, etc.) But I recommend to check the values yourself. (And I'm not sure if a custom player state shouldn't have S_PLAY in front of your name to make STR_ANIM work...)

And remember to ask if anything is unclear, it's my first time explaining lua to others. :dramahog:

 

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

Back
Top