ConnectToServer: Difference between revisions
From Onset Developer Wiki
Created page with "{{Info|Function|Client|1.0}} {{FuncDescription|Connects the game to another server. The connection will happen on the next game tick.}} {{FuncSyntax|ConnectToServer(Address,..." |
No edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
{{FuncDescription|Connects the game to another server. The connection will happen on the next game tick.}} | {{FuncDescription|Connects the game to another server. The connection will happen on the next game tick.}} | ||
{{FuncSyntax|ConnectToServer(Address, Port [, Password])}} | {{FuncSyntax|ConnectToServer(Address, Port [, Password, LevelMap])}} | ||
{{FuncParameters}} | {{FuncParameters}} | ||
Line 9: | Line 9: | ||
{{FuncParam|Port|Server port.}} | {{FuncParam|Port|Server port.}} | ||
{{FuncParamOptional|Password|Optional server password.}} | {{FuncParamOptional|Password|Optional server password.}} | ||
{{FuncParamOptional|LevelMap|Optional path to a level to load (since 1.3.0, see [[Custom_Maps]]).}} | |||
{{FuncReturnValue| | {{FuncReturnValue|Returns '''false''' if this function was already called. If LevelMap was set but is an invalid (non existent) map this function will return '''false''' and no connection will happen. Returns '''true''' on success.}} | ||
== Example == | == Example == | ||
<syntaxhighlight lang="Lua"> | |||
function OnKeyPress(key) | |||
if key == "J" then | |||
ConnectToServer("127.0.0.1", 7777, "") | |||
end | |||
end | |||
AddEvent("OnKeyPress", OnKeyPress) | |||
</syntaxhighlight> | |||
{{RelatedFunctions}} | {{RelatedFunctions}} | ||
*[[GetGameVersion]] | |||
*[[IsGameDevMode]] | |||
*[[IsPlayerInMainMenu]] | |||
*[[InvokeDamageFX]] | |||
*[[UpdateDiscordActivity]] | |||
*[[ConnectToServer]] |
Latest revision as of 15:12, 20 September 2020
Description
Connects the game to another server. The connection will happen on the next game tick.
Syntax
ConnectToServer(Address, Port [, Password, LevelMap])
Parameters
- Address
Server IP or hostname. - Port
Server port. - Password (optional)
Optional server password. - LevelMap (optional)
Optional path to a level to load (since 1.3.0, see Custom_Maps).
Return Value
- Returns false if this function was already called. If LevelMap was set but is an invalid (non existent) map this function will return false and no connection will happen. Returns true on success.
Example
function OnKeyPress(key)
if key == "J" then
ConnectToServer("127.0.0.1", 7777, "")
end
end
AddEvent("OnKeyPress", OnKeyPress)