IsElementOnScreen: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Updated issues)
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Client function}}
{{Client function}}
This function will check if an element is on the screen. Elements behind objects but still in the camera view count as being on screen.
This function is particularly useful for detecting if dynamic objects are in "destroyed" state. Destroyed objects will return false.
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool isElementOnScreen ( element theElement )
bool isElementOnScreen ( element theElement )
</syntaxhighlight>
</syntaxhighlight>
{{New feature/item|3.0141|1.4.0|6987|{{OOP||[[element]]:isOnScreen|onScreen}}}}
===Required Arguments===
===Required Arguments===
*'''theElement:''' The element of which you wish to check wether it's being rendered on screen.
*'''theElement:''' The element of which you wish to check wether it's being rendered on screen.
===Returns===
===Returns===
Returns ''true'' if element is on screen, ''false'' if not.
Returns ''true'' if element is on screen, ''false'' if not.
==Issues==
{{Issues|
{{Issue|2029|isElementOnScreen doesn't work for markers}}
}}
==Example==
==Example==
This function will check if you can see your kill when you die.
This function will check if you can see your killer when you die.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function player_Wasted ( killer, weapon, bodypart )
function player_Wasted ( killer, weapon, bodypart )
Line 17: Line 26:
         -- there was a killer
         -- there was a killer
         if ( isElementOnScreen ( killer ) ) then
         if ( isElementOnScreen ( killer ) ) then
             -- the player who was killed can see his killer
             -- the killer was on screen
             outputChatBox ( "You can still see your killer!", source, 255, 0, 0 )
             outputChatBox ( "You can still see your killer!", 255, 0, 0 )
         else
         else
             -- the player who was killed can not see his killer
             -- the killer was not on screen
             outputChatBox ( "You can not see your killer!", source, 255, 0, 0 )
             outputChatBox ( "You can not see your killer!", 255, 0, 0 )
         end
         end
     end
     end
end
end
addEventHandler ( "onClientPlayerWasted", getRootElement(), player_Wasted )
-- call player_Wasted when only the local player dies
addEventHandler ( "onClientPlayerWasted", localPlayer, player_Wasted )
</syntaxhighlight>
</syntaxhighlight>
==See Also==
{{Client element functions}}

Latest revision as of 10:25, 30 January 2022

This function will check if an element is on the screen. Elements behind objects but still in the camera view count as being on screen.

This function is particularly useful for detecting if dynamic objects are in "destroyed" state. Destroyed objects will return false.

Syntax

bool isElementOnScreen ( element theElement )

OOP Syntax Help! I don't understand this!

Method: element:isOnScreen(...)
Variable: .onScreen

Required Arguments

  • theElement: The element of which you wish to check wether it's being rendered on screen.

Returns

Returns true if element is on screen, false if not.

Issues

Issue ID Description
#2029 isElementOnScreen doesn't work for markers

Example

This function will check if you can see your killer when you die.

function player_Wasted ( killer, weapon, bodypart )
    -- if there even was a killer and the killer isn't the killed player itself
    if ( killer ) and ( killer ~= source ) then
        -- there was a killer
        if ( isElementOnScreen ( killer ) ) then
            -- the killer was on screen
            outputChatBox ( "You can still see your killer!", 255, 0, 0 )
        else
            -- the killer was not on screen
            outputChatBox ( "You can not see your killer!", 255, 0, 0 )
        end
    end
end
-- call player_Wasted when only the local player dies
addEventHandler ( "onClientPlayerWasted", localPlayer, player_Wasted )

See Also