diff --git a/docs/lua/functions.md b/docs/lua/functions.md index 5f5f7968..fed3d060 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -619,6 +619,7 @@ - smlua_misc_utils.h - [collision_find_surface_on_ray](#collision_find_surface_on_ray) + - [get_network_area_timer](#get_network_area_timer)
@@ -11422,6 +11423,24 @@ The `reliable` field will ensure that the packet arrives, but should be used spa
+## [get_network_area_timer](#get_network_area_timer) + +### Lua Example +`local integerValue = get_network_area_timer()` + +### Parameters +- None + +### Returns +- `integer` + +### C Prototype +`u32 get_network_area_timer(void);` + +[:arrow_up_small:](#) + +
+ --- # functions from smlua_obj_utils.h diff --git a/mods/football.lua b/mods/football.lua index 84e6db97..16854fb9 100644 --- a/mods/football.lua +++ b/mods/football.lua @@ -32,7 +32,6 @@ ballActionValues = { gBallTouchedLocal = false gCachedBalls = {} -gInitializeBalls = {} ----------- -- utils -- @@ -128,8 +127,8 @@ function spawn_or_move_ball(x, y, z) obj.oVelZ = 0 obj.oGlobalOwner = my_global_index() - obj.oHitTime = obj.areaTimer - obj.oNetworkTime = obj.areaTimer + obj.oHitTime = get_network_area_timer() + obj.oNetworkTime = get_network_area_timer() network_send_object(obj, false) return obj @@ -615,13 +614,13 @@ function bhv_ball_loop(obj) end -- send out object if we touched it - local updateRateSend = (obj.oGlobalOwner == my_global_index() and (obj.areaTimer - obj.oNetworkTime) > 5) + local updateRateSend = (obj.oGlobalOwner == my_global_index() and (get_network_area_timer() - obj.oNetworkTime) > 5) if gBallTouchedLocal or updateRateSend then if gBallTouchedLocal then obj.oGlobalOwner = my_global_index() - obj.oHitTime = obj.areaTimer + obj.oHitTime = get_network_area_timer() end - obj.oNetworkTime = obj.areaTimer + obj.oNetworkTime = get_network_area_timer() network_send_object(obj, false) end @@ -647,18 +646,6 @@ function bhv_ball_loop(obj) cb.oVelZ = obj.oVelZ end -function ball_update() - -- hack: we have to set the area timer outside of the behavior or bad things happen - for i, obj in ipairs(gInitializeBalls) do - if obj ~= nil then - obj.areaTimerDuration = 0 - obj.areaTimerType = AREA_TIMER_TYPE_MAXIMUM - obj.areaTimer = 0 - end - gInitializeBalls[i] = nil - end -end - id_bhvBall = hook_behavior(nil, OBJ_LIST_DEFAULT, true, bhv_ball_init, bhv_ball_loop) ---------------------------------------------------------------------------------------------------------------- @@ -828,8 +815,8 @@ function gamemode_wait() -- claim the ball if sSoccerBall.oGlobalOwner ~= my_global_index() then sSoccerBall.oGlobalOwner = my_global_index() - sSoccerBall.oHitTime = sSoccerBall.areaTimer - sSoccerBall.oNetworkTime = sSoccerBall.areaTimer + sSoccerBall.oHitTime = get_network_area_timer() + sSoccerBall.oNetworkTime = get_network_area_timer() network_send_object(sSoccerBall, false) end @@ -1284,8 +1271,6 @@ function update() local m = gMarioStates[0] local np = gNetworkPlayers[m.playerIndex] - ball_update() - if np.currAreaSyncValid then gamemode_update() end diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index 3ade1085..164201ea 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -7289,6 +7289,15 @@ int smlua_func_collision_find_surface_on_ray(lua_State* L) { return 1; } +int smlua_func_get_network_area_timer(UNUSED lua_State* L) { + if(!smlua_functions_valid_param_count(L, 0)) { return 0; } + + + lua_pushinteger(L, get_network_area_timer()); + + return 1; +} + /////////////////////// // smlua_obj_utils.h // /////////////////////// @@ -8520,6 +8529,7 @@ void smlua_bind_functions_autogen(void) { // smlua_misc_utils.h smlua_bind_function(L, "collision_find_surface_on_ray", smlua_func_collision_find_surface_on_ray); + smlua_bind_function(L, "get_network_area_timer", smlua_func_get_network_area_timer); // smlua_obj_utils.h smlua_bind_function(L, "obj_get_first", smlua_func_obj_get_first); diff --git a/src/pc/lua/smlua_misc_utils.c b/src/pc/lua/smlua_misc_utils.c index f5a91f7b..ac62fbec 100644 --- a/src/pc/lua/smlua_misc_utils.c +++ b/src/pc/lua/smlua_misc_utils.c @@ -12,3 +12,7 @@ struct RayIntersectionInfo* collision_find_surface_on_ray(f32 startX, f32 startY find_surface_on_ray(orig, end, &info.surface, info.hitPos); return &info; } + +u32 get_network_area_timer(void) { + return gNetworkAreaTimer; +} \ No newline at end of file diff --git a/src/pc/lua/smlua_misc_utils.h b/src/pc/lua/smlua_misc_utils.h index 0e9aa1e6..6c9ebdad 100644 --- a/src/pc/lua/smlua_misc_utils.h +++ b/src/pc/lua/smlua_misc_utils.h @@ -7,5 +7,6 @@ struct RayIntersectionInfo { }; struct RayIntersectionInfo* collision_find_surface_on_ray(f32 startX, f32 startY, f32 startZ, f32 endX, f32 endY, f32 endZ); +u32 get_network_area_timer(void); #endif