require "Advanced_trajectory_core"


local function Advanced_trajectory_OnServerCommand(module, command, arguments)

    local Playershot = getPlayer()
    if not Playershot then return end
	if module == "ATY_shotplayer" then


        local damagepr = math.floor(arguments[1])
        local headpart = {
            BodyPartType.Neck,
            BodyPartType.Head
        }
        local midpart = {
            BodyPartType.Torso_Upper,
            BodyPartType.Torso_Lower,
            BodyPartType.ForeArm_L,
            BodyPartType.ForeArm_R,
            BodyPartType.UpperArm_L,
            BodyPartType.UpperArm_R,
            BodyPartType.Groin,
            BodyPartType.Back
        }
        local lowpart = {
            BodyPartType.UpperLeg_L,
            BodyPartType.UpperLeg_R,
            BodyPartType.LowerLeg_L,
            BodyPartType.LowerLeg_R,
            BodyPartType.Foot_L,
            BodyPartType.Foot_R
        }

        local shotpart = BodyPartType.Foot_R

        if damagepr == 20 then
            shotpart = headpart[ZombRand(#headpart)+1]
        elseif damagepr == 2 then
            shotpart = headpart[ZombRand(#midpart)+1]
        elseif damagepr ==1 then
            shotpart = headpart[ZombRand(#lowpart)+1]
        end

        local bodypart = Playershot:getBodyDamage():getBodyPart(shotpart)

        if bodypart:haveBullet() then
            local deepWound = bodypart:isDeepWounded()
            local deepWoundTime = bodypart:getDeepWoundTime()
            local bleedTime = bodypart:getBleedingTime()
            bodypart:setHaveBullet(false, 0)
            bodypart:setDeepWoundTime(deepWoundTime)
            bodypart:setDeepWounded(deepWound)
            bodypart:setBleedingTime(bleedTime)
        else
            bodypart:setHaveBullet(true, 0)
        end

        Playershot:getBodyDamage():ReduceGeneralHealth(arguments[2]*damagepr*0.6)
  
    elseif module == "ATY_shotsfx" then
        if arguments[2] ==Playershot:getOnlineID() then return end 
        table.insert(Advanced_trajectory.table,arguments[1])
    elseif module == "ATY_reducehealth" then
        
        
        Playershot:getBodyDamage():ReduceGeneralHealth(arguments[1])

    end
        
end



Events.OnServerCommand.Add(Advanced_trajectory_OnServerCommand)