Vanilla Characters Hurt VoiceOver Script help?

Status
Not open for further replies.

Elyos03

↑↑↓↓←→←→ B A START
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.
 
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" .
 
Last edited:
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.
 
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.
 
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)
 
Last edited:
Status
Not open for further replies.

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

Back
Top