--============================================================================
function IPainKiller:OnPrecache()
    Cache:PrecacheActor("PainKiller.CWeapon")
end
--============================================================================
function IPainKiller:OnInitTemplate()
    self._Synchronize = self.Synchronize
    self.Synchronize = nil
end
--============================================================================
function IPainKiller:OnCreateEntity()
    ENTITY.EnableNetworkSynchronization(self._Entity,true,true)

    local param  = "e"
    if self.Ammo.Shurikens > self.Ammo.Electro then param = "s" end
    ENTITY.SetSynchroString(self._Entity,"IPainKiller.CItem"..":"..param)            
    
    self:Client_OnCreateEntity(self._Entity,param)
end
--============================================================================
function IPainKiller:Client_OnCreateEntity(entity,param)
    local e = ENTITY.Create(ETypes.Billboard,"Script","IPainKiller")    
    
    local tex = "HUD/weapons/ikona_painkiller"
    if param == "s" then
        tex = "HUD/weapons/ikona_painkiller"        
    end
    BILLBOARD.SetupCorona(e,1,0,0,0,0,0.25,0,0,0,tex,Color:New(255,255,255,0):Compose(),4,true)    
    ENTITY.SetPosition(e,0,-0.7,0)
    ENTITY.RegisterChild(entity,e,true,0) 
    WORLD.AddEntity(e)
end
--============================================================================
function IPainKiller:OnTake(player)     
    if Game.GMode == GModes.SingleGame or not (Cfg.WeaponsStay and player.EnabledWeapons[self.SlotIndex]) then 
        self.TakeFX(player._Entity,self.Ammo.Shurikens,self.Ammo.Electro)
    end
    if Game.GMode ~= GModes.SingleGame and Cfg.WeaponsStay then return true end
end
--============================================================================
function IPainKiller:TakeFX(pe,aShurikens,aElectro)
    local player = EntityToObject[pe]    
    local t = Templates["IPainKiller.CItem"]
    if player then        
        player.EnabledWeapons[t.SlotIndex] = "PainKiller"
        player.Ammo.Shurikens = player.Ammo.Shurikens + aShurikens
        player.Ammo.Electro = player.Ammo.Electro + aElectro
        player:CheckMaxAmmo()
        if player == Player then 
            player:Client_OnTakeWeapon(t.SlotIndex)
            player:PickupFX() 
        end
    end
    
    t:SndEnt("pickup",pe)
end
Network:RegisterMethod("IPainKiller.TakeFX", NCallOn.ServerAndAllClients, NMode.Reliable, "euu")
--============================================================================
