EffectService

Provides the effect control function.

# Methods

[{"index":"integer PlayEffect(string animationClipRUID, Entity instigator, Vector3 position, float zRotation, Vector3 scale, boolean isLoop = false, Dictionary options = nil)","0":"Plays the effect at a fixed location on the current map and returns a serial number to remove the effect. Returns 0 if it fails to create the effect. The available options are FlipX, FlipY, SortingLayer, OrderInLayer, Alpha, StartFrameIndex, EndFrameIndex, PlayRate, SyncFlip, Color, MaterialID, IgnoreMapLayerCheck, and LitMode."}]

[{"index":"integer PlayEffectAttached(string animationClipRUID, Entity parentEntity, Vector3 localPosition, float localZRotation, Vector3 localScale, boolean isLoop = false, Dictionary options = nil)","0":"Plays the effect attached to parentEntity and returns the serial number to remove the effect. Returns 0 if it fails to create the effect. The available options are FlipX, FlipY, SortingLayer, OrderInLayer, Alpha, StartFrameIndex, EndFrameIndex, PlayRate, SyncFlip, Color, MaterialID, IgnoreMapLayerCheck, and LitMode."}]

[{"index":"void RemoveEffect(integer serial)","0":"Removes the effect using the serial number obtained when playing the effect."}]

##### inherited from Service:

[{"index":"EventHandlerBase ConnectEvent(string key, IScriptFunction eventHandler)","0":"Links events. When a key-type event occurs in this service, a handler is notified. The handler receives event parameters."}]

[{"index":"EventHandlerBase ConnectEvent(Type eventType, IScriptFunction eventHandler)","0":"Links events. This service notifies a handler when an eventType event occurs. The handler receives event parameters."}]

[{"index":"boolean DisconnectEvent(string key, EventHandlerBase eventHandler)","0":"Disconnects the event with the key-type event and the handler."}]

[{"index":"boolean DisconnectEvent(Type eventType, EventHandlerBase eventHandler)","0":"Disconnects the eventType event from its handler."}]

[{"index":"void SendEvent(EventType sendEvent)","0":"Generates an event."}]

# Examples

In this example, we'll create a double jump and the Genesis skill from MapleStory. Double jump uses the event of InputService to be triggered when jumping (Alt or Space) in the air.  
To enable the Genesis skill to be used when the Q key is pressed, held, and released—use RemoveEffect. You can check this by adding it to DefaultPlayer.
    
    
    @Component
    script PlayerAbilityController extends Component
        property number EffectSerial = 0
    
        @EventSender("Service", "InputService")
        handler HandleKeyDownEvent(KeyDownEvent event)
        -- Parameters
        local key = event.key
        --------------------------------------------------------
        if key == KeyboardKey.Space or key == KeyboardKey.LeftAlt then
        	if not self.Entity.RigidbodyComponent:IsOnGround() then
        		local lookDirectionX = self.Entity.PlayerControllerComponent.LookDirectionX
        		self.Entity.RigidbodyComponent:SetForce(Vector2(lookDirectionX * 5, 3))
    
        		local options = { ["FlipX"] = lookDirectionX > 0 }
        		local pos = self.Entity.TransformComponent.Position
    
        		_EffectService:PlayEffect("000000", self.Entity, pos, 0, Vector3.one, false, options)
        		_EffectService:PlayEffect("000000", self.Entity, pos, 0, Vector3.one, false, options)
        	end
        elseif key == KeyboardKey.Q then
        	self.EffectSerial = _EffectService:PlayEffectAttached("000000", self.Entity, Vector3.zero, 0, Vector3.one, true)
        end
        end
    
        @EventSender("Service", "InputService")
        handler HandleKeyUpEvent(KeyUpEvent event)
        -- Parameters
        local key = event.key
        --------------------------------------------------------
        if key == KeyboardKey.Q then
        	_EffectService:RemoveEffect(self.EffectSerial)
    
        	local pos = self.Entity.TransformComponent.Position
    
        	_EffectService:PlayEffect("000000", self.Entity, pos + Vector3(-4, 0, 0), 0, Vector3.one)
        	_EffectService:PlayEffect("000000", self.Entity, pos + Vector3(-2, 0, 0), 0, Vector3.one)
        	_EffectService:PlayEffect("000000", self.Entity, pos + Vector3(0, 0, 0), 0, Vector3.one)
        	_EffectService:PlayEffect("000000", self.Entity, pos + Vector3(2, 0, 0), 0, Vector3.one)
        	_EffectService:PlayEffect("000000", self.Entity, pos + Vector3(4, 0, 0), 0, Vector3.one)
    
        	_EffectService:PlayEffect("000000", self.Entity, pos, 0, Vector3.one)
        end
        end
    end
    

# SeeAlso

  * PlayerControllerComponent
  * RigidbodyComponent
  * TransformComponent
  * KeyboardKey
  * KeyDownEvent
  * KeyUpEvent
  * [Let's Sparkle with Skill Effects!](/docs?postId=70)