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

Status
Not open for further replies.
Attempted to make invincibility music loop...

As said in the topic, I tried to make a script where the music would loop as long as the player is invincible (which includes when the game freezes due to our oh-so-wonderful netcode). Sadly It didn't seem to work with the custom music we made for it, which was in the .ogg format. This was meant to be a workaround to emulate the hardcoding from SRB2Riders and SRB2Kart had with looping music, most especially invincibility themes to save space.

Code:
function A_Invincibility(actor, var1, var2)
    super(actor, var1, var2)
    if (actor.target) and (actor.target.valid) //Make sure the player mobj wasn't destroyed somehow
    and (actor.target.player) and (actor.target.player.valid) //Make sure the player data is accessible from the mobj
        S_ChangeMusic(1039, true, actor.target.player)
    else
        if mariomode == true
        S_ChangeMusic(1041, true, actor.target.player)
    end
end

Not sure what went wrong here...
 
You forgot an end statement after S_ChangeMusic(1041, true, actor.target.player).
 
Fixing Metal Sonic Race object's teleporting problem... with lua...

Code:
addHook("MobjThinker", function(metaltpafix)
    if metaltpafix.subsector.linedef.special == 412
        P_Teleport(x,y,z, MT_TELEPORTMAN)
    end
end, MT_METALSONIC_RACE)
Just as the title says, except I'm not sure about how I'm going with this...
 
Last edited:
Code:
addHook("MobjThinker", function(metaltpafix)
    if metaltpafix.subsector.linedef.special == 412
        P_Teleport(x,y,z, MT_TELEPORTMAN)
    end
end, MT_METALSONIC_RACE)
Just as the title says, except I'm not sure about how I'm going with this...

Well I liked the idea of having Player like objects that normaly don't teleport to teleport so i tried it and this hapenned
SRB2 Error Warning said:
WARNING: testduonlua.lua:2: bad argument #2 to '?' (invalid option 'linedef')
Hook removed.
Well actually I kinda modified it to "work" with my NPCs
So heres the modified code
Code:
addHook("MobjThinker", function(mo)
    if mo.subsector.linedef.special == 412
        P_Teleport(x,y,z, MT_TELEPORTMAN)
    end
end, MT_MATCHNPC)
PS. Sorry for using your code without permission I just wanted to test it and maybe help you if something is wrong with code and if any error pops up.
 
Thanks for the code fix, and I appreciate the help... but it still doesn't seem to do anything...

EDIT: I thought that as long as the teleport linedef was being used, it should affect the object... but the actual effect comes from the sector that affects it, making it activate the teleporter. So I decided to make it towards my customs here...

Code:
addHook("MobjThinker", function(metaltpafix)
    if metaltpafix.subsector.sector.special == 64
    and metaltpafix.subsector.linedef.special == 412
        P_Teleport(x,y,z, MT_METALSONIC_RACE)
    end
end, MT_TELEPORTMAN)
---------- Post added at 11:40 AM ---------- Previous post was at 11:08 AM ----------

Code:
addHook("MobjThinker", function(metaltpafix)
    if (metaltpafix.valid and metaltpafix.type == MT_METALSONIC_RACE)
    and metaltpafix.subsector.sector.special == 64
    and metaltpafix.subsector.linedef.special == 412
        P_Teleport(x,y,z, MT_METALSONIC_RACE)
        print("Teleported.")
    end
end, MT_TELEPORTMAN)
I don't know if you noticed yet... but uh, I don't know what I'm doing DX

Also the print is there to symbolize if the script worked properly.
 
Last edited:
You do realise subsectors don't have a "linedef" variable within them, right? After all, it's sectors themselves that keep track of the linedefs belonging to it, not any of their subsectors. In other words, metaltpafix.subsector.linedef doesn't exist and never will.

Sadly Lua hasn't any direct way to get linedefs belonging to specific sectors yet currently (read: metaltpafix.subsector.sector.linedef doesn't exist either), you'll have to search through all linedefs in the map for any attached to metaltpafix.subsector.sector or something.
 
Last edited:
Code:
addHook("MobjThinker", function(objtrail)
    if (mobj.state >= S_METALSONIC_RUN1 and  mobj.state <= S_METALSONIC_RUN4)
        local thok = P_SpawnMobj(mobj.x, mobj.y, mobj.z, MT_TRAL)
        thok.color = SKINCOLOR_NEONGREEN
    end
end, MT_METALSONIC_RACE)

I'm trying to make the Metal Sonic race object spawn a trail I created, but i'm not that good at dealing with objects other than players...
 
Try changing "function(objtrail)" to "function(mobj)". You made the name of the mobj variable for the function "objtrail" but then you switch to "mobj" for the actual contents of the function itself, which is silly. You need to be consistent with your names!

Helps to double check what you're doing to see if you understand it completely yourself. If you don't, you have a problem.
 
I think it has to do with the the variable "cmd.angleturn". It's in the source code, but it should be readable in Lua. I would start by searching the g_game.c file in the SRB2 Github for all instances of "cmd.angleturn". Another method would be to modify player.mo.angle directly, but I'm not sure if this would work.
 
vAf2vrJ.png


*look at the top-left rings counter*

This HUD is getting annoying... How would you send a patch to the back or bring the text forward?
 
All HUD elements are drawn in the order you used in your custom HUD drawing function. If you want something to appear "above" others, you should write its rendering function last.
 
Additional note: if you're trying to place a HUD element underneath the rings counter, you need to recreate it entirely - as the default stuff is always drawn first.

This is assuming that replacing the graphic for "RINGS" doesn't layer underneath in the first place, which would solve you a lot of hassle if you'd just do it like that.
 
I think it has to do with the the variable "cmd.angleturn". It's in the source code, but it should be readable in Lua. I would start by searching the g_game.c file in the SRB2 Github for all instances of "cmd.angleturn". Another method would be to modify player.mo.angle directly, but I'm not sure if this would work.
So with some careful looking around, it seems that the variable "tspeed" has a certain amount of tics that allow the turning speed to be slow, which is for about 2 tics. Either that has to be increased... unless there is something I'm seriously missing.

EDIT: Here's what I could conjure up. It doesn't do anything. But I think it might actually be a start.

Code:
addHook("ThinkFrame", do
    for player in players.iterate
        if player.mo.rider == 1
        and player.panim == PA_RUN
        and player.cmd.angleturn>>1
            player.cmd.angleturn = player.cmd.angleturn<<16
        end
    end
end)
 
Last edited:
Checking "player.cmd.angleturn>>1" is identical to checking whether abs(player.cmd.angleturn) is greater than 1. Are you sure that's what you want?

Also, left bitshifting by 16 makes the number super tiny, since it's not on the scale of FRACUNIT. To understand what you want to do to the number, first you need to understand the numbers player.cmd.angleturn might hold. Based on prior experience, it's a number between -50 and 50 (yes, an integer - not fixed point decimal.) Try printing it to make sure, then play with various scaling factors (like 5*$1/6, or dividing it by 2...)
 
Holy hell, that's tiny... Alright, lemme toy with this a bit and see what happens.

EDIT: So I decided to let the console print the angleturn value... I need to find a way to get to the thousandths...

EDIT2: I think my goal is to try and decrease the bit-rate that cmd.angleturn outputs, except I'm not sure how I can read/write the bit-rate of angleturn...
 
Last edited:
Code:
addHook("ThinkFrame", do
    for player in players.iterate
        if player.mo.rider == 1
        and player.panim == PA_RUN
        and (player.cmd.angleturn<<16) + ANG2
            player.cmd.angleturn = (player.cmd.angleturn<<16) - ANG10
        end
    end
end)

God, I'm awful at this..

Also happy new year
 
Checking "player.cmd.angleturn>>1" is identical to checking whether abs(player.cmd.angleturn) is greater than 1. Are you sure that's what you want?

Noop, player.cmd.angleturn>>1 is more like dividing by 2. If you noticed it's bitshifting right rather than doing a greater-than comparison.
 
MI, keep in mind that it's a bitshift. That also means the sign bit. In addition, no qualifier is being made on it - so it's checking whether it's nonzero. Checking whether integer division of 2 (or keeping the sign bit) is nonzero is the same as checking whether it's not 0 or 1 - which is slightly off my after-midnight-on-new-years-day assessment of "abs(val int div 2)", which would be true if not 0, 1 or -1.
 
Status
Not open for further replies.

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

Back
Top