2024-08-07 17:11:55 +03:00
|
|
|
local ctx = dofile_once("mods/quant.ew/files/core/ctx.lua")
|
|
|
|
local net = dofile_once("mods/quant.ew/files/core/net.lua")
|
|
|
|
local player_fns = dofile_once("mods/quant.ew/files/core/player_fns.lua")
|
2024-07-01 22:58:04 +03:00
|
|
|
|
|
|
|
local rpc = net.new_rpc_namespace()
|
|
|
|
|
|
|
|
local module = {}
|
|
|
|
|
2024-10-26 19:32:01 -04:00
|
|
|
function rpc.send_money(money)
|
|
|
|
local entity = ctx.rpc_player_data.entity
|
|
|
|
local wallet = EntityGetFirstComponentIncludingDisabled(entity, "WalletComponent")
|
|
|
|
if wallet ~= nil then
|
|
|
|
ComponentSetValue2(wallet, "money", money)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-10-13 21:33:27 -04:00
|
|
|
function rpc.player_update(input_data, pos_data, current_slot, team)
|
2024-07-01 22:58:04 +03:00
|
|
|
local peer_id = ctx.rpc_peer_id
|
2024-08-15 09:16:29 -04:00
|
|
|
|
2024-07-01 22:58:04 +03:00
|
|
|
if not player_fns.peer_has_player(peer_id) then
|
2024-10-13 21:33:27 -04:00
|
|
|
player_fns.spawn_player_for(peer_id, pos_data.x, pos_data.y, team)
|
2024-07-01 22:58:04 +03:00
|
|
|
end
|
|
|
|
local player_data = player_fns.peer_get_player_data(peer_id)
|
2024-10-13 21:33:27 -04:00
|
|
|
|
2024-10-20 06:27:38 -04:00
|
|
|
if team ~= nil and not GameHasFlagRun("ending_game_completed") and not EntityHasTag(player_data.entity, "polymorphed") and ctx.proxy_opt.friendly_fire_team ~= nil then
|
2024-10-13 21:33:27 -04:00
|
|
|
local my_team = ctx.proxy_opt.friendly_fire_team - 1
|
|
|
|
if my_team ~= -1 and team ~= -1 and (team == 0 or my_team == 0 or team ~= my_team) then
|
|
|
|
GenomeSetHerdId(player_data.entity, "player_pvp")
|
|
|
|
else
|
|
|
|
GenomeSetHerdId(player_data.entity, "player")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2024-07-01 22:58:04 +03:00
|
|
|
if input_data ~= nil then
|
|
|
|
player_fns.deserialize_inputs(input_data, player_data)
|
|
|
|
end
|
|
|
|
if pos_data ~= nil then
|
|
|
|
player_fns.deserialize_position(pos_data, player_data)
|
|
|
|
end
|
|
|
|
if current_slot ~= nil then
|
|
|
|
player_fns.set_current_slot(current_slot, player_data)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-09-27 17:41:26 -04:00
|
|
|
function rpc.check_gamemode(gamemode)
|
2024-09-27 18:38:49 -04:00
|
|
|
local mn = np.GetGameModeNr()
|
|
|
|
local gm = np.GetGameModeName(mn)
|
|
|
|
if gamemode ~= gm then
|
2024-09-27 17:41:26 -04:00
|
|
|
GamePrint("Player: " .. ctx.rpc_player_data.name .. ", is on a different gamemode number then you")
|
2024-09-27 18:38:49 -04:00
|
|
|
GamePrint("his game mode: ".. gamemode)
|
|
|
|
GamePrint("your game mode: ".. gm)
|
2024-09-27 17:41:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-07-01 22:58:04 +03:00
|
|
|
function module.on_world_update()
|
|
|
|
local input_data = player_fns.serialize_inputs(ctx.my_player)
|
|
|
|
local pos_data = player_fns.serialize_position(ctx.my_player)
|
|
|
|
local current_slot = player_fns.get_current_slot(ctx.my_player)
|
|
|
|
if input_data ~= nil and pos_data ~= nil then
|
2024-10-13 21:33:27 -04:00
|
|
|
local my_team
|
2024-10-18 07:51:16 -04:00
|
|
|
if ctx.proxy_opt.friendly_fire and GameGetFrameNum() % 60 == 43 and ctx.proxy_opt.friendly_fire_team ~= nil then
|
2024-10-13 21:33:27 -04:00
|
|
|
my_team = ctx.proxy_opt.friendly_fire_team - 1
|
|
|
|
end
|
|
|
|
|
|
|
|
rpc.player_update(input_data, pos_data, current_slot, my_team)
|
2024-09-27 18:38:49 -04:00
|
|
|
if GameGetFrameNum() % 120 == 0 then
|
|
|
|
local n = np.GetGameModeNr()
|
|
|
|
rpc.check_gamemode(np.GetGameModeName(n))
|
2024-09-27 17:41:26 -04:00
|
|
|
end
|
2024-07-01 22:58:04 +03:00
|
|
|
end
|
2024-10-15 17:28:26 -04:00
|
|
|
|
|
|
|
if GameGetFrameNum() % 16 == 7 then
|
|
|
|
local mx, my = GameGetCameraPos()
|
|
|
|
for peer_id, player in pairs(ctx.players) do
|
|
|
|
local ent = player.entity
|
|
|
|
local x, y = EntityGetTransform(ent)
|
2024-10-26 19:32:01 -04:00
|
|
|
local notplayer = EntityHasTag(ent, "ew_notplayer")
|
|
|
|
if x == nil or not EntityGetIsAlive(ent) or (not notplayer and EntityHasTag(ent, "polymorphed")) then
|
|
|
|
goto continue
|
2024-10-19 15:38:35 -04:00
|
|
|
end
|
2024-10-15 17:28:26 -04:00
|
|
|
local dx, dy = x - mx, y - my
|
|
|
|
local cape
|
|
|
|
for _, child in ipairs(EntityGetAllChildren(ent) or {}) do
|
|
|
|
if EntityGetName(child) == "cape" then
|
2024-10-26 19:32:01 -04:00
|
|
|
local cpe = EntityGetFirstComponentIncludingDisabled(child, "VerletPhysicsComponent")
|
|
|
|
local cx, cy = ComponentGetValue2(cpe, "m_position_previous")
|
|
|
|
local dcx, dcy = x - cx, y - cy
|
|
|
|
if dcx * dcx + dcy * dcy > 300 * 300 then
|
|
|
|
EntityKill(child)
|
|
|
|
else
|
|
|
|
cape = child
|
|
|
|
end
|
2024-10-15 17:28:26 -04:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if dx * dx + dy * dy > 300 * 300 then
|
|
|
|
if cape ~= nil then
|
|
|
|
EntityKill(cape)
|
|
|
|
end
|
|
|
|
elseif cape == nil then
|
2024-10-26 19:32:01 -04:00
|
|
|
local player_cape_sprite_file
|
|
|
|
if notplayer then
|
|
|
|
player_cape_sprite_file = "mods/quant.ew/files/system/local_health/notplayer/notplayer_cape.xml"
|
|
|
|
else
|
|
|
|
player_cape_sprite_file = "mods/quant.ew/files/system/player/tmp/" .. peer_id .. "_cape.xml"
|
|
|
|
end
|
2024-10-15 17:28:26 -04:00
|
|
|
local cape2 = EntityLoad(player_cape_sprite_file, x, y)
|
|
|
|
EntityAddChild(ent, cape2)
|
|
|
|
end
|
2024-10-26 19:32:01 -04:00
|
|
|
::continue::
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if GameGetFrameNum() % 60 == 47 then
|
|
|
|
local wallet = EntityGetFirstComponentIncludingDisabled(ctx.my_player.entity, "WalletComponent")
|
|
|
|
if wallet ~= nil then
|
|
|
|
rpc.send_money(ComponentGetValue2(wallet, "money"))
|
2024-10-15 17:28:26 -04:00
|
|
|
end
|
|
|
|
end
|
2024-07-01 22:58:04 +03:00
|
|
|
end
|
|
|
|
|
2024-08-15 09:16:29 -04:00
|
|
|
return module
|