Jump to content

Damage projectile


-Doc-

Recommended Posts

client.lua

addEventHandler ( "onClientVehicleDamage", root, -- creating an event 
    function ( attackerElement ) -- attaching funciton to it 
        if ( getElementModel ( source ) ~= 432 ) then -- checking if vehicle is rhino 
            return; -- if not canceling function 
        end 
         
        local attackerElementType = getElementType ( attackerElement ); -- getting type of attacker element 
        if ( attackerElementType == "projectile" ) then -- checking if it is projectile 
            local projectileType = getProjectileType ( attackerElement ); -- getting type of projectile 
            if ( projectileType == 21 ) then -- checking if projectile has 21 id 
                triggerServerEvent ( "destroy", source ); -- triggering serverside event which will destroy rhino 
            end 
        end 
    end 
); 

server.lua

addEvent ( "destroy", true ); -- adding custom event 
addEventHandler ( "destroy", root, -- attaching it 
    function ( ) -- to this function 
        destroyElement ( source ); -- destroying rhino 
    end 
); 

meta.xml

>    ="client.lua" type="client" />    ="server.lua" type="server" />>

Link to comment
addEvent ( "destroy", true ); -- adding custom event 
addEventHandler ( "destroy", root, -- attaching it 
    function ( ) -- to this function 
        setElementHealth ( source, getElementHealth ( source ) - 250 ); 
    end 
); 

Link to comment
setElementVelocity (veh, vx+(((velX/3)*(-1))/50), vy+(((velY/3)*(-1))/50), vz+(((velZ/3)*(-1))/50) ) 
                bullet = createProjectile(veh, 21, muzzleX, muzzleY, muzzleZ, 1, nil, 255,255,255, velX, velY, velZ) 

im using tank projectile and projectile id its 21

Link to comment

client

addEventHandler ( "onClientVehicleDamage", root, 
    function ( attackerElement ) 
        if ( getElementModel ( source ) ~= 432 ) then 
            return; 
        end 
        
        cancelEvent ( ); 
        if ( attackerElement and getElementType ( attackerElement ) == "projectile" ) then 
            outputChatBox ( "It's projectile!" ); 
            if ( getProjectileType ( attackerElement ) == 21 ) then 
                triggerServerEvent ( "destroy", localPlayer, source ); 
            end 
        end 
    end 
); 

server

addEvent ( "destroy", true ); 
addEventHandler ( "destroy", root, 
    function ( vehicle ) 
        setElementHealth ( vehicle, getElementHealth ( vehicle ) - 250 ); 
    end 
); 

Tell me if 'It's projectile!' appears on chatbox if you shot rhino.

Link to comment
addEventHandler ( "onClientVehicleDamage", root, 
    function ( attackerElement ) 
        outputChatBox ( getElementModel ( source ) .. ": " .. getElementType ( attackerElement ) ); 
        if ( getElementModel ( source ) ~= 432 ) then 
            return; 
        end 
        
        cancelEvent ( ); 
        if ( attackerElement and getElementType ( attackerElement ) == "projectile" ) then 
            if ( getProjectileType ( attackerElement ) == 21 ) then 
                triggerServerEvent ( "destroy", localPlayer, source ); 
            end 
        end 
    end 
); 

Tell me what chatbox outputs now.

Link to comment

client

addEventHandler ( "onClientVehicleDamage", root, 
    function ( attackerElement, weapon ) 
        outputChatBox ( getElementModel ( source ) .. ": " .. weapon ); 
        if ( getElementModel ( source ) ~= 432 ) then 
            return; 
        end 
        
        cancelEvent ( ); 
        if ( attackerElement and getElementType ( attackerElement ) == "projectile" ) then 
            if ( getProjectileType ( attackerElement ) == 21 ) then 
                triggerServerEvent ( "destroy", localPlayer, source ); 
            end 
        end 
    end 
); 

And now? Strange, because it's not projectile.

Link to comment

I know. But, it outputs 'object' or 'vehicle', I can't see 'projectile' on your chatbox while using code below, can you?

addEventHandler ( "onClientVehicleDamage", root, 
    function ( attackerElement ) 
        outputChatBox ( getElementModel ( source ) .. ": " .. getElementType ( attackerElement ) ); 
        if ( getElementModel ( source ) ~= 432 ) then 
            return; 
        end 
        
        cancelEvent ( ); 
        if ( attackerElement and getElementType ( attackerElement ) == "projectile" ) then 
            if ( getProjectileType ( attackerElement ) == 21 ) then 
                triggerServerEvent ( "destroy", localPlayer, source ); 
            end 
        end 
    end 
); 

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...