Jump to content

Attaching M4 to a maverick


Tox

Recommended Posts

Hello I am stuck on a script attaching M4 to a maverick here is the server-side

function createMaverick(source,arac,model,posX,posY,posZ,rotX,rotY,rotZ,ad,scale) 
local Target = getPlayerFromName (source) 
local pX,pY,pZ = getElementPosition (Target) 
local maverick = createVehicle (487, tonumber(posX),tonumber(posY),tonumber(posZ),tonumber(rotX),tonumber(rotY),tonumber(rotZ)) 
kX, kY, kZ = getElementPosition (maverick) 
if (maverick) then 
warpPedIntoVehicle (Target, maverick, 0) 
 end 
 end 
  
addCommandHandler ("maverick", createMaverick) 
  
function attachM4(player) 
  
triggerClientEvent (player,"creatingM4") 
  
  
attachElements (maverick,m4,tonumber(posX),tonumber(posY),tonumber(posZ),tonumber(rotX),tonumber(rotY),tonumber(rotZ) ) 
  
end  
addEventHandler ("creatingM4",resourceRoot, attachM4) 
  
function atesM4 (player) 
triggerClientEvent(player,"firingM4") 
  
  
end 
  
addEventHandler ("firingM4",resourceRoot, atesM4) 

and here is the client-side

  addEvent ("creatingM4",true) 
  addEvent ("firingm4", true) 
  function createM4 () 
  m4 = createWeapon("31", kX, kY, kZ) 
end 
addEventHandler ("creatingM4", resourceRoot, createM4) 
  
function fireM4() 
  
fireWeapon (m4)  
end 
  
addEventHandler("firingM4", resourceRoot, fireM4) 
  
  

Link to comment

try this, and tell me the error

function createMaverick(source,arac,model,posX,posY,posZ,rotX,rotY,rotZ,ad,scale) 
local Target = getPlayerFromName (source) 
local pX,pY,pZ = getElementPosition (Target) 
local x, y, z = getElementPosition (maverick) 
local maverick = createVehicle ( 487, x, y, z + 10 ) -- create the tank 10 units above them 
if (maverick) then 
warpPedIntoVehicle (Target, maverick, 0) 
 end 
 end 
addCommandHandler ("maverick", createMaverick )  
  
function attachM4(source, attacker) 
triggerClientEvent (source,"creatingM4") 
  
  
attachElements (maverick,m4,tonumber(posX),tonumber(posY),tonumber(posZ),tonumber(rotX),tonumber(rotY),tonumber(rotZ) ) 
  
end  
addEventHandler ("creatingM4",resourceRoot, attachM4) 
  
function atesM4 (source ) 
triggerClientEvent(source,"firingM4") 
end 
  
addEventHandler ("firingM4",resourceRoot, atesM4) 

and here is the client-side

  
addEvent ("creatingM4",true) 
addEvent ("firingm4", true) 
  function createM4 () 
  m4 = createWeapon("31", kX, kY, kZ) 
end 
addEventHandler ("creatingM4", resourceRoot, createM4) 
  
function fireM4() 
local weapon = createWeapon("mp5", 0, 0, 3) -- Create a MP5 at the coordinates 0, 0, 3 
fireWeapon(weapon) -- Fire the weapon we spawned 
end 
addEventHandler("firingM4", resourceRoot, fireM4) 

 

Edited by Guest
Link to comment
try this, and tell me the error
function createMaverick(source,arac,model,posX,posY,posZ,rotX,rotY,rotZ,ad,scale) 
local Target = getPlayerFromName (source) 
local pX,pY,pZ = getElementPosition (Target) 
local maverick = createVehicle (487, tonumber(posX),tonumber(posY),tonumber(posZ),tonumber(rotX),tonumber(rotY),tonumber(rotZ)) 
kX, kY, kZ = getElementPosition (maverick) 
if (maverick) then 
warpPedIntoVehicle (Target, maverick, 0) 
 end 
 end 
addCommandHandler ("maverick", createMaverick )  
  
function attachM4(source, attacker) 
triggerClientEvent (source,"creatingM4") 
  
  
attachElements (maverick,m4,tonumber(posX),tonumber(posY),tonumber(posZ),tonumber(rotX),tonumber(rotY),tonumber(rotZ) ) 
  
end  
addEventHandler ("creatingM4",resourceRoot, attachM4) 
  
function atesM4 (source ) 
triggerClientEvent(source,"firingM4") 
end 
  
addEventHandler ("firingM4",resourceRoot, atesM4) 

and here is the client-side

  
addEvent ("creatingM4",true) 
addEvent ("firingm4", true) 
  function createM4 () 
  m4 = createWeapon("31", kX, kY, kZ) 
end 
addEventHandler ("creatingM4", resourceRoot, createM4) 
  
function fireM4() 
local weapon = createWeapon("mp5", 0, 0, 3) -- Create a MP5 at the coordinates 0, 0, 3 
fireWeapon(weapon) -- Fire the weapon we spawned 
end 
addEventHandler("firingM4", resourceRoot, fireM4) 

 

hello, thank you for replying but I still get WARNING from debugscript here are the warnings :

N5NWY5.png

Link to comment
try this, and tell me the error
function createMaverick(source,arac,model,posX,posY,posZ,rotX,rotY,rotZ,ad,scale) 
local Target = getPlayerFromName (source) 
local pX,pY,pZ = getElementPosition (Target) 
local x, y, z = getElementPosition (maverick) 
local maverick = createVehicle ( 487, x, y, z + 10 ) -- create the tank 10 units above them 
if (maverick) then 
warpPedIntoVehicle (Target, maverick, 0) 
 end 
 end 
addCommandHandler ("maverick", createMaverick )  
  
function attachM4(source, attacker) 
triggerClientEvent (source,"creatingM4") 
  
  
attachElements (maverick,m4,tonumber(posX),tonumber(posY),tonumber(posZ),tonumber(rotX),tonumber(rotY),tonumber(rotZ) ) 
  
end  
addEventHandler ("creatingM4",resourceRoot, attachM4) 
  
function atesM4 (source ) 
triggerClientEvent(source,"firingM4") 
end 
  
addEventHandler ("firingM4",resourceRoot, atesM4) 

and here is the client-side

  
addEvent ("creatingM4",true) 
addEvent ("firingm4", true) 
  function createM4 () 
  m4 = createWeapon("31", kX, kY, kZ) 
end 
addEventHandler ("creatingM4", resourceRoot, createM4) 
  
function fireM4() 
local weapon = createWeapon("mp5", 0, 0, 3) -- Create a MP5 at the coordinates 0, 0, 3 
fireWeapon(weapon) -- Fire the weapon we spawned 
end 
addEventHandler("firingM4", resourceRoot, fireM4) 

 

all this is an error lol.

Link to comment
@NearGreen

tries to help a friend is wrong? no one here is professional my friend

its true.

@Tox, use this example as core :P

server

local weapon_state = nil 
  
function createMaverick(thePlayer, command) 
    local pX,pY,pZ = getElementPosition(thePlayer) 
    local _,_,rot = getElementRotation (thePlayer) 
    local maverick = createVehicle (487, pX,pY,pZ) 
    if (maverick) then 
        warpPedIntoVehicle (thePlayer, maverick) 
        triggerClientEvent(thePlayer, "onCreateM4", getRootElement(),pX,pY,pZ) 
        bindKey(thePlayer, "num_0", "both", fire_m4) 
    end 
end 
addCommandHandler ("maverick", createMaverick) 
  
function fire_m4(thePlayer, key, keyState) 
    if (keyState == "down") then 
    weapon_state = "firing" 
    triggerClientEvent(thePlayer, "m4_state", getRootElement(),weapon_state) 
    elseif (keyState == "up") then 
    weapon_state = "ready" 
    triggerClientEvent(thePlayer, "m4_state", getRootElement(),weapon_state)     
    end 
end 

client

addEvent ("onCreateM4",true) 
function createM4 (px,py,pz) 
   m4 = createWeapon("m4", px,py,pz) 
  setWeaponClipAmmo(m4, 99999) 
  attachElementToElement(m4,getPedOccupiedVehicle(localPlayer), 0, 4, 0, 0, 0, 90) 
end 
addEventHandler ("onCreateM4", root, createM4) 
  
 addEvent ("m4_state",true) 
function fire_m4 (state) 
  
   local weapon_state = tostring(state) 
   setWeaponState(m4, weapon_state) 
  
end 
addEventHandler ("m4_state", root, fire_m4) 

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