Jump to content

make an object disapear with a gun


Emile

Recommended Posts

Posted

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

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

  • Moderators
Posted

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

Posted

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

Posted
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

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