Skip to content

Instantly share code, notes, and snippets.

@nathan130200
Created April 24, 2018 22:06
Show Gist options
  • Save nathan130200/4e0a597ee9137768c000022062897f4f to your computer and use it in GitHub Desktop.
Save nathan130200/4e0a597ee9137768c000022062897f4f to your computer and use it in GitHub Desktop.
Script.ReloadScript("scripts/gamerules/SinglePlayer.lua");
function GameRulesSetStandardFuncs(gamerules)
if (not gamerules) then
return;
end;
-- ///////// Server/Client /////////
if (not gamerules.Server) then
gamerules.Server={};
end;
if (not gamerules.Client) then
gamerules.Client={};
end;
if(not gamerules.AreUsable) then
gamerules.AreUsable = SinglePlayer.AreUsable;
end
-- Functions that unfortunately are called by CryAction (Interactor.cpp:47) and thus can't be
-- moved into c++ without engine changes
-- ///////// IsUsable /////////
if (not gamerules.IsUsable) then
gamerules.IsUsable = function (self, srcId, objId)
if not objId then return 0 end;
local obj = System.GetEntity(objId);
if (obj.IsUsable) then
if (obj:IsHidden()) then
return 0;
end;
local src = System.GetEntity(srcId);
if (src and src.actor and (src:IsDead() or (src.actor:GetSpectatorMode()~=0) or src.actorStats.isFrozen)) then
return 0;
end
return obj:IsUsable(src);
end
return 0;
end
end
-- ///////// OnNewUsable /////////
if (not gamerules.OnNewUsable) then
gamerules.OnNewUsable = function (self, srcId, objId, usableId)
if not srcId then return end
if objId and not System.GetEntity(objId) then objId = nil end
local src = System.GetEntity(srcId)
if src and src.SetOnUseData then
src:SetOnUseData(objId or NULL_ENTITY, usableId)
end
if srcId ~= g_localActorId then return end
if self.UsableMessage then
self.UsableMessage = nil
end
end
end
-- ///////// OnUsableMessage /////////
if (not gamerules.OnUsableMessage) then
gamerules.OnUsableMessage = function(self, srcId, objId, objEntityId, usableId)
if srcId ~= g_localActorId then return end
local msg = "";
if objId then
obj = System.GetEntity(objId)
if obj then
if obj.GetUsableMessage then
msg = obj:GetUsableMessage(usableId)
else
local state = obj:GetState()
if state ~= "" then
state = obj[state]
if state.GetUsableMessage then
msg = state.GetUsableMessage(obj, usableId)
end
end
end
end
end
end
end
-- ///////// OnLongHover /////////
if (not gamerules.OnLongHover) then
gamerules.OnLongHover = function(self, srcId, objId)
end
end
if (not gamerules.ProcessActorDamage) then
gamerules.ProcessActorDamage = function(self, hit)
-- Using SinglePlayer ProcessActorDamage
gamerules.GetDamageAbsorption = SinglePlayer.GetDamageAbsorption;
local died = SinglePlayer.ProcessActorDamage(self, hit);
return died;
end
end
if (not gamerules.Createhit) then
gamerules.CreateHit = SinglePlayer.CreateHit;
end
if (not gamerules.CreateExplosion) then
gamerules.CreateExplosion = SinglePlayer.CreateExplosion;
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment