
--[[
    element/nil creator, string theType, float startX, float startY, float startZ [  [, float targetX, float targetY, float targetZ ] [, rotX, rotY, rotZ ], element targetElement, int dimension, int projectileModel, table ignoreElementsList, table extraProperties]
    
    theType: The behavious of the projectile, accepted values: 
		"seeking", -- Projectile will track the targetElement
		"simple"
	
	startX, startY, startZ: The start position
	
	targetX, targetY, targetZ: The target position. If not defined, it will try to get the position of the targetElement instead.
	
	rotX, rotY, rotZ: Start rotation
	
	targetElement: This is the targetElement that the projectile will try to hit.
    
	dimension: The dimension of the projectile. The default value is 0.
	
	projectileModel: any object model
	
	ignoreElementsList: If filled in, it has to be a table with all the elements that can't blow up the projectile. (This is important to use, when you create projectiles from a driving vehicle, else you might blow up yourself...)
	
    extraProperties: If filled in, it has to be a table with custom properties that are not available in the argument list of this function.
    The list is not complete, here are a few of them:
    {
        customBlip = {
            [int icon = 0, int size = 2, int r = 255, int g = 0, int b = 0, int a = 255, int ordering = 0, float visibleDistance = 16383.0, element visibleTo = getRootElement( ) ]
        },
        lifeSpan = int,
        speed = float,
        visualElementOrientation = {
            -- Rotation of the projectile model:
            x = float,
            y = float,
            z = float
        },
        impactDamage = float, -- Used to apply damage to the element that had collision with the projectile. Experimental since the syncer(s) decide the damage of the hitElement.
        explosionType = int, -- The explosion type, default value 2. Use false to disable the explosion. Explosion list: https://wiki.multitheftauto.com/wiki/CreateExplosion
        closeImpact = float, -- This makes the explosion explode when the projectile is close to the target. The default value is 2 units.
        positionPredictMultiplier = float, -- This helps a bit with predicting the position of the player. This value is multiplied with the velocity of the targetElement. The default value is 60.
    }
]]

local acceptedTypes = {
    ["seeking"] =  true,
    ["simple"] = true
}



function createCustomProjectile ( creator, theType, startX, startY, startZ, targetX, targetY, targetZ, rotX, rotY, rotZ, targetElement, dimension, projectileModel, ignoreElementsList, extraProperties)
    
    if eventName and not clientSide and not client then
        return
    end 

    startX = tonumber(startX)
    startY = tonumber(startY)
    startZ = tonumber(startZ)

    targetX = tonumber(targetX)
    targetY = tonumber(targetY)
    targetZ = tonumber(targetZ)

    if not (startX and startY and startZ) then
        return
    end


    if creator ~= nil and not isElement(creator) then

        return
    end

    if not acceptedTypes[theType] then
        theType = "simple"
    end

    if targetElement ~= nil and not isElement(targetElement) then

        return
    end

    if targetElement then
        if not (targetX and targetY and targetZ) then
            targetX, targetY, targetZ  = getElementPosition(targetElement)
        end
    elseif not (targetX and targetY and targetZ) then
        return
    end

    dimension = tonumber(dimension) or 0

    projectileModel = tonumber(projectileModel) or 345

    if clientSide then
        triggerServerEvent("requestCreateCustomProjectile", resourceRoot, creator, theType, startX, startY, startZ, targetX, targetY, targetZ, rotX, rotY, rotZ, targetElement, dimension, projectileModel, ignoreElementsList, extraProperties)
    else
        initializeCustomProjectile(creator, theType, startX, startY, startZ, targetX, targetY, targetZ, rotX, rotY, rotZ, targetElement, dimension, projectileModel, ignoreElementsList, extraProperties)
    end
end


