MTA:Eir/functions/engineCreateLight: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 8: Line 8:


===Arguments===
===Arguments===
*'''type:''' decides which type that light should have, can be '''point''', '''spot''', '''spot_soft''', '''directional''' or '''ambient''' (currently '''spot''' and '''spot_soft''' do not work)
*'''type:''' decides which type that light should have, can be '''point''', '''spot''', '''spot_soft''', '''directional''' or '''ambient'''


===Returns===
===Returns===
Line 27: Line 27:


lightFrame.setPosition( 0, 0, 10 ); -- repositions the light
lightFrame.setPosition( 0, 0, 10 ); -- repositions the light
</syntaxhighlight>
</section>
<section name="Client" class="client" show="true">
This snippet creates a spotlight that point in the direction of the player.
<syntaxhighlight lang="lua">
local light = engineCreateLight( "spot" );
light.setColor( 1, 1, 1, 1 );
light.setAttenuation( 0, 10, 8 );
light.setRadius( 150 );
light.setFalloff( 1.5 );
local lightFrame = engineCreateFrame();
light.setParent( lightFrame );
light.addToScene();
local function updateLight()
    local playerMatrix = localPlayer.getMatrix();
    -- todo
    playerMatrix.destroy();
end
addEventHandler( "onClientFrame", root, updateLight );
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>

Revision as of 12:35, 14 March 2014

This function creates a RenderWare RpLight object. A light is an object that affects its surrouding RpAtomic instances in a certain radius and casts effects on them. The most notable effect is the pointlight, that colors its surroundings based on attenuation settings.

Syntax

rplight engineCreateLight ( string type )

Arguments

  • type: decides which type that light should have, can be point, spot, spot_soft, directional or ambient

Returns

Returns the rplight object if creation was successful, false otherwise.

Example

Click to collapse [-]
Client

This snippet creates a RenderWare light object and sets it up properly.

local light = engineCreateLight( "point" ); -- creates the new point light
light.setColor(1, 1, 1, 1); -- gives the point light a bright color
light.setAttenuation(0.8, 1.4, 4); -- makes the light fade somewhat
light.setRadius(100); -- makes the light affect atomics in a 100 unit radius

local lightFrame = engineCreateFrame(); -- create a 3D transformation for the light
light.setParent( lightFrame ); -- attaches the light to its frame, the light can now be active in the world.
light.addToScene(); -- activates the light object, so it illuminates its surroundings

lightFrame.setPosition( 0, 0, 10 ); -- repositions the light
Click to collapse [-]
Client

This snippet creates a spotlight that point in the direction of the player.

local light = engineCreateLight( "spot" );
light.setColor( 1, 1, 1, 1 );
light.setAttenuation( 0, 10, 8 );
light.setRadius( 150 );
light.setFalloff( 1.5 );

local lightFrame = engineCreateFrame();
light.setParent( lightFrame );
light.addToScene();

local function updateLight()
    local playerMatrix = localPlayer.getMatrix();

    -- todo

    playerMatrix.destroy();
end

addEventHandler( "onClientFrame", root, updateLight );