Look here:
The place in the action list where "immortal" is makes a difference. If it's not nr 1 it will not work.
Players should not be able to damage the unit if it is sett correctly.
Mission Scripting
Function: isActive Added with: 1.2.0
Member Of: Unit
Syntax: boolean Unit.isActive(Class Self )
Description: Returns a boolean value if the unit is activated. Units set to late activation would return false if checked by this function.
For anyone who needs a side select script!
Scraped this together from examples on the Forum and a lot of testing. Enjoy!
--- Install in <DCS profile path>\Scripts\Hooks\
-- ONLY WORKS IN MULTIPLAYER! YOU CAN NOT TEST THIS IN THE SINGLEPLAYER!
-- USES LFS and IO to save and load files!
net.log("-- HOOK: Side Select v100 loading...")
sideCall = {}
sidesel = {}
-- The line below gets your DCS profile path: <DCS profile path>\Scripts\
sidesel.loadDir = lfs.writedir() .. [[Scripts\]]
sidesel.saveFilename = "sideselect_save.lua"
-- Settings:
sidesel.verboslog = false
-- Define the sides and corresponding slot names
local sides = {
["blue"] = "blue",
["red"] = "red",
}
sidesel.sideplayerTbl = {}
sidesel.adminTbl = {}
-- Uncomment and add UCID of Admins that can run Admin commands in chat!
--sidesel.adminTbl["admin players ucid"] = "admin"
--sidesel.adminTbl["admin players ucid"] = "admin"
--sidesel.adminTbl["admin players ucid"] = "admin"
--sidesel.adminTbl["admin players ucid"] = "admin"
-- Function to handle chat messages
function onChatMessage(message, from)
local ucid = net.get_player_info(from, 'ucid')
local _playername = net.get_player_info(from, 'name')
local playerId = net.get_player_info(from, 'id')
local playerside = nil
-- Check if the message is a side selection
local side = sides[string.lower(message)]
if (sidesel.sideplayerTbl[ucid] ~= nil) then
elseif (sidesel.sideplayerTbl[ucid] == nil) then
if side then
sidesel.sideplayerTbl[ucid] = {
["side"]= side,
["nicename"]= _playername,
}
net.log(" ---------------- " .. _playername .. " - Selected SIDE : " .. side)
local msg = string.format(" You are now on the %s Side!", side)
net.send_chat_to(msg, playerId)
-- Save Table to file!
sidesel.save()
end
else
--some error
net.log(" ---------------- ERROR: some error MSG")
end -- of if(sidesel.sideplayerTbl[ucid] == nil) then
-- Admin Commands
if (sidesel.adminTbl[ucid] ~= nil) then
if (string.lower(message) == "-reloadsides") then
net.log("-- HOOK: Is Admin player! - reloadsides - Name: " .. _playername .. " - UCID: " .. ucid)
local lpath = sidesel.loadDir .. sidesel.saveFilename
if file_exists(lpath) then
assert(loadfile(lpath))()
if (loadsideplayerTbl) then
sidesel.sideplayerTbl = loadsideplayerTbl
end
end
net.log("-- HOOK: Reloaded save file!")
end -- of if (string.lower(message) == "-reloadsides") then
if (string.lower(message) == "-purgesides") then
net.log("-- HOOK: Is Admin player! - purgesides - Name: " .. _playername .. " - UCID: " .. ucid)
sidesel.sideplayerTbl = {}
net.log("-- HOOK: Pureged Side Table file!")
end -- of if (string.lower(message) == "-reloadsides") then
if (string.lower(message) == "-printtable") then
net.log("-- HOOK: Is Admin player! - print table - Name: " .. _playername .. " - UCID: " .. ucid)
net.log("-- HOOK: : -printtable Running: ")
for key,value in pairs(sidesel.sideplayerTbl) do
if (sidesel.verboslog == true) then
net.log("-- HOOK: : Key: " .. key)
--net.log("-- HOOK: : Value: " .. value) -- Table cant print
end
for skey,svalue in pairs(sidesel.sideplayerTbl[key]) do
if (sidesel.verboslog == true) then
net.log("-- HOOK: : sKey: " .. skey)
net.log("-- HOOK: : sValue: " .. svalue)
end
end
end
net.log("-- HOOK: -printtable End!")
end -- of if (string.lower(message) == "-reloadsides") then
end
end -- of if (playerside == nil) or (adminplayer ~= nil) then
function sideCall.onPlayerConnect(playerId)
local ucid = net.get_player_info(playerId, 'ucid')
local playerName = net.get_player_info(playerId, 'name')
net.log("---------------- Player: " .. playerName .. " - Connected: " .. ucid)
end
function sideCall.onPlayerTryChangeSlot(playerId, side, slotId)
local playerName = net.get_player_info(playerId, 'name')
net.log(" ---------------- Player Changed Slot: " .. playerName)
local ucid = net.get_player_info(playerId, 'ucid')
local sidename = ""
if (side == 1) then
sidename = "red"
elseif (side == 2) then
sidename = "blue"
else
sidename = "spectator"
end
if (sidesel.sideplayerTbl[ucid] == nil) then
-- New player with no side selected
net.log(" ---------------- " .. playerName .. " - No SIDE Selected!")
local message = string.format(" Player: %s - Please select a side by Typing red or blue in chat!", playerName)
net.send_chat_to(message, playerId)
return false
elseif (sidesel.sideplayerTbl[ucid] ~= nil) then
if (sidesel.sideplayerTbl[ucid].side == sidename) then
net.log(" ---------------- " .. playerName .. " - Correct side : " .. sidename .. " - Has Side: " .. sidesel.sideplayerTbl[ucid].side)
elseif (sidename == "spectator") then
net.log(" ---------------- " .. playerName .. " - Spectator side : " .. sidename)
elseif (sidesel.sideplayerTbl[ucid].side ~= sidename) then
local message = string.format("You are not allowed to join that side: %s - Please select a slot on the other side!", playerName)
net.send_chat_to(message, playerId)
net.log(" ---------------- " .. playerName .. " - Wrong side : " .. sidename .. " - Has Side: ".. sidesel.sideplayerTbl[ucid].side)
return false
end -- of if (sidesel.sideplayerTbl[ucid].side == sidename) then
else
--some error
net.log(" ---------------- ERROR: Something went wrong with finding the player in sidesel.sideplayerTbl")
end -- of if(sidesel.sideplayerTbl[ucid] == nil) then
end
function sidesel.save()
net.log('-- HOOK: : sideselect - Running sidesel.save()')
wFile = io.open(sidesel.loadDir .. sidesel.saveFilename, 'w')
wFile:write('loadsideplayerTbl = {}' .. '\n')
for key,value in pairs(sidesel.sideplayerTbl) do
if (sidesel.verboslog == true) then
net.log("-- HOOK: : Key: " .. key)
end
wFile:write('loadsideplayerTbl["' .. key .. '"] = {\n')
for skey,svalue in pairs(sidesel.sideplayerTbl[key]) do
if (sidesel.verboslog == true) then
net.log("-- HOOK: : sKey: " .. skey)
net.log("-- HOOK: : sValue: " .. svalue)
end
wFile:write('["' .. skey .. '"]= "' .. svalue .. '",\n')
end
wFile:write('}\n')
end -- of for key,value in pairs(sidesel.sideplayerTbl) do
wFile:write('net.log("-- HOOK:sideselect - Save file has been loaded")' .. '\n')
wFile:close()
wFile = nil
end
function sidesel.load()
-- local loadpath = sidesel.loadDir .. sidesel.saveFilename
-- net.log('-- HOOK: Loading save file : ' .. loadpath)
-- assert(loadfile(loadpath))()
local loadpath = sidesel.loadDir .. sidesel.saveFilename
if file_exists(loadpath) then
assert(loadfile(loadpath))()
if (loadsideplayerTbl) then
sidesel.sideplayerTbl = loadsideplayerTbl
net.log("-- HOOK: Loaded save file Table : loadsideplayerTbl")
end
net.log("-- HOOK: Loaded save file : " .. loadpath)
end
if (sidesel.verboslog == true) then
for key,value in pairs(sidesel.sideplayerTbl) do
net.log("-- HOOK: : Key: " .. key)
for skey,svalue in pairs(sidesel.sideplayerTbl[key]) do
net.log("-- HOOK: : sKey: " .. skey)
net.log("-- HOOK: : sValue: " .. svalue)
end
end
end -- of if (sidesel.verboslog == true) then
end
function file_exists(name)
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end
end
sideCall.onMissionLoadEnd = function()
net.log('-- HOOK: onMissionLoadEnd()')
if (loadsideplayerTbl ~= nil) then
if (sidesel.verboslog == true) then
net.log('loadsideplayerTbl is NOT nil')
end
if (sidesel.verboslog == true) then
for key,value in pairs(loadsideplayerTbl) do
net.log("-- HOOK: Loaded Key: " .. key)
net.log("-- HOOK: Loaded Value: " .. value)
end
end
else
if (sidesel.verboslog == true) then
net.log('loadsideplayerTbl is nil')
end
end
end
-- Add the chat message handler function to the server event loop
DCS.setUserCallbacks({
onChatMessage = onChatMessage,
})
DCS.setUserCallbacks(sideCall)
-- Load Save file
sidesel.load()
net.log("-- HOOK: Side Select script loaded!")