Jump to content

[HELP] Batpod!


mox.workz

Recommended Posts

Posted

Hey guyz! I need all your expertise again., I just happened to download a Batpod Bike., and Yeah! it's cool!

and i want it to be more cooler., I wonder and wishing that there's a way that I could make it Fire/Shoots Bullets 'coz it has guns it in.,

Posted

Batpod bike? Can you tell us some more details?

And you can attach elements to vehicles by MTA's functions:

attachElements 

And fire that element (weapon in this case) onClientKey event.

Posted

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

Posted
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

Posted (edited)

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
Posted
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:

Posted (edited)
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
Posted
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

Posted

addCommandHandler on serverside and trigger that for client by:

triggerClientEvent(player, "createBatPod", player) 

Then try, i think that would work.

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

Posted
Create weapon on serverside.

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

try to use this :

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

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

Posted

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 

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

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