Well, this is Smallg's script with a few changes to fit your needs.
carrytorch.lua - Intended to be attached to the torch
-- Allows the player to pick-up the item (torch), carry it and then drop
-- Note - entity with this script must have Physics > No & Static Mode > No
--Smallg's script, with few changes to fit your needs. - 3com
local i_state = {}
local itemdist = 100
local yangle = 0
local tCheckTime = {}
function carrytorch_init(e)
i_state[e] = "start"
end
function carrytorch_main(e)
if i_state[e] == "start" then
tCheckTime[e] = GetTimer(e)
i_state[e] = "initial"
end
PlayerDX = g_Entity[e]['x'] - g_PlayerPosX;
PlayerDY = g_Entity[e]['y'] - g_PlayerPosY;
PlayerDZ = g_Entity[e]['z'] - g_PlayerPosZ;
PlayerDist = math.sqrt(math.abs(PlayerDX^2)+math.abs(PlayerDY^2)+math.abs(PlayerDZ^2));
if PlayerDist < 150 then
if i_state[e] == "initial" and GetTimer(e) > tCheckTime[e] + 500 then
Prompt ("Press E To Pick torch")
if g_KeyPressE == 1 then
GravityOff(e)
CollisionOff(e)
Show (e)
yangle=g_PlayerAngY
i_state[e] = "carried"
PlaySound(e,0)
ActivateIfUsed(e)
tCheckTime[e] = GetTimer(e)
end
end
end -- end if player dist
if i_state[e] == "carried" then
--calculate and then hold the item 'itemdist' in front of player
itemx=g_PlayerPosX
itemz=g_PlayerPosZ
itemy=g_PlayerPosY
itemx = itemx+math.sin(math.rad(g_PlayerAngY))*itemdist
itemz = itemz+math.cos(math.rad(g_PlayerAngY))*itemdist
itemy = itemy-math.sin(math.rad(g_PlayerAngX))*itemdist
-- hide if view angle drops underground or too high - adjust as needed
if g_PlayerAngX > -50 and g_PlayerAngX < 25 then
Show(e)
else
Hide(e)
end
SetPosition(e,itemx,itemy-15,itemz)
-- mirror precisely the player Y angle for the items rotation to player
yangle = g_PlayerAngY
if g_PlayerAngY >= 360 then
yangle = g_PlayerAngY - (360 * (math.floor(g_PlayerAngY / 360)))
elseif g_PlayerAngY < 0 and g_PlayerAngY > -360 then
yangle = g_PlayerAngY + 360
elseif g_PlayerAngY <= -360 then
yangle = g_PlayerAngY + (360 * ( -1 * (math.floor(g_PlayerAngY / 360))))
end
FaceAngle = yangle + 180
if FaceAngle > 360 then
FaceAngle = FaceAngle - 360
end
--adjust the '-20' to tilt the item further away/towards the player whilst being carried (set to 0 for flat)
SetRotation(e,(g_PlayerAngX-20 * -1),FaceAngle,0)
--SetRotation(e,0,FaceAngle,0)
--check if player wants to drop item and if so drop
if g_KeyPressE == 1 and GetTimer(e) > tCheckTime[e] + 500 then
SetRotation(e,0,FaceAngle,0)
GravityOn(e)
CollisionOn(e)
item_x = g_PlayerPosX
if g_Entity[e]['x'] < item_x + 30 then
itemx=g_PlayerPosX
itemz=g_PlayerPosZ
itemy=g_PlayerPosY
ResetPosition(e,itemx,itemy,itemz)
i_state[e] = "done"
PlaySound(e,1)
else
GravityOff(e)
CollisionOff(e)
Show (e)
yangle=g_PlayerAngY
i_state[e] = "carried"
ActivateIfUsed(e)
tCheckTime[e] = GetTimer(e)
end
end -- g_KeyPressE == 1...
end -- i_state[e] == "carried"
end -- of main function
function carrytorch_exit(e)
end
carryflame.lua - Intended to be attached to the flame
-- Allows the player to pick-up the item (flame), carry it and then drop
-- Note - entity with this script must have Physics > No & Static Mode > No
local i_state = {}
local itemdist = 100
local yangle = 0
local tCheckTime = {}
function carryflame_init(e)
i_state[e] = "start"
end
function carryflame_main(e)
if i_state[e] == "start" then
tCheckTime[e] = GetTimer(e)
i_state[e] = "initial"
end
PlayerDX = g_Entity[e]['x'] - g_PlayerPosX;
PlayerDY = g_Entity[e]['y'] - g_PlayerPosY;
PlayerDZ = g_Entity[e]['z'] - g_PlayerPosZ;
PlayerDist = math.sqrt(math.abs(PlayerDX^2)+math.abs(PlayerDY^2)+math.abs(PlayerDZ^2));
if PlayerDist < 150 then
if i_state[e] == "initial" and GetTimer(e) > tCheckTime[e] + 500 then
Prompt ("Press E To Pick flame")
if g_KeyPressE == 1 then
GravityOff(e)
CollisionOff(e)
Show (e)
yangle=g_PlayerAngY
i_state[e] = "carried"
PlaySound(e,0)
ActivateIfUsed(e)
tCheckTime[e] = GetTimer(e)
end
end
end -- end if player dist
if i_state[e] == "carried" then
--calculate and then hold the item 'itemdist' in front of player
itemx=g_PlayerPosX
itemz=g_PlayerPosZ
itemy=g_PlayerPosY
itemx = itemx+math.sin(math.rad(g_PlayerAngY))*itemdist
itemz = itemz+math.cos(math.rad(g_PlayerAngY))*itemdist
itemy = itemy-math.sin(math.rad(g_PlayerAngX))*itemdist
-- hide if view angle drops underground or too high - adjust as needed
if g_PlayerAngX > -50 and g_PlayerAngX < 25 then
Show(e)
else
Hide(e)
end
SetPosition(e,itemx,itemy,itemz)
-- mirror precisely the player Y angle for the items rotation to player
yangle = g_PlayerAngY
if g_PlayerAngY >= 360 then
yangle = g_PlayerAngY - (360 * (math.floor(g_PlayerAngY / 360)))
elseif g_PlayerAngY < 0 and g_PlayerAngY > -360 then
yangle = g_PlayerAngY + 360
elseif g_PlayerAngY <= -360 then
yangle = g_PlayerAngY + (360 * ( -1 * (math.floor(g_PlayerAngY / 360))))
end
FaceAngle = yangle + 180
if FaceAngle > 360 then
FaceAngle = FaceAngle - 360
end
--adjust the '-20' to tilt the item further away/towards the player whilst being carried (set to 0 for flat)
SetRotation(e,(g_PlayerAngX-20 * -1),FaceAngle,0)
--SetRotation(e,0,FaceAngle,0)
--check if player wants to drop item and if so drop
if g_KeyPressE == 1 and GetTimer(e) > tCheckTime[e] + 500 then
SetRotation(e,0,FaceAngle,0)
GravityOn(e)
CollisionOn(e)
item_x = g_Entity[17]['x']
if g_Entity[e]['x'] < item_x + 30 then
itemx = g_Entity[17]['x']
itemy = g_Entity[17]['y']
itemz = g_Entity[17]['z']
ResetPosition(e,itemx,itemy,itemz)
i_state[e] = "done"
PlaySound(e,1)
else
GravityOff(e)
CollisionOff(e)
Show (e)
yangle=g_PlayerAngY
i_state[e] = "carried"
ActivateIfUsed(e)
tCheckTime[e] = GetTimer(e)
end
end -- g_KeyPressE == 1...
end -- i_state[e] == "carried"
end -- of main function
function carryflame_exit(e)
end
In action
There's something I do not get is that the flame emits its own light and shadows.
The flame uses the effect (decal_animate4.fx), but I do not know how to change it, if is this achievable.
Using a simple torch and decal named (torch flame 2) it is stock one.
enjoy
3com
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz
OS: Windows 8.1 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics