Imposter Posted May 24, 2013 Share Posted May 24, 2013 I know I have asked this before, but I have tried it many times and what was suggested didn't work, so here I am asking again, can someone please show me how to make the createWeapon function sync with the server? Here is the rough shooting code I have for the client side: theWeapon = nil; function onClientResourceStart() theWeaponID = 362; if (theWeaponID == 362) then thePlayer = getLocalPlayer(); outputChatBox("A minigun will be added to your vehicle...") theCar = getPedOccupiedVehicle(thePlayer); local x, y, z = getElementPosition(theCar); local hisWeapon = createWeapon("minigun", x, y, z); if ((theCar) and (hisWeapon)) then attachElements(hisWeapon, theCar, 0, 0, 0); setElementRotation(hisWeapon, 2, 45, 123); --theWeaponFireTimer = setTimer(fireVehicleWeapon, 50, 0, true); setWeaponOwner(hisWeapon, thePlayer); setElementData(hisWeapon, "owner", thePlayer); setElementData(thePlayer, "theGun", hisWeapon); setWeaponAmmo(hisWeapon, 500); if (thePlayer == getLocalPlayer()) then outputChatBox("Your minigun has been enabled!"); --bindKey("lctrl", "down", shootWeapon, hisWeapon, true) theWeapon = hisWeapon; end end elseif (theWeaponID == 359) then end end addEventHandler("onClientResourceStart", getRootElement(), onClientResourceStart); addCommandHandler("createWeapon", attachWeaponToVehicle); function onClientPreRender() if (getKeyState("lctrl") == true) then shootWeapon(theWeapon, true); end end addEventHandler("onClientPreRender", getRootElement(), onClientPreRender); --function shootWeapon(theKey, theKeyState, theWeapon, isSoundEnabled) function shootWeapon(theWeapon, isSoundEnabled) --outputChatBox("FIRING!"); --if (theKeyState == "down") then if (theWeapon) then --local rx, ry, rz = getElementRotation(theCar); --setElementRotation(theWeapon, rx, ry, rz); fireWeapon(theWeapon); if (isSoundEnabled == true) then local x, y, z = getElementPosition(theWeapon); theWeaponSound = playSound3D("minigun_base.mp3", x, y, z, false); end else --removeVehicleWeapon(); end --end end Link to comment
PaiN^ Posted May 25, 2013 Share Posted May 25, 2013 setWeaponAmmo is a server side only function . Link to comment
Castillo Posted May 25, 2013 Share Posted May 25, 2013 Wrong, is server side when you use it to set the player weapon ammo, and client side for custom weapons. Link to comment
PaiN^ Posted May 25, 2013 Share Posted May 25, 2013 Lol, i didn't check the wiki xP I saw it orange and i thought it's a server side only. ( This should be fixed ) Link to comment
Imposter Posted May 25, 2013 Author Share Posted May 25, 2013 Hey guys, is there any better way I can do this? this causes the game to freeze due to the for loop! function shootTheWeapon(thePlayer) for weaponKey, weaponValue in pairs(theWeapons) do if (getElementData(weaponValue, "owner") == thePlayer) then shootWeapon(weaponValue, true); end end end addEvent("shootTheWeapon", true); addEventHandler("shootTheWeapon", getRootElement(), shootTheWeapon); I have done this method because sending the weapon as an argument to the server doesn't work, the server receives it as a nil object. Link to comment
Imposter Posted May 26, 2013 Author Share Posted May 26, 2013 is there any other way I can make the weapon fire with the lctrl? the onClientRender seems to be laggy. Link to comment
iPrestege Posted May 26, 2013 Share Posted May 26, 2013 What about ( bindKey ) Function . Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now