diff --git a/game/experiment/addons/gmod_compatibility/scripts/lua/includes/modules/gmod_compatibility/sh_init.lua b/game/experiment/addons/gmod_compatibility/scripts/lua/includes/modules/gmod_compatibility/sh_init.lua index e8b65ee37e..b48db04580 100644 --- a/game/experiment/addons/gmod_compatibility/scripts/lua/includes/modules/gmod_compatibility/sh_init.lua +++ b/game/experiment/addons/gmod_compatibility/scripts/lua/includes/modules/gmod_compatibility/sh_init.lua @@ -56,6 +56,17 @@ function math.random(min, max) return originalMathRandom(min, max) end +function math.pow(base, exponent) + return base ^ exponent +end + +-- Since Lua 5.3 non-integers give an error +local originalRandomSeed = math.randomseed + +function math.randomseed(seed) + originalRandomSeed(math.floor(seed)) +end + util = Utilities util.PrecacheModel = _R.Entity.PrecacheModel util.PrecacheSound = _R.Entity.PrecacheSound @@ -69,6 +80,7 @@ util.NetworkStringToID = function() return 0 end -- Not needed for us. util.TraceLine = Traces.TraceLine util.TraceHull = Traces.TraceHull util.TraceEntity = Traces.TraceEntity +util.PointContents = Traces.PointContents util.JSONToTable = function(json) return Json.Decode(json) @@ -83,6 +95,8 @@ util.CRC = function(unencoded) return tostring(Serializers.Crc32(unencoded)) end +util.SharedRandom = Randoms.SharedRandomFloat + ents = { Create = Entities.CreateByName, @@ -214,6 +228,8 @@ IsFirstTimePredicted = Predictions.IsFirstTimePredicted LerpVector = Vectors.Lerp RecipientFilter = RecipientFilters.Create +EffectData = Effects.Create +util.Effect = Effects.Dispatch system.AppTime = Systems.GetSecondsSinceAppActive system.IsOSX = Systems.IsOsx @@ -401,6 +417,12 @@ game = { GetMap = Engines.GetLevelName, } +local EFFECT_DATA_META = FindMetaTable("EffectData") +EFFECT_DATA_META.GetEntIndex = EFFECT_DATA_META.GetEntityIndex +EFFECT_DATA_META.SetEntIndex = EFFECT_DATA_META.SetEntityIndex +EFFECT_DATA_META.GetAttachment = EFFECT_DATA_META.GetAttachmentIndex +EFFECT_DATA_META.SetAttachment = EFFECT_DATA_META.SetAttachmentIndex + local VECTOR_META = FindMetaTable("Vector") VECTOR_META.AngleEx = VECTOR_META.AngleWithUp VECTOR_META.Distance = VECTOR_META.DistanceTo @@ -432,6 +454,7 @@ function ANGLE_META:Set(angleToCopy) end local ENTITY_META = FindMetaTable("Entity") +ENTITY_META.EntIndex = ENTITY_META.GetEntityIndex ENTITY_META.Health = ENTITY_META.GetHealth ENTITY_META.GetPos = ENTITY_META.GetPosition ENTITY_META.SetPos = ENTITY_META.SetPosition @@ -459,6 +482,8 @@ ENTITY_META.GetNumBodyGroups = ENTITY_META.GetBodyGroupsCount ENTITY_META.WaterLevel = ENTITY_META.GetWaterLevel ENTITY_META.SetMaterial = ENTITY_META.SetMaterialOverride ENTITY_META.GetMaterial = ENTITY_META.GetMaterialOverride +ENTITY_META.GetAbsVelocity = ENTITY_META.GetLocalVelocity +ENTITY_META.SetAbsVelocity = ENTITY_META.SetLocalVelocity function ENTITY_META:GetDTAngle(index) return self:GetNetworkDataValue(_E.NETWORK_VARIABLE_TYPE.ANGLE, index) @@ -611,7 +636,7 @@ WEAPON_META.Ammo1 = WEAPON_META.GetPrimaryAmmoCount WEAPON_META.Ammo2 = WEAPON_META.GetSecondaryAmmoCount local PLAYER_META = FindMetaTable("Player") -PLAYER_META.GetShootPos = ENTITY_META.GetEyePosition +PLAYER_META.GetShootPos = ENTITY_META.GetWeaponShootPosition PLAYER_META.UserID = PLAYER_META.GetUserId PLAYER_META.AccountID = PLAYER_META.GetAccountId PLAYER_META.SteamID = PLAYER_META.GetSteamId @@ -641,6 +666,14 @@ PLAYER_META.KeyReleased = PLAYER_META.WasKeyReleased PLAYER_META.GetFOV = PLAYER_META.GetFov PLAYER_META.SetFOV = PLAYER_META.SetFov +function PLAYER_META:LagCompensation(shouldStart) + if (shouldStart) then + self:StartLagCompensation() + else + self:FinishLagCompensation() + end +end + function PLAYER_META:Crouching() return self:IsFlagSet(_E.ENGINE_FLAG.DUCKING) end diff --git a/game/experiment/gamemodes/deathmatch/gamemode/init.lua b/game/experiment/gamemodes/deathmatch/gamemode/init.lua index 11019efb0e..2c69679bc3 100644 --- a/game/experiment/gamemodes/deathmatch/gamemode/init.lua +++ b/game/experiment/gamemodes/deathmatch/gamemode/init.lua @@ -49,7 +49,7 @@ function GM:GiveDefaultItems(client) local defaultWeaponName = Engines.GetClientConsoleVariableValue(Engines.IndexOfEdict(client), "cl_defaultweapon") local defaultWeapon = client:OwnsWeaponOfType(defaultWeaponName) - if (ToBaseEntity(defaultWeapon) ~= NULL) then + if (defaultWeapon ~= NULL) then client:SwitchWeapon(defaultWeapon) else client:SwitchWeapon(client:OwnsWeaponOfType("weapon_physcannon")) diff --git a/game/experiment/gamemodes/super/gamemode/init.lua b/game/experiment/gamemodes/super/gamemode/init.lua index fe2dbb0ac5..f04d9cafb3 100644 --- a/game/experiment/gamemodes/super/gamemode/init.lua +++ b/game/experiment/gamemodes/super/gamemode/init.lua @@ -54,7 +54,7 @@ function GM:GiveDefaultItems(client) local defaultWeaponName = Engines.GetClientConsoleVariableValue(Engines.IndexOfEdict(client), "cl_defaultweapon") local defaultWeapon = client:OwnsWeaponOfType(defaultWeaponName) - if (ToBaseEntity(defaultWeapon) ~= NULL) then + if (defaultWeapon ~= NULL) then client:SwitchWeapon(defaultWeapon) else client:SwitchWeapon(client:OwnsWeaponOfType("weapon_physcannon")) diff --git a/game/experiment/scripts/lua/includes/extensions/entity.lua b/game/experiment/scripts/lua/includes/extensions/entity.lua index 5f73551b7e..6eab8e2c5b 100644 --- a/game/experiment/scripts/lua/includes/extensions/entity.lua +++ b/game/experiment/scripts/lua/includes/extensions/entity.lua @@ -9,24 +9,6 @@ if (GAMEUI) then return end -local printError = debug.PrintError - -function ToBaseEntity(pEntity) - if (not pEntity or type(pEntity) ~= "entity") then - return NULL - end - - local success, hEntity = xpcall(_R.Entity.GetBaseEntity, printError, pEntity) - if (not success) then - hEntity = NULL - end - if _DEBUG then - assert(hEntity ~= NULL) - end - - return hEntity -end - local ENTITY_META = _R.CBaseAnimating -- Source has inconsistent naming conventions for these, lets just support both name styles. diff --git a/game/experiment/scripts/lua/includes/extensions/weapon.lua b/game/experiment/scripts/lua/includes/extensions/weapon.lua index 6829709f9b..8fc84de98e 100644 --- a/game/experiment/scripts/lua/includes/extensions/weapon.lua +++ b/game/experiment/scripts/lua/includes/extensions/weapon.lua @@ -27,7 +27,7 @@ function _R.Weapon.WeaponSound( self, sound_type, soundtime ) -- WeaponSound( self, sound_type, soundtime ) -- else local shootsound = self:GetShootSound( sound_type ) - if ( ToBaseEntity( client ) ~= NULL ) then + if ( client ~= NULL ) then client:EmitSound( shootsound ) else self:EmitSound( shootsound ) diff --git a/game/experiment/scripts/lua/includes/modules/networks.lua b/game/experiment/scripts/lua/includes/modules/networks.lua index e798c07c53..4e8ede7b67 100644 --- a/game/experiment/scripts/lua/includes/modules/networks.lua +++ b/game/experiment/scripts/lua/includes/modules/networks.lua @@ -711,16 +711,16 @@ end if (SERVER) then function MODULE.Send(client) - if (not currentOutgoingMessage) then - error("Networks.Send was called without calling Networks.Start.") - end + if (not currentOutgoingMessage) then + error("Networks.Send was called without calling Networks.Start.") + end - local socketClient = MODULE.ClientToSocketClient(client) + local socketClient = MODULE.ClientToSocketClient(client) - local data = currentOutgoingMessage:GetPackedData() - currentOutgoingMessage = nil + local data = currentOutgoingMessage:GetPackedData() + currentOutgoingMessage = nil - if (not socketClient) then + if (not socketClient) then debug("Client is not connected yet, queueing message...", client) MODULE.QueueMessage(client, data) return @@ -729,17 +729,37 @@ if (SERVER) then socketClient:send(data) end - function MODULE.Broadcast() - if (not currentOutgoingMessage) then - error("Networks.Broadcast was called without calling Networks.Start.") - end + function MODULE.Broadcast() + if (not currentOutgoingMessage) then + error("Networks.Broadcast was called without calling Networks.Start.") + end - for _, socketClient in ipairs(socketClients) do - MODULE.Send(socketClient.client) - end + for _, socketClient in ipairs(socketClients) do + MODULE.Send(socketClient.client) + end - currentOutgoingMessage = nil - end + currentOutgoingMessage = nil + end + + function MODULE.SendOmit(clientOrClientsToExclude) + if (not currentOutgoingMessage) then + error("Networks.SendOmit was called without calling Networks.Start.") + end + + local clientsToExclude = type(clientOrClientsToExclude) == "table" and clientOrClientsToExclude or {clientOrClientsToExclude} + + for _, socketClient in ipairs(socketClients) do + local client = socketClient.client + + if (table.HasValue(clientsToExclude, client)) then + continue + end + + MODULE.Send(client) + end + + currentOutgoingMessage = nil + end --- Sends the message to all players that have the entity in their PVS --- @param entity any diff --git a/game/experiment/scripts/lua/weapons/weapon_experiment_base_scripted/shared.lua b/game/experiment/scripts/lua/weapons/weapon_experiment_base_scripted/shared.lua index a12ab9c171..2154d65122 100644 --- a/game/experiment/scripts/lua/weapons/weapon_experiment_base_scripted/shared.lua +++ b/game/experiment/scripts/lua/weapons/weapon_experiment_base_scripted/shared.lua @@ -1,5 +1,5 @@ SWEP.PrintName = "#HL2_357Handgun" -SWEP.ViewModel = "models/weapons/v_357.mdl" +SWEP.ViewModel = "models/weapons/v_pistol.mdl" SWEP.WorldModel = "models/weapons/w_357.mdl" SWEP.AnimationPrefix = "python" SWEP.InventorySlot = 1 @@ -9,7 +9,7 @@ SWEP.MaxClip = 6 SWEP.MaxClip2 = -1 SWEP.DefaultClip = 6 SWEP.DefaultClip2 = -1 -SWEP.PrimaryAmmo = "357" +SWEP.PrimaryAmmo = "Pistol" SWEP.SecondaryAmmo = "None" SWEP.Weight = 7 @@ -46,93 +46,158 @@ SWEP.m_acttable = { 1093, 982, false }, { 1064, 983, false }, -}; +} function SWEP:Initialize() - self.m_bReloadsSingly = false; - self.m_bFiresUnderwater = false; + -- TODO: implement these + -- self.m_bReloadsSingly = false + -- self.m_bFiresUnderwater = false end function SWEP:Precache() end -function SWEP:PrimaryAttack() - -- Only the player fires this way so we can cast - local pPlayer = self:GetOwner(); +--[[ + Here for Gmod compatibility +--]] +function SWEP:ShootEffects() + local owner = self:GetOwner() + + self:SendWeaponAnimation(_E.ACTIVITY.ACT_VM_PRIMARYATTACK) + owner:DoMuzzleFlash() + owner:SetAnimation(_E.PLAYER_ANIMATION.ATTACK1) +end + +function SWEP:ShootBullet(damage, amountOfBullets, spread, ammoType, force, tracer) + local owner = self:GetOwner() + local bulletInfo = { + Src = owner:GetWeaponShootPosition(), + Dir = owner:GetAimVector(0.08715574274766), + Spread = Vector(spread.x, spread.y, 0), + + Num = amountOfBullets, + AmmoType = ammoType or self.Primary.Ammo, + Tracer = tracer or 5, + + Damage = damage, + Force = force or 1, + } + + owner:FireBullets(bulletInfo) + + self:ShootEffects() +end + +function SWEP:OnRemove() +end + +function SWEP:OwnerChanged() +end + +function SWEP:Ammo1() + return self:GetOwner():GetAmmoCount(self:GetPrimaryAmmoType()) +end + +function SWEP:Ammo2() + return self:GetOwner():GetAmmoCount(self:GetSecondaryAmmoType()) +end + +function SWEP:DoImpactEffect(trace, damageType) + return false +end - if (ToBaseEntity(pPlayer) == NULL) then - return; +function SWEP:CanPrimaryAttack() + if (self:Clip1() <= 0) then -- TODO: implement: and not self.m_bFireOnEmpty) then + return false end - if (self.m_iClip1 <= 0) then - if (not self.m_bFireOnEmpty) then - self:Reload(); - else - self:WeaponSound(0); - self.m_flNextPrimaryAttack = 0.15; - end + return true +end - return; +function SWEP:PrimaryAttack() + if (not self:CanPrimaryAttack()) then + self:EmitSound("Weapon_Pistol.Empty") + self:SetNextPrimaryFire(Engines.GetCurrentTime() + 0.2) + self:Reload() + + return end - self:WeaponSound(1); - pPlayer:DoMuzzleFlash(); + local owner = self:GetOwner() - self:SendWeaponAnim(180); - pPlayer:SetAnimation(5); - ToHL2MPPlayer(pPlayer):DoAnimationEvent(0); + if (owner == NULL) then + return + end - self.m_flNextPrimaryAttack = gpGlobals.curtime() + 0.75; - self.m_flNextSecondaryAttack = gpGlobals.curtime() + 0.75; + self:EmitWeaponSound(1) - self.m_iClip1 = self.m_iClip1 - 1; + owner:DoAnimationEvent(_E.PLAYER_ANIMATION_EVENT.PLAYERANIMEVENT_ATTACK_PRIMARY) - local vecSrc = pPlayer:Weapon_ShootPosition(); - local vecAiming = pPlayer:GetAutoaimVector(0.08715574274766); + self:SetNextPrimaryFire(Engines.GetCurrentTime() + 0.75) + self:SetNextSecondaryFire(Engines.GetCurrentTime() + 0.75) - local info = { - m_iShots = 1, - m_vecSrc = vecSrc, - m_vecDirShooting = vecAiming, - m_vecSpread = - vec3_origin, - m_flDistance = MAX_TRACE_LENGTH, - m_iAmmoType = self.m_iPrimaryAmmoType - }; - info.m_pAttacker = pPlayer; + self:TakePrimaryAmmo(1) - -- Fire the bullets, and force the first shot to be perfectly accuracy - pPlayer:FireBullets(info); + self:ShootBullet(self.Damage, 1, 0.01, self.Primary.Ammo) - --Disorient the player - local angles = pPlayer:GetLocalAngles(); + -- Disorient the player + local angles = owner:GetLocalAngles() - angles.x = angles.x + random.RandomInt(-1, 1); - angles.y = angles.y + random.RandomInt(-1, 1); - angles.z = 0; + angles.x = angles.x + Randoms.RandomInt(-1, 1) + angles.y = angles.y + Randoms.RandomInt(-1, 1) + angles.z = 0 - if not _CLIENT then - pPlayer:SnapEyeAngles(angles); + if (not CLIENT) then + owner:SnapEyeAngles(angles) end - pPlayer:ViewPunch(QAngle(-8, random.RandomFloat(-2, 2), 0)); + owner:ViewPunch(Angles.Create(-8, Randoms.RandomFloat(-2, 2), 0)) - if (self.m_iClip1 == 0 and pPlayer:GetAmmoCount(self.m_iPrimaryAmmoType) <= 0) then + if (self:Clip1() == 0 and owner:GetAmmoCount(self:GetPrimaryAmmoType()) <= 0) then -- HEV suit - indicate out of ammo condition - pPlayer:SetSuitUpdate("!HEV_AMO0", 0, 0); + owner:SetSuitUpdate("!HEV_AMO0", 0, 0) end end function SWEP:SecondaryAttack() end +function SWEP:TakePrimaryAmmo(num) + if (self:Clip1() <= 0) then + if (self:Ammo1() <= 0) then + return + end + self:GetOwner():RemoveAmmo(num, self:GetPrimaryAmmoType()) + + return + end + + self:SetClip1(self:Clip1() - num) +end + +function SWEP:TakeSecondaryAmmo(num) + if (self:Clip2() <= 0) then + if (self:Ammo2() <= 0) then + return + end + + self:GetOwner():RemoveAmmo(num, self:GetSecondaryAmmoType()) + + return + end + + self:SetClip2(self:Clip2() - num) +end + function SWEP:Reload() - local fRet = self:DefaultReload(self:GetMaxClip1(), self:GetMaxClip2(), 182); + local fRet = self:DefaultReload(self:GetMaxClip1(), self:GetMaxClip2(), _E.ACTIVITY.ACT_VM_RELOAD) + if (fRet) then - -- self:WeaponSound( 6 ); - ToHL2MPPlayer(self:GetOwner()):DoAnimationEvent(3); + -- self:WeaponSound( 6 ) + self:GetOwner():DoAnimationEvent(_E.PLAYER_ANIMATION_EVENT.PLAYERANIMEVENT_RELOAD) end - return fRet; + + return fRet end function SWEP:Think() @@ -142,6 +207,7 @@ function SWEP:CanHolster() end function SWEP:Deploy() + return true end function SWEP:GetDrawActivity() @@ -149,6 +215,7 @@ function SWEP:GetDrawActivity() end function SWEP:Holster(pSwitchingTo) + return true end function SWEP:ItemPostFrame() diff --git a/src/game/client/cdll_client_int.cpp b/src/game/client/cdll_client_int.cpp index bb04f95c73..859046bcd5 100644 --- a/src/game/client/cdll_client_int.cpp +++ b/src/game/client/cdll_client_int.cpp @@ -2209,6 +2209,14 @@ void SimulateEntities() pEnt->Simulate(); } } + +#ifdef LUA_SDK + if ( L ) + { + LUA_CALL_HOOK_BEGIN( "Think" ); + LUA_CALL_HOOK_END( 0, 0 ); + } +#endif } bool AddDataChangeEvent( IClientNetworkable *ent, DataUpdateType_t updateType, int *pStoredEvent ) @@ -2219,11 +2227,13 @@ bool AddDataChangeEvent( IClientNetworkable *ent, DataUpdateType_t updateType, i // Make sure we don't already have an event queued for this guy. if ( *pStoredEvent >= 0 ) { - Assert( g_DataChangedEvents[*pStoredEvent].m_pEntity == ent ); + CDataChangedEvent &pEvent = g_DataChangedEvents[*pStoredEvent]; + + Assert( pEvent.m_pEntity == ent ); // DATA_UPDATE_CREATED always overrides DATA_UPDATE_CHANGED. if ( updateType == DATA_UPDATE_CREATED ) - g_DataChangedEvents[*pStoredEvent].m_UpdateType = updateType; + pEvent.m_UpdateType = updateType; return false; } diff --git a/src/game/client/lc_baseplayer.cpp b/src/game/client/lc_baseplayer.cpp index ec28968aba..b343aa58ac 100644 --- a/src/game/client/lc_baseplayer.cpp +++ b/src/game/client/lc_baseplayer.cpp @@ -3,27 +3,28 @@ #include "luamanager.h" #include "luasrclib.h" #include "lbaseplayer_shared.h" +#include "iclientmode.h" // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" -// Moved to 'Players' library -//static int CBasePlayer_GetLocalPlayer( lua_State *L ) -//{ -// CBaseEntity::PushLuaInstanceSafe( L, CBasePlayer::GetLocalPlayer() ); -// return 1; -//} -// -//static const luaL_Reg CBasePlayermeta[] = { -// { "GetLocalPlayer", CBasePlayer_GetLocalPlayer }, -// { NULL, NULL } }; +LUA_REGISTRATION_INIT( Player ) + +LUA_BINDING_BEGIN( Player, ShouldDrawLocalPlayer, "class", "Whether the player's player model will be drawn." ) +{ + lua_pushboolean( L, g_pClientMode->ShouldDrawLocalPlayer( LUA_BINDING_ARGUMENT( luaL_checkplayer, 1, "player" ) ) ); + return 1; +} +LUA_BINDING_END( "boolean", "True if the player's player model will be drawn." ) /* ** Open CBasePlayer object */ LUALIB_API int luaopen_CBasePlayer( lua_State *L ) { - //LUA_PUSH_METATABLE_TO_EXTEND( L, LUA_BASEPLAYERMETANAME ); - //luaL_register( L, NULL, CBasePlayermeta ); + LUA_PUSH_METATABLE_TO_EXTEND( L, LUA_BASEPLAYERMETANAME ); + + LUA_REGISTRATION_COMMIT( Player ); + return 1; } diff --git a/src/game/server/lplayer.cpp b/src/game/server/lplayer.cpp index 867f96b11e..60faa13906 100644 --- a/src/game/server/lplayer.cpp +++ b/src/game/server/lplayer.cpp @@ -49,6 +49,15 @@ LUA_BINDING_BEGIN( Player, CreateViewModel, "class", "Create a view model for th } LUA_BINDING_END() +// TODO: This should be part of CBaseEntity, but currently only players are checked for m_bLagCompensation +LUA_BINDING_BEGIN( Player, SetLagCompensated, "class", "Set the player's lag compensation." ) +{ + lua_CBasePlayer *player = LUA_BINDING_ARGUMENT( luaL_checkplayer, 1, "player" ); + player->m_bLagCompensation = LUA_BINDING_ARGUMENT( luaL_checkboolean, 2, "lagCompensation" ); + return 0; +} +LUA_BINDING_END() + LUA_BINDING_BEGIN( Player, HideViewModels, "class", "Hide all view models for the player." ) { lua_CBasePlayer *player = LUA_BINDING_ARGUMENT( luaL_checkplayer, 1, "player" ); diff --git a/src/game/server/physics_main.cpp b/src/game/server/physics_main.cpp index 9a84fe8af9..cbd673d0b6 100644 --- a/src/game/server/physics_main.cpp +++ b/src/game/server/physics_main.cpp @@ -1989,6 +1989,14 @@ void Physics_RunThinkFunctions( bool simulating ) if ( !simulating ) { +#ifdef LUA_SDK + if ( L ) + { + LUA_CALL_HOOK_BEGIN( "Think" ); + LUA_CALL_HOOK_END( 0, 0 ); + } +#endif + // only simulate players for ( int i = 1; i <= gpGlobals->maxClients; i++ ) { diff --git a/src/game/shared/baseentity_shared.cpp b/src/game/shared/baseentity_shared.cpp index d7035fd14f..a3eaf189cd 100644 --- a/src/game/shared/baseentity_shared.cpp +++ b/src/game/shared/baseentity_shared.cpp @@ -1980,8 +1980,17 @@ void CBaseEntity::FireBullets( const FireBulletsInfo_t &info ) } #endif // #ifdef PORTAL - MakeTracer( vecTracerSrc, Tracer, pAmmoDef->TracerType( info.m_iAmmoType ) ); - + // Experiment; added m_pszTracerType + if ( info.m_pszTracerType && info.m_pszTracerType[0] != 0 ) + { + Vector vNewSrc = vecTracerSrc; + int iAttachment = GetTracerAttachment(); + UTIL_Tracer( vNewSrc, Tracer.endpos, entindex(), iAttachment, 0.0f, false, info.m_pszTracerType ); + } + else + { + MakeTracer( vecTracerSrc, Tracer, pAmmoDef->TracerType( info.m_iAmmoType ) ); + } #ifdef PORTAL if ( pShootThroughPortal ) { diff --git a/src/game/shared/experiment/experiment_gamerules.cpp b/src/game/shared/experiment/experiment_gamerules.cpp index c22e849141..00c97e7fa9 100644 --- a/src/game/shared/experiment/experiment_gamerules.cpp +++ b/src/game/shared/experiment/experiment_gamerules.cpp @@ -485,11 +485,6 @@ float CExperimentRules::FlPlayerSpawnTime( CBasePlayer *pPlayer ) void CExperimentRules::Think( void ) { -#ifdef LUA_SDK - LUA_CALL_HOOK_BEGIN( "Think" ); - LUA_CALL_HOOK_END( 0, 0 ); -#endif - #ifndef CLIENT_DLL CGameRules::Think(); @@ -574,7 +569,6 @@ void CExperimentRules::Think( void ) } ManageObjectRelocation(); - #endif } diff --git a/src/game/shared/experiment/weapon_experimentbase_scriptedweapon.cpp b/src/game/shared/experiment/weapon_experimentbase_scriptedweapon.cpp index da08f90b02..3720dbf28d 100644 --- a/src/game/shared/experiment/weapon_experimentbase_scriptedweapon.cpp +++ b/src/game/shared/experiment/weapon_experimentbase_scriptedweapon.cpp @@ -143,7 +143,8 @@ acttable_t *CExperimentScriptedWeapon::ActivityList( void ) #ifdef LUA_SDK lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "m_acttable" ); - lua_remove( L, -2 ); + lua_remove( L, -2 ); // Remove the reference table + if ( lua_istable( L, -1 ) ) { for ( int i = 0; i < LUA_MAX_WEAPON_ACTIVITIES; i++ ) @@ -293,11 +294,11 @@ void CExperimentScriptedWeapon::InitScriptedWeapon( void ) // Andrew; This redundancy is pretty annoying. // Classname Q_strncpy( m_pLuaWeaponInfo->szClassName, className, MAX_WEAPON_STRING ); - SetClassname( className ); + SetClassname( m_pLuaWeaponInfo->szClassName ); m_pLuaWeaponInfo->bParsedScript = true; - // Get (or init) the ref table + // Get (or init) the ref table (popped near the end of this function) LUA_GET_REF_TABLE( L, this ); // Printable name @@ -601,6 +602,9 @@ void CExperimentScriptedWeapon::InitScriptedWeapon( void ) } lua_pop( L, 1 ); // Pop the Damage field + // Pop the LUA_GET_REF_TABLE + lua_pop( L, 1 ); + LUA_CALL_HOOK_BEGIN( "PreEntityInitialize" ); CBaseEntity::PushLuaInstanceSafe( L, this ); LUA_CALL_HOOK_END( 1, 0 ); @@ -681,10 +685,12 @@ void CExperimentScriptedWeapon::Precache( void ) // Precache models (preload to avoid hitch) m_iViewModelIndex = 0; m_iWorldModelIndex = 0; + if ( GetViewModel() && GetViewModel()[0] ) { m_iViewModelIndex = CBaseEntity::PrecacheModel( GetViewModel() ); } + if ( GetWorldModel() && GetWorldModel()[0] ) { m_iWorldModelIndex = CBaseEntity::PrecacheModel( GetWorldModel() ); @@ -721,7 +727,7 @@ const char *CExperimentScriptedWeapon::GetViewModel( int ) const { lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "ViewModel" ); - lua_remove( L, -2 ); + lua_remove( L, -2 ); // Remove the reference table LUA_RETURN_STRING(); } @@ -737,7 +743,7 @@ const char *CExperimentScriptedWeapon::GetWorldModel( void ) const { lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "WorldModel" ); - lua_remove( L, -2 ); + lua_remove( L, -2 ); // Remove the reference table LUA_RETURN_STRING(); } @@ -753,7 +759,7 @@ const char *CExperimentScriptedWeapon::GetAnimPrefix( void ) const { lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "AnimationPrefix" ); - lua_remove( L, -2 ); + lua_remove( L, -2 ); // Remove the reference table LUA_RETURN_STRING(); } @@ -769,7 +775,7 @@ const char *CExperimentScriptedWeapon::GetPrintName( void ) const { lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "PrintName" ); - lua_remove( L, -2 ); + lua_remove( L, -2 ); // Remove the reference table LUA_RETURN_STRING(); } @@ -785,7 +791,7 @@ int CExperimentScriptedWeapon::GetMaxClip1( void ) const { lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "MaxClip" ); - lua_remove( L, -2 ); + lua_remove( L, -2 ); // Remove the reference table LUA_RETURN_INTEGER(); } @@ -801,7 +807,7 @@ int CExperimentScriptedWeapon::GetMaxClip2( void ) const { lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "MaxClip2" ); - lua_remove( L, -2 ); + lua_remove( L, -2 ); // Remove the reference table LUA_RETURN_INTEGER(); } @@ -817,7 +823,7 @@ int CExperimentScriptedWeapon::GetDefaultClip1( void ) const { lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "DefaultClip" ); - lua_remove( L, -2 ); + lua_remove( L, -2 ); // Remove the reference table LUA_RETURN_INTEGER(); } @@ -833,7 +839,7 @@ int CExperimentScriptedWeapon::GetDefaultClip2( void ) const { lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "DefaultClip2" ); - lua_remove( L, -2 ); + lua_remove( L, -2 ); // Remove the reference table LUA_RETURN_INTEGER(); } @@ -849,7 +855,7 @@ bool CExperimentScriptedWeapon::IsMeleeWeapon() const { lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "MeleeWeapon" ); - lua_remove( L, -2 ); + lua_remove( L, -2 ); // Remove the reference table LUA_RETURN_BOOLEAN_FROM_INTEGER(); } @@ -865,7 +871,7 @@ int CExperimentScriptedWeapon::GetWeight( void ) const { lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "Weight" ); - lua_remove( L, -2 ); + lua_remove( L, -2 ); // Remove the reference table LUA_RETURN_INTEGER(); } @@ -881,7 +887,7 @@ bool CExperimentScriptedWeapon::AllowsAutoSwitchTo( void ) const { lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "AutoSwitchTo" ); - lua_remove( L, -2 ); + lua_remove( L, -2 ); // Remove the reference table LUA_RETURN_BOOLEAN_FROM_INTEGER(); } @@ -897,7 +903,7 @@ bool CExperimentScriptedWeapon::AllowsAutoSwitchFrom( void ) const { lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "AutoSwitchFrom" ); - lua_remove( L, -2 ); + lua_remove( L, -2 ); // Remove the reference table LUA_RETURN_BOOLEAN_FROM_INTEGER(); } @@ -913,7 +919,7 @@ int CExperimentScriptedWeapon::GetWeaponFlags( void ) const { lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "WeaponFlags" ); - lua_remove( L, -2 ); + lua_remove( L, -2 ); // Remove the reference table LUA_RETURN_INTEGER(); } @@ -929,7 +935,7 @@ int CExperimentScriptedWeapon::GetSlot( void ) const { lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "InventorySlot" ); - lua_remove( L, -2 ); + lua_remove( L, -2 ); // Remove the reference table LUA_RETURN_INTEGER(); } @@ -945,7 +951,7 @@ int CExperimentScriptedWeapon::GetPosition( void ) const { lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "InventorySlotPosition" ); - lua_remove( L, -2 ); + lua_remove( L, -2 ); // Remove the reference table LUA_RETURN_INTEGER(); } diff --git a/src/game/shared/gameinfostore.cpp b/src/game/shared/gameinfostore.cpp index 052a365915..e5d8603b82 100644 --- a/src/game/shared/gameinfostore.cpp +++ b/src/game/shared/gameinfostore.cpp @@ -35,6 +35,7 @@ void CGameInfoStore::FireGameEvent( IGameEvent *event ) Q_strncpy( m_pszServerAddress, pszServerAddress, sizeof( m_pszServerAddress ) ); Q_strncpy( m_pszServerName, pszServerName, sizeof( m_pszServerName ) ); + m_bIsDedicatedServer = event->GetBool( "dedicated" ); } else if ( Q_strcmp( eventType, "game_newmap" ) == 0 ) { diff --git a/src/game/shared/gameinfostore.h b/src/game/shared/gameinfostore.h index 3f9ac00249..a5ba951048 100644 --- a/src/game/shared/gameinfostore.h +++ b/src/game/shared/gameinfostore.h @@ -29,6 +29,11 @@ class CGameInfoStore : public CGameEventListener return m_pszMapName; } + bool IsDedicatedServer() + { + return m_bIsDedicatedServer; + } + virtual CBasePlayer* GetPlayerByAddress(const char* pszAddress) { int mapIndex = m_mapPlayerIndexToAddress.Find(pszAddress); @@ -45,6 +50,7 @@ class CGameInfoStore : public CGameEventListener char m_pszServerAddress[46]; // 39 (ipv6) + 6 (port) + 1 (null terminator) = 46 char m_pszServerName[512]; char m_pszMapName[512]; + bool m_bIsDedicatedServer; CUtlStringMap< int > m_mapPlayerIndexToAddress; }; diff --git a/src/game/shared/lbasecombatweapon_shared.cpp b/src/game/shared/lbasecombatweapon_shared.cpp index f9400d9034..82a049c59a 100644 --- a/src/game/shared/lbasecombatweapon_shared.cpp +++ b/src/game/shared/lbasecombatweapon_shared.cpp @@ -160,6 +160,24 @@ LUA_BINDING_BEGIN( Weapon, Clip2, "class", "The amount of ammo in the secondary } LUA_BINDING_END( "integer", "The amount of ammo in the secondary clip." ) +LUA_BINDING_BEGIN( Weapon, SetClip1, "class", "Set the amount of ammo in the primary clip." ) +{ + lua_CBaseCombatWeapon *pWeapon = LUA_BINDING_ARGUMENT( luaL_checkweapon, 1, "entity" ); + int iClip = LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "clip" ); + pWeapon->m_iClip1 = iClip; + return 0; +} +LUA_BINDING_END() + +LUA_BINDING_BEGIN( Weapon, SetClip2, "class", "Set the amount of ammo in the secondary clip." ) +{ + lua_CBaseCombatWeapon *pWeapon = LUA_BINDING_ARGUMENT( luaL_checkweapon, 1, "entity" ); + int iClip = LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "clip" ); + pWeapon->m_iClip2 = iClip; + return 0; +} +LUA_BINDING_END() + LUA_BINDING_BEGIN( Weapon, DefaultDeploy, "class", "Default deploy." ) { lua_CBaseCombatWeapon *pWeapon = LUA_BINDING_ARGUMENT( luaL_checkweapon, 1, "entity" ); @@ -929,7 +947,7 @@ LUA_BINDING_BEGIN( Weapon, SecondaryAttack, "class", "Secondary attack." ) } LUA_BINDING_END() -LUA_BINDING_BEGIN( Weapon, SendViewModelAnim, "class", "Send view model animation." ) +LUA_BINDING_BEGIN( Weapon, SendViewModelAnimation, "class", "Send view model animation." ) { lua_CBaseCombatWeapon *pWeapon = LUA_BINDING_ARGUMENT( luaL_checkweapon, 1, "entity" ); int iSequence = LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "sequence" ); @@ -938,7 +956,7 @@ LUA_BINDING_BEGIN( Weapon, SendViewModelAnim, "class", "Send view model animatio } LUA_BINDING_END() -LUA_BINDING_BEGIN( Weapon, SendWeaponAnim, "class", "Send weapon animation." ) +LUA_BINDING_BEGIN( Weapon, SendWeaponAnimation, "class", "Send weapon animation." ) { lua_CBaseCombatWeapon *pWeapon = LUA_BINDING_ARGUMENT( luaL_checkweapon, 1, "entity" ); int iActivity = LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "activity" ); @@ -1174,7 +1192,7 @@ LUA_BINDING_BEGIN( Weapon, WeaponIdle, "class", "Weapon idle." ) } LUA_BINDING_END() -LUA_BINDING_BEGIN( Weapon, WeaponSound, "class", "Weapon sound." ) +LUA_BINDING_BEGIN( Weapon, EmitWeaponSound, "class", "Weapon sound." ) { lua_CBaseCombatWeapon *pWeapon = LUA_BINDING_ARGUMENT( luaL_checkweapon, 1, "entity" ); int iSound = LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "soundType" ); diff --git a/src/game/shared/lbaseentity_shared.cpp b/src/game/shared/lbaseentity_shared.cpp index ea16c4d5f3..fe9a5aa99c 100644 --- a/src/game/shared/lbaseentity_shared.cpp +++ b/src/game/shared/lbaseentity_shared.cpp @@ -380,7 +380,7 @@ LUA_BINDING_BEGIN( Entity, EmitSound, "class", "Emit sound." ) lua_CBaseEntity *pEntity = LUA_BINDING_ARGUMENT( luaL_checkentity, 1, "entity" ); const char *pszSoundName = LUA_BINDING_ARGUMENT( luaL_checkstring, 2, "soundName" ); - int flSoundLevel = LUA_BINDING_ARGUMENT_WITH_DEFAULT( luaL_optnumber, 3, 75, "soundLevel" ); + soundlevel_t soundLevel = LUA_BINDING_ARGUMENT_ENUM_WITH_DEFAULT( soundlevel_t, 3, SNDLVL_NORM, "soundLevel" ); float flPitchPercent = LUA_BINDING_ARGUMENT_WITH_DEFAULT( luaL_optnumber, 4, 100, "pitchPercent" ); float flVolume = LUA_BINDING_ARGUMENT_WITH_DEFAULT( luaL_optnumber, 5, 1, "volume" ); int nChannel = LUA_BINDING_ARGUMENT_WITH_DEFAULT( luaL_optnumber, 6, pEntity->IsWeapon() ? CHAN_WEAPON : CHAN_AUTO, "channel" ); @@ -390,7 +390,11 @@ LUA_BINDING_BEGIN( Entity, EmitSound, "class", "Emit sound." ) CRecipientFilter *filter = nullptr; if ( lua_isrecipientfilter( L, 9 ) ) - filter = &LUA_BINDING_ARGUMENT( luaL_checkrecipientfilter, 9, "filter" ); + filter = &LUA_BINDING_ARGUMENT_NILLABLE( luaL_checkrecipientfilter, 9, "filter" ); + else + { + filter = new CPASAttenuationFilter( pEntity, soundLevel ); + } float duration = 0; int iEntIndex = pEntity->entindex(); @@ -399,7 +403,7 @@ LUA_BINDING_BEGIN( Entity, EmitSound, "class", "Emit sound." ) params.m_pSoundName = pszSoundName; params.m_nChannel = nChannel; params.m_flVolume = flVolume; - params.m_SoundLevel = ( soundlevel_t )flSoundLevel; + params.m_SoundLevel = soundLevel; params.m_nFlags = nSoundFlags; params.m_nPitch = flPitchPercent; params.m_pOrigin = &pEntity->GetAbsOrigin(); @@ -413,6 +417,8 @@ LUA_BINDING_BEGIN( Entity, EmitSound, "class", "Emit sound." ) lua_pushnumber( L, duration ); + delete[] filter; + return 1; } LUA_BINDING_END( "number", "The sound duration." ) diff --git a/src/game/shared/lbaseplayer_shared.cpp b/src/game/shared/lbaseplayer_shared.cpp index 516725760c..509cb6b9ce 100644 --- a/src/game/shared/lbaseplayer_shared.cpp +++ b/src/game/shared/lbaseplayer_shared.cpp @@ -10,6 +10,7 @@ #else #include "lbaseanimating.h" #include "player_resource.h" +#include "ilagcompensationmanager.h" #endif #include "lbasecombatweapon_shared.h" #include "lbaseentity_shared.h" @@ -17,10 +18,10 @@ #include "mathlib/lvector.h" #include "lvphysics_interface.h" #include +#include // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" -#include /* ** access functions (stack -> C) @@ -935,6 +936,42 @@ LUA_BINDING_BEGIN( Player, SetLadderNormal, "class", "Set the player's ladder no } LUA_BINDING_END() +LUA_BINDING_BEGIN( Player, StartLagCompensation, "class", "Set the player's lag compensation. On the client this does nothing." ) +{ +#ifndef CLIENT_DLL + lua_CBasePlayer *player = LUA_BINDING_ARGUMENT( luaL_checkplayer, 1, "player" ); + + if ( lagcompensation->IsCurrentlyDoingLagCompensation() ) + { + DevWarning( "Cannot start lag compensation while already having started it!\n" ); + return 0; + } + + // Move other players back to history positions based on local player's lag + lagcompensation->StartLagCompensation( player, + player->GetCurrentCommand() ); +#endif + return 0; +} +LUA_BINDING_END() + +LUA_BINDING_BEGIN( Player, FinishLagCompensation, "class", "Set the player's lag compensation. On the client this does nothing." ) +{ +#ifndef CLIENT_DLL + lua_CBasePlayer *player = LUA_BINDING_ARGUMENT( luaL_checkplayer, 1, "player" ); + + if ( !lagcompensation->IsCurrentlyDoingLagCompensation() ) + { + DevWarning( "Cannot finish lag compensation when not having started it!\n" ); + return 0; + } + + lagcompensation->FinishLagCompensation( player ); +#endif + return 0; +} +LUA_BINDING_END() + LUA_BINDING_BEGIN( Player, SetMaxSpeed, "class", "Set the player's current max speed." ) { lua_CBasePlayer *player = LUA_BINDING_ARGUMENT( luaL_checkplayer, 1, "player" ); @@ -1234,6 +1271,14 @@ LUA_BINDING_BEGIN( Player, GetViewPunchAngles, "class", "Get the player's view p } LUA_BINDING_END( "Angle", "The player's view punch angle." ) +LUA_BINDING_BEGIN( Player, SetViewPunchAngles, "class", "Set the player's view punch angle." ) +{ + lua_CBasePlayer *player = LUA_BINDING_ARGUMENT( luaL_checkplayer, 1, "player" ); + player->m_Local.m_vecPunchAngle = LUA_BINDING_ARGUMENT( luaL_checkangle, 2, "angle" ); + return 0; +} +LUA_BINDING_END() + LUA_BINDING_BEGIN( Player, CanSwitchToWeapon, "class", "Check if the player can switch to a weapon." ) { lua_pushboolean( @@ -1307,7 +1352,7 @@ LUA_BINDING_BEGIN( Player, WasKeyReleased, "class", "Check if a key was released } LUA_BINDING_END( "boolean", "Whether the key was released." ) -LUA_BINDING_BEGIN( Player, WeaponShootPosition, "class", "Get the player's weapon shoot position." ) +LUA_BINDING_BEGIN( Player, GetWeaponShootPosition, "class", "Get the player's weapon shoot position." ) { Vector v = LUA_BINDING_ARGUMENT( luaL_checkplayer, 1, "player" )->Weapon_ShootPosition(); lua_pushvector( L, v ); diff --git a/src/game/shared/leffect_dispatch_data.cpp b/src/game/shared/leffect_dispatch_data.cpp index 6b8be90754..982a472ac3 100644 --- a/src/game/shared/leffect_dispatch_data.cpp +++ b/src/game/shared/leffect_dispatch_data.cpp @@ -42,15 +42,37 @@ LUALIB_API lua_CEffectData &luaL_checkeffect( lua_State *L, int narg ) LUA_REGISTRATION_INIT( EffectData ) -#ifdef CLIENT_DLL -LUA_BINDING_BEGIN( EffectData, GetEntityIndex, "class", "Get the entity index.", "client" ) +LUA_BINDING_BEGIN( EffectData, GetAngles, "class", "Get the angles of the effect." ) { lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); - lua_pushinteger( L, data.entindex() ); + lua_pushangle( L, data.m_vAngles ); return 1; } -LUA_BINDING_END( "integer", "Entity index." ) -#endif +LUA_BINDING_END( "Angle", "Angles" ) + +LUA_BINDING_BEGIN( EffectData, GetAttachmentIndex, "class", "Get the attachment ID for the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + lua_pushinteger( L, data.m_nAttachmentIndex ); + return 1; +} +LUA_BINDING_END( "integer", "Attachment ID" ) + +LUA_BINDING_BEGIN( EffectData, GetColor, "class", "Get the byte described as the color of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + lua_pushinteger( L, data.m_nColor ); + return 1; +} +LUA_BINDING_END( "integer", "Color" ) + +LUA_BINDING_BEGIN( EffectData, GetDamageType, "class", "Get the damage type of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + lua_pushinteger( L, data.m_nDamageType ); + return 1; +} +LUA_BINDING_END( "integer", "Damage type" ) LUA_BINDING_BEGIN( EffectData, GetEffectNameIndex, "class", "Get the effect name index." ) { @@ -60,16 +82,242 @@ LUA_BINDING_BEGIN( EffectData, GetEffectNameIndex, "class", "Get the effect name } LUA_BINDING_END( "integer", "Effect name index." ) -#ifdef CLIENT_DLL -LUA_BINDING_BEGIN( EffectData, GetEntity, "class", "Get the entity.", "client" ) +#ifndef CLIENT_DLL +LUA_BINDING_BEGIN( EffectData, GetEntityIndex, "class", "Get the entity index of the entity the effect is assigned to.", "server" ) { lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + lua_pushinteger( L, data.m_nEntIndex ); + return 1; +} +LUA_BINDING_END( "integer", "Entity index." ) +#endif + +LUA_BINDING_BEGIN( EffectData, GetEntity, "class", "Get the entity the effect is assigned to." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); +#ifdef CLIENT_DLL CBaseEntity::PushLuaInstanceSafe( L, data.GetEntity() ); +#else + CBaseEntity::PushLuaInstanceSafe( L, CBaseEntity::Instance( data.m_nEntIndex ) ); +#endif + return 1; +} +LUA_BINDING_END( "Entity", "The entity the effect is assigned to." ) + +LUA_BINDING_BEGIN( EffectData, GetFlags, "class", "Get the flags of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + lua_pushinteger( L, data.m_fFlags ); return 1; } -LUA_BINDING_END( "Entity", "Entity." ) +LUA_BINDING_END( "integer", "The flags of the effect." ) + +LUA_BINDING_BEGIN( EffectData, GetHitBox, "class", "Get the hit box ID of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + lua_pushinteger( L, data.m_nHitBox ); + return 1; +} +LUA_BINDING_END( "integer", "Hit box ID" ) + +LUA_BINDING_BEGIN( EffectData, GetMagnitude, "class", "Get the magnitude of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + lua_pushnumber( L, data.m_flMagnitude ); + return 1; +} +LUA_BINDING_END( "number", "Magnitude" ) + +LUA_BINDING_BEGIN( EffectData, GetMaterialIndex, "class", "Get the material index of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + lua_pushinteger( L, data.m_nMaterial ); + return 1; +} +LUA_BINDING_END( "integer", "Material index" ) + +LUA_BINDING_BEGIN( EffectData, GetNormal, "class", "Get the normalized direction vector of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + lua_pushvector( L, data.m_vNormal ); + return 1; +} +LUA_BINDING_END( "Vector", "Normal" ) + +LUA_BINDING_BEGIN( EffectData, GetOrigin, "class", "Get the origin position of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + lua_pushvector( L, data.m_vOrigin ); + return 1; +} +LUA_BINDING_END( "Vector", "Origin" ) + +LUA_BINDING_BEGIN( EffectData, GetRadius, "class", "Get the radius of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + lua_pushnumber( L, data.m_flRadius ); + return 1; +} +LUA_BINDING_END( "number", "Radius" ) + +LUA_BINDING_BEGIN( EffectData, GetScale, "class", "Get the scale of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + lua_pushnumber( L, data.m_flScale ); + return 1; +} +LUA_BINDING_END( "number", "Scale" ) + +LUA_BINDING_BEGIN( EffectData, GetStart, "class", "Get the start position of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + lua_pushvector( L, data.m_vStart ); + return 1; +} +LUA_BINDING_END( "Vector", "Start" ) + +LUA_BINDING_BEGIN( EffectData, GetSurfacePropertyIndex, "class", "Get the surface property index of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + lua_pushinteger( L, data.m_nSurfaceProp ); + return 1; +} +LUA_BINDING_END( "integer", "Surface property index" ) + +LUA_BINDING_BEGIN( EffectData, SetAngles, "class", "Set the angles of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + data.m_vAngles = LUA_BINDING_ARGUMENT( luaL_checkangle, 2, "angles" ); + return 0; +} +LUA_BINDING_END() + +LUA_BINDING_BEGIN( EffectData, SetAttachmentIndex, "class", "Set the attachment ID for the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + data.m_nAttachmentIndex = LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "attachment" ); + return 0; +} +LUA_BINDING_END() + +LUA_BINDING_BEGIN( EffectData, SetColor, "class", "Set the byte described as the color of the effect. What this does differs per effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + data.m_nColor = LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "color" ); + return 0; +} +LUA_BINDING_END() + +LUA_BINDING_BEGIN( EffectData, SetDamageType, "class", "Set the damage type of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + data.m_nDamageType = LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "damageType" ); + return 0; +} +LUA_BINDING_END() + +#ifndef CLIENT_DLL +LUA_BINDING_BEGIN( EffectData, SetEntityIndex, "class", "Set the entity index of the entity the effect is assigned to.", "server" ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + data.m_nEntIndex = LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "entityIndex" ); + return 0; +} +LUA_BINDING_END() #endif +LUA_BINDING_BEGIN( EffectData, SetEntity, "class", "Set the entity the effect is assigned to." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); +#ifdef CLIENT_DLL + data.m_hEntity = LUA_BINDING_ARGUMENT( luaL_checkentity, 2, "entity" ); +#else + data.m_nEntIndex = LUA_BINDING_ARGUMENT( luaL_checkentity, 2, "entity" )->entindex(); +#endif + return 0; +} +LUA_BINDING_END() + +LUA_BINDING_BEGIN( EffectData, SetFlags, "class", "Set the flags of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + data.m_fFlags = LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "flags" ); + return 0; +} +LUA_BINDING_END() + +LUA_BINDING_BEGIN( EffectData, SetHitBox, "class", "Set the hit box ID of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + data.m_nHitBox = LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "hitBoxIndex" ); + return 0; +} +LUA_BINDING_END() + +LUA_BINDING_BEGIN( EffectData, SetMagnitude, "class", "Set the magnitude of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + data.m_flMagnitude = LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "magnitude" ); + return 0; +} +LUA_BINDING_END() + +LUA_BINDING_BEGIN( EffectData, SetMaterialIndex, "class", "Set the material index of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + data.m_nMaterial = LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "materialIndex" ); + return 0; +} +LUA_BINDING_END() + +LUA_BINDING_BEGIN( EffectData, SetNormal, "class", "Set the normalized direction vector of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + data.m_vNormal = LUA_BINDING_ARGUMENT( luaL_checkvector, 2, "normal" ); + return 0; +} +LUA_BINDING_END() + +LUA_BINDING_BEGIN( EffectData, SetOrigin, "class", "Set the origin position of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + data.m_vOrigin = LUA_BINDING_ARGUMENT( luaL_checkvector, 2, "origin" ); + return 0; +} +LUA_BINDING_END() + +LUA_BINDING_BEGIN( EffectData, SetRadius, "class", "Set the radius of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + data.m_flRadius = LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "radius" ); + return 0; +} +LUA_BINDING_END() + +LUA_BINDING_BEGIN( EffectData, SetScale, "class", "Set the scale of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + data.m_flScale = LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "scale" ); + return 0; +} +LUA_BINDING_END() + +LUA_BINDING_BEGIN( EffectData, SetStart, "class", "Set the start position of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + data.m_vStart = LUA_BINDING_ARGUMENT( luaL_checkvector, 2, "start" ); + return 0; +} +LUA_BINDING_END() + +LUA_BINDING_BEGIN( EffectData, SetSurfacePropertyIndex, "class", "Set the surface property index of the effect." ) +{ + lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); + data.m_nSurfaceProp = LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "surfaceProperties" ); + return 0; +} +LUA_BINDING_END() + LUA_BINDING_BEGIN( EffectData, __index, "class", "Get the entity." ) { lua_CEffectData &data = LUA_BINDING_ARGUMENT( luaL_checkeffect, 1, "effectData" ); @@ -255,7 +503,7 @@ LUA_BINDING_BEGIN( Effects, SpawnBloodImpact, "library", "Creates a blood impact LUA_BINDING_END() // Experiment; Disabled because we never push trace_t pointers, instead we push it as a table struct -//LUA_BINDING_BEGIN( Effects, SpawnBloodDecalTrace, "library", "Creates a blood decal trace effect." ) +// LUA_BINDING_BEGIN( Effects, SpawnBloodDecalTrace, "library", "Creates a blood decal trace effect." ) //{ // trace_t *trace = LUA_BINDING_ARGUMENT( luaL_checktrace, 1, "trace" ); // int color = LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "color" ); @@ -264,10 +512,10 @@ LUA_BINDING_END() // // return 0; //} -//LUA_BINDING_END() +// LUA_BINDING_END() // Experiment; Disabled because we never push trace_t pointers -//LUA_BINDING_BEGIN( Effects, SpawnDecalTrace, "library", "Creates a decal trace effect." ) +// LUA_BINDING_BEGIN( Effects, SpawnDecalTrace, "library", "Creates a decal trace effect." ) //{ // trace_t *trace = LUA_BINDING_ARGUMENT( luaL_checktrace, 1, "trace" ); // const char *decalName = LUA_BINDING_ARGUMENT( luaL_checkstring, 2, "decalName" ); @@ -276,7 +524,7 @@ LUA_BINDING_END() // // return 0; //} -//LUA_BINDING_END() +// LUA_BINDING_END() #ifdef GAME_DLL @@ -301,12 +549,12 @@ LUA_BINDING_END() /* * TODO: Expose the types - DONT_BLEED = -1, + DONT_BLEED = -1, - BLOOD_COLOR_RED = 0, - BLOOD_COLOR_YELLOW, - BLOOD_COLOR_GREEN, - BLOOD_COLOR_MECH, + BLOOD_COLOR_RED = 0, + BLOOD_COLOR_YELLOW, + BLOOD_COLOR_GREEN, + BLOOD_COLOR_MECH, */ LUA_BINDING_BEGIN( Effects, SpawnBloodStream, "library", "Creates a blood stream effect. Color can be DONT_BLEED(-1), BLOOD_COLOR_RED(0), BLOOD_COLOR_YELLOW(1), BLOOD_COLOR_GREEN(2), BLOOD_COLOR_MECH(3) - enums don't exist yet in Lua", "server" ) { @@ -354,7 +602,7 @@ LUA_BINDING_BEGIN( Effects, SpawnBubbleTrail, "library", "Creates a bubble trail } LUA_BINDING_END() -#endif // GAME_DLL +#endif // GAME_DLL /* ** Open CEffectData object diff --git a/src/game/shared/lrender.cpp b/src/game/shared/lrender.cpp index 748b558e33..70520c9af0 100644 --- a/src/game/shared/lrender.cpp +++ b/src/game/shared/lrender.cpp @@ -16,6 +16,9 @@ #include #include #include +#include "beamdraw.h" +#include "materialsystem/limaterial.h" +#include "iviewrender_beams.h" #endif // memdbgon must be the last include file in a .cpp file!!! @@ -211,7 +214,8 @@ LUA_BINDING_END() LUA_BINDING_BEGIN( Renders, SetLightingOrigin, "library", "Set the lighting origin.", "client" ) { - g_pMaterialSystem->GetRenderContext()->SetLightingOrigin( LUA_BINDING_ARGUMENT( luaL_checkvector, 1, "lightingOrigin" ) ); + CMatRenderContextPtr pRenderContext( materials ); + pRenderContext->SetLightingOrigin( LUA_BINDING_ARGUMENT( luaL_checkvector, 1, "lightingOrigin" ) ); return 0; } LUA_BINDING_END() @@ -247,7 +251,8 @@ LUA_BINDING_BEGIN( Renders, SetAmbientLightCube, "library", "Set the ambient lig } } - g_pMaterialSystem->GetRenderContext()->SetAmbientLightCube( cubeFaces ); + CMatRenderContextPtr pRenderContext( materials ); + pRenderContext->SetAmbientLightCube( cubeFaces ); return 0; } @@ -267,7 +272,8 @@ LUA_BINDING_BEGIN( Renders, ResetAmbientLightCube, "library", "Reset the ambient cubeFaces[i].Init( r, g, b, 1.0f ); } - g_pMaterialSystem->GetRenderContext()->SetAmbientLightCube( cubeFaces ); + CMatRenderContextPtr pRenderContext( materials ); + pRenderContext->SetAmbientLightCube( cubeFaces ); return 0; } @@ -297,7 +303,8 @@ LUA_BINDING_BEGIN( Renders, SetLight, "library", "Set a light.", "client" ) desc.m_Phi = 0.0f; desc.m_Falloff = 1.0f; - g_pMaterialSystem->GetRenderContext()->SetLight( LUA_BINDING_ARGUMENT( luaL_checknumber, 6, "lightIndex" ), desc ); + CMatRenderContextPtr pRenderContext( materials ); + pRenderContext->SetLight( LUA_BINDING_ARGUMENT( luaL_checknumber, 6, "lightIndex" ), desc ); return 0; } @@ -329,7 +336,8 @@ LUA_BINDING_BEGIN( Renders, ClearBuffers, "library", "Clear the buffers.", "clie bool bClearDepth = LUA_BINDING_ARGUMENT( lua_toboolean, 2, "clearDepth" ); bool bClearStencil = LUA_BINDING_ARGUMENT( lua_toboolean, 3, "clearStencil" ); - g_pMaterialSystem->GetRenderContext()->ClearBuffers( bClearColor, bClearDepth, bClearStencil ); + CMatRenderContextPtr pRenderContext( materials ); + pRenderContext->ClearBuffers( bClearColor, bClearDepth, bClearStencil ); return 0; } @@ -338,7 +346,9 @@ LUA_BINDING_END() LUA_BINDING_BEGIN( Renders, ClearColor, "library", "Clear the color.", "client" ) { lua_Color clr = LUA_BINDING_ARGUMENT( luaL_checkcolor, 1, "color" ); - g_pMaterialSystem->GetRenderContext()->ClearColor4ub( clr.r(), clr.g(), clr.b(), clr.a() ); + + CMatRenderContextPtr pRenderContext( materials ); + pRenderContext->ClearColor4ub( clr.r(), clr.g(), clr.b(), clr.a() ); return 0; } LUA_BINDING_END() @@ -350,8 +360,9 @@ LUA_BINDING_BEGIN( Renders, SetScissorRectangle, "library", "Set the scissor rec int nRight = LUA_BINDING_ARGUMENT( luaL_checknumber, 3, "right" ); int nBottom = LUA_BINDING_ARGUMENT( luaL_checknumber, 4, "bottom" ); bool bEnableScissor = LUA_BINDING_ARGUMENT( lua_toboolean, 5, "enableScissor" ); - - g_pMaterialSystem->GetRenderContext()->SetScissorRect( nLeft, nTop, nRight, nBottom, bEnableScissor ); + + CMatRenderContextPtr pRenderContext( materials ); + pRenderContext->SetScissorRect( nLeft, nTop, nRight, nBottom, bEnableScissor ); return 0; } @@ -360,7 +371,9 @@ LUA_BINDING_END() LUA_BINDING_BEGIN( Renders, SetWriteDepthToDestinationAlpha, "library", "Set the write depth to destination alpha.", "client" ) { bool bEnable = LUA_BINDING_ARGUMENT( lua_toboolean, 1, "enable" ); - g_pMaterialSystem->GetRenderContext()->SetIntRenderingParameter( INT_RENDERPARM_WRITE_DEPTH_TO_DESTALPHA, bEnable ); + + CMatRenderContextPtr pRenderContext( materials ); + pRenderContext->SetIntRenderingParameter( INT_RENDERPARM_WRITE_DEPTH_TO_DESTALPHA, bEnable ); return 0; } LUA_BINDING_END() @@ -496,6 +509,63 @@ LUA_BINDING_BEGIN( Renders, GetViewEntity, "library", "Returns the entity the cl } LUA_BINDING_END( "Entity", "The view entity." ) +LUA_BINDING_BEGIN( Renders, SetMaterial, "library", "Binds a material for use in the next render operations", "client" ) +{ + IMaterial *pMaterial = LUA_BINDING_ARGUMENT( luaL_checkmaterial, 1, "material" ); + + CMatRenderContextPtr pRenderContext( materials ); + pRenderContext->Bind( pMaterial ); + + return 0; +} +LUA_BINDING_END() + +LUA_BINDING_BEGIN( Renders, DrawSprite, "library", "Draws a sprite", "client" ) +{ + Vector position = LUA_BINDING_ARGUMENT( luaL_checkvector, 1, "position" ); + float width = LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "width" ); + float height = LUA_BINDING_ARGUMENT( luaL_checknumber, 3, "height" ); + lua_Color color = LUA_BINDING_ARGUMENT_WITH_DEFAULT( luaL_optcolor, 4, lua_Color( 255, 255, 255, 255 ), "color" ); + + color32 rawColor = { color.r(), color.g(), color.b(), color.a() }; + DrawSprite( position, width, height, rawColor ); + + return 0; +} +LUA_BINDING_END() + +LUA_BINDING_BEGIN( Renders, DrawBeam, "library", "Draws a beam", "client" ) +{ + Vector &start = LUA_BINDING_ARGUMENT( luaL_checkvector, 1, "start" ); + Vector &end = LUA_BINDING_ARGUMENT( luaL_checkvector, 2, "end" ); + float width = LUA_BINDING_ARGUMENT( luaL_checknumber, 3, "width" ); + float textureStart = LUA_BINDING_ARGUMENT( luaL_checknumber, 4, "textureStart" ); + float textureEnd = LUA_BINDING_ARGUMENT( luaL_checknumber, 5, "textureEnd" ); + lua_Color color = LUA_BINDING_ARGUMENT_WITH_DEFAULT( luaL_optcolor, 6, lua_Color( 255, 255, 255, 255 ), "color" ); + + CMatRenderContextPtr pRenderContext( materials ); + CBeamSegDraw beamDraw; + beamDraw.Start( pRenderContext, 2, NULL ); + + BeamSeg_t seg; + seg.m_flAlpha = 1.0; + seg.m_flWidth = width; + + seg.m_vPos = start; + seg.m_flTexCoord = textureStart; + seg.m_vColor = color.ToVector(); + beamDraw.NextSeg( &seg ); + + seg.m_vPos = end; + seg.m_flTexCoord = textureEnd; + seg.m_vColor = color.ToVector(); + beamDraw.NextSeg( &seg ); + + beamDraw.End(); + + return 0; + } + LUA_BINDING_END() #endif // CLIENT_DLL /* diff --git a/src/game/shared/lshareddefs.cpp b/src/game/shared/lshareddefs.cpp index 1821861835..f902d9eed4 100644 --- a/src/game/shared/lshareddefs.cpp +++ b/src/game/shared/lshareddefs.cpp @@ -20,19 +20,19 @@ LUA_API lua_FireBulletsInfo_t lua_tofirebulletsinfo( lua_State *L, int idx ) if ( !lua_isnil( L, -1 ) ) info.m_bPrimaryAttack = luaL_checkboolean( L, -1 ); lua_pop( L, 1 ); - lua_getfield( L, idx, "m_flDamageForceScale" ); + lua_getfield( L, idx, "Force" ); if ( !lua_isnil( L, -1 ) ) info.m_flDamageForceScale = luaL_checknumber( L, -1 ); lua_pop( L, 1 ); - lua_getfield( L, idx, "m_flDistance" ); + lua_getfield( L, idx, "Distance" ); if ( !lua_isnil( L, -1 ) ) info.m_flDistance = luaL_checknumber( L, -1 ); lua_pop( L, 1 ); - lua_getfield( L, idx, "m_iAmmoType" ); + lua_getfield( L, idx, "AmmoType" ); if ( !lua_isnil( L, -1 ) ) info.m_iAmmoType = luaL_checknumber( L, -1 ); lua_pop( L, 1 ); - lua_getfield( L, idx, "m_iDamage" ); + lua_getfield( L, idx, "Damage" ); if ( !lua_isnil( L, -1 ) ) info.m_flDamage = luaL_checknumber( L, -1 ); lua_pop( L, 1 ); @@ -40,35 +40,39 @@ LUA_API lua_FireBulletsInfo_t lua_tofirebulletsinfo( lua_State *L, int idx ) if ( !lua_isnil( L, -1 ) ) info.m_iPlayerDamage = luaL_checknumber( L, -1 ); lua_pop( L, 1 ); - lua_getfield( L, idx, "m_iShots" ); + lua_getfield( L, idx, "Num" ); // TODO: adhere to our own conventions (this is for easy gmod compat atm) if ( !lua_isnil( L, -1 ) ) info.m_iShots = luaL_checknumber( L, -1 ); lua_pop( L, 1 ); - lua_getfield( L, idx, "m_iTracerFreq" ); + lua_getfield( L, idx, "Tracer" ); if ( !lua_isnil( L, -1 ) ) info.m_iTracerFreq = luaL_checknumber( L, -1 ); lua_pop( L, 1 ); + lua_getfield( L, idx, "TracerName" ); + if ( !lua_isnil( L, -1 ) ) + info.m_pszTracerType = strdup( luaL_checkstring( L, -1 ) ); + lua_pop( L, 1 ); lua_getfield( L, idx, "m_nFlags" ); if ( !lua_isnil( L, -1 ) ) info.m_nFlags = luaL_checknumber( L, -1 ); lua_pop( L, 1 ); - lua_getfield( L, idx, "m_pAdditionalIgnoreEnt" ); + lua_getfield( L, idx, "IgnoreEntity" ); if ( !lua_isnil( L, -1 ) ) info.m_pAdditionalIgnoreEnt = lua_toentity( L, -1 ); lua_pop( L, 1 ); - lua_getfield( L, idx, "m_pAttacker" ); + lua_getfield( L, idx, "Attacker" ); if ( !lua_isnil( L, -1 ) ) info.m_pAttacker = lua_toentity( L, -1 ); lua_pop( L, 1 ); - lua_getfield( L, idx, "m_vecDirShooting" ); + lua_getfield( L, idx, "Dir" ); // TODO: adhere to our own conventions (this is for easy gmod compat atm) if ( !lua_isnil( L, -1 ) ) info.m_vecDirShooting = luaL_checkvector( L, -1 ); lua_pop( L, 1 ); - lua_getfield( L, idx, "m_vecSpread" ); + lua_getfield( L, idx, "Spread" ); if ( !lua_isnil( L, -1 ) ) info.m_vecSpread = luaL_checkvector( L, -1 ); lua_pop( L, 1 ); - lua_getfield( L, idx, "m_vecSrc" ); + lua_getfield( L, idx, "Source" ); if ( !lua_isnil( L, -1 ) ) info.m_vecSrc = luaL_checkvector( L, -1 ); lua_pop( L, 1 ); diff --git a/src/game/shared/luamanager.cpp b/src/game/shared/luamanager.cpp index 4b42abbaa9..4dd9e14fd1 100644 --- a/src/game/shared/luamanager.cpp +++ b/src/game/shared/luamanager.cpp @@ -2415,6 +2415,7 @@ CON_COMMAND_F_COMPLETION( lua_openscript, "Load and run a Lua file", 0, DoFileCo #endif #if DEBUG +#define MAX_STACK_DUMP 100 static void DumpLuaStack( lua_State *L ) { int n = lua_gettop( L ); /* number of objects */ @@ -2422,7 +2423,7 @@ static void DumpLuaStack( lua_State *L ) CUtlString dumpStack = "Lua Stack:\n"; - for ( i = 1; i <= n; i++ ) + for ( i = 1; i <= min( n, MAX_STACK_DUMP ); i++ ) { if ( lua_istable( L, -1 ) ) { @@ -2453,10 +2454,21 @@ static void DumpLuaStack( lua_State *L ) { dumpStack += "\nWarning: "; dumpStack += n; - dumpStack += " object(s) left on the stack!\n"; + dumpStack += " object(s) left on the stack!"; + + if ( n > MAX_STACK_DUMP ) + { + dumpStack += " (only the first "; + dumpStack += MAX_STACK_DUMP; + dumpStack += " objects are shown)"; + } + } + else + { + dumpStack += "Stack is empty, that's great!"; } - Warning( "%s", dumpStack.Get() ); + Warning( "%s\n", dumpStack.Get() ); } #ifdef CLIENT_DLL diff --git a/src/game/shared/luamanager.h b/src/game/shared/luamanager.h index 1764559ec3..10b5f6eb48 100644 --- a/src/game/shared/luamanager.h +++ b/src/game/shared/luamanager.h @@ -209,7 +209,7 @@ } #define LUA_RETURN_NONE_IF_FALSE() \ - if ( lua_gettop( L ) == 1 ) \ + if ( lua_gettop( L ) >= 1 ) \ { \ if ( lua_isboolean( L, -1 ) ) \ { \ @@ -223,7 +223,7 @@ } #define LUA_RETURN_NONE_IF_TRUE() \ - if ( lua_gettop( L ) == 1 ) \ + if ( lua_gettop( L ) >= 1 ) \ { \ if ( lua_isboolean( L, -1 ) ) \ { \ @@ -251,7 +251,7 @@ } #define LUA_RETURN_BOOLEAN() \ - if ( lua_gettop( L ) == 1 ) \ + if ( lua_gettop( L ) >= 1 ) \ { \ if ( lua_isboolean( L, -1 ) ) \ { \ @@ -277,7 +277,7 @@ } #define LUA_RETURN_NUMBER() \ - if ( lua_gettop( L ) == 1 ) \ + if ( lua_gettop( L ) >= 1 ) \ { \ if ( lua_isnumber( L, -1 ) ) \ { \ @@ -290,7 +290,7 @@ } #define LUA_RETURN_INTEGER() \ - if ( lua_gettop( L ) == 1 ) \ + if ( lua_gettop( L ) >= 1 ) \ { \ if ( lua_isnumber( L, -1 ) ) \ { \ @@ -303,7 +303,7 @@ } #define LUA_RETURN_BOOLEAN_FROM_INTEGER() \ - if ( lua_gettop( L ) == 1 ) \ + if ( lua_gettop( L ) >= 1 ) \ { \ if ( lua_isnumber( L, -1 ) ) \ { \ @@ -316,7 +316,7 @@ } #define LUA_RETURN_ACTIVITY() \ - if ( lua_gettop( L ) == 1 ) \ + if ( lua_gettop( L ) >= 1 ) \ { \ if ( lua_isnumber( L, -1 ) ) \ { \ @@ -329,7 +329,7 @@ } #define LUA_RETURN_STRING() \ - if ( lua_gettop( L ) == 1 ) \ + if ( lua_gettop( L ) >= 1 ) \ { \ if ( lua_isstring( L, -1 ) ) \ { \ @@ -342,7 +342,7 @@ } #define LUA_RETURN_WEAPON() \ - if ( lua_gettop( L ) == 1 ) \ + if ( lua_gettop( L ) >= 1 ) \ { \ if ( lua_isuserdata( L, -1 ) && \ luaL_testudata( L, -1, LUA_BASECOMBATWEAPONLIBNAME ) ) \ @@ -360,7 +360,7 @@ ( luaL_testudata( L, Index, LUA_BASEENTITYMETANAME ) || luaL_testudata( L, Index, LUA_BASEANIMATINGLIBNAME ) || luaL_testudata( L, Index, LUA_CBASEFLEXLIBNAME ) || luaL_testudata( L, Index, LUA_BASECOMBATWEAPONLIBNAME ) || luaL_testudata( L, -1, LUA_BASEPLAYERMETANAME ) || luaL_testudata( L, Index, LUA_EXPERIMENTPLAYERLIBNAME ) ) #define LUA_RETURN_ENTITY() \ - if ( lua_gettop( L ) == 1 ) \ + if ( lua_gettop( L ) >= 1 ) \ { \ if ( LUA_IS_ENTITY( L, -1 ) ) \ { \ @@ -377,7 +377,7 @@ ( luaL_testudata( L, Index, LUA_BASEPLAYERMETANAME ) || luaL_testudata( L, Index, LUA_EXPERIMENTPLAYERLIBNAME ) ) #define LUA_RETURN_PLAYER() \ - if ( lua_gettop( L ) == 1 ) \ + if ( lua_gettop( L ) >= 1 ) \ { \ if ( LUA_IS_PLAYER( L, -1 ) ) \ { \ @@ -390,7 +390,7 @@ } #define LUA_RETURN_VECTOR() \ - if ( lua_gettop( L ) == 1 ) \ + if ( lua_gettop( L ) >= 1 ) \ { \ if ( lua_isvector( L, -1 ) ) \ { \ @@ -403,7 +403,7 @@ } #define LUA_RETURN_ANGLE() \ - if ( lua_gettop( L ) == 1 ) \ + if ( lua_gettop( L ) >= 1 ) \ { \ if ( lua_isangle( L, -1 ) ) \ { \ @@ -416,7 +416,7 @@ } #define LUA_RETURN_VALUE_IF_TRUE( value ) \ - if ( lua_gettop( L ) == 1 ) \ + if ( lua_gettop( L ) >= 1 ) \ { \ if ( lua_isboolean( L, -1 ) ) \ { \ @@ -430,7 +430,7 @@ } #define LUA_RETURN_VALUE_IF_FALSE( value ) \ - if ( lua_gettop( L ) == 1 ) \ + if ( lua_gettop( L ) >= 1 ) \ { \ if ( lua_isboolean( L, -1 ) ) \ { \ @@ -444,7 +444,7 @@ } #define LUA_RETURN_VALUE_IF_BOOLEAN( ValueTrue, ValueFalse ) \ - if ( lua_gettop( L ) == 1 ) \ + if ( lua_gettop( L ) >= 1 ) \ { \ if ( lua_isboolean( L, -1 ) ) \ { \ diff --git a/src/game/shared/shareddefs.h b/src/game/shared/shareddefs.h index dc0ac7c621..78975a578f 100644 --- a/src/game/shared/shareddefs.h +++ b/src/game/shared/shareddefs.h @@ -727,6 +727,7 @@ struct FireBulletsInfo_t CBaseEntity *m_pAdditionalIgnoreEnt; bool m_bPrimaryAttack; bool m_bUseServerRandomSeed; + const char *m_pszTracerType; }; //----------------------------------------------------------------------------- diff --git a/src/public/Color.h b/src/public/Color.h index 421a6b2a2c..526286b262 100644 --- a/src/public/Color.h +++ b/src/public/Color.h @@ -68,7 +68,7 @@ class Color inline int g() const { return _color[1]; } inline int b() const { return _color[2]; } inline int a() const { return _color[3]; } - + unsigned char &operator[](int index) { return _color[index]; diff --git a/src/public/lColor.h b/src/public/lColor.h index 4edb5f81ad..0324bd63fc 100644 --- a/src/public/lColor.h +++ b/src/public/lColor.h @@ -22,6 +22,11 @@ class LColor : public Color lua_newtable( L ); m_nTableReference = luaL_ref( L, LUA_REGISTRYINDEX ); } + + Vector &ToVector() const + { + return Vector( r(), g(), b() ); + } }; /* type for Color functions */ diff --git a/src/public/lcdll_int.cpp b/src/public/lcdll_int.cpp index 41f92a7bf0..280bf65670 100644 --- a/src/public/lcdll_int.cpp +++ b/src/public/lcdll_int.cpp @@ -380,6 +380,14 @@ LUA_BINDING_BEGIN( Engines, IsDrawingLoadingImage, "library", "Check if the clie } LUA_BINDING_END( "boolean", "True if the client is drawing a loading image, false otherwise." ) +LUA_BINDING_BEGIN( Engines, IsDedicatedServer, "library", "Check if the server is dedicated. Internally this is getting this information from the server_spawn event." ) +{ + lua_pushboolean( L, g_pGameInfoStore->IsDedicatedServer() ); + + return 1; +} +LUA_BINDING_END( "boolean", "True if the server is dedicated, false otherwise." ) + LUA_BINDING_BEGIN( Engines, IsHammerRunning, "library", "Check if Hammer is running." ) { lua_pushboolean( L, engine->IsHammerRunning() ); diff --git a/src/public/lenumerations_shared.cpp b/src/public/lenumerations_shared.cpp index c89c2d6dfb..4ec5ceb26a 100644 --- a/src/public/lenumerations_shared.cpp +++ b/src/public/lenumerations_shared.cpp @@ -315,6 +315,49 @@ LUALIB_API int luaopen_SharedEnumerations( lua_State *L ) lua_pushenum( L, HUD_PRINTCENTER, "CENTER" ); LUA_SET_ENUM_LIB_END( L ); + LUA_SET_ENUM_LIB_BEGIN( L, "PLAYER_ANIMATION_EVENT" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_ATTACK_PRIMARY, "ATTACK_PRIMARY" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_ATTACK_SECONDARY, "ATTACK_SECONDARY" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_ATTACK_GRENADE, "ATTACK_GRENADE" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_RELOAD, "RELOAD" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_RELOAD_LOOP, "RELOAD_LOOP" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_RELOAD_END, "RELOAD_END" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_JUMP, "JUMP" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_SWIM, "SWIM" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_DIE, "DIE" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_FLINCH_CHEST, "FLINCH_CHEST" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_FLINCH_HEAD, "FLINCH_HEAD" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_FLINCH_LEFTARM, "FLINCH_LEFT_ARM" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_FLINCH_RIGHTARM, "FLINCH_RIGHT_ARM" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_FLINCH_LEFTLEG, "FLINCH_LEFT_LEG" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_FLINCH_RIGHTLEG, "FLINCH_RIGHT_LEG" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_DOUBLEJUMP, "DOUBLE_JUMP" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_CANCEL, "CANCEL" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_SPAWN, "SPAWN" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_SNAP_YAW, "SNAP_YAW" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_CUSTOM, "CUSTOM" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_CUSTOM_GESTURE, "CUSTOM_GESTURE" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_CUSTOM_SEQUENCE, "CUSTOM_SEQUENCE" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_CUSTOM_GESTURE_SEQUENCE, "CUSTOM_GESTURE_SEQUENCE" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_ATTACK_PRE, "ATTACK_PRE" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_ATTACK_POST, "ATTACK_POST" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_GRENADE1_DRAW, "GRENADE1_DRAW" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_GRENADE2_DRAW, "GRENADE2_DRAW" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_GRENADE1_THROW, "GRENADE1_THROW" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_GRENADE2_THROW, "GRENADE2_THROW" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_VOICE_COMMAND_GESTURE, "VOICE_COMMAND_GESTURE" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_DOUBLEJUMP_CROUCH, "DOUBLE_JUMP_CROUCH" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_STUN_BEGIN, "STUN_BEGIN" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_STUN_MIDDLE, "STUN_MIDDLE" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_STUN_END, "STUN_END" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_PASSTIME_THROW_BEGIN, "PASSTIME_THROW_BEGIN" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_PASSTIME_THROW_MIDDLE, "PASSTIME_THROW_MIDDLE" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_PASSTIME_THROW_END, "PASSTIME_THROW_END" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_PASSTIME_THROW_CANCEL, "PASSTIME_THROW_CANCEL" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_ATTACK_PRIMARY_SUPER, "ATTACK_PRIMARY_SUPER" ); + lua_pushenum( L, PlayerAnimEvent_t::PLAYERANIMEVENT_COUNT, "COUNT" ); + LUA_SET_ENUM_LIB_END( L ); + return 0; } diff --git a/src/public/mathlib/lvector.cpp b/src/public/mathlib/lvector.cpp index 41e43ea2e2..597cf24957 100644 --- a/src/public/mathlib/lvector.cpp +++ b/src/public/mathlib/lvector.cpp @@ -104,7 +104,7 @@ LUA_BINDING_BEGIN( Vector, DistanceTo, "class", "Calculates the distance between } LUA_BINDING_END( "number", "The distance between the two vectors." ) -LUA_BINDING_BEGIN( Vector, DistanceToSqr, "class", "Calculates the squared distance between two vectors." ) +LUA_BINDING_BEGIN( Vector, DistanceToAsSqr, "class", "Calculates the squared distance between two vectors." ) { lua_Vector vec1 = LUA_BINDING_ARGUMENT( luaL_checkvector, 1, "vector1" ); lua_Vector vec2 = LUA_BINDING_ARGUMENT( luaL_checkvector, 2, "vector2" );