mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
#NET
* Added logic to get player ID from client object
This commit is contained in:
parent
036b6b77b1
commit
c08b39f148
@ -23,7 +23,7 @@ do
|
|||||||
-- @field #NET
|
-- @field #NET
|
||||||
NET = {
|
NET = {
|
||||||
ClassName = "NET",
|
ClassName = "NET",
|
||||||
Version = "0.0.1"
|
Version = "0.0.2"
|
||||||
}
|
}
|
||||||
|
|
||||||
--- Instantiate a new NET object.
|
--- Instantiate a new NET object.
|
||||||
@ -47,6 +47,31 @@ function NET:SendChat(Message,ToAll)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Find the PlayerID by name
|
||||||
|
-- @param #NET self
|
||||||
|
-- @param #string Name The player name whose ID to find
|
||||||
|
-- @return #number PlayerID or nil
|
||||||
|
function NET:GetPlayerIdByName(Name)
|
||||||
|
local playerList = self:GetPlayerList()
|
||||||
|
for i=1,#playerList do
|
||||||
|
local playerName = net.get_name(i)
|
||||||
|
if playerName == Name then
|
||||||
|
return playerList[i]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Find the PlayerID from a CLIENT object.
|
||||||
|
-- @param #NET self
|
||||||
|
-- @param Wrapper.Client#CLIENT Client The client
|
||||||
|
-- @return #number PlayerID or nil
|
||||||
|
function NET:GetPlayerIDFromClient(Client)
|
||||||
|
local name = Client:GetPlayerName()
|
||||||
|
local id = self:GetPlayerIdByName(name)
|
||||||
|
return id
|
||||||
|
end
|
||||||
|
|
||||||
--- Send chat message to a specific player.
|
--- Send chat message to a specific player.
|
||||||
-- @param #NET self
|
-- @param #NET self
|
||||||
-- @param #string Message The text message
|
-- @param #string Message The text message
|
||||||
@ -54,8 +79,8 @@ end
|
|||||||
-- @param Wrapper.Client#CLIENT FromClient (Optional) Client sending the message
|
-- @param Wrapper.Client#CLIENT FromClient (Optional) Client sending the message
|
||||||
-- @return #NET self
|
-- @return #NET self
|
||||||
function NET:SendChatToPlayer(Message, ToClient, FromClient)
|
function NET:SendChatToPlayer(Message, ToClient, FromClient)
|
||||||
local PlayerId = ToClient:GetID()
|
local PlayerId = self:GetPlayerIDFromClient(ToClient)
|
||||||
local FromId = FromClient:GetID()
|
local FromId = self:GetPlayerIDFromClient(FromClient)
|
||||||
if Message and PlayerId and FromId then
|
if Message and PlayerId and FromId then
|
||||||
net.send_chat_to(Message, tonumber(PlayerId) , tonumber(FromId))
|
net.send_chat_to(Message, tonumber(PlayerId) , tonumber(FromId))
|
||||||
elseif Message and PlayerId then
|
elseif Message and PlayerId then
|
||||||
@ -103,7 +128,7 @@ function NET:GetMyPlayerID()
|
|||||||
return net.get_my_player_id()
|
return net.get_my_player_id()
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Returns the playerID of the server. Currently always 1.
|
--- Returns the playerID of the server. Currently always returns 1.
|
||||||
-- @param #NET self
|
-- @param #NET self
|
||||||
-- @return #number ID
|
-- @return #number ID
|
||||||
function NET:GetServerID()
|
function NET:GetServerID()
|
||||||
@ -127,7 +152,7 @@ end
|
|||||||
-- 'ucid' : Unique Client Identifier, SERVER ONLY
|
-- 'ucid' : Unique Client Identifier, SERVER ONLY
|
||||||
--
|
--
|
||||||
function NET:GetPlayerInfo(Client,Attribute)
|
function NET:GetPlayerInfo(Client,Attribute)
|
||||||
local PlayerID = Client:GetID()
|
local PlayerID = self:GetPlayerIDFromClient(Client)
|
||||||
if PlayerID then
|
if PlayerID then
|
||||||
return net.get_player_info(tonumber(PlayerID), Attribute)
|
return net.get_player_info(tonumber(PlayerID), Attribute)
|
||||||
else
|
else
|
||||||
@ -141,7 +166,7 @@ end
|
|||||||
-- @param #string Message (Optional) The message to send.
|
-- @param #string Message (Optional) The message to send.
|
||||||
-- @return #boolean success
|
-- @return #boolean success
|
||||||
function NET:Kick(Client,Message)
|
function NET:Kick(Client,Message)
|
||||||
local PlayerID = Client:GetID()
|
local PlayerID = self:GetPlayerIDFromClient(Client)
|
||||||
if PlayerID and tonumber(PlayerID) ~= 1 then
|
if PlayerID and tonumber(PlayerID) ~= 1 then
|
||||||
return net.kick(tonumber(PlayerID), Message)
|
return net.kick(tonumber(PlayerID), Message)
|
||||||
else
|
else
|
||||||
@ -168,7 +193,7 @@ end
|
|||||||
--
|
--
|
||||||
-- mynet:GetPlayerStatistic(Client,7) -- return number of ejects
|
-- mynet:GetPlayerStatistic(Client,7) -- return number of ejects
|
||||||
function NET:GetPlayerStatistic(Client,StatisticID)
|
function NET:GetPlayerStatistic(Client,StatisticID)
|
||||||
local PlayerID = Client:GetID()
|
local PlayerID = self:GetPlayerIDFromClient(Client)
|
||||||
local stats = StatisticID or 0
|
local stats = StatisticID or 0
|
||||||
if stats > 7 or stats < 0 then stats = 0 end
|
if stats > 7 or stats < 0 then stats = 0 end
|
||||||
if PlayerID then
|
if PlayerID then
|
||||||
@ -178,13 +203,12 @@ function NET:GetPlayerStatistic(Client,StatisticID)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return the name of a given client. Same a CLIENT:GetPlayerName().
|
--- Return the name of a given client. Same a CLIENT:GetPlayerName().
|
||||||
-- @param #NET self
|
-- @param #NET self
|
||||||
-- @param Wrapper.Client#CLIENT Client The client
|
-- @param Wrapper.Client#CLIENT Client The client
|
||||||
-- @return #string Name
|
-- @return #string Name or nil if not obtainable
|
||||||
function NET:GetName(Client)
|
function NET:GetName(Client)
|
||||||
local PlayerID = Client:GetID()
|
local PlayerID = self:GetPlayerIDFromClient(Client)
|
||||||
if PlayerID then
|
if PlayerID then
|
||||||
return net.get_name(tonumber(PlayerID))
|
return net.get_name(tonumber(PlayerID))
|
||||||
else
|
else
|
||||||
@ -198,7 +222,7 @@ end
|
|||||||
-- @return #number SideID i.e. 0 : spectators, 1 : Red, 2 : Blue
|
-- @return #number SideID i.e. 0 : spectators, 1 : Red, 2 : Blue
|
||||||
-- @return #number SlotID
|
-- @return #number SlotID
|
||||||
function NET:GetSlot(Client)
|
function NET:GetSlot(Client)
|
||||||
local PlayerID = Client:GetID()
|
local PlayerID = self:GetPlayerIDFromClient(Client)
|
||||||
if PlayerID then
|
if PlayerID then
|
||||||
local side,slot = net.get_slot(tonumber(PlayerID))
|
local side,slot = net.get_slot(tonumber(PlayerID))
|
||||||
return side,slot
|
return side,slot
|
||||||
@ -214,7 +238,7 @@ end
|
|||||||
-- @param #number SlotID Slot number
|
-- @param #number SlotID Slot number
|
||||||
-- @return #boolean Success
|
-- @return #boolean Success
|
||||||
function NET:ForceSlot(Client,SideID,SlotID)
|
function NET:ForceSlot(Client,SideID,SlotID)
|
||||||
local PlayerID = Client:GetID()
|
local PlayerID = self:GetPlayerIDFromClient(Client)
|
||||||
if PlayerID then
|
if PlayerID then
|
||||||
return net.force_player_slot(tonumber(PlayerID), SideID, SlotID )
|
return net.force_player_slot(tonumber(PlayerID), SideID, SlotID )
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user