SRB2 Message Board  

Go Back   SRB2 Message Board > Sonic Robo Blast 2 > Help

Reply
 
Thread Tools Search this Thread
Old 4 Weeks Ago   #1
Murilo
Elyos03
 
Murilo's Avatar
Default How do i make a Char. Ability Replacement Script

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 by Murilo; 4 Weeks Ago at 06:54 PM.
Murilo is offline   Reply With Quote
Old 4 Weeks Ago   #2
Monster Iestyn
Friendly Neighbour-Hood
Moderator
 
Monster Iestyn's Avatar
Default

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.
Attached Files
File Type: lua abilityspecial-example.lua (826 Bytes, 28 views)
Monster Iestyn is offline   Reply With Quote
Old 4 Weeks Ago   #3
Murilo
Elyos03
 
Murilo's Avatar
Default

Quote:
Originally Posted by Monster Iestyn View Post
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!
Murilo is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:35 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.