澄清一下,因为在标题中很难解释。
-- file that contains this code is > "player.lua"
local ply = FindMetaTable("Player")
ply.LastDamageType = "N/A"
此代码为所有玩家实体设置一个新变量。该变量只是对玩家造成伤害的最后一个实体的字符串。这是通过以下代码实现的:
-- file that contains this code is > "init.lua"
AddCSLuaFile("shared.lua")
AddCSLuaFile("cl_init.lua")
include("shared.lua")
include("player.lua")
-->
--> OTHER METHODS THAT I DIDN'T INCLUDE
-->
function GM:PlayerShouldTakeDamage(ply, attacker)
ply.LastDamageType=tostring(attacker)
return true
end
我做这一切的目的是因为我想要一个显示这个字符串的 hud 元素,这样客户就可以看到最后对他造成伤害的东西是什么。
问题是,客户端文件“cl_init”上的变量为零,但是如果我通过客户端和服务器端打印包含播放器中所有数据的表。除了我创建的变量“LastDamageType”之外,两个表都是相同的
-- file that contains this code is > "cl_init.lua"
include("shared.lua")
surface.CreateFont("dayz_font",{font="Arial",size=24,weight=400})
function GM:HUDPaint()
local ply = LocalPlayer()
draw.SimpleText("you are "..ply:Nick(),"dayz_font", 150,10,Color(255,120,50),TEXT_ALIGN_CENTER)//TargetID
surface.SetFont("TargetID")
surface.SetTextColor(Color(30,70,130))
surface.SetTextPos(surface.ScreenWidth()-200 ,20)
surface.DrawText("You have ")
surface.SetTextColor(Color(200,90,30))
surface.DrawText(ply:Health())
surface.SetTextColor(Color(30,70,130))
surface.DrawText(" health")
surface.SetTextPos(surface.ScreenWidth()-200 ,35)
surface.DrawText(""..tostring(Entity(1):GetTable().LastDamageType))
-- FOR DEBUGGING PURPOSES, I'M USING "Entity(1)" TO GET MY PLAYER
-- I KNOW THAT "LocalPlayer()" PROBABLY ALSO EQUATES TO THE SAME THING
-- AS WHAT "Entity(1)" IS AT THIS MOMENT BECAUSE I'M TESTING THIS IN SINGLEPLAYER.
end
所以看起来客户端和服务器端的玩家数据不是同一个东西,它们必须同步或类似的东西......或者我错过了让它们保持同步的重要东西?
/////////////////////////////////////////附加信息 //////////////////////////////////////////////// //
这些是我做的时候我的玩家实体的所有变量的打印列表
PrintTable(Entity(1):GetTable())
在客户端和服务器端。第一个列表在服务器上,第二个在客户端上。我会用 =========================== 将它们分开
我知道您可能不想通过列表查看 Ctrl+F 并输入“LastDamageType”以突出显示它。
///////////////////////////////////////// 服务器端
CWAttachments:
am_flechetterounds = true
am_magnum = true
am_matchgrade = true
am_slugrounds = true
bg_ak74_rpkbarrel = true
bg_ak74_ubarrel = true
bg_ak74foldablestock = true
bg_ak74heavystock = true
bg_ak74rpkmag = true
bg_ar1560rndmag = true
bg_ar15heavystock = true
bg_ar15sturdystock = true
bg_bipod = true
bg_deagle_compensator = true
bg_deagle_extendedbarrel = true
bg_foldsight = true
bg_longbarrel = true
bg_longbarrelmr96 = true
bg_longris = true
bg_magpulhandguard = true
bg_mp530rndmag = true
bg_mp5_kbarrel = true
bg_mp5_sdbarrel = true
bg_nostock = true
bg_regularbarrel = true
bg_retractablestock = true
bg_ris = true
bg_sg1scope = true
md_acog = true
md_aimpoint = true
md_anpeq15 = true
md_cobram2 = true
md_eotech = true
md_foregrip = true
md_kobra = true
md_m203 = true
md_microt1 = true
md_pbs1 = true
md_pso1 = true
md_saker = true
md_tundra9mm = true
CalcIdeal = 990
CalcSeqOverride = -1
DTVar = function: 0x1ca93680
EditValue = function: 0x2ac6c878
GetEditingData = function: 0x18501238
GetNetworkKeyValue = function: 0x1caf7ec0
GetNetworkVars = function: 0x1caf9640
LastDamageType = Entity [0][worldspawn]
LastPlayerTrace = 859.94995117188
LastSpawnpoint = Entity [61][info_player_start]
NetworkVar = function: 0x2375b100
NetworkVarElement = function: 0x23785a08
NetworkVarNotify = function: 0x1844e3c8
PlayerTrace:
Entity = Entity [0][worldspawn]
Fraction = 0.49089023470879
FractionLeftSolid = 0
Hit = true
HitBox = 0
HitGroup = 0
HitNoDraw = false
HitNonWorld = false
HitNormal = -1.000000 0.000000 0.000000
HitPos = 15359.968750 950.995850 -12563.697266
HitSky = true
HitTexture = TOOLS/TOOLSSKYBOX
HitWorld = true
MatType = 88
Normal = 0.998662 0.047185 -0.021163
PhysicsBone = 0
StartPos = -704.000000 192.000000 -12223.280273
StartSolid = false
SurfaceProps = 77
RestoreNetworkVars = function: 0x184b21a8
SCarMouseMoveX = 0
SCarMouseMoveY = 0
SetNetworkKeyValue = function: 0x1838a3f8
SetupEditing = function: 0x0f107ab8
SetupKeyValue = function: 0x1844da70
WT_RagdollRoper_Roping = false
canChat = 864.94995117188
dt:
m_CurrentPlayerClass:
ClassID = 125
Func = function: 0x1ca70b58
Player = Player [1][UbErZ Andrew900460]
m_bFlashlight = true
m_bInSwim = false
m_bWasNoclipping = false
m_bWasOnGround = true
///////////////////////////////////////// ////////////// 客户端
CWAttachments:
am_flechetterounds = true
am_magnum = true
am_matchgrade = true
am_slugrounds = true
bg_ak74_rpkbarrel = true
bg_ak74_ubarrel = true
bg_ak74foldablestock = true
bg_ak74heavystock = true
bg_ak74rpkmag = true
bg_ar1560rndmag = true
bg_ar15heavystock = true
bg_ar15sturdystock = true
bg_bipod = true
bg_deagle_compensator = true
bg_deagle_extendedbarrel = true
bg_foldsight = true
bg_longbarrel = true
bg_longbarrelmr96 = true
bg_longris = true
bg_magpulhandguard = true
bg_mp530rndmag = true
bg_mp5_kbarrel = true
bg_mp5_sdbarrel = true
bg_nostock = true
bg_regularbarrel = true
bg_retractablestock = true
bg_ris = true
bg_sg1scope = true
md_acog = true
md_aimpoint = true
md_anpeq15 = true
md_cobram2 = true
md_eotech = true
md_foregrip = true
md_kobra = true
md_m203 = true
md_microt1 = true
md_pbs1 = true
md_pso1 = true
md_saker = true
md_tundra9mm = true
CalcIdeal = 990
CalcSeqOverride = -1
ChatGestureWeight = 0
DTVar = function: 0x2be3b410
EditValue = function: 0x3053c750
GetEditingData = function: 0x2bb01b30
GetNetworkKeyValue = function: 0x2bb01d18
GetNetworkVars = function: 0x2bb01d38
LastPlayerTrace = 859.96203613281
NetworkVar = function: 0x2bb01c98
NetworkVarElement = function: 0x2bab5340
NetworkVarNotify = function: 0x2bb01cd8
PlayerTrace:
Entity = Entity [0][worldspawn]
Fraction = 0.49089023470879
FractionLeftSolid = 0
Hit = true
HitBox = 0
HitGroup = 0
HitNoDraw = false
HitNonWorld = false
HitNormal = -1.000000 0.000000 0.000000
HitPos = 15359.968750 950.995850 -12563.697266
HitSky = true
HitTexture = TOOLS/TOOLSSKYBOX
HitWorld = true
MatType = 88
Normal = 0.998662 0.047185 -0.021163
PhysicsBone = 0
StartPos = -704.000000 192.000000 -12223.280273
StartSolid = false
SurfaceProps = 77
RestoreNetworkVars = function: 0x2bb01d58
SetNetworkKeyValue = function: 0x2bb01cf8
SetupEditing = function: 0x2bb01c38
SetupKeyValue = function: 0x2bb01c58
dt:
m_CurrentPlayerClass:
ClassID = 125
Func = function: 0x30283ff8
Player = Player [1][UbErZ Andrew900460]
m_bInSwim = false
m_bWasNoclipping = false
m_bWasOnGround = true