SRB2 Message Board  

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

Reply
 
Thread Tools Search this Thread
Old 11-01-2017   #1
Elyos03
 
Elyos03's Avatar
Default Vanilla Characters Hurt VoiceOver Script help?

How can a make one of the three Vanilla Characters say something everytime it gets hurt with LUA? I've been thinking of a WAD that makes Knuckles say "Oh No" everytime he gets hit.
__________________
Is 2.2 out yet?
Elyos03 is offline   Reply With Quote
Old 11-01-2017   #2
jameds
James
Default

Doing some quick research on the wiki will answer many editing questions...

Looks like you can make a SOC that does this (see http://wiki.srb2.org/wiki/Object#Sounds.)
Scrolling down on that page shows an example too.

Here's a SOC tutorial: http://wiki.srb2.org/wiki/Object_creation_tutorial


Also, I think these sorts of questions go in Editing/Help.
jameds is offline   Reply With Quote
Old 11-01-2017   #3
-CG7244-
ewe''
 
-CG7244-'s Avatar
Default

Or, you can do that in Lua:

Code:
addHook("ThinkFrame", function(p)
    for p in players.iterate
	    if p.mo and p.mo.skin == "knuckles" --character that will play the sound
		
		    if not P_PlayerInPain(p)
			    p.readytodosound = 1
				p.dosound = 0
			elseif p.readytodosound
                p.dosound = 1
				p.readytodosound = 0
			else
                p.dosound = 0
			end
            
            if p.dosound
                S_StartSound(p.mo, sfx_buzz3)			
			end
		end
	end
end)
"sfx_buzz3" is the sound that will be played, and to make it play once, you need to make a custom variable like I did.

P_PlayerDoPain, is the action when the player gets hurt.

EDIT: You always need to use the "sfx_" to use a sound, example, if you want to use the sound "DSBUZZ3" , you will write "sfx_buzz3" I mean, without the "DS", also, can be any sound, including custom ones. I hope this helped you.

Anyway, remember, if you want to use it with another character, replace "knuckles" with the character's SKIN NAME like: "skinname" .
__________________
Quote:
<CG7244> We spriters can see EACH DETAIL
My wad page: https://sites.google.com/view/carloswadjunk

Last edited by -CG7244-; 11-01-2017 at 11:31 PM.
-CG7244- is offline   Reply With Quote
Old 11-01-2017   #4
Elyos03
 
Elyos03's Avatar
Default

Quote:
Originally Posted by -CG7244- View Post
Or, you can do that in Lua:

Code:
addHook("ThinkFrame", function(p)
    for p in players.iterate
        if p.mo and p.mo.skin == "knuckles" --character that will play the sound
        
            if not P_PlayerInPain(p)
                p.readytodosound = 1
                p.dosound = 0
            elseif p.readytodosound
                p.dosound = 1
                p.readytodosound = 0
            else
                p.dosound = 0
            end
            
            if p.dosound
                S_StartSound(p.mo, sfx_buzz3)            
            end
        end
    end
end)
"sfx_buzz3" is the sound that will be played, and to make it play once, you need to make a custom variable like I did.

P_PlayerDoPain, is the action when the player gets hurt.

EDIT: You always need to use the "sfx_" to use a sound, example, if you want to use the sound "DSBUZZ3" , you will write "sfx_buzz3" I mean, without the "DS", also, can be any sound, including custom ones. I hope this helped you.

Anyway, remember, if you want to use it with another character, replace "knuckles" with the character's SKIN NAME like: "skinname" .
Thanks, i've couldn't finish my idea WAD without your help. Not sure if i can release it on here or Sapheros' homepage.
__________________
Is 2.2 out yet?
Elyos03 is offline   Reply With Quote
Old 11-02-2017   #5
Rob
Administrator
 
Rob's Avatar
Default

Quote:
Originally Posted by -CG7244- View Post
Or, you can do that in Lua
Lua has horrible overhead. Something that can be done purely in SOC should be done in SOC.
Rob is offline   Reply With Quote
Old 11-02-2017   #6
Elyos03
 
Elyos03's Avatar
Default

Quote:
Originally Posted by Rob View Post
Lua has horrible overhead. Something that can be done purely in SOC should be done in SOC.
At least the LUA method works fine. I'm really satisfied with the result.
__________________
Is 2.2 out yet?
Elyos03 is offline   Reply With Quote
Old 11-02-2017   #7
-CG7244-
ewe''
 
-CG7244-'s Avatar
Default

Quote:
Originally Posted by Rob View Post
Lua has horrible overhead. Something that can be done purely in SOC should be done in SOC.
At least, the voice is heard while playing the "rings sound", anyway, if he wants to use the voice only, just use for example "DSALTOW1 = DSHURT" in S_SKIN lump.
__________________
Quote:
<CG7244> We spriters can see EACH DETAIL
My wad page: https://sites.google.com/view/carloswadjunk
-CG7244- is offline   Reply With Quote
Old 11-03-2017   #8
Monster Iestyn
Friendly Neighbour-Hood
Moderator
 
Monster Iestyn's Avatar
Default

Quote:
Originally Posted by Elyos03 View Post
At least the LUA method works fine. I'm really satisfied with the result.
Just so you know, Lua isn't an acronym.

EDIT: Besides which there is an even simpler method of making players play sounds when hurt with Lua:

Instead of using the ThinkFrame hook, use the MobjDamage hook:

Code:
// playerow, the function that actually contains the code we want to run when the player is damaged
//
// target is the mobj_t that was hurt (in this case of course, this should be you)
// inflictor is the mobj_t that dealt the damage
// source is the mobj_t that spawned the inflictor, if it is not the inflictor itself
// damage is the amount of damage that was dealt to "target"
//
// in this example only "target" really matters though, but you can take advantage of the above arguments for alternative sounds perhaps
//
local function playerow(target, inflictor, source, damage)
	if target.skin == "knuckles" // is this player using the knuckles skin?
		S_StartSound(target, sfx_example) // if so, play a sound!
	end
end

// Now, we use addHook to link the function above to the damaging code
// "MobjDamage" is a hook to link a function call to the damaging code, specifically after the game has decided yes the object should definitely be hurt
// playerow of course is the function defined above
// the final argument of addHook for this kind of hook determines what type of object "target" should be in order for the function to run;
//     in this case it should only affect players who were damaged, which is why it is set to "MT_PLAYER" here
//
addHook("MobjDamage", playerow, MT_PLAYER)
I added a bunch of comments in case that helps (no idea if this works offhand I just wrote it on the spot tbh, but it should give you a general idea how to use the hook at least)
__________________
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.

Last edited by Monster Iestyn; 11-03-2017 at 04:02 AM.
Monster Iestyn 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:22 AM.


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