Paste: radiation sv_hooks.lua
Author: | lauscript |
Mode: | lua |
Date: | Sat, 9 Jun 2012 02:04:21 |
Plain Text |
local PLUGIN = PLUGIN;
local radiationSounds = {
"/player/geiger1.wav",
"/player/geiger2.wav",
"/player/geiger3.wav"
};
function PLUGIN:OpenAuraInitPostEntity() self:LoadRadiationAreas(); end;
function PLUGIN:Tick()
if( !self.NextCheck or self.NextCheck < CurTime() )then
self.NextCheck = CurTime() + 3;
for k,v in pairs(_player.GetAll())do
if(v.observerMode or !v:Alive())then continue; end;
local plyInZone = false;
local hasIncreased = false;
for k2, v2 in pairs(self.radiationZones) do
if (openAura.entity:IsInBox(v, v2.minimum, v2.maximum) ) then
local clothes = v:GetCharacterData("clothes");
local HasMask = v:GetSharedVar("wearingRespirator");
local increase = 1;
local shouldEmit = true;
if (clothes) then
local itemTable = openAura.item:Get(clothes);
if (itemTable and itemTable.radiationProtection) then
increase = math.Clamp(increase - itemTable.radProtection,0,1);
end;
end;
if ( HasMask ) then
local filterQuality = v:GetSharedVar("filterQuality") or 0;
if ( filterQuality >= 1 ) then
v:SetCharacterData( "filterQuality", filterQuality - 1 );
v:SetSharedVar( "filterQuality", filterQuality -1 );
increase = increase / 2;
shouldEmit = false;
end;
end;
if ( shouldEmit ) then
if( !v.LastPainSound or v.LastPainSound < CurTime() )then
v.LastPainSound = CurTime() + 6;
v:EmitSound("avoxgaming/health_sound/breath/outdoor_whitout_mask_die.wav", 50, 100 );
end;
end;
v:SetCharacterData("radiation", v:GetCharacterData("radiation") + increase);
hasIncreased = true;
plyInZone = true;
break;
end;
end;
if(!plyInZone)then
if(v:GetCharacterData("radiation") > 25)then
v:SetCharacterData("radiation", v:GetCharacterData("radiation") + .5);
hasIncreased = true;
elseif(v:GetCharacterData("radiation") > 0)then
v:SetCharacterData("radiation", v:GetCharacterData("radiation") - .2);
end;
end;
if(hasIncreased)then
v:EmitSound(table.Random(radiationSounds));
end;
end;
end;
end;
function PLUGIN:PlayerSaveCharacterData(player, data)
if ( data["radiation"] ) then
data["radiation"] = math.Round( data["radiation"] );
end;
end;
function PLUGIN:PlayerRestoreCharacterData(player, data)
data["radiation"] = data["radiation"] or 0;
end;
function PLUGIN:PostPlayerSpawn(player, lightSpawn, changeClass, firstSpawn)
if (!firstSpawn and !lightSpawn) then
player:SetCharacterData("radiation", 0);
end;
end;
function PLUGIN:PlayerSetSharedVars(player, curTime)
player:SetSharedVar( "radiation", math.Round( player:GetCharacterData("radiation") ) );
end;
New Annotation