Duon's Lua Help Thread (Because I know I need one)

Status
Not open for further replies.
Back Already? Well um, I've been a little concerned about trying to prevent players from dying with no rings in hand, like some competitive games that have features like that. Here's what I could conjure up so far:
Code:
addHook("ThinkFrame", do
    for player in players.iterate
        if player.mo
        and player.mo.health < 1        
            player.mo.health = 1
        end
    end
end)
I'm not entirely sure how I can check if the player gets hurt or anything like that, mostly because I have no idea what I'm doing.

---------- Post added at 02:40 PM ---------- Previous post was at 02:15 PM ----------

Back Already? Well um, I've been a little concerned about trying to prevent players from dying with no rings in hand, like some competitive games that have features like that. Here's what I could conjure up so far:
Code:
addHook("ThinkFrame", do
    for player in players.iterate
        if player.mo
        and player.mo.health < 1        
            player.mo.health = 1
        end
    end
end)
I'm not entirely sure how I can check if the player gets hurt or anything like that, mostly because I have no idea what I'm doing.
 
Maybe try the ShouldDamage or MobjDamage hooks and either return a value or don't, depending on the amount of Rings if the object is a player.
 
Lat' helped me out on reworking this idea, but now i need to figure out how exactly do I let the player die every other way besides getting hurt by enemies.

Code:
addHook("ShouldDamage", function(player)
 if player.health < 2
  P_DoPlayerPain(player.player)
 return false
 end
end, MT_PLAYER)
 
Use the second "argument" of the function (not of the hook), referred to as "inflictor" on the Wiki, to determine if an object causes damage.
If it is, you'll just have to check if it's an enemy. If it's not, check the third "argument" of the function, referred to as "source", see if it exists, and see if that's an enemy.
If either objects are enemies, return false, otherwise either don't return anything, or just "return" or return nil.
Of course, this might not work that well if an enemy shoots a projectile, then gets bopped before you get hurt by the projectile, such that the "inflictor" is not an enemy and doesn't have a valid "source".
 
Code:
    if mobj.trail %1050 == 1
    and not mobj.trail == 0
Apparently this prevents the function from working entirely. I originally wanted it to work AFTER the first check, which is 0, but it seems to ignore any other checks. Is there a way to disable the first check without preventing the function to ignore the rest?
 
Tbh, this is getting very confusing... Can you even modify the bit-rate cmd.angleturn executes?

Thanks so much for the help, but now I think I want to get back to this topic mostly because I have the time to work on it, and also because it's on my bucket list for the Riders Mod.
 
fucking hell what did i do to deserve this

Code:
    local function checkm(v, player)
        if player
        and player.checkmark == nil
LINE 302    player.checkmark = 0
        end
        
        if player.checkmark > 0
            v.drawString(110, 90, "CHECK", V_ALLOWLOWERCASE|V_GREENMAP,"middle")
        end
        
        if player.checkmark > 2*TICRATE
            player.checkmark = 0
        end
    end
hud.add(checkm)
SRB2 log.txt said:
WARNING: riderlevels.wad|LUA_SHLD:302: Do not alter player_t in HUD rendering code!
 
Exactly what it says: you're altering a player struct variable in HUD rendering code. HUD code only runs clientside so naturally the game won't let you change variables that are supposed to sync online.
 
It was supposed to be clientside, It's supposed to be a notification for if the player passes the check point successfully. Maybe I gave the idea the wrong approach?

EDIT: Holy hell I came at this the wrong way entirely, I think I want to detect the starpost activator sectors.

EDIT2: Okay, so now thanks to Lat' again I have the starpost one figured out, but now I want to make one for the finish line, except despite crossing it, it doesn't seem to activate.

Code:
        if player.mo.subsector.sector.special == 40960 then
            player.startcheck = 1
        else
            player.startcheck = 0
        end

EDIT 3: Eh, fuck it, if no one has a possible solution, I'm hoping someone great at lua can help me out with that bit rate on cmd.angleturn so I don't feel like Motorroach's criticism goes to waste. ;-;
 
Last edited:
Alright, a little over a month later and I've done things, very... interesting things...

yKZvbzg.gif
(apologies for the stolen stage, needed a placeholder)
hK4Wa


So I've been slowly learning the functions of SOC for bosses! Thanks to the wiki, I can truly understand how to bring these old bosses into the latest version of SRB2.

Though, I'm currently stuck with one of the boss ports I've been working on. I've recently been messing around with Twisted Mobile, a boss that was from SRB2 Morphed. Me and LJ Sonik ported it successfully last year, though today, I decided to redesign it to act like an actual boss, (mostly so that the boss hud lua would work on it) except there was one function from SRB2 Morphed that I have yet to understand. A_MultiShot. I have no idea how this move is supposed to work as the boss uses this attack at one point. Is there like a demonstration or gif to show off A_MultiShot?

EDIT: After realizing that egghide.soc had A_MultiShot, I decided to reference that and got this beautiful result.
zmYxqdF.gif
 
Last edited:
Code:
addHook("MobjThinker", function(fshield)
    if (fshield.eflags & MFE_UNDERWATER)
    and not (fshield.player.powers[pw_invulnerability])
    and not fshield.subsector.sector.special == 3
        P_RemoveMobj(fshield)
    end
end, MT_GREENORB)

Trying to make a fire shield that will go out in the water, but not in lava falls (hence the "subsector.sector.special == 3")
 
Status
Not open for further replies.

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

Back
Top