-- DESCRIPTION: This is a custom behavior for Melee fighting with speech. -- DESCRIPTION: When the target is within [RANGE=500] distance, the character will attack the target using melee combat, either using fists, or with a melee weapon if equipped. -- DESCRIPTION: They can optionally [RunAway!=0] and be [InstantlyKillable!=1]. -- DESCRIPTION: Stand and speak with multiple speaks. -- DESCRIPTION: [UseEKey!=0] -- DESCRIPTION: [Volume=80(0,100)] -- DESCRIPTION: [Delay=1] (seconds) -- DESCRIPTION: [NumberOfSpeaks=1(1,4)] -- DESCRIPTION: Speech file (.wav) for lip-sync [SPEECH0$=""] -- DESCRIPTION: Speech file (.wav) for lip-sync [SPEECH1$=""] -- DESCRIPTION: Speech file (.wav) for lip-sync [SPEECH2$=""] -- DESCRIPTION: Speech file (.wav) for lip-sync [SPEECH3$=""] master_interpreter_core = require "scriptbank\\masterinterpreter" g_Melee_Attack_With_Speech = {} g_Melee_Attack_With_Speech_behavior = {} g_Melee_Attack_With_Speech_behavior_count = 0 function Melee_Attack_With_Speech_init(e) g_Melee_Attack_With_Speech[e] = {} g_Melee_Attack_With_Speech[e]["bycfilename"] = "scriptbank\\user\\Melee_Attack_With_Speech.byc" g_Melee_Attack_With_Speech_behavior_count = master_interpreter_core.masterinterpreter_load (g_Melee_Attack_With_Speech[e], g_Melee_Attack_With_Speech_behavior ) Melee_Attack_With_Speech_properties(e,0,0,0) end function Melee_Attack_With_Speech_properties(e, range, runaway, instantlykillable) g_Melee_Attack_With_Speech[e]['range'] = range g_Melee_Attack_With_Speech[e]['runaway'] = runaway g_Melee_Attack_With_Speech[e]['instantlykillable'] = instantlykillable master_interpreter_core.masterinterpreter_restart (g_Melee_Attack_With_Speech[e], g_Entity[e]) end function Melee_Attack_With_Speech_main(e) if g_Melee_Attack_With_Speech[e] ~= nil and g_Melee_Attack_With_Speech_behavior_count > 0 then g_Melee_Attack_With_Speech_behavior_count = master_interpreter_core.masterinterpreter (g_Melee_Attack_With_Speech_behavior, g_Melee_Attack_With_Speech_behavior_count, e, g_Melee_Attack_With_Speech[e], g_Entity[e]) end end function my_stand_and_speak_properties( e, usekey, volume, delay, num ) local peep = peeps[ e ] if peep == nil then return end peep.UseEKey = usekey == 1 peep.Volume = volume peep.Delay = delay * 1000 peep.NumSpks = num end ----------------------------------------------------- local U = require "scriptbank\\utillib" function my_stand_and_speak_init( e ) local Ent = g_Entity[ e ] peeps[ e ] = { state = 'idle', speech = 0 } CharacterControlManual( e ) CharacterControlUnarmed( e ) AISetEntityControl( Ent.obj, AI_MANUAL ) SetEntityHealthSilent( e, 999999 ) SetAnimationName( e, "Idle" ) LoopAnimation( e ) end local function Speak( e, num, vol ) PlaySpeech( e, num ) SetSound( e, num ) SetSoundVolume( vol ) end function my_stand_and_speak_main( e ) local peep = peeps[ e ] if peep == nil then return end if peep.state == 'idle' and U.PlayerLookingNear( e, 100, 150 ) then if peep.speech == 0 or ( peep.UseEKey and g_KeyPressE == 1 ) then peep.state = 'speak' elseif peep.delay ~= nil and g_Time > peep.delay then peep.state = 'speak' end elseif peep.state == 'speak' then Speak( e, peep.speech, peep.Volume ) peep.state = 'wait' elseif peep.state == 'wait' then SendMessageF( "lookattargete", e, 0 ) SendMessageF( "lookatplayer", e, 10 ) if GetSpeech( e ) == 0 then peep.speech = peep.speech + 1 if peep.speech > peep.NumSpks then peep.state = 'done' else if not peep.UseEKey then peep.delay = g_Time + peep.Delay else peep.delay = math.huge end peep.state = 'idle' end end end --PromptLocal( e, peep.state .. ", " .. peep.speech .. ", " .. GetSpeech( e ) ) end