Jump to content

plane bombing script


Xwad

Recommended Posts

This script makes possible to drop bombs from planes. My problem is that the bomb is not exploding when its velocity is 0 :/ pls help!

SERVER SIDED

Timers = {} 
  
function attach(playerSource, commandName) 
    if isPedInVehicle(playerSource) == true then 
        x,y,z = getElementPosition(playerSource) 
        rx,ry,rz = getVehicleRotation(getPedOccupiedVehicle(playerSource)) 
         
            missle = createObject(3786,x,y,z,rx,ry,rz) 
            --attachElements(vehicle,getPedOccupiedVehicle(playerSource),0,0,-1.7,rz,ry,rz) 
            attachElements(missle,getPedOccupiedVehicle(playerSource),0,0,-1.1,0,355,270) 
        end 
end 
  
  
function detach(playerSource, commandName) 
    if isPedInVehicle(playerSource) == true then 
        x,y,z = getElementPosition(playerSource) 
        rx,ry,rz = getVehicleRotation(getPedOccupiedVehicle(playerSource)) 
         
                detachElements(missle) 
                vx,vy,vz = getElementVelocity(getPedOccupiedVehicle(playerSource)) 
                vehicle = createVehicle(602, x,y,z-2,rx,ry,rz) 
                setElementVelocity(vehicle,vx,vy,vz) 
                setElementAlpha ( vehicle, 0 ) 
                attachElements(missle,vehicle,0,0,0,0,0,270) 
                for i = 1,50 do 
                    if Timers[i] == null then 
                        Timers[i] = setTimer(checkBlow, 100,500, vehicle, playerSource, i) 
                        break 
                    end 
              end 
       end 
end 
  
  
  
function checkBlow(vehicle, thePlayer, index) 
    vx,vy,vz = getElementVelocity(vehicle) 
    vehicle1x, vehicle1y, vehicle1z = getElementPosition ( vehicle ) 
    if isPedInVehicle(thePlayer) then 
        vehicle2x, vehicle2y, vehicle2z = getElementPosition ( getPedOccupiedVehicle(thePlayer) ) 
        outputChatBox("checkBlow", source, 0, 0, 200) 
  
     if vx+vy+vz == 0 then 
     outputChatBox("blow", source, 255, 0, 0) 
        local x,y,z = getElementPosition(vehicle) 
            createExplosion ( x+5,y+5,z, 10) 
        Timers[index] = null 
        blowVehicle(vehicle) 
     end 
end 
end 
  
  
addCommandHandler("a", attach) 
addCommandHandler("d", detach) 

Edited by Guest
Link to comment
  • Moderators

I can't find errors, except that the code will be bugged, when used by multiple users at the same time.

Debug your code! Check if the speed is actually 0!

if vx+vy+vz == 0 then 
--... 
else  
   outputDebugString("Velocity: ".. (vx+vy+vz)) 
end 

Line 27: null doesn't exist in lua, but nil does.

Use locals! and store them inside with tables or elementdata. You script serverside, so tables or elementdata's are required when you use the script for multiple players!

Link to comment

I got no debug:( i edited a little bit the script but its still not working:/

Timers = {} 
  
function attach(playerSource, commandName) 
       local theVehicle = getPedOccupiedVehicle ( playerSource ) 
       if theVehicle then 
        
        x,y,z = getElementPosition(theVehicle) 
        rx,ry,rz = getVehicleRotation(theVehicle) 
         
        missle = createObject(3786,x,y,z,rx,ry,rz) 
         
        attachElements(missle,theVehicle,0,0,-1.1,0,0,-90) 
    end 
end 
  
  
function detach(playerSource, commandName) 
       local theVehicle = getPedOccupiedVehicle ( playerSource ) 
       if theVehicle then 
        
        x,y,z = getElementPosition(playerSource) 
        rx,ry,rz = getVehicleRotation(getPedOccupiedVehicle(playerSource)) 
        vx,vy,vz = getElementVelocity(getPedOccupiedVehicle(playerSource)) 
         
                detachElements(missle) 
                veh = createVehicle(602, x,y,z-2,rx,ry,rz) 
                setElementVelocity(veh,vx,vy,vz) 
                --setElementAlpha ( veh, 0 ) 
                attachElements(missle,veh,0,0,0,0,0,270) 
                for i = 1,50 do 
                    if Timers[i] == nil then 
                        Timers[i] = setTimer(checkBlow, 100,500, veh, playerSource, i) 
                        break 
                    end 
              end 
       end 
end 
  
  
  
function checkBlow(veh, playerSource, index) 
    vx,vy,vz = getElementVelocity(veh) 
    if isPedInVehicle(playerSource) then 
        outputChatBox("checkBlow", source, 0, 0, 200) 
  
     if vx+vy+vz == 0 then 
     outputChatBox("blow", source, 255, 0, 0) 
        local x,y,z = getElementPosition(vehicle) 
        Timers[index] = nil 
        blowVehicle(vehicle) 
        else 
   outputDebugString("Velocity: ".. (vx+vy+vz)) 
end 
end 
end 
  
  
addCommandHandler("a", attach) 
addCommandHandler("d", detach) 

Link to comment

Try it.

local bombs = {} 
  
function attach(playerSource, commandName) 
      --if bombs[playerSource] then return end 
      local theVehicle = getPedOccupiedVehicle ( playerSource ) 
     if theVehicle then 
        
          local x,y,z = getElementPosition(theVehicle) 
          local rx,ry,rz = getVehicleRotation(theVehicle) 
        
          if not bombs[playerSource] then 
               bombs[playerSource] = {} 
          end 
  
          bombs[playerSource].missle = createObject(3786,x,y,z,rx,ry,rz) 
          bombs[playerSource].occVehicle = theVehicle 
  
     attachElements(bombs[playerSource].missle,bombs[playerSource].occVehicle,0,0,-1.1,0,0,-90) 
     end 
end 
  
  
function detach(playerSource, commandName) 
     local p_tbl = bombs[playerSource] 
     if not p_tbl then return end 
  
     local theVehicle = getPedOccupiedVehicle ( playerSource ) 
     if theVehicle and theVehicle == p_tbl.occVehicle then 
        
          local x,y,z = getElementPosition(playerSource) 
          local rx,ry,rz = getVehicleRotation(theVehicle) 
          local vx,vy,vz = getElementVelocity(theVehicle) 
        
          detachElements(p_tbl.missle) 
          p_tbl.fallveh = createVehicle(602, x,y,z-2,180,0,rz) 
          setElementVelocity(p_tbl.fallveh,vx,vy,vz) 
          --setElementAlpha ( p_tbl.fallveh, 0 ) 
  
     attachElements(p_tbl.missle,p_tbl.fallveh,0,0,0,0,0,270) 
     end 
end 
  
addEventHandler("onVehicleDamage", root, function() 
     for player, tbl in pairs(bombs) do 
          if tbl.fallveh == source then 
               if isElement(tbl.fallveh) then 
                    blowVehicle(tbl.fallveh) 
               end 
               bombs[player] = nil 
               return 
          end 
     end 
end) 
  
addCommandHandler("a", attach) 
addCommandHandler("d", detach) 

Link to comment

the onVehicleDemage is not always demaging so i tryied to make it with attaching a colShape to the missle. The problem is that its not creating the exlposion when the col has been hitted.

  
function shapeHit() 
if getElementType ( targetElem ) == "object" then 
local x,y,z = getElementPosition(veh1) 
createExplosion ( x,y,z, 10) 
end 
end 
addEventHandler ( "onColShapeHit", col1, shapeHit ) 
  

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