SetElementCollidableWith: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Added OOP syntax)
(add Weapon to supported element types)
 
(4 intermediate revisions by 2 users not shown)
Line 7: Line 7:
*[[Vehicle]]
*[[Vehicle]]
*[[Object]]
*[[Object]]
{{Added feature/item|1.5.9|1.5.8|21348|
* [[Element/Weapon|Weapon]]
}}


==Syntax==  
==Syntax==  
Line 12: Line 15:
bool setElementCollidableWith ( element theElement, element withElement, bool enabled )  
bool setElementCollidableWith ( element theElement, element withElement, bool enabled )  
</syntaxhighlight>
</syntaxhighlight>
{{New feature/item|3.0141|1.4.0|6987|{{OOP||[[element]]:setCollidableWith||isElementCollidableWith}}}}
{{OOP||[[element]]:setCollidableWith||isElementCollidableWith}}


===Required Arguments===  
===Required Arguments===  
Line 25: Line 28:
<section name="Client" class="client" show="true">
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function ghostmode_on()
function ghostmode_on()
local v = getPedOccupiedVehicle(localPlayer) -- Get her's Vehicle ID
local playerVehicle = getPedOccupiedVehicle(localPlayer) -- Get the players vehicle
for index,vehicle in ipairs(getElementsByType("vehicle")) do --LOOP through all Vehicles
if(playerVehicle) then -- Check the return value.
setElementCollidableWith(vehicle, v, false) -- Set the Collison off with the Other vehicles.
for i,v in pairs(getElementsByType("vehicle")) do --LOOP through all vehicles
setElementCollidableWith(v, playerVehicle, false) -- Set the collison off with the other vehicles.
end
outputChatBox("You are now a Ghost")
end
end
outputChatBox("You are now a Ghost :P",thePlayer)
end
end
addCommandHandler("ghostmode", ghostmode_on) -- Add the /ghostmode Command.
addCommandHandler("ghostmode", ghostmode_on) -- Add the /ghostmode Command.
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>

Latest revision as of 21:31, 7 October 2022

This function can be used to set an element to collide with another element. An element with collisions disabled does not interact physically with the other element.
Note: You can only use this function with the element types listed below.

Syntax

bool setElementCollidableWith ( element theElement, element withElement, bool enabled ) 

OOP Syntax Help! I don't understand this!

Method: element:setCollidableWith(...)
Counterpart: isElementCollidableWith


Required Arguments

  • theElement: The element which colliding you want to change
  • withElement: The other element you wish the first entity to collide with
  • enabled: A boolean to indicate whether elements should be able to collide with eachother (true) or not (false)

Returns

Returns true if the collisions were set succesfully, false otherwise.

Example

Click to collapse [-]
Client
function ghostmode_on()
	local playerVehicle = getPedOccupiedVehicle(localPlayer) -- Get the players vehicle
	if(playerVehicle) then -- Check the return value.
		for i,v in pairs(getElementsByType("vehicle")) do --LOOP through all vehicles
			setElementCollidableWith(v, playerVehicle, false) -- Set the collison off with the other vehicles.
		end
		outputChatBox("You are now a Ghost")
	end
end
addCommandHandler("ghostmode", ghostmode_on) -- Add the /ghostmode Command.

See Also