Voltaism Dev Tips: Difference between revisions

From Onset Developer Wiki
Voltaism (talk | contribs)
No edit summary
Voltaism (talk | contribs)
No edit summary
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
WIP
'''WIP'''


== Serverside Tips ==
== Serverside Tips ==
==== Restart self using an exported function ====
'''Package 1:'''
<syntaxhighlight lang="Lua">
function RestartPackage(package_name)
    Delay(1, function()
        StopPackage(package_name)
    end)
    Delay(1000, function()
    StartPackage(package_name)
    end)
    return true
end
AddFunctionExport("RestartPackage", RestartPackage)
</syntaxhighlight>
'''Package 2:'''
<syntaxhighlight lang="Lua">
local package1 = ImportPackage("package1")
package1.RestartPackage(GetPackageName())
</syntaxhighlight>


== Clientside Tips ==
== Clientside Tips ==
==== Disable a remote player/npc collisions properly ====
<syntaxhighlight lang="Lua">
local npc_actor = GetNPCActor(npc)
local Capsule = npc_actor:GetComponentsByClass(UCapsuleComponent.Class())[1] -- Get capsule component of the npc actor
Capsule:SetCollisionResponseToChannel(ECollisionChannel.ECC_Pawn, ECollisionResponse.ECR_Ignore) -- Disable Capsule collision with players
Capsule:SetCollisionResponseToChannel(ECollisionChannel.ECC_Camera, ECollisionResponse.ECR_Ignore) -- Disable capsule collision with camera
Capsule:SetCollisionResponseToChannel(ECollisionChannel.ECC_GameTraceChannel1, ECollisionResponse.ECR_Ignore) -- Disable capsule collision with bullets
for i, v in ipairs(npc_actor:GetComponents()) do
    if v:GetClassName() == "USkeletalMeshComponent" then
        v:SetCollisionResponseToChannel(ECollisionChannel.ECC_GameTraceChannel1, ECollisionResponse.ECR_Ignore) -- Disable skeletal mesh component collision with bullets
    end
end
</syntaxhighlight>
==== Change vehicle velocity ====
<syntaxhighlight lang="Lua">
local veh = GetPlayerVehicle(GetPlayerId())
if (veh ~= 0 and IsValidVehicle(veh) and GetVehicleDriver(veh) == GetPlayerId()) then -- The player has to be the driver or the vehicle won't be synced
    local vehsk = GetVehicleSkeletalMeshComponent(veh)
    vehsk:SetPhysicsAngularVelocityInDegrees(FVector(vax, vay, vaz), bAddToCurrent)
    vehsk:SetPhysicsLinearVelocity(FVector(vx, vy, vz), bAddToCurrent)
end
</syntaxhighlight>
==== Change walking animations / skeleton ====
You'll need unreal engine installed in order to do this, it's experimental and it breaks [[SetPlayerAnimation]].
First make a new plugin, create an animation blueprint then make your own state machines... and link it to the output pose.
<syntaxhighlight lang="Lua">
local SKComp = GetNPCSkeletalMeshComponent(npc, "Body") -- for an npc but you can do it with a player
local SKMesh = SKComp:GetSkeletalMesh()
SKMesh:SetPostProcessAnimBlueprint(UClass.LoadFromAsset("/vzombies/Zombie/Zombie_Anim_BP"))
SKComp:InitAnim(false)
function GetZombiePostProcessInstance(npc) -- Get the post process animation instance
    local SKComp = GetNPCSkeletalMeshComponent(npc, "Body")
    return SKComp:GetPostProcessInstance()
end
local PP = GetZombiePostProcessInstance(npc)
PP:ProcessEvent("SetAttacking", true) -- You can call animation blueprint functions
</syntaxhighlight>
==== Enter a vehicle when the player press F, even while being far from the door ====
<syntaxhighlight lang="Lua">
AddEvent("OnKeyPress", function(key)
    if (key == "F" and GetPlayerVehicle(GetPlayerId()) == 0) then
        local veh = GetStreamedVehicles()[1]
        if (veh and GetVehicleDriver(veh) == 0) then
            local plyactor = GetPlayerActor()
            local x, y, z = GetVehicleDoorLocation(veh, 1)
            plyactor:SetActorLocation(FVector(x, y, z + 50)) -- Teleport the player at the vehicle door
        end
    end
end)
</syntaxhighlight>
==== Do a LineTrace from the player ====
This is the best way to do it for me, even if it returns an HitResult, it doesn't have the bug where it returns nothing if it collides at the start of
the LineTrace (And it starts from the middle of the player), i still think that adding collision with the local player to LineTraces was a bad idea.
<syntaxhighlight lang="Lua">
function LineTraceFromPlayer(ToDistanceFromPlayer, complex)
    local x, y, z = GetPlayerLocation(GetPlayerId())
    local fx, fy, fz = GetCameraForwardVector()
    local bResult, HitResult = UKismetSystemLibrary.LineTraceSingle(GetPlayerActor(), FVector(x, y, z), FVector(x + fx * ToDistanceFromPlayer, y + fy * ToDistanceFromPlayer, z + fz * ToDistanceFromPlayer), UEngineTypes.ConvertToTraceType(ECollisionChannel.ECC_Visibility), complex, {}, EDrawDebugTrace.None, true, FLinearColor(1.0, 0.0, 0.0, 1.0), FLinearColor(0.0, 1.0, 0.0, 1.0), 10.0)
    return bResult, HitResult
end
local bResult, HitResult = LineTraceFromPlayer(100, true)
if bResult then
    local actor = HitResult:GetActor()
    if actor then
        AddPlayerChat(actor:GetName())
    end
end
</syntaxhighlight>
==== Reset material slot ====
<syntaxhighlight lang="Lua">
local sk = GetPlayerSkeletalMeshComponent(GetPlayerId(), "WeaponMesh")
if sk then
    sk:SetMaterial(0, UMaterialInterface.LoadFromAsset())
end
</syntaxhighlight>
== Global/Other Tips ==
==== Call/Edit a function/variable with a string ====
<syntaxhighlight lang="Lua">
_ENV["function_" .. "test"] = function(nb)
  print("Hi", nb)
end
function_test(0)
_ENV["function_test"](1)
_ENV["vartest"] = 1
print(vartest)
print(_ENV["vartest"])
</syntaxhighlight>
==== Add rotations ====
<syntaxhighlight lang="Lua">
function AddRotation(r, r2)
    r = r + r2
    if r > 180 then
      r = -180 + (r - 180)
    elseif r < -180 then
      r = 180 + (r + 180)
    end
    return r
end
local rx, ry, rz = AddRotation(120, 70), AddRotation(-160, -40), AddRotation(60, 90)
</syntaxhighlight>
==== Launch the game twice ====
Before starting, you need to have 2 steam accounts with Onset on the accounts.
First, create a folder for the steam clone, grab the steam.exe on your computer (C:\Program Files (x86)\Steam\steam.exe for me) then copy and paste this file
in the new folder. Now you need to install [https://github.com/sandboxie-plus/Sandboxie/releases Sandboxie] (I use the classic one), a third party program that allows you to
sandbox apps. Start Sandboxie, click on Sandbox --> Create New Sandbox, put a name for it then create it. Right click on the sandbox you created then go to
Sandbox Settings, go to Resource Access --> File Access --> Full Access then press '''Add''' and add the steam clone folder, save the settings. Now you can
right click on the sandbox then Run Sandboxed --> Run Any Program then start the steam.exe in the steam clone folder. Login to your alt account, install Onset and you can launch it. To close the sandbox, right click on the sandbox --> Terminate Programs.
==== Explore game files ====
This could be useful for clothes paths.
You need to install [https://www.gildor.org/en/projects/umodel umodel]. Start umodel, put the path to the game files (Steam\steamapps\common\Onset) then press OK.
Now you can explore the game files.
==== See materials slots of game static meshes ====
You'll need to [https://dev.playonset.com/wiki/Voltaism_Dev_Tips#Explore_game_files explore game files], open a static mesh then click on "StaticMesh" --> "Material IDs", then the materials IDs will be showed and they will be linked to a color so you can see where they are applied on the mesh.

Latest revision as of 19:41, 15 September 2021

WIP

Serverside Tips

Restart self using an exported function

Package 1:

function RestartPackage(package_name)
    Delay(1, function()
        StopPackage(package_name)
    end)
    Delay(1000, function()
	    StartPackage(package_name)
    end)
    return true
end
AddFunctionExport("RestartPackage", RestartPackage)

Package 2:

local package1 = ImportPackage("package1")
package1.RestartPackage(GetPackageName())

Clientside Tips

Disable a remote player/npc collisions properly

local npc_actor = GetNPCActor(npc)
local Capsule = npc_actor:GetComponentsByClass(UCapsuleComponent.Class())[1] -- Get capsule component of the npc actor
Capsule:SetCollisionResponseToChannel(ECollisionChannel.ECC_Pawn, ECollisionResponse.ECR_Ignore) -- Disable Capsule collision with players
Capsule:SetCollisionResponseToChannel(ECollisionChannel.ECC_Camera, ECollisionResponse.ECR_Ignore) -- Disable capsule collision with camera
Capsule:SetCollisionResponseToChannel(ECollisionChannel.ECC_GameTraceChannel1, ECollisionResponse.ECR_Ignore) -- Disable capsule collision with bullets
for i, v in ipairs(npc_actor:GetComponents()) do
    if v:GetClassName() == "USkeletalMeshComponent" then
        v:SetCollisionResponseToChannel(ECollisionChannel.ECC_GameTraceChannel1, ECollisionResponse.ECR_Ignore) -- Disable skeletal mesh component collision with bullets
    end
end

Change vehicle velocity

local veh = GetPlayerVehicle(GetPlayerId())
if (veh ~= 0 and IsValidVehicle(veh) and GetVehicleDriver(veh) == GetPlayerId()) then -- The player has to be the driver or the vehicle won't be synced
    local vehsk = GetVehicleSkeletalMeshComponent(veh)
    vehsk:SetPhysicsAngularVelocityInDegrees(FVector(vax, vay, vaz), bAddToCurrent)
    vehsk:SetPhysicsLinearVelocity(FVector(vx, vy, vz), bAddToCurrent)
end

Change walking animations / skeleton

You'll need unreal engine installed in order to do this, it's experimental and it breaks SetPlayerAnimation. First make a new plugin, create an animation blueprint then make your own state machines... and link it to the output pose.

local SKComp = GetNPCSkeletalMeshComponent(npc, "Body") -- for an npc but you can do it with a player
local SKMesh = SKComp:GetSkeletalMesh()
SKMesh:SetPostProcessAnimBlueprint(UClass.LoadFromAsset("/vzombies/Zombie/Zombie_Anim_BP"))
SKComp:InitAnim(false)

function GetZombiePostProcessInstance(npc) -- Get the post process animation instance
    local SKComp = GetNPCSkeletalMeshComponent(npc, "Body")
    return SKComp:GetPostProcessInstance()
end

local PP = GetZombiePostProcessInstance(npc)
PP:ProcessEvent("SetAttacking", true) -- You can call animation blueprint functions

Enter a vehicle when the player press F, even while being far from the door

AddEvent("OnKeyPress", function(key)
    if (key == "F" and GetPlayerVehicle(GetPlayerId()) == 0) then
        local veh = GetStreamedVehicles()[1]
        if (veh and GetVehicleDriver(veh) == 0) then
            local plyactor = GetPlayerActor()
            local x, y, z = GetVehicleDoorLocation(veh, 1)
            plyactor:SetActorLocation(FVector(x, y, z + 50)) -- Teleport the player at the vehicle door
        end
    end
end)

Do a LineTrace from the player

This is the best way to do it for me, even if it returns an HitResult, it doesn't have the bug where it returns nothing if it collides at the start of the LineTrace (And it starts from the middle of the player), i still think that adding collision with the local player to LineTraces was a bad idea.

function LineTraceFromPlayer(ToDistanceFromPlayer, complex)
    local x, y, z = GetPlayerLocation(GetPlayerId())
    local fx, fy, fz = GetCameraForwardVector()
    local bResult, HitResult = UKismetSystemLibrary.LineTraceSingle(GetPlayerActor(), FVector(x, y, z), FVector(x + fx * ToDistanceFromPlayer, y + fy * ToDistanceFromPlayer, z + fz * ToDistanceFromPlayer), UEngineTypes.ConvertToTraceType(ECollisionChannel.ECC_Visibility), complex, {}, EDrawDebugTrace.None, true, FLinearColor(1.0, 0.0, 0.0, 1.0), FLinearColor(0.0, 1.0, 0.0, 1.0), 10.0)
    return bResult, HitResult
end

local bResult, HitResult = LineTraceFromPlayer(100, true)
if bResult then
     local actor = HitResult:GetActor()
     if actor then
         AddPlayerChat(actor:GetName())
     end
 end

Reset material slot

local sk = GetPlayerSkeletalMeshComponent(GetPlayerId(), "WeaponMesh")
if sk then
    sk:SetMaterial(0, UMaterialInterface.LoadFromAsset())
end

Global/Other Tips

Call/Edit a function/variable with a string

_ENV["function_" .. "test"] = function(nb)
   print("Hi", nb)
end
function_test(0)
_ENV["function_test"](1)

_ENV["vartest"] = 1
print(vartest)
print(_ENV["vartest"])

Add rotations

function AddRotation(r, r2)
    r = r + r2
    if r > 180 then
       r = -180 + (r - 180)
    elseif r < -180 then
       r = 180 + (r + 180)
    end
    return r
end
local rx, ry, rz = AddRotation(120, 70), AddRotation(-160, -40), AddRotation(60, 90)

Launch the game twice

Before starting, you need to have 2 steam accounts with Onset on the accounts. First, create a folder for the steam clone, grab the steam.exe on your computer (C:\Program Files (x86)\Steam\steam.exe for me) then copy and paste this file in the new folder. Now you need to install Sandboxie (I use the classic one), a third party program that allows you to sandbox apps. Start Sandboxie, click on Sandbox --> Create New Sandbox, put a name for it then create it. Right click on the sandbox you created then go to Sandbox Settings, go to Resource Access --> File Access --> Full Access then press Add and add the steam clone folder, save the settings. Now you can right click on the sandbox then Run Sandboxed --> Run Any Program then start the steam.exe in the steam clone folder. Login to your alt account, install Onset and you can launch it. To close the sandbox, right click on the sandbox --> Terminate Programs.

Explore game files

This could be useful for clothes paths. You need to install umodel. Start umodel, put the path to the game files (Steam\steamapps\common\Onset) then press OK. Now you can explore the game files.

See materials slots of game static meshes

You'll need to explore game files, open a static mesh then click on "StaticMesh" --> "Material IDs", then the materials IDs will be showed and they will be linked to a color so you can see where they are applied on the mesh.