Search the Community
Showing results for tags 'destroy weapon'.
-
Hello there, I've been having some trouble with the DestroyElement function. (destroyHydraGun function, line 42-51) The rest of the script works fine. An uzi is created when a player enters a Hydra, but it doesn't seem to destroy the uzi when a player exits the vehicle. What am I doing wrong? function hydraFunctions() -- ignore this function local vehicle = getPedOccupiedVehicle(localPlayer) if(vehicle)then if getElementModel(vehicle) == 520 then outputChatBox ("Hydra guns installed") toggleControl ( "accelerate", true ) toggleControl ( "brake_reverse", true ) toggleControl ( "vehicle_secondary_fire", false ) toggleControl ( "vehicle_fire", false ) setControlState ( "special_control_up", true) toggleControl ( "special_control_down", false) local x, y, z = getElementPosition(vehicle) local weapon = createWeapon("uzi", x, y, z) attachElements ( weapon, vehicle, 0, 4, 1, 0, 0, 90) end end end addEventHandler ( "onClientPlayerVehicleEnter", getLocalPlayer(), hydraFunctions ) function hydraFiring() -- ignore this function local vehicle = getPedOccupiedVehicle(localPlayer) if(vehicle)then if getElementModel(vehicle) == 520 then setWeaponClipAmmo(weapon, 500) setWeaponFiringRate(weapon, 90) setWeaponState(weapon, "firing") outputChatBox ("guns activated") end end end function hydraStopping() -- ignore this function local vehicle = getPedOccupiedVehicle(localPlayer) if(vehicle)then if getElementModel(vehicle) == 520 then setWeaponState(weapon, "ready") outputChatBox ("guns deactivated") end end end function destroyHydraGun -- This function doesn't work local vehicle = getPedOccupiedVehicle(localPlayer) if(vehicle)then if getElementModel(vehicle) == 520 then local attached = getElementAttachedTo (vehicle) if ( attached ) then destroyElement ( weapon ) end end addEventHandler("onClientPlayerVehicleExit", getLocalPlayer(), destroyHydraGun ) bindKey("mouse1", "down", hydraFiring) bindKey("mouse1", "up", hydraStopping) bindKey("lctrl", "down", hydraFiring) bindKey("lctrl", "up", hydraStopping)