Jump to content

Imposter

Members
  • Posts

    188
  • Joined

  • Last visited

Everything posted by Imposter

  1. is there any other way I can make the weapon fire with the lctrl? the onClientRender seems to be laggy.
  2. 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.
  3. Do you have the resource 'play' running? If so, disable it and try again.
  4. 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
  5. SolidSnake14, could you please show how to make It sync? It was quite hard to understand, since I didnt know what you meant the the element, I am trying it attach a minigun to a car.
  6. Error: [string "theWeapon = createWeapon("minigun", 0, 0, 0..."]:1: attempt to call global 'createWeapon' (a nil value) Well then they are wrong..... >version uptodate< Same thing I got, and I am even on the Beta/Nightlies.
  7. You can't, i just tried, it isnt serverside, also, could someone help me make the synchronization system? I was making one before but SolidSnake14 said if you make it on all the clients, it would sync, but I dont know, I've tried. If I did something wrong, can someone help me?
  8. It is also a server side feature? D: I thought it was clientside
  9. Well that is helpful. If you think my code is right, lemme know.
  10. Does it? I just coded this, I am going to install MTA on my old computer to test it out today. weapon_client.lua function attachWeaponToVehicle(thePlayer, theWeaponID) if (theWeaponID == 362) then outputChatBox("A minigun will be added to your vehicle...") theCar = getPedOccupiedVehicle(getLocalPlayer()); local x, y, z = getElementPosition(theCar); local hisWeapon = createWeapon("minigun", x, y, z); if ((theCar) and (hisWeapon)) then attachElements(hisWeapon, theCar, 0, 0, 0); --theWeaponFireTimer = setTimer(fireVehicleWeapon, 50, 0, true); setWeaponOwner(hisWeapon, getLocalPlayer()); setElementData(hisWeapon, "owner", thePlayer); setWeaponAmmo(hisWeapon, 500); if (thePlayer == getLocalPlayer()) then outputChatBox("Your minigun has been enabled!"); bindKey("lctrl", "down", shootWeapon, hisWeapon, true) end end elseif (theWeaponID == 359) then end end addEvent("attachWeaponToVehicle", true); addEventHandler("attachWeaponToVehicle", getRootElement(), attachWeaponToVehicle); function shootWeapon(theKey, theKeyState, 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("audio/minigun_base.mp3", x, y, z, false); end else --removeVehicleWeapon(); end end end race_server.lua addEvent('onPlayerPickUpRacePickup') addEvent('onPlayerPickUpRacePickupInternal', true) addEventHandler('onPlayerPickUpRacePickupInternal', g_Root, function(pickupID, respawntime) if checkClient( false, source, 'onPlayerPickUpRacePickupInternal' ) then return end local pickup = g_Pickups[table.find(g_Pickups, 'id', pickupID)] local vehicle = g_Vehicles[source] if not pickup or not vehicle then return end if respawntime and tonumber(respawntime) >= 50 then table.insert(unloadedPickups, pickupID) clientCall(g_Root, 'unloadPickup', pickupID) TimerManager.createTimerFor("map"):setTimer(ServerLoadPickup, tonumber(respawntime), 1, pickupID) end if pickup.type == 'nitro' then addVehicleUpgrade(vehicle, 1010) elseif pickup.type == 'minigun' then --outputChatBox("Giving Minigun...", source); --triggerClientEvent("removeVehicleWeapon", source); --triggerClientEvent("addVehicleWeapon", source, 362 local thePlayers = getElementsByType("player"); for theKey, thePlayer in ipairs(thePlayers) do triggerClientEvent("attachWeaponToVehicle", thePlayer, source, 362); end elseif pickup.type == 'rl' then --triggerClientEvent("removeVehicleWeapon", source); --triggerClientEvent("addVehicleWeapon", source, 359); local thePlayers = getElementsByType("player"); for theKey, thePlayer in ipairs(thePlayers) do triggerClientEvent("attachWeaponToVehicle", thePlayer, source, 359); end elseif pickup.type == 'vehiclechange' then if getElementModel(vehicle) ~= tonumber(pickup.vehicle) then clientCall(source, 'removeVehicleNitro') setVehicleID(vehicle, pickup.vehicle) if pickup.paintjob or pickup.upgrades then setVehiclePaintjobAndUpgrades(vehicle, pickup.paintjob, pickup.upgrades) end end end triggerEvent('onPlayerPickUpRacePickup', source, pickupID, pickup.type, pickup.vehicle) end )
  11. By vehicle element, you mean the car? or the weapon? then attach it, ok. I will do that tomorrow morning since it is quite late now. Anyways, have a good night and thanks for your help.
  12. Well I just tried to try that, and I got confused ... This is what I have... race_server.lua addEvent('onPlayerPickUpRacePickup') addEvent('onPlayerPickUpRacePickupInternal', true) addEventHandler('onPlayerPickUpRacePickupInternal', g_Root, function(pickupID, respawntime) if checkClient( false, source, 'onPlayerPickUpRacePickupInternal' ) then return end local pickup = g_Pickups[table.find(g_Pickups, 'id', pickupID)] local vehicle = g_Vehicles[source] if not pickup or not vehicle then return end if respawntime and tonumber(respawntime) >= 50 then table.insert(unloadedPickups, pickupID) clientCall(g_Root, 'unloadPickup', pickupID) TimerManager.createTimerFor("map"):setTimer(ServerLoadPickup, tonumber(respawntime), 1, pickupID) end if pickup.type == 'nitro' then addVehicleUpgrade(vehicle, 1010) elseif pickup.type == 'minigun' then outputChatBox("Giving Minigun...", source); triggerClientEvent("removeVehicleWeapon", source); triggerClientEvent("addVehicleWeapon", source, 362); elseif pickup.type == 'vehiclechange' then if getElementModel(vehicle) ~= tonumber(pickup.vehicle) then clientCall(source, 'removeVehicleNitro') setVehicleID(vehicle, pickup.vehicle) if pickup.paintjob or pickup.upgrades then setVehiclePaintjobAndUpgrades(vehicle, pickup.paintjob, pickup.upgrades) end end end triggerEvent('onPlayerPickUpRacePickup', source, pickupID, pickup.type, pickup.vehicle) end ) weapon_client.lua theCar = nil; theWeapon = nil; theWeaponFireTimer = nil; theWeaponSound = nil; function addVehicleWeapon(weaponID) if (weaponID == 362) then outputChatBox("A minigun will be added to your vehicle...") theCar = getPedOccupiedVehicle(getLocalPlayer()); local x, y, z = getElementPosition(theCar); theWeapon = createWeapon("minigun", x, y, z); if ((theCar) and (theWeapon)) then attachElements(theWeapon, theCar, 0, 0, 0); theWeaponFireTimer = setTimer(fireVehicleWeapon, 50, 0, true); setWeaponOwner(theWeapon, getLocalPlayer()); setWeaponAmmo(theWeapon, 500); end end end addEvent("addVehicleWeapon", true); addEventHandler("addVehicleWeapon", getRootElement(), addVehicleWeapon); function fireVehicleWeapon(isSoundEnabled) if (theWeapon) then if (getKeyState("lctrl") == true) 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("audio/minigun_base.mp3", x, y, z, false); end end else removeVehicleWeapon(); end end function removeVehicleWeapon() if (theWeapon) then if (theWeaponFireTimer) then killTimer(theWeaponFireTimer); end destroyElement(theWeapon); outputChatBox("Removing weapon..."); end end addEvent("removeVehicleWeapon", true); addEventHandler("removeVehicleWeapon", getRootElement(), removeVehicleWeapon); function onClientPlayerWasted() if (theWeaponFireTimer) then killTimer(theWeaponFireTimer); if (theWeaponSound) then stopSound(theWeaponSound); end end destroyElement(theWeapon); end addEventHandler("onClientPlayerWasted", getLocalPlayer(), onClientPlayerWasted); I don't know what to do. D: I am guessing I need to use getElementsByType("player") to send the weapon to the clients and add it to a table so it can be removed when the client's upgrade is removed. How will I create it on the other clients too? I am so confused.
  13. Well I am not sure, I need to detect the damage the that is done by the weapons to any player or vehicle, since you know why I asked about the pickups, I am adding weapons to cars, and I've done that but I don't know how to synchronize it, if you would help me out, I would be really really happy.
  14. That would be quite difficult D: since the necessary events do not exist or I don't know which ones to use, would you give me a hand with the handlers? So far I know I can use OnClientPlayerDamage for player damage, but for vehicle damage I don't know what to use. Thanks again. >_>
  15. Thanks so much, that is what I kinda did but it used to give code errors, I will try this out right now. You are the best. NooP ___________ Edit: Thanks Castillo this works! I also have another question, last time I posted about creating weapons client side and shooting, if I did CreateWeapon, would this be synchronized? If not, could someone guide me on how to do it? Thanks again.
  16. Hey guys, I wanted help with trying to add custom pickups to the race gamemode, I have looked at the edf and the lua files, I see where the scripter has put his, but I don't know how to put custom ones, when I put one, it seems to break, any help will be greatly appreciated. Hoping Castillo or 50p respond. Thanks, NooP
  17. Hey is it possible to launch gun projectiles from a vehicle (attaching it is no problem)? such as mini gun projectiles? which function do i use? I don't want to use createProjectile as it doesn't have what i want If yes, please help, any alternatives are greatly appreciated. Thanks, NooP
  18. One more quick question, why does math.random not work with floats? NVM, i just divided it.
  19. Mhm, I used local cx, cy, cz = getPositionFromElementOffset( theCar, 2, -4, 0 ); local lx, ly, lz = getPositionFromElementOffset( theCar, 1, 3, 1 );
  20. thank you, i didnt know how to do it, now i do, thanks so much 50p.
  21. But that still doesn't explain how to set the rotation so that it is always in that view function setCamera() local theCar = getPedOccupiedVehicle(getLocalPlayer()) local x, y, z = getElementPosition(theCar) local rx, ry, rz = getElementRotation(theCar) setCameraMatrix(x-3*rx, y-3*ry, z, x+1, y+1, z+1) end addEventHandler("onClientPreRender", root, setCamera) addEventHandler("onClientResourceStart", resourceRoot, setCamera) addCommandHandler("setcamera", setCamera)
  22. --Bump-- Anyone? TAPL? Solidsnake14? 50p?
  23. Hey guys, I am trying to make a camera that looks up at the back up the car near the left wheel. Can somebody please help me out? function setCamera() local x, y, z = getElementPosition(getLocalPlayer()) local rx, ry, rz = getElementRotation(getLocalPlayer()) setCameraMatrix(x-3, y-3, z, x+1, y+1, z+1) end addEventHandler("onClientPreRender", root, setCamera) addEventHandler("onClientResourceStart", resourceRoot, setCamera) addCommandHandler("setcamera", setCamera) --[[function resetCamera() end addCommandHandler("resetcamera", resetCamera)--]]
  24. I guess i should try that, first with commands but in the end, I am hoping to replace all of the gta cars
×
×
  • Create New...