Simplish lua problem
<div class="IPBDescription">Need to get Player SteamId in function NS2Gamerules:OnEntityCreate()</div>Hi, I am having problems trying to get player SteamId in function NS2Gamerules:OnEntityCreate(entity). Function is found at lua/NS2GameRules.lua file.
Normally I use:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local client = Server.GetOwner(player)
local steamId = client.GetUserId()<!--c2--></div><!--ec2-->
to get the steamId but can't really use that there it seems.
Function below will get SteamId sometimes, but not always and anyway its not very good way to get it. This won't get it when player exists commander chair or spawns from infantry portal at least.
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local origin = entity.GetOrigin()
for index, player in ientitylist(Shared.GetEntitiesWithClassname("Player")) do
local porg = player:GetOrigin()
if porg.x == origin.x and porg.y == origin.y and porg.z == origin.z then
local client = Server.GetOwner(player)
if client ~= nil then
local steamId = client:GetUserId()
break
end
end
end<!--c2--></div><!--ec2-->
I have tried some other ways to get it also, but not been able to get it 100% of time. So I wonder if anyone has any ideas how to get it there?
Normally I use:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local client = Server.GetOwner(player)
local steamId = client.GetUserId()<!--c2--></div><!--ec2-->
to get the steamId but can't really use that there it seems.
Function below will get SteamId sometimes, but not always and anyway its not very good way to get it. This won't get it when player exists commander chair or spawns from infantry portal at least.
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local origin = entity.GetOrigin()
for index, player in ientitylist(Shared.GetEntitiesWithClassname("Player")) do
local porg = player:GetOrigin()
if porg.x == origin.x and porg.y == origin.y and porg.z == origin.z then
local client = Server.GetOwner(player)
if client ~= nil then
local steamId = client:GetUserId()
break
end
end
end<!--c2--></div><!--ec2-->
I have tried some other ways to get it also, but not been able to get it 100% of time. So I wonder if anyone has any ideas how to get it there?
Comments