Jump to content

[HELP] Vehicle Gun Rotate Problem


Recommended Posts

Hi, i have a problem with rotate a gun in or out of vehicle

debugscript says:

WARNING: fs_vehicleGun\server.lua:17: Bad argument @ 'triggerClientEvent' [Expected string at argument 1, got nil]

Server Side:

--[[addEvent("onPlayerVehicleEnter", true)
addEventHandler("onPlayerVehicleEnter", getRootElement(),]]--

function createArmedBobcat(source)
    local lx,ly,lz = getElementPosition(source) -- get the position of the player
    local lx = lx + 5 -- add 5 units to the x position
    
    veh = createVehicle( 422, lx, ly, lz) -- create a bobcat
    base = createObject( 2985, 2,2,2) -- create a minigun_base object
    setElementCollisionsEnabled ( base, false ) -- the minigun_base damages the car
    -- you could alternatively load an empty col file for the minigun object
    attachElements ( base, veh,  x,y,z,rx,ry,rz) -- attach the base to the bobcat
end
addCommandHandler("bobcat", createArmedBobcat)

function rotateGun()
    triggerClientEvent(source, "rotateGunHandler", source)
end
addCommandHandler("rotate", rotateGun)

Client Side:

function enterGun_Handler(localPlayer)
end
addEventHandler("onClientColShapeHit", root, enterGun_Handler)

local x,y,z,rx,ry,rz= 0,-1.5,-0.1,0,0,-90

function rotateIt(cmd, addZ)
    if(addZ) then
        rz=rz+addZ
        setElementAttachedOffsets (base,x,y,z,rx,ry,rz) --update offsets
    end
end
addEvent("rotateGunHandler", true)
addEventHandler("rotateGunHandler", root, rotateIt)


 

Edited by SphinxDev
wrong client code
Link to comment

addcommandHandler can also be used on the client just put the command directly on the client and avoid using the triggerClientEvent

 

Server:

--[[addEvent("onPlayerVehicleEnter", true)
addEventHandler("onPlayerVehicleEnter", getRootElement(),]]--

function createArmedBobcat(source)
    local lx,ly,lz = getElementPosition(source) -- get the position of the player
    local lx = lx + 5 -- add 5 units to the x position
    
    veh = createVehicle( 422, lx, ly, lz) -- create a bobcat
    base = createObject( 2985, 2,2,2) -- create a minigun_base object
    setElementCollisionsEnabled ( base, false ) -- the minigun_base damages the car
    -- you could alternatively load an empty col file for the minigun object
    attachElements ( base, veh,  x,y,z,rx,ry,rz) -- attach the base to the bobcat
end
addCommandHandler("bobcat", createArmedBobcat)

Client

function enterGun_Handler(localPlayer)
end
addEventHandler("onClientColShapeHit", root, enterGun_Handler)

local x,y,z,rx,ry,rz= 0,-1.5,-0.1,0,0,-90

function rotateIt(command, addZ)
    if(addZ) then
        rz=rz+addZ
        setElementAttachedOffsets (base,x,y,z,rx,ry,rz) --update offsets
    end
end
addCommandHandler("rotate", rotateGun)

in Server  you receives playerSource, command,  --> args
and client only command and --> args
try

 

It may still work for you but the function asks for two variables that you defined as cmd and addZ but when you run it from the server it is not sending any data, eg:

 

 -- CLIENT
function greetingHandler ( message )
    outputChatBox ( "The server says: " .. message )
end
addEvent( "onGreeting", true )
addEventHandler( "onGreeting", localPlayer, greetingHandler )


-- SERVER 
function greetingCommandOne ( playerSource, commandName, playerName )
    if playerName then
        local thePlayer = getPlayerFromName ( playerName )
        if thePlayer then
            triggerClientEvent ( thePlayer, "onGreeting", thePlayer, "Hello World!" )
        else
        end
    else
    end 
end
addCommandHandler ( "greet_one", greetingCommandOne )

 

Edited by AndresTVz
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...