Xwad Posted April 11, 2016 Share Posted April 11, 2016 (edited) 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 April 11, 2016 by Guest Link to comment
Moderators IIYAMA Posted April 11, 2016 Moderators Share Posted April 11, 2016 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
Xwad Posted April 11, 2016 Author Share Posted April 11, 2016 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
Xwad Posted April 11, 2016 Author Share Posted April 11, 2016 Or is it possible to blow the vehicle when its hitting a world object? Link to comment
Moderators IIYAMA Posted April 11, 2016 Moderators Share Posted April 11, 2016 Or is it possible to blow the vehicle when its hitting a world object? https://wiki.multitheftauto.com/wiki/On ... eCollision Possible, (there are some vehicles that don't work, especially planes) See my bug report: https://bugs.multitheftauto.com/view.php?id=8265 Link to comment
Xwad Posted April 11, 2016 Author Share Posted April 11, 2016 And is the event also triggering if i am not inside the vehicle? I dont want it for plane, i want it for the car "alpha" (id: 602) Link to comment
undefined Posted April 11, 2016 Share Posted April 11, 2016 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
Xwad Posted April 11, 2016 Author Share Posted April 11, 2016 Wow zoRRoM! onVehicleDemage is a very good idea! the only problem is that its exploding immediatelly.. maybe becaouse the object is demaging it? Link to comment
Xwad Posted April 11, 2016 Author Share Posted April 11, 2016 Now i have edit it and its working but its not always exploding cuz sometimes the vehicle does not take any demage:/ for example if i drop the bomb from low height. Link to comment
undefined Posted April 11, 2016 Share Posted April 11, 2016 Add it for high damage. setVehicleHandling(p_tbl.fallveh, "collisionDamageMultiplier", 10) And add it to disable collisions. setElementCollidableWith(p_tbl.fallveh, p_tbl.missle, false) Link to comment
_DrXenon Posted April 11, 2016 Share Posted April 11, 2016 Maybe use getElementSpeed, it is a useful function, If not, Try attaching a col shape to the missle and whenever any element hit sthe col shape that is attacjed to the missle, MISSLE blows. I Hope i hepled. Link to comment
Xwad Posted April 14, 2016 Author Share Posted April 14, 2016 Good idea i try it thanks! Link to comment
Xwad Posted April 16, 2016 Author Share Posted April 16, 2016 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
undefined Posted April 16, 2016 Share Posted April 16, 2016 Multiplier elements doesn't contain GTA worlds. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now