help with ability lua

chipakpaka

Member
i'm trying to make an ability lua that is a combination of rolling and a melee attack. here is what i made so far:

Lua:
addHook("SpinSpecial", function()
if p.mo.skin == "idk"
    and p.cmd.buttons & BT_SPIN then
        and P_IsObjectOnGround(p.mo)
    if not (p.pflags == PF_SPINNING) then
p.mo.state = S_PLAY_ROLL
        p.pflags = PF_SPINNING
              P_InstaThrust(p.mo, p.mo.angle, p.maxdash*FRACUNIT)
          p.powers[pw_strong] = STR_MELEE
        end
    end
end)

when i load it in the it doesn't show me any "warning" at first, but when i try to use the ability it shows me something about "attempt to index global 'p' (a number value)". can anyone please tell my why that is, and maybe point out other potential flaws in the code?
 
THE MAIN PROBLEM + HOW TO FIX

i'm trying to make an ability lua that is a combination of rolling and a melee attack.

when i load it in the it doesn't show me any "warning" at first, but when i try to use the ability it shows me something about "attempt to index global 'p' (a number value)". can anyone please tell my why that is...?

Seems like you forgot to put p as the thingy to call the player userdata!

In the very first line of your code piece, add p inside the ()s (I suddenly forgot their names in English... :dramahog:) of your SpinSpecial hook function.
Lua:
addHook("SpinSpecial", function(p) // 'p' gets recognized as the player



OTHER STUFF YOU MIGHT WANT TO FIX

That's it for the main problem, but...
...and maybe point out other potential flaws in the code?

|__________________________| OVERWRITING ABILITIES |_____|
Some hook types do special stuff when returning a certain value.
In the case of SpinSpecial hooks, returning true causes the character's defined ability to get overwritten by whatever the function does.
If your character's S_SKIN ability2 is NOT CA2_NONE, you can return true at the end of your function to ignore completely the default ability.
Overwriting abilities:
addHook("SpinSpecial", function(player)
    if player.mo.skin == "sonic"
        // Do cool stuff...
        return true // Cancel Sonic's default spin ability
    end
end)

|________________| ADDING INSTEAD OF REPLACING |_____|
In line 7, you're modifying the player's player flags, but there's something off here...
I don't know if it's intentional or not, but you are replacing any player flags with PF_SPINNING. I'm assuming this wasn't intentional, and if that's the case, add a dollar symbol ($), then a vertical bar (|) to the left of the constant itself.

The resulting line of code should look like this:
Lua:
p.pflags = $|PF_SPINNING

|________________________| ADJUSTING TO THE SCALE |_____|
I've seen lots of SRB2 scripts with the same problem: The scale isn't getting accounted.

"The scale doesn't affects a player's speed, right?"

It does.

Don't worry, though. This can be fixed by simply replacing FRACUNIT with p.mo.scale!
Lua:
P_InstaThrust(p.mo, p.mo.angle, p.maxdash*p.mo.scale)



Good luck with your project, and notify me about any problems related to all this I've said!
(Pardon me for any misspelling. I don't talk English, plus I'm writing this at midnight...)

hand_five.png
 
THE MAIN PROBLEM + HOW TO FIX



Seems like you forgot to put p as the thingy to call the player userdata!

In the very first line of your code piece, add p inside the ()s (I suddenly forgot their names in English... :dramahog:) of your SpinSpecial hook function.
Lua:
addHook("SpinSpecial", function(p) // 'p' gets recognized as the player



OTHER STUFF YOU MIGHT WANT TO FIX

That's it for the main problem, but...


|__________________________| OVERWRITING ABILITIES |_____|
Some hook types do special stuff when returning a certain value.
In the case of SpinSpecial hooks, returning true causes the character's defined ability to get overwritten by whatever the function does.
If your character's S_SKIN ability2 is NOT CA2_NONE, you can return true at the end of your function to ignore completely the default ability.
Overwriting abilities:
addHook("SpinSpecial", function(player)
    if player.mo.skin == "sonic"
        // Do cool stuff...
        return true // Cancel Sonic's default spin ability
    end
end)

|________________| ADDING INSTEAD OF REPLACING |_____|
In line 7, you're modifying the player's player flags, but there's something off here...
I don't know if it's intentional or not, but you are replacing any player flags with PF_SPINNING. I'm assuming this wasn't intentional, and if that's the case, add a dollar symbol ($), then a vertical bar (|) to the left of the constant itself.

The resulting line of code should look like this:
Lua:
p.pflags = $|PF_SPINNING

|________________________| ADJUSTING TO THE SCALE |_____|
I've seen lots of SRB2 scripts with the same problem: The scale isn't getting accounted.

"The scale doesn't affects a player's speed, right?"

It does.

Don't worry, though. This can be fixed by simply replacing FRACUNIT with p.mo.scale!
Lua:
P_InstaThrust(p.mo, p.mo.angle, p.maxdash*p.mo.scale)



Good luck with your project, and notify me about any problems related to all this I've said!
(Pardon me for any misspelling. I don't talk English, plus I'm writing this at midnight...)

View attachment 164537
this has helped me solve many of the problems i had with the code, and i am super grateful for that. however, i've also encountered a new problem: it holds my character in place while doing the rolling animation for as long as i hold the spin button. do you know how to solve that? here is that code:

Lua:
addHook("SpinSpecial", function(p)
if p.mo.skin == "idk"
    and P_IsObjectOnGround(p.mo)
    and p.cmd.buttons & BT_SPIN then
        if not (p.pflags == PF_SPINNING) then
        P_InstaThrust(p.mo, p.mo.angle, p.maxdash*p.mo.scale)
        p.mo.state = S_PLAY_ROLL
        p.pflags = $|PF_SPINNING
        p.powers[pw_strong] = STR_MELEE
        return true
        end
    end
end)
 
THE MAIN PROBLEM + HOW TO FIX



Seems like you forgot to put p as the thingy to call the player userdata!

In the very first line of your code piece, add p inside the ()s (I suddenly forgot their names in English... :dramahog:) of your SpinSpecial hook function.
Lua:
addHook("SpinSpecial", function(p) // 'p' gets recognized as the player



OTHER STUFF YOU MIGHT WANT TO FIX

That's it for the main problem, but...


|__________________________| OVERWRITING ABILITIES |_____|
Some hook types do special stuff when returning a certain value.
In the case of SpinSpecial hooks, returning true causes the character's defined ability to get overwritten by whatever the function does.
If your character's S_SKIN ability2 is NOT CA2_NONE, you can return true at the end of your function to ignore completely the default ability.
Overwriting abilities:
addHook("SpinSpecial", function(player)
    if player.mo.skin == "sonic"
        // Do cool stuff...
        return true // Cancel Sonic's default spin ability
    end
end)

|________________| ADDING INSTEAD OF REPLACING |_____|
In line 7, you're modifying the player's player flags, but there's something off here...
I don't know if it's intentional or not, but you are replacing any player flags with PF_SPINNING. I'm assuming this wasn't intentional, and if that's the case, add a dollar symbol ($), then a vertical bar (|) to the left of the constant itself.

The resulting line of code should look like this:
Lua:
p.pflags = $|PF_SPINNING

|________________________| ADJUSTING TO THE SCALE |_____|
I've seen lots of SRB2 scripts with the same problem: The scale isn't getting accounted.

"The scale doesn't affects a player's speed, right?"

It does.

Don't worry, though. This can be fixed by simply replacing FRACUNIT with p.mo.scale!
Lua:
P_InstaThrust(p.mo, p.mo.angle, p.maxdash*p.mo.scale)



Good luck with your project, and notify me about any problems related to all this I've said!
(Pardon me for any misspelling. I don't talk English, plus I'm writing this at midnight...)

View attachment 164537
My problem is also solved, Thank you.
 
this has helped me solve many of the problems i had with the code, and i am super grateful for that. however, i've also encountered a new problem: it holds my character in place while doing the rolling animation for as long as i hold the spin button. do you know how to solve that?
After testing it myself, and changing around some stuff, the problem seems to be... p.maxdash?
I couldn't find any other way of fixing this but changing the variable or directly using a number instead.
 

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

Back
Top