2kristof2 Posted May 7, 2014 Share Posted May 7, 2014 hello, I'm a very beginner and trying to learn lua. I need 1 script but unfortunately i have no idea how to do it I guess I have to use it: https://wiki.multitheftauto.com/wiki/On ... eCollision What do i want: When my vehicle touch a Object(all objects with ID=xxx), the vehicle will be blown (player killed) Thanks for help, Krzysztof Link to comment
Castillo Posted May 7, 2014 Share Posted May 7, 2014 You must use that event and the following functions: getElementModel -- To check if the object is X model. blowVehicle -- To blow the vehicle. Link to comment
2kristof2 Posted May 8, 2014 Author Share Posted May 8, 2014 well i tried to do something but i started scripting yesterday so the script can be not sensible.. Anyway it doesn't work. Me = getLocalPlayer function Main (hitPlayer, matchingDimension) vehicle = getPedOccupiedVehicle ( hitPlayer ) if hitPlayer ~= Me then if source == getElementModel(hitElement)==3458) then blowVehicle ( vehicle ) end end end addEventHandler( "onClientVehicleCollision", getRootElement(), Main) Link to comment
Dealman Posted May 8, 2014 Share Posted May 8, 2014 I haven't tested it, but you could try this; function blowOnCollisionWithModel_Handler(hitElement) if(source ~= getPedOccupiedVehicle(localPlayer)) then if(getElementModel(hitElement) == 3458) then blowVehicle(source); end end end addEventHandler("onClientVehicleCollision", getRootElement(), blowOnCollisionWithModel_Handler); Link to comment
2kristof2 Posted May 8, 2014 Author Share Posted May 8, 2014 unfortunately it doesn't work Link to comment
Dealman Posted May 8, 2014 Share Posted May 8, 2014 Try this and see what it outputs when you hit the model you want. function blowOnCollisionWithModel_Handler(hitElement) outputChatBox("You collided with Model: [#FF2626"..tostring(getElementModel(hitElement)).."#BB0000]", 187, 0, 0, true); end addEventHandler("onClientVehicleCollision", getRootElement(), blowOnCollisionWithModel_Handler); Do note that due to how onClientVehicleCollision works, chat may or may not be spammed with messages. Link to comment
2kristof2 Posted May 8, 2014 Author Share Posted May 8, 2014 This: "you collided with object [3458]" without explosion Link to comment
Dealman Posted May 8, 2014 Share Posted May 8, 2014 Try this. If it still doesn't work, try commenting out the first if statement(also remember the end that closes it!). function blowOnCollisionWithModel_Handler(hitElement) if(source ~= getPedOccupiedVehicle(localPlayer)) then if(hitElement == 3458) then blowVehicle(source); end end end addEventHandler("onClientVehicleCollision", getRootElement(), blowOnCollisionWithModel_Handler); Link to comment
2kristof2 Posted May 8, 2014 Author Share Posted May 8, 2014 maybe i'm doing something wrong but it still doesn't work for me Link to comment
2kristof2 Posted May 10, 2014 Author Share Posted May 10, 2014 should i replace first "if"? i don't understund.. Link to comment
Castillo Posted May 10, 2014 Share Posted May 10, 2014 The problem with Dealman's script is that he's checking if hitElement is equal to 3458, but it won't work, because hitElement is a element, not a number. So, you must first check if the element is valid using isElement and then use getElementModel to obtain the element model. function blowOnCollisionWithModel_Handler ( hitElement ) if ( source ~= getPedOccupiedVehicle ( localPlayer ) ) then if ( isElement ( hitElement ) and getElementModel ( hitElement ) == 3458 ) then blowVehicle ( source ) end end end addEventHandler ( "onClientVehicleCollision", getRootElement(), blowOnCollisionWithModel_Handler ) Link to comment
2kristof2 Posted May 11, 2014 Author Share Posted May 11, 2014 i tested it 5 times (race gamemode) and it still doesn't work D: (I used carshade - 3458 and infernus to hit the object) Link to comment
Castillo Posted May 11, 2014 Share Posted May 11, 2014 I believe the problem is here: if ( source ~= getPedOccupiedVehicle ( localPlayer ) ) then Change "~=" to "==" ( without the quotes ) and it'll work ( tested ). Link to comment
2kristof2 Posted May 11, 2014 Author Share Posted May 11, 2014 thank you I really needed it! 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