SinaAmp Posted March 12, 2021 Share Posted March 12, 2021 hi guys how i can give function to gun shot (and preventing damage) for destroy only vehicles? (I want to make a admin tool that destroy veh and its replace with colt45) Link to comment
Scripting Moderators xLive Posted March 12, 2021 Scripting Moderators Share Posted March 12, 2021 You need to use this event onPlayerWeaponFire check if the parameter hitElement exists and it's a vehicle -- getElementType (element) == "vehicle" then you can use destoryElement to destroy it. Link to comment
SinaAmp Posted March 12, 2021 Author Share Posted March 12, 2021 thank you @xLive but every thing i tried not worked can u give me example script? Link to comment
Scripting Moderators xLive Posted March 12, 2021 Scripting Moderators Share Posted March 12, 2021 (edited) 6 hours ago, SinaAmp said: thank you @xLive but every thing i tried not worked can u give me example script? Oh its my fault sorry! Quote hitElement: an element which was hit by a shot. Currently this can be only another player. it doesn't work with vehicles i don't know if there's another event to use. Edited March 12, 2021 by xLive 1 Link to comment
SinaAmp Posted March 13, 2021 Author Share Posted March 13, 2021 oh ok thank you @xLive Link to comment
Tekken Posted March 13, 2021 Share Posted March 13, 2021 (edited) You can with OnClientPlayerWeaponFire Edited March 13, 2021 by Tekken Typo 1 Link to comment
SinaAmp Posted March 13, 2021 Author Share Posted March 13, 2021 thank you @Tekken why my script does not destroy vehicles? -- client function DesVeh(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement ) if weapon == 22 and getElementType(hitElement)=="vehicle" then destroyElement(hitElement) outputChatBox ( "Your vehicle has been destroyed!", 0, 255, 0 ) else outputChatBox ( "opssss !", 255, 0, 0 ) end end addEventHandler ( "onClientPlayerWeaponFire", root, DesVeh ) Link to comment
SpecT Posted March 13, 2021 Share Posted March 13, 2021 It doesn't work because probably the vehicle was spawned from server side. This means you should destroy the vehicle from the same side. Use triggerServerEvent, pass the hitElement in it and destroy the vehicle in server side. Link to comment
SinaAmp Posted March 14, 2021 Author Share Posted March 14, 2021 @SpecT whats wrong with my serverside script? i doesn't receive any error in debugscript 3 -- client function DesVeh(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement ) if weapon == 22 and getElementType(hitElement)=="vehicle" then triggerServerEvent("onAdminShot" , hitElement) outputChatBox ( "Your vehicle has been destroyed!", 0, 255, 0 ) else outputChatBox ( "opssss !", 255, 0, 0 ) end end addEventHandler ( "onClientPlayerWeaponFire", root, DesVeh ) -- server function DesMyVeh(hitElement) if isElement(hitElement) and getElementType(hitElement) == "vehicle" then fixVehicle(hitElement) end end addEvent("onAdminShot",true); addEventHandler("onAdminShot",root,DesMyVeh); Link to comment
SpecT Posted March 14, 2021 Share Posted March 14, 2021 (edited) Wait.. what exactly do you want to do with the vehicle when you shoot it ? From your first post I see you want the weapon to destroy the vehicles it hits. And in the code you posted above has fixVehicle function. Is it a mistake or intentional? You can either use destroyElement or blowVehicle (for explosion effect). Edited March 14, 2021 by SpecT Link to comment
SinaAmp Posted March 14, 2021 Author Share Posted March 14, 2021 @SpecToh sorry i forgot to edit my code in forum that (fixvehicle(hitElement)) is my test code i replaced that with destroyElement(hitElement) but again that not worked Link to comment
SpecT Posted March 14, 2021 Share Posted March 14, 2021 Oh actually I didn't notice a mistake in the triggerServerEvent. Now this should work: triggerServerEvent("onAdminShot", resourceRoot, hitElement) 1 Link to comment
SinaAmp Posted March 14, 2021 Author Share Posted March 14, 2021 thank you @SpecT that worked 1 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