SetElementAlpha: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (fix oop syntax)
(Fixed some mistakes)
Line 31: Line 31:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function toggleInvis ( thePlayer )  -- thePlayer is whoever executed the command
function toggleInvis ( thePlayer )  -- thePlayer is whoever executed the command
        if getElementAlpha( thePlayer ) == 0 then -- if the player is NOT invisible
  if getElementAlpha( thePlayer ) == 0 then -- if the player is invisible
setElementAlpha ( thePlayer, 0 ) -- set the players alpha to 0 (make them invisible)
      setElementAlpha ( thePlayer, 255 ) -- set the player alpha to 255.
else -- else, if the source player IS visible
  else -- else, if the player is visible
setElementAlpha ( thePlayer, 255 ) -- set the players alpha to 255 (make them 100% visible)
      setElementAlpha ( thePlayer, 0 ) -- set the players alpha to 0.
end
  end
end
end
addCommandHandler ( "invis", toggleInvis ) -- When /invis is typed, the function 'toggleInvis' will start.
addCommandHandler ( "invis", toggleInvis ) -- When /invis is typed, the function 'toggleInvis' will start.
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>

Revision as of 13:07, 4 September 2016

This function sets the alpha (transparency) value for the specified element. This can be a player, ped, object, vehicle or weapon.

Syntax

bool setElementAlpha ( element theElement, int alpha )

OOP Syntax Help! I don't understand this!

Method: element:setAlpha(...)
Variable: .alpha
Counterpart: getElementAlpha


Required Arguments

  • theElement: The element whose alpha you want to set.
  • alpha: The alpha value to set. Values are 0-255, where 255 is fully opaque and 0 is fully transparent.
    • Note: Objects are fully transparent at 140.

Returns

Returns true or false if invalid arguments were passed.

Example

Click to collapse [-]
Clientside example

This example makes the player invisible.

function invisible()
        setElementAlpha(localPlayer, 0)
end
addCommandHandler ( "invisible", invisible )
Click to collapse [-]
Serverside example

This example lets you toggle invisibility when you write /invis.

function toggleInvis ( thePlayer )  -- thePlayer is whoever executed the command
   if getElementAlpha( thePlayer ) == 0 then -- if the player is invisible
       setElementAlpha ( thePlayer, 255 ) -- set the player alpha to 255.
   else	-- else, if the player is visible
       setElementAlpha ( thePlayer, 0 )	-- set the players alpha to 0.
   end
end
addCommandHandler ( "invis", toggleInvis ) -- When /invis is typed, the function 'toggleInvis' will start.

See Also