Search the Community
Showing results for tags 'multiplayer'.
-
Hi It would be really helpful to get this coverted to LUA to assist in development of Steamworks/Multiplayer. It's been tricky to use only the basic documentation to get it done, without an example. https://www.leadwerks.com/learn/Steamworks_GetPacket?lang=cpp Example This example demonstrates lobbies, voice chat, and simple player movement. #include "UltraEngine.h" #include "Steamworks/Steamworks.h" #include "ComponentSystem.h" using namespace UltraEngine; class Player : public Object { public: static inline std::map<uint64_t, shared_ptr<Player> > players; shared_ptr<Entity> entity; WString name; uint64_t userid; static std::shared_ptr<Player> Get(shared_ptr<World> world, const uint64_t userid) { if (players[userid]) return players[userid]; auto player = std::make_shared<Player>(); player->entity = CreatePivot(world); auto model = CreateCylinder(world, 0.25, 1.8); model->SetPosition(0, 0.9, 0); model->SetParent(player->entity); model->SetCollider(nullptr); player->userid = userid; players[userid] = player; return player; } static void Remove(const uint64_t userid) { players[userid] = nullptr; } }; struct PlayerState { Vec3 position; float yaw; }; int main(int argc, const char* argv[]) { // Initialize Steam if (not Steamworks::Initialize()) { RuntimeError("Steamworks failed to initialize."); return 1; } // Get the displays auto displays = GetDisplays(); // Create a window auto window = CreateWindow("Ultra Engine", 0, 0, 1280 * displays[0]->scale, 720 * displays[0]->scale, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); // Create a framebuffer auto framebuffer = CreateFramebuffer(window); // Create world auto world = CreateWorld(); world->SetGravity(0, -18, 0); // Create lobby auto lobbyid = Steamworks::CreateLobby(Steamworks::LOBBY_PUBLIC); Print("Lobby: " + String(lobbyid)); // Spawn local player auto player = Player::Get(world, Steamworks::GetUserId()); player->entity->AddComponent<FirstPersonControls>(); // Add lighting auto light = CreateDirectionalLight(world); light->SetRotation(55, 35, 0); // Add a floor auto floor = CreateBox(world, 50, 1, 50); floor->SetPosition(0, -0.5, 0); auto mtl = CreateMaterial(); mtl->SetTexture(LoadTexture("https://github.com/UltraEngine/Documentation/raw/master/Assets/Materials/Developer/griid_gray.dds")); floor->SetMaterial(mtl); // Main loop while (not window->KeyDown(KEY_ESCAPE) and not window->Closed()) { while (PeekEvent()) { const auto e = WaitEvent(); switch (e.id) { case Steamworks::EVENT_LOBBYINVITEACCEPTED: case Steamworks::EVENT_LOBBYDATACHANGED: case Steamworks::EVENT_LOBBYUSERJOIN: case Steamworks::EVENT_LOBBYUSERLEAVE: case Steamworks::EVENT_LOBBYUSERDISCONNECT: auto info = e.source->As<Steamworks::LobbyEventInfo>(); auto username = Steamworks::GetUserName(info->userid); switch (e.id) { case Steamworks::EVENT_LOBBYINVITEACCEPTED: Print("Invite accepted to lobby " + String(info->lobbyid)); lobbyid = info->lobbyid; if (not Steamworks::JoinLobby(info->lobbyid)) { lobbyid = 0; Print("Failed to join lobby"); } break; case Steamworks::EVENT_LOBBYDATACHANGED: Print("New lobby owner " + username); break; case Steamworks::EVENT_LOBBYUSERJOIN: Print("User " + username + " joined"); if (not Player::players[info->userid]) { // Spawn remote player Player::Get(world, info->userid); } break; case Steamworks::EVENT_LOBBYUSERLEAVE: Print("User " + username + " left"); // Remove remote player Player::Remove(info->userid); break; case Steamworks::EVENT_LOBBYUSERDISCONNECT: Print("User " + username + " disconnected"); // Remove remote player Player::Remove(info->userid); break; } break; } } // Receive player data PlayerState state; while (true) { auto pak = Steamworks::GetPacket(); if (not pak) break; if (pak->data->GetSize() == sizeof(PlayerState)) { auto player = Player::Get(world, pak->userid); if (player) { pak->data->Peek(0, (const char*)&state, pak->data->GetSize()); player->entity->SetPosition(state.position); player->entity->SetRotation(state.yaw); } } } //Receive text messages while (true) { auto pak = Steamworks::GetPacket(1); if (not pak) break; String s = pak->data->PeekString(0); Print(Steamworks::GetUserName(pak->userid) + ": " + WString(s)); } // Send player data auto userid = Steamworks::GetUserId(); auto player = Player::players[userid]; state.position = player->entity->position; state.yaw = player->entity->rotation.y; Steamworks::BroadcastPacket(lobbyid, &state, sizeof(PlayerState), 0, Steamworks::P2PSEND_UNRELIABLENODELAY); // Enable voice chat when the C key is pressed bool record = window->KeyDown(KEY_C); Steamworks::RecordVoice(record); String title = "Ultra Engine"; if (record) title += " (Microphone Enabled)"; window->SetText(title); // Update world world->Update(); // Render world world->Render(framebuffer); // Update Steamworks Steamworks::Update(); } // Close Steam Steamworks::Shutdown(); return 0; }
- 2 replies
-
- lua
- steamworks
-
(and 1 more)
Tagged with:
-
I loaded up the multiplayer example but it did not show any signs of being online. How do you use it ? There was no chat on and no signs of being online just a blank walled off room that has an FPS player to walk around and that is it. I was hoping to see a working small example template of a multiplayer game in action just to see how it is done. Instead all there is is a blank FPS walk around room !
- 5 replies
-
- multiplayer
- template
-
(and 4 more)
Tagged with:
-
is there any multiplayer online example yet ?
- 9 replies
-
- multiplayer
- online
-
(and 1 more)
Tagged with:
-
function Script:UpdateWorld() if(srvr == nil) then srvr = Server:Create(8888) srvr:Publish("GG2", "GoodGame",10) client = Client:Create() end cnt = client:CountServers("GG2",15) --print("Count of servers = ") --print(cnt) if window:KeyHit(Key.T) then aa = client:GetServer(0) bb = aa.addres print(bb) bb = "127.0.0.1" client:Connect(bb,8888) client:Send(1,"Connected") end msg = srvr:Update() if(msg ~= nil) then print("Msg =") print(msg) end end Hello! PLS help me. When writing such code and clicking on 'T', as a result, messages from the client do not come and the ip server is always equal to "nil". Please help me. Sorry in advance for maybe a stupid question. Output: msg = absent; bb = nil; cnt(if enable) = 1;
-
function Script:UpdateWorld() if(srvr == nil) then srvr = Server:Create(8888) srvr:Publish("GG2", "GoodGame",10) client = Client:Create() end cnt = client:CountServers("GG2",15) --print("Count of servers = ") --print(cnt) if window:KeyHit(Key.T) then aa = client:GetServer(0) bb = aa.addres print(bb) bb = "127.0.0.1" client:Connect(bb,8888) client:Send(1,"Connected") end msg = srvr:Update() if(msg ~= nil) then print("Msg =") print(msg) end end Hello! I bought a professional edition and for 3 days I've been trying to understand how it works. When writing such code and clicking on 'T', as a result, messages from the client do not come and the ip server is always equal to "nil". Please help me. Sorry in advance for maybe a stupid question. Output: msg = absent; bb = nil; cnt(if enable) = 1;
-
Hi there, I'm hoping to start a bit of a conversation regarding multiplayer game concepts using LE. I have read a few threads regarding multiplayer but there are not that many going in to depth, but then I've also seen some videos of what some people have managed implement (such as synced vehicle physics). My game isn't quite at the multiplayer stage yet, but hopefully I'll have a lot of it planned by the time it comes around. Firstly, I'd like to point out the fact that I like how LE uses a simple "do it yourself" messaging system, as oppose to having that extra layer on top that does the job for you. Not only the more you do yourself the more you learn, but the control over it so much better if your trying to create something like an information bubble. Sending and receiving basic messages from connection, to chat, kicked, banned etc. are a simple case. But syncing other life in the world becomes more difficult. After working with the Half Life 1 engine for several years I've picked up a few ideal concepts. What I've gathered is, sending messages to update a player's coordinates every time they move is a lost cause. Sending a key press to the server and have the server simulate the player's movement appears like an optimal way to go. The player will press the forward key, and that key press would be sent to the server, and with the server knowing the player's spawn location, it would be able to simulate movement based on this key press. The only catch I've found so far, is when setting an entity to use CharacterPhysics, you use SetInput() to control them. Assuming this is the right way to go, how would you send a key press message to the server if the player input is controlled by the engine? Or is there a more effective way? Then you also have vehicle physics. I don't have a lot of experience with LE yet, so I'll also put forward this question - does the physics engine have any randomisation in it? Or, if I crashed one vehicle into another, at the exact same spot, same angle, exact same force, will it result in the exact same physical reaction each time? This knowledge would also help fill the gap. Please share any ideas that your happy to give away. Thanks in advance.
-
can someone help me with RakNet? create a multiplayer game to study.
-
I was wondering if you can put letters in leadwerks game engine, if yes where it is and also can you do multiplayer? or play game at local so someone can play.
- 3 replies
-
- letter
- multiplayer
-
(and 1 more)
Tagged with: