(SOLVED)How to relate the tail follow object to the player's skin

Mr Bones

Member
How do I configure or add the MT_TAILSOVERLAY sprites to show up according to the players actions?
I tried both this, to draw existing sprites
local function DashT(mobj)
for mobj in MT_TAILSOVERLAY
if player.mo.state == S_ECLIP_DASH //dash with GASP sprites
mobj.state = S_TAILSOVERLAY_GASP
end
end
and different variations of this
addHook("PlayerThink", function(player) do
for mobj in mobjs.iterate()
for player in players.iterate()
if player.mo.skin == "eclipse
if player.panim == PA_ROLL or player.panim == PA_JUMP
mobj.flags2 = $|MF2_DONTDRAW
to not draw a sprite, but still they both work the opposite than expected.
 
You're better off porting the function from c, using a custom followitem, and modifying that than messing vvith the tails from lua, since much of the behavior is hardcoded and unavoidable. You can find it in p_user.c from the source code I think.
 
You're better off porting the function from c, using a custom followitem, and modifying that than messing vvith the tails from lua, since much of the behavior is hardcoded and unavoidable. You can find it in p_user.c from the source code I think.
I see. The c function is still gonna be a little problem for me though
 
whats missing now?
 

Attachments

  • Captura de Tela (37).png
    Captura de Tela (37).png
    130.8 KB · Views: 80
  • Captura de Tela (38).png
    Captura de Tela (38).png
    134.8 KB · Views: 95
  • Captura de Tela (39).png
    Captura de Tela (39).png
    132.9 KB · Views: 82
whats missing now?
you've done great vvith it so far! You're not done porting though, here's some things you still need to fix:
  • Those variables at the start are basically locals, as C frees them at the end of the function instead of piling them up into a memory leak. In lua, you need to add a local keyword to recreate this behavior, and prevent srb2 from throwing a fit about globals. You don't need the type either.
  • C uses a ; to define a new line of code/the end of an instruction. Actually using it as a full replacement for line breaks makes code litterally unreadable, so the srb2 programmers made sure to always include both. Lua just uses the line breaks to define this, so there's no need for them anymore. I don't know if ;s parse under lua, but it's probably best to assume it doesn't.
  • slade is recognizing add as something that exists, seeing by the yellow text. You might be overwriting a global function or something, so rename add and all instances of it here to fix that.
  • MT_WHIPTAIL is an integer value, and can't really be for-looped. You should try using the "MobjThinker" hook to replace it. At the bottom of this function, you'll see this: end). To make the hook run specifically for all MT_WHIPTAIL objects, do this; end, MT_WHIPTAIL) It makes more sense if you do what i do and store the function as a local instead of storing the entire function in the addHook function. Both are valid though.
  • I get the feeling you removed the comment on initial position..., whatever the case it will throw an error in both languages, so either check the c function again or put the // back
  • P_SetMobjState(mobj, state); is replaced in lua with editing the state value directly, like this: mobj.state = state
  • chosenstate and some other variables are given their proper value by the end, but aren't used to set anything that affects the actual object. Try checking the C function again, or reimplement them based off of their names.
I know the list looks intimidating, and it's probably because it is. A lot of errors I've seen here look like inexperience with just lua, but you're still learning, and a lot by what I can tell! It's probably best that you try to avoid porting functions until you get more comfortable with lua and scripting in general. There are other ways to get around that original problem, such as actively avoiding using tails at all, or inserting the tails back in the sprites you're using. You might want to focus on eclipse's other abilties for now, and if you really can't get around this problem, just quote me or something to get my attention.
 
Last edited:
you've done great vvith it so far! You're not done porting though, here's some things you still need to fix:
  • Those variables at the start are basically locals, as C frees them at the end of the function instead of piling them up into a memory leak. In lua, you need to add a local keyword to recreate this behavior, and prevent srb2 from throwing a fit about globals.
  • Again with those variables at the start, types in lua are part of what is stored in a variable, and can be read with the type() function. In short, you don't define locals/variables in lua with a type like in c, and the var keyword needs to be used instead to define a variable regardless of type. Here's what one should look like: local var zoffs = 0
  • C uses a ; to define a new line of code/the end of an instruction. Actually using it as a full replacement for line breaks makes code litterally unreadable, so the srb2 programmers made sure to always include both. Lua just uses the line breaks to define this, so there's no need for them anymore. I don't know if ;s parse under lua, but it's probably best to assume it doesn't.
  • slade is recognizing add as something that exists, seeing by the yellow text. You might be overwriting a global function or something, so rename add and all instances of it here to fix that.
  • MT_WHIPTAIL is an integer value, and can't really be for-looped. You should try using the "MobjThinker" hook to replace it. At the bottom of this function, you'll see this: end). To make the hook run specifically for all MT_WHIPTAIL objects, do this; end, MT_WHIPTAIL) It makes more sense if you do what i do and store the function as a local instead of storing the entire function in the addHook function. Both are valid though.
  • I get the feeling you removed the comment on initial position..., whatever the case it will throw an error in both languages, so either check the c function again or put the // back
  • P_SetMobjState(mobj, state); is replaced in lua with editing the state value directly, like this: mobj.state = state
  • chosenstate and some other variables are given their proper value by the end, but aren't used to set anything that affects the actual object. Try checking the C function again, or reimplement them based off of their names.
I know the list looks intimidating, and it's probably because it is. A lot of errors I've seen here look like inexperience with just lua, but you're still learning, and a lot by what I can tell! It's probably best that you try to avoid porting functions until you get more comfortable with lua and scripting in general. There are other ways to get around that original problem, such as actively avoiding using tails at all, or inserting the tails back in the sprites you're using. You might want to focus on eclipse's other abilties for now, and if you really can't get around this problem, just quote me or something to get my attention.
Ok, so I did most of the stuff, but I don't really know what to do about the add part, how to replace it and how to make the angle stuff work. Sinse the (rollangle > ANGLE_180) ? 2 : 0; give me a syntax error.
And thanks for the help so far.
 
Last edited:
Ok, so I did most of the stuff, but I don't really know what to do about the add part, how to replace it and how to make the angle stuff work. Sinse the (rollangle > ANGLE_180) ? 2 : 0; give me a syntax error.
And thanks for the help so far.
I didn't notice a lot about that bit of the code. oops.
  • Every if statement needs an end statement. You're missing some here since c allows you to execute one line of code after an if-statement without having to put braces, while lua doesn't.
  • Going off of a google search on this one, but the line can be recreated like this:
The code:
add = 0
if (rollangle > ANGLE_180)
   add = 2
end
  • renaming the add variable is just replacing every instance of the vvord "add" vvith something else. The ? line has nothing to do vvith that, it just happens to be a problem using that variable.
  • I told you before that you needed a var keyvvord for variables, but I forgot that's not the case at all. I've updated the post to fix that, but yeah, sorry about that.
 
I didn't notice a lot about that bit of the code. oops.
  • Every if statement needs an end statement. You're missing some here since c allows you to execute one line of code after an if-statement without having to put braces, while lua doesn't.
  • Going off of a google search on this one, but the line can be recreated like this:
The code:
add = 0
if (rollangle > ANGLE_180)
   add = 2
end
  • renaming the add variable is just replacing every instance of the vvord "add" vvith something else. The ? line has nothing to do vvith that, it just happens to be a problem using that variable.
  • I told you before that you needed a var keyvvord for variables, but I forgot that's not the case at all. I've updated the post to fix that, but yeah, sorry about that.
nerd gaming
teach me how to code pleseeeee(joke)
 
I didn't notice a lot about that bit of the code. oops.
  • Every if statement needs an end statement. You're missing some here since c allows you to execute one line of code after an if-statement without having to put braces, while lua doesn't.
  • Going off of a google search on this one, but the line can be recreated like this:
The code:
add = 0
if (rollangle > ANGLE_180)
   add = 2
end
  • renaming the add variable is just replacing every instance of the vvord "add" vvith something else. The ? line has nothing to do vvith that, it just happens to be a problem using that variable.
  • I told you before that you needed a var keyvvord for variables, but I forgot that's not the case at all. I've updated the post to fix that, but yeah, sorry about that.
I replaced it with this
add:
local function addi(mobj)
add = 0
if (rollangle > ANGLE_180)
   add = 2
end
end
But now it got a problem with the rollangle += ANG15 in this part, the game says its missing a = near +.
Lua:
    if (player.panim == PA_RUN)
        backwards = -5*FRACUNIT;
        mobj.state = S_WHIPTAIL_STND
        end
        if (addi)
            rollangle = InvAngle(rollangle);
        rollangle += ANG15; // modify the thresholds to be nice clean numbers
        if (rollangle > ANG60)
            mobj.state = S_WHIPTAIL_PLUS60DEGREES + addi;
        else if (rollangle > ANG30)
            mobj.state = S_WHIPTAIL_PLUS30DEGREES + addi;
        else
            mobj.state = S_WHIPTAIL_0DEGREES;
            end
        end
    end
 
Last edited:
I replaced it with this
add:
local function addi(mobj)
add = 0
if (rollangle > ANGLE_180)
   add = 2
end
end
But now it got a problem with the rollangle += ANG15 in this part, the game says its missing a = near +.
Lua:
    if (player.panim == PA_RUN)
        backwards = -5*FRACUNIT;
        mobj.state = S_WHIPTAIL_STND
        end
        if (addi)
            rollangle = InvAngle(rollangle);
        rollangle += ANG15; // modify the thresholds to be nice clean numbers
        if (rollangle > ANG60)
            mobj.state = S_WHIPTAIL_PLUS60DEGREES + addi;
        else if (rollangle > ANG30)
            mobj.state = S_WHIPTAIL_PLUS30DEGREES + addi;
        else
            mobj.state = S_WHIPTAIL_0DEGREES;
            end
        end
    end
You don't need to make everything a function, and doing that resulted in the add variable both being assumed as a global and never utilized. You also still haven't renamed add to something else. That snippet of code was originally intended to be pasted inside the original location of that line, but it's okay to do it like this, as long as you fix vvhat I just said. For the += issue, lua does something different. += is meant to add the value on the right to the variable on the left. It's a shorthand for doing... this: veryunderstandablelanguage = veryunderstandablelanguage + 1 Lua doesn't have this exactly, but it has a more direct solution. the $ character is called the pseudovariable, and is only valid syntax when setting a value. It's value is the same as the variable you're setting to. Essentially it lets you do this: veryunderstandablelanguage = $ + 1, and that's much less cluttered. You don't have to implement the psuedovariable in your code, but it's nice.

Given the little complexity of this entire issue though, here's a better idea than having you port a function as your intro to lua:

PostThinkFrame is the last hook before rendering/interpolation. The hook basically allows you to force something to do whatever you want before rendering, even if the object really doesn't like it. I'm not sure why I didn't tell you to do this at the start to be honest. Here's an example:
code The:
local function DashT()
    -- PostThinkFrame doesn't give you any arguments and runs once per tic
    -- that's not going to stop me from running code for everyone tho
    for player in players.iterate
        -- this loops through all the players in the game, no matter what
        -- I've seen people put these in conditional/circumstancial hooks like AbilitySpecial
        -- don't do that, looping through each player causes code to run for every player, even if a different player used the ability instead.
        -- be aware of what you're doing
        if player.mo and player.mo.skin == "eclipse" and player.followmobj and p.mo.state == S_ECLIP_DASH then
            player.followmobj.state = S_TAILSOVERLAY_GASP -- this is fine as long as you don't have multiple frames in the gasp animation, which is very unlikely
        end
    end
end
addHook("PostThinkFrame", DashT)
 

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

Back
Top