Jump to content

[HELP] Batpod!


mox.workz

Recommended Posts

HELP!!!"

local screenW,screenH = guiGetScreenSize() 
local weapon1 
local weapon2 
function attach ( ) 
      local theVehicle = getPedOccupiedVehicle ( localPlayer ) 
      if theVehicle then 
    local x,y,z = getElementPosition ( theVehicle ) 
    weapon1 = createWeapon("minigun", x, y, z + 1) 
    weapon2 = createWeapon("minigun", x, y, z + 1) 
    attachElements ( weapon1, theVehicle, 0, 0, 0 ) 
    attachElements ( weapon2, theVehicle, 0, 1, 0 ) 
    setWeaponClipAmmo(weapon1, 99999) 
    setWeaponClipAmmo(weapon2, 99999) 
    setWeaponState(weapon1, "firing") 
    setWeaponState(weapon2, "firing") 
    setWeaponProperty(weapon1, "fire_rotation", 0, -30, -1) 
    setWeaponProperty(weapon2, "fire_rotation", 0, -30, -1) 
end 
end 
addCommandHandler ( "attach", attach ) 

I already attached it but the miniguns are attached and facing in the right.,

Link to comment
Use setElementRotation on creating weapon1 and weapon2.

or add the xyz rotoation to attach elements code itself.

Just edit the line 10 and 11 with this

attachElements ( weapon1, theVehicle, 0, 0, 0, 20, 30, 90 ) 
    attachElements ( weapon2, theVehicle, 0, 1, 0, 20, 30, 90 ) 

Full code

local screenW,screenH = guiGetScreenSize() 
local weapon1 
local weapon2 
function attach ( ) 
      local theVehicle = getPedOccupiedVehicle ( localPlayer ) 
      if theVehicle then 
    local x,y,z = getElementPosition ( theVehicle ) 
    weapon1 = createWeapon("minigun", x, y, z + 1) 
    weapon2 = createWeapon("minigun", x, y, z + 1) 
attachElements ( weapon1, theVehicle, 0, 0, 0, 20, 30, 90 ) 
    attachElements ( weapon2, theVehicle, 0, 1, 0, 20, 30, 90 ) 
    setWeaponClipAmmo(weapon1, 99999) 
    setWeaponClipAmmo(weapon2, 99999) 
    setWeaponState(weapon1, "firing") 
    setWeaponState(weapon2, "firing") 
    setWeaponProperty(weapon1, "fire_rotation", 0, -30, -1) 
    setWeaponProperty(weapon2, "fire_rotation", 0, -30, -1) 
end 
end 
addCommandHandler ( "attach", attach ) 

http://i.imgur.com/G8iF23N.jpg

Link to comment

Here: I found something it all worked well BUT....

the guns are just client sided, I mean I'm just the only one who can see it., here is my code:

Server:

local weapon_state = nil 
  
function createBatPod(thePlayer, command) 
    local pX,pY,pZ = getElementPosition(thePlayer) 
    local _,_,rot = getElementRotation (thePlayer) 
    local Batpod = createVehicle (522, pX,pY,pZ) 
    if (Batpod) then 
        warpPedIntoVehicle (thePlayer, Batpod) 
        triggerClientEvent(thePlayer, "onCreateUzi", getRootElement(),pX,pY,pZ) 
        bindKey(thePlayer, "vehicle_fire", "both", fire_uzi) 
    end 
end 
addCommandHandler ("batpod", createBatPod) 
  
function fire_uzi(thePlayer, key, keyState) 
    if (keyState == "down") then 
    weapon_state = "firing" 
    triggerClientEvent(thePlayer, "uzi_state", getRootElement(),weapon_state) 
    elseif (keyState == "up") then 
    weapon_state = "ready" 
    triggerClientEvent(thePlayer, "uzi_state", getRootElement(),weapon_state)    
    end 
end 

Client:

addEvent ("onCreateUzi",true) 
function createUzi (px,py,pz) 
   uzi = createWeapon("uzi", px,py,pz) 
  setWeaponClipAmmo(uzi, 99999) 
  attachElementToElement(uzi,getPedOccupiedVehicle(localPlayer), 0, 1.2, 0, 0, 0, 90) 
end 
addEventHandler ("onCreateUzi", root, createUzi) 
  
 addEvent ("uzi_state",true) 
function fire_uzi (state) 
  
   local weapon_state = tostring(state) 
   setWeaponState(uzi, weapon_state) 
  
end 
addEventHandler ("uzi_state", root, fire_uzi) 

this one is quite cool actually 'coz it automatically warp me to the summoned vehicle.

the vehicle will appear to all player in the server because I guess it is declared in the Server Side but the gun which is the UZI will not. i dont know how to declare the weapon in the server side..,

I'm the only who can see it.

Pls help..

Edited by Guest
Link to comment
I don't understand what are you trying to do.

This is what I'm Trying to do:

cxgTo1C.png

and this is what the script does:

When I encode the command "batpod", it creates a vehicle and automatically warped me into it, then in triggers the event which is it creates weapon: Uzi and attached it to the Vehicle:Bat Pod(522)..

My problem is I'm the only one who can see the Uzi. :shock:

Link to comment
Create weapon on serverside.

how? this is what i did., still no luck.,

  
local weapon_state = nil 
  
function createBatPod(thePlayer, command) 
    local pX,pY,pZ = getElementPosition(thePlayer) 
    local _,_,rot = getElementRotation (thePlayer) 
    local Batpod = createVehicle (522, pX,pY,pZ) 
    if (Batpod) then 
        warpPedIntoVehicle (thePlayer, Batpod) 
        triggerClientEvent(thePlayer, "onCreateUzi", getRootElement(),pX,pY,pZ) 
        bindKey(thePlayer, "vehicle_fire", "both", fire_uzi) 
    end      
    local uzi = createWeapon("uzi", px,py,pz) 
end 
addCommandHandler ("batpod", createBatPod) 
  
function fire_uzi(thePlayer, key, keyState) 
    if (keyState == "down") then 
    weapon_state = "firing" 
    triggerClientEvent(thePlayer, "uzi_state", getRootElement(),weapon_state) 
    elseif (keyState == "up") then 
    weapon_state = "ready" 
    triggerClientEvent(thePlayer, "uzi_state", getRootElement(),weapon_state)    
    end 
end 

Edited by Guest
Link to comment
Just sayi8ng, If you are changing the weapon from minigun to uzi just because minigun is overpowered then you can reduce the power of minigun.

nope., I can change the weapon to anything later., all I need to know now is how to make it appear to everyone., I don't know how to create weapon in server side which sync to client side.,

xD

Link to comment
addCommandHandler on serverside and trigger that for client by:
triggerClientEvent(player, "createBatPod", player) 

Then try, i think that would work.

there's no wrong when creating the vehicle batpod., it appears in every users., the only problem is creating the weapon which doesn't appears to other player., only to the player who executes the command.,

Link to comment
post full code here

here:

server:

local weapon_state = nil 
  
function createBatPod(thePlayer, command) 
    local pX,pY,pZ = getElementPosition(thePlayer) 
    local _,_,rot = getElementRotation (thePlayer) 
    local Batpod = createVehicle (522, pX,pY,pZ) 
    if (Batpod) then 
        warpPedIntoVehicle (thePlayer, Batpod) 
        triggerClientEvent(root, "onCreateUzi", getRootElement(),pX,pY,pZ) 
        bindKey(thePlayer, "vehicle_fire", "both", fire_uzi) 
    end 
end 
addCommandHandler ("batpod", createBatPod) 
  
  
function fire_uzi(thePlayer, key, keyState) 
    if (keyState == "down") then 
    weapon_state = "firing" 
    triggerClientEvent(thePlayer, "uzi_state", getRootElement(),weapon_state) 
    elseif (keyState == "up") then 
    weapon_state = "ready" 
    triggerClientEvent(thePlayer, "uzi_state", getRootElement(),weapon_state)   
    end 
end 

client:

addEvent ("onCreateUzi",true) 
function createUzi (px,py,pz) 
   uzi = createWeapon("uzi", px,py,pz) 
  setWeaponClipAmmo(uzi, 99999) 
  attachElementToElement(uzi,getPedOccupiedVehicle(localPlayer), 0, 1.2, 0, 0, 0, 90) 
end 
addEventHandler ("onCreateUzi", root, createUzi) 
  
 addEvent ("uzi_state",true) 
function fire_uzi (state) 
  
   local weapon_state = tostring(state) 
   setWeaponState(uzi, weapon_state) 
  
end 
addEventHandler ("uzi_state", root, fire_uzi) 
  

still the same problem., all worked fine but the other players in the server can't be hit or even see the attached uzi in the vehicle.,

Link to comment

ok try this :

-- Client side

addEvent ("onCreateUzi",true) 
function createUzi (vehicle,px,py,pz) 
     uzi = createWeapon("uzi", px,py,pz) 
     setWeaponClipAmmo(uzi, 99999) 
    attachElementToElement(uzi,vehicle, 0, 1.2, 0, 0, 0, 90) 
end 
addEventHandler ("onCreateUzi", root, createUzi) 
  
  
function fire_uzi (state) 
     local weapon_state = tostring(state) 
     setWeaponState(uzi, weapon_state) 
end 
 addEvent ("uzi_state",true) 
addEventHandler ("uzi_state", root, fire_uzi) 

-- Server side

function createBatPod(thePlayer, command) 
    local pX,pY,pZ = getElementPosition(thePlayer) 
    local _,_,rot = getElementRotation (thePlayer) 
    local Batpod = createVehicle (522, pX,pY,pZ) 
    if (Batpod) then 
        warpPedIntoVehicle (thePlayer, Batpod) 
        triggerClientEvent(root, "onCreateUzi", root,Batpod,pX,pY,pZ) 
        bindKey(thePlayer, "vehicle_fire", "both", fire_uzi) 
    end 
end 
addCommandHandler ("batpod", createBatPod) 
  
  
function fire_uzi(thePlayer, key, keyState) 
    if (keyState == "down") then 
    weapon_state = "firing" 
    triggerClientEvent(thePlayer, "uzi_state", getRootElement(),weapon_state) 
    elseif (keyState == "up") then 
    weapon_state = "ready" 
    triggerClientEvent(thePlayer, "uzi_state", getRootElement(),weapon_state)   
    end 
end 

Link to comment
Create weapon on serverside.

lol you can't use CreateWeapon() funtion server side.

try to use this :

triggerClientEvent(root, "onCreateUzi", root,pX,pY,pZ) 

Excuse me, read my second reply, i also suggested creating weapon via serverside by triggerClientEvent :P

addCommandHandler on serverside and trigger that for client by:
triggerClientEvent(player, "createBatPod", player) 

Then try, i think that would work.

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