Emile Posted October 2, 2014 Share Posted October 2, 2014 Hello, I would like to have a script that would make the object disapear when we shoot at it. I tried with function Hit(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement) if weapon == 31 then if (getElementModel(hitElement) == 2021) then destroyElement(hitElement) end end end addEventHandler("onClientPlayerWeaponFire", getLocalPlayer(), Hit) but it doesnt work. Thanks Link to comment
King12 Posted October 2, 2014 Share Posted October 2, 2014 function Hit(weapon, _, _, _, _, _, hitElement) if weapon == 31 then if ( getElementType ( hitElement ) == "object" ) and ( getElementModel ( hitElement ) == 2021 ) then destroyElement(hitElement) end end end addEventHandler("onClientPlayerWeaponFire", localPlayer, Hit) or function Hit(weapon, _, _, _, _, _, hitElement) if weapon == 31 and getElementType ( hitElement ) == "object" ) and ( getElementModel ( hitElement ) == 2021 ) then destroyElement(hitElement) end addEventHandler("onClientPlayerWeaponFire", localPlayer, Hit) not sure of them. Link to comment
Moderators IIYAMA Posted October 2, 2014 Moderators Share Posted October 2, 2014 @GoldenEye Debug your code, manually. Here: https://wiki.multitheftauto.com/wiki/Debugging Afaik you would see this warning from the code which which is posted here: getElementModel: Expect element at argument one, got boolean/nil. (when you don't hit an element) Learn to debug your code or you will never be able to solve your problem. Link to comment
Emile Posted October 2, 2014 Author Share Posted October 2, 2014 it doesnt work, I also tried to put `if hitElement then` but the object doesn't disapear. Thanks Link to comment
Moderators IIYAMA Posted October 2, 2014 Moderators Share Posted October 2, 2014 repost the code with debug lines in it and debug all variables in the code. Link to comment
Emile Posted October 2, 2014 Author Share Posted October 2, 2014 if I use King12's code I get `getElementType: Expected element at argument one, got nil.` if I add `if isElement(hitElement) then` I dont get any error but the object doesnt disapear. thanks Link to comment
King12 Posted October 2, 2014 Share Posted October 2, 2014 What about now? -- Deleted I've tried everysingle way to make it work but it seems the event is bugged. Link to comment
King12 Posted October 3, 2014 Share Posted October 3, 2014 You have to create the object in client-side using createObject Because server-side objects can't be destroyed by this event Link to comment
Emile Posted October 4, 2014 Author Share Posted October 4, 2014 What if I want that other players see that the element is destroyed? Link to comment
King12 Posted October 4, 2014 Share Posted October 4, 2014 What if I want that other players see that the element is destroyed? Well you can't then.. You can destroy the object with onPlayerTarget event 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