How to make a character play a sound when it moves

Status
Not open for further replies.

Puppyfaic

Member
Like Blade's Metal Sonic, I'd like to know how to go about making a character repeat a specific sound when it's moving. I tried looking at his Metal Sonic to figure it out but I don't speak Lua or SOC.
 
Maybe, I can help. How do you want the sound to be played, and what is it for?

---------------------------------------------------

Well, I may as well post some code just to give you some help.

Code:
addHook("ThinkFrame", do //Adds a ThinkFrame hook.
	for player in players.iterate //Gets the local player
		if (player.mo and player.mo.skin == "skinname") //Change "skinname" to the character's skin you want to use.
		and (player.pflags & PF_NIGHTSMODE) //Do not intefere with nights, it may crash the game.
			
			if not player.mo.footsteptimer //If the variable "footsteptimer" doesn't exist,
				player.mo.footsteptimer = 0 //Create the variable.
			end // End this block
			
			player.mo.footsteptimer = $1 + 1 //Add 1 to footsteptimer every tick. "$1" gets the variable's current value.
			
			if (player.panic == PA_RUN) //Change to PA_WALK if you want it to happen when walking.
			and player.mo.footsteptimer > TICRATE/2 //If half a second has passed since the last step sound,
				S_StartSound(player.mo, sfx_soundname) //Replace "soundname" with whatever the sound name is, removing "DS" from the beginning.
				player.mo.footsteptimer = 0 //Reset the foostep timer.
			end //End this block.
		end //End the player and nightsmode check block
	end //End the player iteration
end) //Finish the hook.

Everything is commented to give instructions and to help. It took me 10 minutes to write that all out.
 
Last edited:
It's for a joke character, and I want it to play and repeat DSSTATU2 whenever it's moving. I tried using the script you provided and I can't get it to work.
Code:
addHook("ThinkFrame", do //Adds a ThinkFrame hook.
	for player in players.iterate //Gets the local player
		if (player.mo and player.mo.skin == "Gargoyle") //Change "skinname" to the character's skin you want to use.
		and (player.pflags & PF_NIGHTSMODE) //Do not intefere with nights, it may crash the game.
			
			if not player.mo.footsteptimer //If the variable "footsteptimer" doesn't exist,
				player.mo.footsteptimer = 0 //Create the variable.
			end // End this block
			
			player.mo.footsteptimer = $1 + 1 //Add 1 to footsteptimer every tick. "$1" gets the variable's current value.
			
			if (player.panic == PA_RUN) //Change to PA_WALK if you want it to happen when walking.
			and player.mo.footsteptimer > TICRATE/2 //If half a second has passed since the last step sound,
				S_StartSound(player.mo, sfx_STATU2) //Replace "soundname" with whatever the sound name is, removing "DS" from the beginning.
				player.mo.footsteptimer = 0 //Reset the foostep timer.
			end //End this block.
		end //End the player and nightsmode check block
	end //End the player iteration
end) //Finish the hook.
 
Last edited:
"and (player.pflags & PF_NIGHTSMODE)" should be "and not (player.pflags & PF_NIGHTSMODE)", and "player.panic" should be "player.panim", to begin with.
 
Certain textures? You mean like on maps? That's probably something you would do with linedef executors in the map itself rather than a script.
 
I think that glaber means different sounds for walking on things depending on what it actually IS.
Y'know, if you're walking on solid ground textures, it sounds like you're walking on it. If you're treading snow, you'd hear the gentle crunch of the snow when you run over it. If you're running over grass, you'd hear it as if you were doing just that.

If glaber doesn't mean that, I'm lost. :P
 
"and (player.pflags & PF_NIGHTSMODE)" should be "and not (player.pflags & PF_NIGHTSMODE)", and "player.panic" should be "player.panim", to begin with.

Alright, I did that and it still doesn't work...

Code:
addHook("ThinkFrame", do //Adds a ThinkFrame hook.
	for player in players.iterate //Gets the local player
		if (player.mo and player.mo.skin == "Gargoyle") //Change "skinname" to the character's skin you want to use.
		and not (player.pflags & PF_NIGHTSMODE) //Do not intefere with nights, it may crash the game.
			
			if not player.mo.footsteptimer //If the variable "footsteptimer" doesn't exist,
				player.mo.footsteptimer = 0 //Create the variable.
			end // End this block
			
			player.mo.footsteptimer = $1 + 1 //Add 1 to footsteptimer every tick. "$1" gets the variable's current value.
			
			if (player.panim == PA_RUN) //Change to PA_WALK if you want it to happen when walking.
			and player.mo.footsteptimer > TICRATE/2 //If half a second has passed since the last step sound,
				S_StartSound(player.mo, sfx_STATU2) //Replace "soundname" with whatever the sound name is, removing "DS" from the beginning.
				player.mo.footsteptimer = 0 //Reset the foostep timer.
			end //End this block.
		end //End the player and nightsmode check block
	end //End the player iteration
end) //Finish the hook.
 
Last edited:
"and (player.pflags & PF_NIGHTSMODE)" should be "and not (player.pflags & PF_NIGHTSMODE)", and "player.panic" should be "player.panim", to begin with.

Sorry, I was tired at the time of writing the script.
I also wrote it in the plain text editor for the message.

Thank you for correcting my silly mistake though.

---------- Post added at 11:15 PM ---------- Previous post was at 11:13 PM ----------

Oh, I forgot to mention, "sfx_STATU2" should be lowercase.

Also, you need to add this line to the top of the code:

Code:
freeslot("sfx_statu2")
 
Code:
freeslot("sfx_statu2")

addHook("ThinkFrame", do //Adds a ThinkFrame hook.
	for player in players.iterate //Gets the local player
		if (player.mo and player.mo.skin == "Gargoyle") //Change "skinname" to the character's skin you want to use.
		and not (player.pflags & PF_NIGHTSMODE) //Do not intefere with nights, it may crash the game.
			
			if not player.mo.footsteptimer //If the variable "footsteptimer" doesn't exist,
				player.mo.footsteptimer = 0 //Create the variable.
			end // End this block
			
			player.mo.footsteptimer = $1 + 1 //Add 1 to footsteptimer every tick. "$1" gets the variable's current value.
			
			if (player.panim == PA_RUN) //Change to PA_WALK if you want it to happen when walking.
			and player.mo.footsteptimer > TICRATE/2 //If half a second has passed since the last step sound,
				S_StartSound(player.mo, sfx_statu2) //Replace "soundname" with whatever the sound name is, removing "DS" from the beginning.
				player.mo.footsteptimer = 0 //Reset the foostep timer.
			end //End this block.
		end //End the player and nightsmode check block
	end //End the player iteration
end) //Finish the hook.

Still not working.
 
Last edited:
i will make darksms wad

---------- Post added at 03:11 PM ---------- Previous post was at 03:10 PM ----------

what slade beta i download ?
 
Status
Not open for further replies.

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

Back
Top