Skip to content

Commit e70d3a2

Browse files
committed
Fix hl2sb gamemode
1 parent c9a3150 commit e70d3a2

File tree

7 files changed

+45
-35
lines changed

7 files changed

+45
-35
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
template: lua-class-function.html
3-
title: AddRecipientsByPAS
3+
title: AddRecipientsByPas
44
icon: lua-shared
55
tags:
66
- lua
@@ -9,10 +9,10 @@ tags:
99
- needs-example
1010
lua:
1111
library: RecipientFilter
12-
function: AddRecipientsByPAS
12+
function: AddRecipientsByPas
1313
realm: shared
1414
description: "Adds recipients by potentially audible set"
15-
15+
1616
arguments:
1717
- position: 1
1818
name: "filter"
@@ -21,9 +21,9 @@ lua:
2121
name: "position"
2222
type: Vector
2323
returns:
24-
24+
2525
---
2626

2727
<div class="lua__search__keywords">
28-
RecipientFilter:AddRecipientsByPAS &#x2013; Adds recipients by potentially audible set
28+
RecipientFilter:AddRecipientsByPas &#x2013; Adds recipients by potentially audible set
2929
</div>
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
template: lua-class-function.html
3-
title: AddRecipientsByPVS
3+
title: AddRecipientsByPvs
44
icon: lua-shared
55
tags:
66
- lua
@@ -9,10 +9,10 @@ tags:
99
- needs-example
1010
lua:
1111
library: RecipientFilter
12-
function: AddRecipientsByPVS
12+
function: AddRecipientsByPvs
1313
realm: shared
1414
description: "Adds recipients by potentially visible set"
15-
15+
1616
arguments:
1717
- position: 1
1818
name: "filter"
@@ -21,9 +21,9 @@ lua:
2121
name: "position"
2222
type: Vector
2323
returns:
24-
24+
2525
---
2626

2727
<div class="lua__search__keywords">
28-
RecipientFilter:AddRecipientsByPVS &#x2013; Adds recipients by potentially visible set
28+
RecipientFilter:AddRecipientsByPvs &#x2013; Adds recipients by potentially visible set
2929
</div>

game/experiment/addons/gmod_compatibility/scripts/lua/includes/modules/gmod_compatibility/sh_init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ engine.TickInterval = Engines.GetIntervalPerTick
267267
SoundDuration = Engines.GetSoundDuration
268268
GetHostName = Engines.GetServerName
269269
Player = Players.FindByUserId
270+
EmitSound = Sounds.Play
270271

271272
PrecacheParticleSystem = ParticleSystems.Precache
272273
GetPredictionPlayer = Predictions.GetPredictionPlayer

game/experiment/gamemodes/hl2sb/gamemode/shared.lua

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function GM:FlWeaponTryRespawn(targetWeapon)
2828
return 0
2929
end
3030

31-
function GM:PlayerPlayStepSound(client, vecOrigin, psurface, fvol, force)
31+
function GM:PlayerPlayStepSound(client, vecOrigin, psurface, volume, force)
3232
if (Engines.GetMaxClients() > 1 and ConsoleVariables.FindVariable("sv_footsteps"):GetFloat() == 0) then
3333
return false
3434
end
@@ -69,32 +69,25 @@ function GM:PlayerPlayStepSound(client, vecOrigin, psurface, fvol, force)
6969
end
7070

7171
-- Only cache if there's one option. Otherwise we'd never here any other sounds
72-
if (params.count == 1) then
73-
client:SetStepSoundCache(nSide, "m_usSoundNameIndex", stepSoundName)
74-
client:SetStepSoundCache(nSide, "m_SoundParameters", params)
75-
end
72+
if (params.count == 1) then
73+
client:SetStepSoundCache(nSide, "m_usSoundNameIndex", stepSoundName)
74+
client:SetStepSoundCache(nSide, "m_SoundParameters", params)
75+
end
76+
77+
stepSoundName = pSoundName
7678
end
7779

7880
local filter = RecipientFilters.Create()
79-
filter:AddRecipientsByPAS(vecOrigin)
81+
filter:AddRecipientsByPas(vecOrigin)
8082

8183
if not CLIENT then
8284
-- in MP, server removes all players in the vecOrigin's PVS, these players generate the footsteps client side
8385
if (Engines.GetMaxClients() > 1) then
84-
filter:RemoveRecipientsByPVS(vecOrigin)
86+
filter:RemoveRecipientsByPvs(vecOrigin)
8587
end
8688
end
8789

88-
local ep = {}
89-
ep.m_nChannel = 4; -- CHAN_BODY
90-
ep.m_pSoundName = params.soundname
91-
ep.m_flVolume = fvol
92-
ep.m_SoundLevel = params.soundlevel
93-
ep.m_nFlags = 0
94-
ep.m_nPitch = params.pitch
95-
ep.m_pOrigin = vecOrigin
96-
97-
_R.Entity.EmitSound(filter, client:GetEntityIndex(), ep)
90+
Sounds.Play(stepSoundName, vecOrigin, 0, _E.SOUND_CHANNEL.BODY, volume, params.soundlevel, 0, params.pitch, 0, filter)
9891
return false
9992
end
10093

src/game/shared/gmod_luabase.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ int CLuaBase::CreateMetaTable( const char *strName )
9494
}
9595
else
9696
{
97-
Assert( 0 ); // TODO: Does this happen?
97+
// TODO: This else is reached when running `lua_run require("mysqloo")` twice,
98+
// causing it to run this CreateMetaTable method twice.
99+
return m_mapMetaTableNameToID.Find( strName );
98100
}
99101

100102
return m_mapMetaTableNameToID.Count() - 1;

src/game/shared/lrecipientfilter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ LUA_BINDING_BEGIN( RecipientFilter, AddRecipient, "class", "Adds a single recipi
7878
}
7979
LUA_BINDING_END()
8080

81-
LUA_BINDING_BEGIN( RecipientFilter, AddRecipientsByPAS, "class", "Adds recipients by potentially audible set" )
81+
LUA_BINDING_BEGIN( RecipientFilter, AddRecipientsByPas, "class", "Adds recipients by potentially audible set" )
8282
{
8383
LUA_BINDING_ARGUMENT( luaL_checkrecipientfilter, 1, "filter" ).AddRecipientsByPAS( LUA_BINDING_ARGUMENT( luaL_checkvector, 2, "position" ) );
8484
return 0;

src/public/lsounds.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "luasrclib.h"
44
#include <lsounds.h>
55
#include <engine/IEngineSound.h>
6+
#include <lrecipientfilter.h>
67

78
// memdbgon must be the last include file in a .cpp file!!!
89
#include "tier0/memdbgon.h"
@@ -551,10 +552,23 @@ LUA_BINDING_BEGIN( Sounds, Play, "library", "Plays a sound emitting from a place
551552
{
552553
const char *pszSoundName = LUA_BINDING_ARGUMENT( luaL_checkstring, 1, "soundName" ); // doc: sound script name or sound file name relative to sound/ folder
553554
const Vector vecOrigin = LUA_BINDING_ARGUMENT( luaL_checkvector, 2, "origin" ); // doc: position of the sound
554-
soundlevel_t soundLevel = LUA_BINDING_ARGUMENT_ENUM_WITH_DEFAULT( soundlevel_t, 3, SNDLVL_NORM, "soundLevel" );
555-
float flPitchPercent = LUA_BINDING_ARGUMENT_WITH_DEFAULT( luaL_optnumber, 4, 100, "pitchPercent" );
555+
int entityIndex = ( int )LUA_BINDING_ARGUMENT_WITH_DEFAULT( luaL_optnumber, 3, SOUND_FROM_WORLD, "entity" );
556+
SOUND_CHANNEL channel = ( SOUND_CHANNEL )LUA_BINDING_ARGUMENT_WITH_DEFAULT( luaL_optnumber, 4, SOUND_CHANNEL::CHAN_AUTO, "channel" );
556557
float flVolume = LUA_BINDING_ARGUMENT_WITH_DEFAULT( luaL_optnumber, 5, 1, "volume" );
557-
int nDSP = LUA_BINDING_ARGUMENT_WITH_DEFAULT( luaL_optnumber, 6, 0, "dsp" );
558+
soundlevel_t soundLevel = LUA_BINDING_ARGUMENT_ENUM_WITH_DEFAULT( soundlevel_t, 6, SNDLVL_NORM, "soundLevel" );
559+
int soundFlags = LUA_BINDING_ARGUMENT_WITH_DEFAULT( luaL_optnumber, 7, 0, "soundFlags" );
560+
float flPitchPercent = LUA_BINDING_ARGUMENT_WITH_DEFAULT( luaL_optnumber, 8, 100, "pitchPercent" );
561+
int nDSP = LUA_BINDING_ARGUMENT_WITH_DEFAULT( luaL_optnumber, 9, 0, "dsp" );
562+
lua_CRecipientFilter filter;
563+
564+
if ( lua_isrecipientfilter( L, 10 ) )
565+
{
566+
filter = LUA_BINDING_ARGUMENT_NILLABLE( luaL_checkrecipientfilter, 10, "filter" );
567+
}
568+
else
569+
{
570+
filter = CPASAttenuationFilter( vecOrigin, soundLevel );
571+
}
558572

559573
float duration = 0;
560574

@@ -568,10 +582,10 @@ LUA_BINDING_BEGIN( Sounds, Play, "library", "Plays a sound emitting from a place
568582
params.m_flSoundTime = 0;
569583
params.m_pflSoundDuration = &duration;
570584
params.m_bWarnOnDirectWaveReference = false;
585+
params.m_nChannel = channel;
586+
params.m_nFlags = soundFlags;
571587

572-
CPVSFilter filter( vecOrigin );
573-
574-
CBaseEntity::EmitSound( filter, SOUND_FROM_WORLD, params );
588+
CBaseEntity::EmitSound( filter, entityIndex, params );
575589

576590
lua_pushnumber( L, duration );
577591

0 commit comments

Comments
 (0)