SRB2 Message Board  

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

Reply
 
Thread Tools Search this Thread
Old 08-18-2017   #1
Elyos03
 
Elyos03'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 Elyos03; 08-18-2017 at 06:54 PM.
Elyos03 is offline   Reply With Quote
Old 08-18-2017   #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, 68 views)
__________________
My page stuffed full of MIDI goodness!
The Hitchhiker's Guide to the Robo-Hoodiverse
Timeline of Sonic Robo Blast History!

That's an uppercase i, not a lowercase L, for the record.
Monster Iestyn is offline   Reply With Quote
Old 08-18-2017   #3
Elyos03
 
Elyos03'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!
Elyos03 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 06:20 PM.


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