Pretty new to LUA and I have an idea, wonder if anyone could point me in the right direction?

So like, I’m fairly new to LUA and don’t have a great deal of time on my hands but the time I do have I spend on coding to improve my Murder server.
I recently got an idea but not sure if it can be done and if it can how easy it will be…
Idea;
When the murderer is wearing a certain player model I want it to say different things when he loses / wins, is this possible and if so how easy / hard is it?

I don’t know the murder script but it is I gues quite easy
some thing to help you on your way



ply:GetModel()
ply:GetTeam == TEAM_MURDERER --or whatever team yust check the team file or shared file mostly in 
--there
--Search for the round win function and hook it on that function


The end round code is this;


	if data.reason == 3 then
		winner:SetText("Bystanders win! The murderer rage quit")
		winner:SetTextColor(Color(255, 255, 255))
	elseif data.reason == 2 then
		winner:SetText("Bystanders win!")
		winner:SetTextColor(Color(20, 120, 255))
	elseif data.reason == 1 then
		winner:SetText("The murderer wins!")
		winner:SetTextColor(Color(190, 20, 20))
	end

So I’m not sure where I would put ply:GetModel().
Would I put it next to the elseif and put ply:GetModel() &&?
(I also don’t know where to find the data.reason)

It may be easier to set up a table with the model being the key, and a default key…’

Here is the short-storage-method example where the full model path excluding models/players/ and excluding .mdl extension is used for the table:


local MODEL_SPECIFIC_SOUNDS = {
	// If you want full-path - models/player/ and -.mdl ( DEFAULT because the _mdl = string.sub( _mdl, 15, string.len( _mdl ) - 4 ); IS ACTIVE )
	[ "group03m/male_03" ] = {
		[ WINTYPE_LOSE ] = "vo/npc/male01/no01.wav";
		[ WINTYPE_WIN ] = "vo/npc/male01/no02.wav";
		[ WINTYPE_TIME ] = "vo/npc/male01/goodgod.wav";
	};

	default = {
		[ WINTYPE_LOSE ] = "vo/npc/female01/no01.wav";
		[ WINTYPE_WIN ] = "vo/npc/female01/no02.wav";
		[ WINTYPE_TIME ] = "vo/npc/female01/goodgod.wav";
	};
};

// This hook would need to be your on-win hook...
hook.Add( "OnWin", "PlayModelSpecificWinSounds", function( _p, _wintype )
	local _mdl = _p:GetModel( ); -- FULL PATH

	// If you only want to use "group03m/male_03" as the model instead of models/player/group03m/male_03.mdl ( IF you ALWAYS use models/player/ folder.. the last 4 can always be stripped because the file should always be a mdl )
	_mdl = string.sub( _mdl, 15, string.len( _mdl ) - 4 ); -- DEFAULT

	// Ternary which verifies if the model has a sound-table AND the win-type sound exists, otherwise it uses the default table which MUST exist...
	local _sound = ( MODEL_SPECIFIC_SOUNDS[ _mdl ] && MODEL_SPECIFIC_SOUNDS[ _mdl ][ _wintype ] ) && MODEL_SPECIFIC_SOUNDS[ _mdl ][ _wintype ] || MODEL_SPECIFIC_SOUNDS.default[ _wintype ];

	// Play the sound:
	_p:EmitSound( _sound );
end

Hopefully this is clear.

[editline]4th August 2014[/editline]

I turned it into a “tutorial” with different examples, including one for TTT where each player will play their own win/lose/time-limit sound on round-end as example 1, and 3 more examples depending how you want the data to be stored: https://dl.dropboxusercontent.com/u/26074909/tutoring/sound/spawn_entity_in_front_of_player_by_calc_size_of_object.lua.html