Name of Script: soldier_companion.lua
Developer name: cybernescence
Description: Getting tired of wading into battle on your own? Take a comrade (or several) with you!
Non commercial or commercial use.
Sorry, your new companion doesn't actually help you in battle yet, but at least you have some company with a lot of gun waving around
Still learning lua
-- LUA - A soldier as a companion (tested on stock Masked Soldier) - v0.2 - cybernescence
-- LUA Script - precede every function and global member with lowercase name of script
function soldier_companion_init(e)
CharacterControlUnarmed(e)
ModulateSpeed(e,1.0)
end
function soldier_companion_main(e)
-- Get Player Distance from Companion
tPlayDist = GetPlayerDistance(e)
-- Entity Object Number of Companion
EntObjNo = g_Entity[e]['obj'];
-- Prompt(tPlayDist)
-- Stick With Player
if tPlayDist < 200 then
if tPlayDist < 100 then
--MoveBackward(e,5)
end
ModulateSpeed(e,1.0)
AIEntityGoToPosition(EntObjNo, (g_PlayerPosX - 20), (g_PlayerPosZ + 20))
AIEntityStop(EntObjNo)
--CollisionOn(e)
if ai_aggro_entity ~= nil then
tDistX = g_Entity[e]['x'] - ai_aggro_x
tDistZ = g_Entity[e]['z'] - ai_aggro_z
tDist = math.sqrt(math.abs(tDistX*tDistX) + math.abs(tDistZ*tDistZ))
if tDist < ai_aggro_range then
-- Prompt("Enemy Action!")
CharacterControlArmed(e)
tRotate = math.random(20,70)
RotateY(e,tRotate)
tMove = math.random(10,20)
MoveForward(e,tMove)
-- tFire = math.random(100,200) / 100.0
-- if tFire > 1.5 then
-- FireWeapon(e)
-- end
else
CharacterControlUnarmed(e)
CharacterControlFidget(e)
LookAtPlayer(e)
RotateToPlayer(e)
end
else
CharacterControlUnarmed(e)
CharacterControlFidget(e)
LookAtPlayer(e)
RotateToPlayer(e)
end
else
-- Get Companion To Player (at start and if gets lost)
if tPlayDist > 1200 then
CollisionOff(e)
SetPosition(e, (g_PlayerPosX - 10), g_PlayerPosY, (g_PlayerPosZ + 10))
-- SetPosition(e, (g_PlayerPosX), g_PlayerPosY, (g_PlayerPosZ))
CollisionOn(e)
RotateToPlayer(e)
CharacterControlUnarmed(e)
CharacterControlFidget(e)
else
if tPlayDist > 600 then
-- Go Find Player At A Run (Random Speed)
tSpeed = math.random(140,170) / 100.0
-- tSpeed = 1.5
ModulateSpeed(e,tSpeed)
CharacterControlUnarmed(e)
SetCharacterToRun(e)
RotateToPlayer(e)
AIEntityGoToPosition(EntObjNo, (g_PlayerPosX - 10), (g_PlayerPosZ + 10))
CharacterControlFidget(e)
else
-- Follow Player At A Fast Walk (between 200 and 600 away)
ModulateSpeed(e, 1.2)
CharacterControlUnarmed(e)
SetCharacterToWalk(e)
RotateToPlayer(e)
AIEntityGoToPosition(EntObjNo, (g_PlayerPosX), (g_PlayerPosZ))
CharacterControlFidget(e)
end
end
end
end