Skip to content

Commit

Permalink
Lua: update example script with more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Jun 26, 2024
1 parent ff35a24 commit 525b785
Showing 1 changed file with 77 additions and 2 deletions.
79 changes: 77 additions & 2 deletions lua-api/examples/hello_world.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
print("Initializing hello_world.lua")

UEVR_UObjectHook.activate()

local api = uevr.api;
local uobjects = uevr.types.FUObjectArray.get()

Expand All @@ -16,7 +18,24 @@ local once = true
local last_world = nil
local last_level = nil

uevr.sdk.callbacks.on_post_engine_tick(function(engine, delta)

end)

local spawn_once = true

uevr.sdk.callbacks.on_pre_engine_tick(function(engine, delta)
--[[if spawn_once then
local cheat_manager_c = api:find_uobject("Class /Script/Engine.CheatManager")
local cheat_manager = UEVR_UObjectHook.get_first_object_by_class(cheat_manager_c)
print(tostring(cheat_manager_c))
cheat_manager:Summon("Something_C")
spawn_once = false
end]]

local game_engine_class = api:find_uobject("Class /Script/Engine.GameEngine")
local game_engine = UEVR_UObjectHook.get_first_object_by_class(game_engine_class)

Expand Down Expand Up @@ -68,9 +87,61 @@ uevr.sdk.callbacks.on_pre_engine_tick(function(engine, delta)
--pawn.BaseEyeHeight = 0.0
--pawn.bActorEnableCollision = not pawn.bActorEnableCollision

local pawn_level = pawn:GetLevel()
local actor_component_c = api:find_uobject("Class /Script/Engine.ActorComponent");
print("actor_component_c class: " .. tostring(actor_component_c))
local test_component = pawn:GetComponentByClass(actor_component_c)

print("TestComponent: " .. tostring(test_component))

local controller = pawn.Controller

if controller ~= nil then
print("Controller: " .. controller:get_full_name())

local velocity = controller:GetVelocity()
print("Velocity: " .. tostring(velocity.x) .. ", " .. tostring(velocity.y) .. ", " .. tostring(velocity.z))

local test = Vector3d.new(1.337, 1.0, 1.0)
print("Test: " .. tostring(test.x) .. ", " .. tostring(test.y) .. ", " .. tostring(test.z))

print("Pawn level: " .. pawn_level:get_full_name())
controller:SetActorScale3D(Vector3d.new(1.337, 1.0, 1.0))

local actor_scale_3d = controller:GetActorScale3D()
print("ActorScale3D: " .. tostring(actor_scale_3d.x) .. ", " .. tostring(actor_scale_3d.y) .. ", " .. tostring(actor_scale_3d.z))


local control_rotation = controller:GetControlRotation()

print("ControlRotation: " .. tostring(control_rotation.Pitch) .. ", " .. tostring(control_rotation.Yaw) .. ", " .. tostring(control_rotation.Roll))
control_rotation.Pitch = 1.337

controller:SetControlRotation(control_rotation)
control_rotation = controller:GetControlRotation()

print("New ControlRotation: " .. tostring(control_rotation.Pitch) .. ", " .. tostring(control_rotation.Yaw) .. ", " .. tostring(control_rotation.Roll))
end

local primary_actor_tick = pawn.PrimaryActorTick

if primary_actor_tick ~= nil then
print("PrimaryActorTick: " .. tostring(primary_actor_tick))

-- Print various properties, this is testing of StructProperty as PrimaryActorTick is a struct
local tick_interval = primary_actor_tick.TickInterval
print("TickInterval: " .. tostring(tick_interval))

print("bAllowTickOnDedicatedServer: " .. tostring(primary_actor_tick.bAllowTickOnDedicatedServer))
print("bCanEverTick: " .. tostring(primary_actor_tick.bCanEverTick))
print("bStartWithTickEnabled: " .. tostring(primary_actor_tick.bStartWithTickEnabled))
print("bTickEvenWhenPaused: " .. tostring(primary_actor_tick.bTickEvenWhenPaused))
else
print("PrimaryActorTick is nil")
end

local control_input_vector = pawn.ControlInputVector
pawn.ControlInputVector.x = 1.337

print("ControlInputVector: " .. tostring(control_input_vector.x) .. ", " .. tostring(control_input_vector.y) .. ", " .. tostring(control_input_vector.z))

local is_actor_tick_enabled = pawn:IsActorTickEnabled()
print("IsActorTickEnabled: " .. tostring(is_actor_tick_enabled))
Expand All @@ -90,6 +161,10 @@ uevr.sdk.callbacks.on_pre_engine_tick(function(engine, delta)

print("New LifeSpan: " .. tostring(life_span))
pawn:SetLifeSpan(og_life_span) -- resets it back to default

local net_driver_name = pawn.NetDriverName:to_string()

print("NetDriverName: " .. net_driver_name)
end

if player_controller ~= nil then
Expand Down

0 comments on commit 525b785

Please sign in to comment.