Jump to content

Problem with onClientProjectileCreation


JoZeFSvK

Recommended Posts

Hey i want create command for VIP and i have problem :x

Server

rRoot = getResourceRootElement(getThisResource()) 
  
function raketa (player, command) 
local accountname = getAccountName (getPlayerAccount(player)) 
if isObjectInACLGroup ( "user." .. accountname, aclGetGroup ( "Admin" )) or isObjectInACLGroup ( "user." .. accountname, aclGetGroup ( "vip" ) ) then 
outputChatBox("#1e90ff*#ffffff~TS~ #ffff00VIP#ffffff: You enabled rocket!", player, 255, 255, 255, true ) 
  triggerClientEvent("onRaketa", root) 
else outputChatBox ( "#1e90ff~TS~*#ffffff You dont have permission for this command", player, 255, 0, 0, true ) return end 
end 
addCommandHandler("rocket", raketa) 
  

Client

local rocketColor = {0, 102, 255, 255} 
  
local rootElement = getRootElement() 
local localPlayer = getLocalPlayer() 
  
local markers = {} 
  
addEvent( "onRaketa", true ) 
addEventHandler( "onRaketa", root,  
function updateMarkers() 
    for i,m in pairs(markers) do 
        if getProjectileType(m[2]) then 
            local rx, ry, rz = getElementPosition(m[2]) 
            setElementPosition(m[1], rx, ry, rz) 
        else 
            markers[i] = nil 
            destroyElement(m[1]) 
        end 
    end 
end 
--addEventHandler("onClientRender", rootElement, updateMarkers) 
  
function onRocketCreate(creator) 
    if getProjectileType(source) ~= 19 then 
        return 
    end 
    setTimer(function(source) 
        local rx, ry, rz = getElementPosition(source) 
        local marker = createMarker(rx, ry, rz, "corona", 5, rocketColor[1], rocketColor[2], rocketColor[3], rocketColor[4]) 
        table.insert(markers, {marker, source}) 
    end, math.random(50, 100), 1, source) 
end 
addEventHandler("onClientProjectileCreation", rootElement, onRocketCreate) 

i have problem :D i dont know where add addevent handler I tried different but i have problems :x thank you

Link to comment

Try it :

addEvent( "onRaketa", true ) 
addEventHandler( "onRaketa", root, 
function updateMarkers() 
    for i,m in pairs(markers) do 
        if getProjectileType(m[2]) then 
            local rx, ry, rz = getElementPosition(m[2]) 
            setElementPosition(m[1], rx, ry, rz) 
        else 
            markers[i] = nil 
            destroyElement(m[1]) 
        end 
    end 
end) --I add ")" to close EventHandler 
addEventHandler("onClientRender", rootElement, updateMarkers) 

Link to comment

-- Server Side --

function raketa(player) 
    local accountName = getAccountName(getPlayerAccount(player)) 
    if isObjectInACLGroup("user."..accountName, aclGetGroup("Admin")) or isObjectInACLGroup("user."..accountName, aclGetGroup("vip")) then 
        if not getElementData(player, "VIPRocket") then 
            setElementData(player, "VIPRocket", true) 
            outputChatBox("#1e90ff*#ffffff~TS~ #ffff00VIP#ffffff: You enabled rocket!", player, 255, 255, 255, true) 
        else 
            setElementData(player, "VIPRocket", false) 
            outputChatBox("#1e90ff*#ffffff~TS~ #ffff00VIP#ffffff: You disable rocket!", player, 255, 255, 255, true) 
        end 
    else  
        outputChatBox("#1e90ff~TS~*#ffffff You dont have permission for this command", player, 255, 0, 0, true) 
    end 
end 
addCommandHandler("rocket", raketa) 

-- Client Side --

local rocketColor = {0, 102, 255, 255} 
  
local markers = {} 
  
function updateMarkers() 
    for i,m in pairs(markers) do 
        if isElement(m[2]) then 
            local rx, ry, rz = getElementPosition(m[2]) 
            setElementPosition(m[1], rx, ry, rz) 
        else 
            markers[i] = nil 
            destroyElement(m[1]) 
        end 
    end 
end 
addEventHandler("onClientRender", root, updateMarkers) 
  
function onRocketCreate(creator) 
    if getElementData(creator, "VIPRocket") and getProjectileType(source) == 19 then 
        setTimer(function(source) 
            local rx, ry, rz = getElementPosition(source) 
            local marker = createMarker(rx, ry, rz, "corona", 5, rocketColor[1], rocketColor[2], rocketColor[3], rocketColor[4]) 
            table.insert(markers, {marker, source}) 
        end, math.random(50, 100), 1, source) 
    end 
end 
addEventHandler("onClientProjectileCreation", root, onRocketCreate) 

Link to comment

oh i was think you will use it with weapon where the creator will be the player but in you case the creator is the hunter.

So you need to get the driver of the hunter because the element data is with the player.

Change this:

if getElementData(creator, "VIPRocket") and getProjectileType(source) == 19 then 

To:

if getElementData(getVehicleController(creator), "VIPRocket") and getProjectileType(source) == 19 then 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...