Jump to content

Shoot RC bandit gun form other vehicle

Recommended Posts

Hey there, sorry that im making a new topic for pretty much the same thing but I really need help here! Ive made this code:


<script src="racer1.lua" type="server"></script> 
<script src="racer1_cl.lua" type="server"></script> 


function makeracer( source, key, keyState ) 
    local gunner = createPed ( 0, 1990, 2620, 11) 
    bindKey(source, "mouse1", "down", shoot) 
    car = createVehicle (402, 1990, 2620,12) 
    gun1 = createObject ( 362, 1990, 2620, 11) 
    shoot1 = createVehicle (464, 1990, 2620, 11) 
    attachElements (gun1, car, 0, 1.5, 0.5, 0, 30, 90) 
    attachElements (shoot1, car, 0, 2, 0.2) 
    setVehicleDamageProof(shoot1, true) 
    setElementAlpha ( shoot1, 0) 
    setElementCollisionsEnabled(shoot1, false) 
    setVehicleLocked ( shoot1, true )  
    setVehicleEngineState ( shoot1, false ) 
    warpPedIntoVehicle ( gunner, shoot1) 
    setElementAlpha ( gunner, 0) 
addCommandHandler("car", makeracer) 
function shoot() 
    triggerClientEvent ("shootgun", gunner) 


function shootgun() 
    setPedControlState ( gunner, "vehicle_fire", true) 
addEvent("shootgun", true) 
addCommandHandler("car", makeracer) 

Ive only started scripting in the last month so its probs a dumb error. I want the invisible ped (gunner) who is in the invisible RC baron (shoot1) attached to the buffalo (car) to shoot the RC barons gun when the player (driving the buffalo) presses LMB. Whats wrong with what ive got?

Link to comment

1. Your racer1_cl.lua is set as server-side script.

2. You haven't added any handler to "shootgun" event.

3. If racer1_cl.lua will be client-side then there is no gunner defined anywhere.

4. Making it client-side isn't ideal. Not sure if everyone will be able to see it shooting.

Link to comment

Try to fix the script first (my post above, 1-3) and ignore my last point for the time being. Once you get it shooting, test it with somebody to see it it's synced. It might be synced.

Link to comment

I'd advise you to use element data. It's synced automatically by default, so you can set it on one client and all other clients will be able to see the changes and react to them.



When the key is pressed or released, use setElementData to change the data, such as:

setElementData(ped, "shooting", keyState) 

And when element data of ped changes, set control state to whatever getElementData returns:

local ctrlstate = getElementData(source, "shooting") 

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