Jump to content

MountedVeh


CapY

Recommended Posts

I have this code(Ace_Gambit is the original creator of it) for mounting weapons onto a vehicle's passenger side for shooting that.

I want edit it.

I wanna aim with that minigun(mouse aiming)

Client:

local root = getRootElement() 
local player = getLocalPlayer() 
  
local toggleVehicleWeapon = false 
local previousTick = getTickCount() 
local projectileType = 20 
  
function updateVehicleWeapon(source, dataName) 
  if (getElementType(source) ==  "vehicle" and dataName == "toggleVehicleWeapon") then 
    toggleVehicleWeapon = (getElementData(source, dataName) and isPedInVehicle(player)) 
  end 
end 
  
function callbackDataChange(dataName) 
  updateVehicleWeapon(source, dataName) 
end 
  
function callbackVehicleEnter(thePlayer, seat) 
  updateVehicleWeapon(source, "toggleVehicleWeapon") 
end 
  
function callbackRender() 
  if (getControlState("vehicle_fire") and toggleVehicleWeapon) then 
    if (getTickCount() > (previousTick + 150) and previousTick > 0) then 
      fireProjectile() 
    end 
  end 
end 
  
function fireProjectile() 
  local vehicle = getPedOccupiedVehicle(player) 
  local gun = false 
  local gX, gY, gZ = 0, 0, 0 
  local gRotX, gRotY, gRotZ = 0, 0, 0 
  local pX, pY, pZ = 0, 0, 0 
  local vX, vY, vZ = 0, 0, 0 
  local currentLoSOffset = 3.5 
  local zPosOffset = 1.1 
  local thrust = 2.0 
  previousTick = 0 
  if (vehicle) then 
    if (#getAttachedElements(vehicle) > 0) then 
      gun = getAttachedElements(vehicle)[1] 
      if (gun) then 
        gX, gY, gZ = getElementPosition(gun) 
        gRotX, gRotY, gRotZ = getElementRotation(gun) 
        pX = gX - math.sin(-math.rad(gRotZ + 90)) * currentLoSOffset 
        pY = gY + math.cos(-math.rad(gRotZ + 90)) * currentLoSOffset 
        pZ = gZ + zPosOffset 
        vX = math.sin (math.rad((gRotZ + 90))) * thrust 
        vY = math.cos(math.rad((gRotZ + 90))) * thrust 
        vZ = 0 
        createExplosion(pX, pY, pZ, 5, true, -1.0, false) 
        createProjectile(player, projectileType, pX, pY, pZ, 0, nil, 0, 0, 0, vX, vY, vZ) 
      end 
    end 
  end 
  previousTick = getTickCount() 
end 
  
function changeProjectileType(commandName, arg) 
  projectileType = tonumber(arg) or 20 
end 
  
addEventHandler("onClientElementDataChange", root, callbackDataChange, true) 
addEventHandler("onClientVehicleEnter", root, callbackVehicleEnter, true) 
addEventHandler("onClientRender", root, callbackRender, true) 
  
addCommandHandler("guntype", changeProjectileType) 

Server(little edited by me):

local guns = 
  { 
    [411] = 
      { 
        ["xPosOffset"] = 0, 
        ["yPosOffset"] = 1.0, 
        ["zPosOffset"] = -0.5 
      } 
  } 
  
function attachMod(playerSource, commandName) 
  local vehicle = getPedOccupiedVehicle(playerSource) 
  local gun = false 
  if (vehicle) then 
    gun = guns[getElementModel(vehicle)] or false 
    if (gun) then 
      attachElements(createObject(2985, 0, 0, -100, 0, 0, 0), vehicle, gun.xPosOffset, gun.yPosOffset, gun.zPosOffset, 0, 0, 90) 
      setElementData(vehicle, "toggleVehicleWeapon", true) 
    end 
  end 
end 
  
function detachMod(playerSource, commandName) 
  local vehicle = getPedOccupiedVehicle(playerSource) 
  if (vehicle) then 
    for _, element in ipairs(getAttachedElements(vehicle)) do 
      destroyElement(element) 
    end 
    setElementData(vehicle, "toggleVehicleWeapon", false) 
  end 
end 
  
addCommandHandler("mountit", attachMod, false) 
addCommandHandler("unmountit", detachMod, false) 

Is these 2 functions i must include in client side ?

moveObject:

-- Find a player called 'someguy' 
someGuy = getPlayerFromNick ( "someguy" ) 
-- If a player called someguy was found then 
if ( someGuy ) then 
    -- Get the player's position 
    x, y, z = getElementPosition ( someGuy ) 
    -- Create a bed (1700) object near to the player 
    bed = createObject ( 1700, x + 5, y, z ) 
    -- Move the bed towards the player over 3 seconds (3000 milliseconds) 
    moveObject ( bed, 3000, x, y, z ) 
    -- Tell the player in the chat box 
    outputChatBox ( "Moving a bed towards you!", someGuy ) 
else 
    -- Tell everyone that a player called 'someguy' could not be found 
    outputChatBox ( "Player someguy doesn't exist" ) 
end 

setObjectRotation:

function onResourceStart ( name, root ) 
    -- predefined variables, needed for the math code below 
    rotX = 0 
    rotY = 0 
    rotZ = 0 
    -- assign element named 'minigun' in map file to variable 
    pirateship = getElementByID ( "minigun" ) 
end 
  
function chatboxShipRotateLeft ( playerSource, commandName ) -- On console command 'increaserotations' 
    outputChatBox ( "Rotational values increased" ) 
    -- rotations = rotations + 10 
    rotX = rotX + 10 
    rotY = rotY + 10 
    rotZ = rotZ + 10 
    -- Changed rotation is applied 
    setObjectRotation ( minigun, rotX, rotY, rotZ ) 
end      
  
function chatboxMinigunRotateRight ( playerSource, commandName ) -- On console command 'decreaserotations' 
    outputChatBox ( "Rotational values decreased" ) 
    -- rotations = rotations - 10 
    rotX = rotX - 10 
    rotY = rotY - 10 
    rotZ = rotZ - 10 
    -- Changed rotation is applied 
    setObjectRotation ( minigun, rotX, rotY, rotZ ) 
end 
  
-- Set up event and command handlers 
addEventHandler ( "onResourceStart", getRootElement(), onResourceStart ) 
  
addCommandHandler ( "increaserotations", chatboxShipRotateLeft ) 
addCommandHandler ( "decreaserotations", chatboxShipRotateRight)  

And my problem is that IDK how to add it to let it work ...

Edited by Guest
Link to comment

hmm. i and one of my friends next project is this shooting whit minigun if this code is workin only add

  
 if getKeyState( "here put your buton whit you whant to aim" ) == true then 
  
  

if this code its not working and you can't fix it then when my code is ready i will help you

Link to comment

So here it is :

local root = getRootElement() 
local player = getLocalPlayer() 
  
local toggleVehicleWeapon = false 
local previousTick = getTickCount() 
local projectileType = 20 
  
function updateVehicleWeapon(source, dataName) 
  if (getElementType(source) ==  "vehicle" and dataName == "toggleVehicleWeapon") then 
    toggleVehicleWeapon = (getElementData(source, dataName) and isPedInVehicle(player)) 
  end 
end 
  
function callbackDataChange(dataName) 
  updateVehicleWeapon(source, dataName) 
end 
  
function callbackVehicleEnter(thePlayer, seat) 
  updateVehicleWeapon(source, "toggleVehicleWeapon") 
end 
  
function callbackRender() 
  if (getControlState("vehicle_fire") and toggleVehicleWeapon) then 
  if getKeyState( "rclick" ) == true then 
    createProjectile(player,projectileType, pX, pY, pZ, 0, nil, 0, 0, 0, vX, vY, vZ)) 
    elseif (getTickCount() > (previousTick + 150) and previousTick > 0) then 
      fireProjectile() 
    end 
  end 
end 
  
function fireProjectile() 
  local vehicle = getPedOccupiedVehicle(player) 
  local gun = false 
  local gX, gY, gZ = 0, 0, 0 
  local gRotX, gRotY, gRotZ = 0, 0, 0 
  local pX, pY, pZ = 0, 0, 0 
  local vX, vY, vZ = 0, 0, 0 
  local currentLoSOffset = 3.5 
  local zPosOffset = 1.1 
  local thrust = 2.0 
  previousTick = 0 
  if (vehicle) then 
    if (#getAttachedElements(vehicle) > 0) then 
      gun = getAttachedElements(vehicle)[1] 
      if (gun) then 
        gX, gY, gZ = getElementPosition(gun) 
        gRotX, gRotY, gRotZ = getElementRotation(gun) 
        pX = gX - math.sin(-math.rad(gRotZ + 90)) * currentLoSOffset 
        pY = gY + math.cos(-math.rad(gRotZ + 90)) * currentLoSOffset 
        pZ = gZ + zPosOffset 
        vX = math.sin (math.rad((gRotZ + 90))) * thrust 
        vY = math.cos(math.rad((gRotZ + 90))) * thrust 
        vZ = 0 
        createExplosion(pX, pY, pZ, 5, true, -1.0, false) 
        createProjectile(player, projectileType, pX, pY, pZ, 0, nil, 0, 0, 0, vX, vY, vZ) 
      end 
    end 
  end 
  previousTick = getTickCount() 
end 
  
function changeProjectileType(commandName, arg) 
  projectileType = tonumber(arg) or 20 
end 
  
addEventHandler("onClientElementDataChange", root, callbackDataChange, true) 
addEventHandler("onClientVehicleEnter", root, callbackVehicleEnter, true) 
addEventHandler("onClientRender", root, callbackRender, true) 
  
addCommandHandler("guntype", changeProjectileType) 
  
  
         
  

It doesn't want to fire anymore and still nothing with aim .

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