Voltaism Dev Tips

From Onset Developer Wiki
Revision as of 18:30, 8 July 2021 by Voltaism (talk | contribs) (Add sandboxie tip)

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)

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.