Skip to content

Commit

Permalink
Fix fire not always working in PlayerAdded
Browse files Browse the repository at this point in the history
  • Loading branch information
nezuo committed Jan 1, 2024
1 parent 9513bf1 commit 6b9d136
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
20 changes: 12 additions & 8 deletions zap/src/output/luau/server.luau
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ end

local player_map = {}

Players.PlayerAdded:Connect(function(player)
player_map[player] = {
buff = buffer.create(64),
used = 0,
size = 64,
inst = {},
}
end)
local function load_player(player: Player)
if not player_map[player] then
player_map[player] = {
buff = buffer.create(64),
used = 0,
size = 64,
inst = {},
}
end

load(player_map[player])
end

Players.PlayerRemoving:Connect(function(player)
player_map[player] = nil
Expand Down
14 changes: 7 additions & 7 deletions zap/src/output/luau/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ impl<'a> ServerOutput<'a> {
self.indent();

match ev.evty {
EvType::Reliable => self.push_line(&format!("load(player_map[{player}])")),
EvType::Reliable => self.push_line(&format!("load_player({player})")),
EvType::Unreliable => self.push_line("load_empty()"),
}

Expand Down Expand Up @@ -327,9 +327,9 @@ impl<'a> ServerOutput<'a> {
match ev.evty {
EvType::Reliable => {
self.push_line("local buff, used, inst = outgoing_buff, outgoing_used, outgoing_inst");
self.push_line("for player, outgoing in player_map do");
self.push_line("for _, player in Players:GetPlayers() do");
self.indent();
self.push_line("load(outgoing)");
self.push_line("load_player(player)");
self.push_line("alloc(used)");
self.push_line("buffer.copy(outgoing_buff, outgoing_apos, buff, 0, used)");
self.push_line("table.move(inst, 1, #inst, #outgoing_inst + 1, outgoing_inst)");
Expand Down Expand Up @@ -371,11 +371,11 @@ impl<'a> ServerOutput<'a> {
match ev.evty {
EvType::Reliable => {
self.push_line("local buff, used, inst = outgoing_buff, outgoing_used, outgoing_inst");
self.push_line("for player, outgoing in player_map do");
self.push_line("for _, player in Players:GetPlayers() do");
self.indent();
self.push_line(&format!("if player ~= {except} then"));
self.indent();
self.push_line("load(outgoing)");
self.push_line("load_player(player)");
self.push_line("alloc(used)");
self.push_line("buffer.copy(outgoing_buff, outgoing_apos, buff, 0, used)");
self.push_line("table.move(inst, 1, #inst, #outgoing_inst + 1, outgoing_inst)");
Expand All @@ -389,7 +389,7 @@ impl<'a> ServerOutput<'a> {
EvType::Unreliable => {
self.push_line("local buff = buffer.create(outgoing_used)");
self.push_line("buffer.copy(buff, 0, outgoing_buff, 0, outgoing_used)");
self.push_line("for player in player_map do");
self.push_line("for _, player in Players:GetPlayers() do");
self.indent();
self.push_line(&format!("if player ~= {except} then"));
self.indent();
Expand Down Expand Up @@ -429,7 +429,7 @@ impl<'a> ServerOutput<'a> {
self.push_line("local buff, used, inst = outgoing_buff, outgoing_used, outgoing_inst");
self.push_line(&format!("for _, player in {list} do"));
self.indent();
self.push_line("load(player_map[player])");
self.push_line("load_player(player)");
self.push_line("alloc(used)");
self.push_line("buffer.copy(outgoing_buff, outgoing_apos, buff, 0, used)");
self.push_line("table.move(inst, 1, #inst, #outgoing_inst + 1, outgoing_inst)");
Expand Down

0 comments on commit 6b9d136

Please sign in to comment.