Voltaism Dev Tips: Difference between revisions

From Onset Developer Wiki
mNo edit summary
(add client tip)
Line 25: Line 25:


== 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>


== Global/Other Tips ==
== Global/Other Tips ==

Revision as of 19:36, 6 July 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

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"])