How do i make a Char. Ability Replacement Script

Status
Not open for further replies.

Elyos03

↑↑↓↓←→←→ B A START
How do i change a Character Ability for Vanilla Characters with LUA Scripts? I know that the Lock On WAD Changes Sonic's ability from Thok to Homing Thok. How's that possible?
 
Last edited:
Simple, you use the "AbilitySpecial" hook.

More information here: https://wiki.srb2.org/wiki/Lua/Hooks#AbilitySpecial

Here's a tip though, if you want to make sure your ability doesn't act like your character has multiability, you should check if PF_THOKKED has already been set in the player's pflags (player.pflags) and, if not, set the PF_THOKKED flag after the ability has been used once. Landing on the ground will then remove the PF_THOKKED flag for you.

Here's an example:

Code:
// declare and define a function with a single parameter
// "p" is the player this function is being called for
local function AbilityExample(p)
	if p.mo.skin != "sonic" // is this your skin?
		return false // do whatever's normal if not
	end

	if (p.pflags & PF_THOKKED) // don't do anything if you've already used this
		return true // override normal behavior (in case the character would normally have thok or something)
	end

	print("I just pressed jump in midair!") // make a print message (yes I'm using this as an example "ability" lol"

	p.pflags = $ | PF_THOKKED // add this flag to prevent ability being used again this jump
	
	return true // override normal behavior (in case the character would normally have thok or something)
end

addHook("AbilitySpecial", AbilityExample) // hook the function

This example Lua script will cause Sonic to print "I just pressed jump in midair!" in the console instead of using the thok. It will not affect any other character.

I've also attached the script to this post if you want to easily get it and play it in-game to see for yourself.
 

Attachments

  • abilityspecial-example.lua
    826 bytes · Views: 259
Simple, you use the "AbilitySpecial" hook.

More information here: https://wiki.srb2.org/wiki/Lua/Hooks#AbilitySpecial

Here's a tip though, if you want to make sure your ability doesn't act like your character has multiability, you should check if PF_THOKKED has already been set in the player's pflags (player.pflags) and, if not, set the PF_THOKKED flag after the ability has been used once. Landing on the ground will then remove the PF_THOKKED flag for you.

Here's an example:

Code:
// declare and define a function with a single parameter
// "p" is the player this function is being called for
local function AbilityExample(p)
    if p.mo.skin != "sonic" // is this your skin?
        return false // do whatever's normal if not
    end

    if (p.pflags & PF_THOKKED) // don't do anything if you've already used this
        return true // override normal behavior (in case the character would normally have thok or something)
    end

    print("I just pressed jump in midair!") // make a print message (yes I'm using this as an example "ability" lol"

    p.pflags = $ | PF_THOKKED // add this flag to prevent ability being used again this jump
    
    return true // override normal behavior (in case the character would normally have thok or something)
end

addHook("AbilitySpecial", AbilityExample) // hook the function
This example Lua script will cause Sonic to print "I just pressed jump in midair!" in the console instead of using the thok. It will not affect any other character.

I've also attached the script to this post if you want to easily get it and play it in-game to see for yourself.
That's a good example, but you just showed me with Print Messages. A better example would be replacing his Thok with the Double Jump. Thanks for showing me the Ability Special Script anyway!
 
Status
Not open for further replies.

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

Back
Top