Voltaism Dev Tips: Difference between revisions
From Onset Developer Wiki
No edit summary |
No edit summary |
||
Line 95: | Line 95: | ||
print(vartest) | print(vartest) | ||
print(_ENV["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> | </syntaxhighlight> |
Revision as of 14:58, 7 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
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)