# "To" Actions

These are special tags that allows you to execute the action to a certain group of players. These tags need to be added before the action.

## TO ALL

It will execute the action for all players on the server. Use this format: `"to_all: <action>"`

```yaml
- 'to_all: message: &a%player% just leveled up!'
- 'to_all: message: &7Hello &a%to:player% &7your level is &a%to:player_level%&7!'
```

## TO TARGET

This is a special action for [`player_attack`](https://ajneb97.gitbook.io/conditionalevents/event-types/player-events#player-attack) , [`player_kill`](https://ajneb97.gitbook.io/conditionalevents/event-types/player-events#player-kill) , [`entity_interact`](https://ajneb97.gitbook.io/conditionalevents/event-types/other-events#entity-interact) and [`player_fish`](https://ajneb97.gitbook.io/conditionalevents/event-types/player-events#player-fish) events. It will execute the action for the target of the event. Use this format: `"to_target: <action>"`

```yaml
 - 'to_target: give_potion_effect: POISON;120;1'
 - 'to_target: message: &cYou were poisoned by &e%player%&c!'
```

{% hint style="success" %}
This can target both players and living entities, so you can use certain actions on entities as well.
{% endhint %}

## TO WORLD

It will execute the action for all players in a world. Use this format:\
`"to_world: <world>: <action>"`

```yaml
- 'to_world: spawn: message: &6This message is sended to all players in the SPAWN world.'
- 'to_world: %player_world%: message: &6Hello to this world!'
```

## TO RANGE

It will execute the action for all players inside a certain radius of blocks.

* You can decide whether to include the player involved in this event or not.&#x20;
* You can also decide whether to include any other entity (and not only players).

Use this format:\
`"to_range: <radius>;<include_player>;<include_entities>: <action>"`

```yaml
- 'to_range: 10;true: message: &6This message is sended to all players in a radius of 10 blocks!'
- 'to_range: 10;false: message: &6%player% says: &7Hello %to:player%!'
- 'to_range: 5;false;true: damage; 10'
```

## TO PLAYER

It will execute the action for a certain player. Use this format:\
`"to_player: <player>: <action>"`

```yaml
to_player: %arg_1%: message: &d[PM] &8[&e%player% -> &eYou&8]&7: &f%args_substring_2-99%
```

### Full Example

```yaml
example:
    type: player_command
    conditions:
    - "%main_command% == /message"
    - "%args_length% < 2 execute error1"
    - "%parseother_{arg_1}_{player_online}% == no execute error2"
    actions:
      default:
      - "cancel_event: true"
      - "message: &d[PM] &8[&eYou &7-> &e%arg_1%&8]&7: &f%args_substring_2-99%"
      - "to_player: %arg_1%: message: &d[PM] &8[&e%player% -> &eYou&8]&7: &f%args_substring_2-99%"
      error1:
      - "cancel_event: true"
      - "message: &cYou must use &7/message <player> <text>"
      error2:
      - "cancel_event: true"
      - "message: &cThat player is not online."
```

This is an example of a private message system. When the player uses the /message \<player> \<text> command, and the selected player is online, a message will be sent to that player and the one using the command.

## TO CONDITION

It will execute the action for all the players that accomplish certain conditions. It is necessary to have previously defined a condition group in the config, as show below:

```yaml
Config:
  to_condition_groups:
    group1:
    - "%player_world% == spawn"
    group2:
    - ...
    group3:
    - ...
```

{% hint style="info" %}
You can create multiple **to condition** groups following the same format as the usual conditions, excluding the "execute" option.
{% endhint %}

Next, you can use the previously created condition group "group1" in a to\_condition action using the following format:\
`"to_condition: <group>: <action>"`

```yaml
to_condition: group1: message: &7This message will be received by anyone who accomplish the <group1> condition
```

### Full Example

```yaml
Config:
  to_condition_groups:
    group1:
    - "%player_has_permission_conditionalevents.somepermission% == yes"
test:
    type: player_command
    conditions:
    - "%command% == /test"
    actions:
      default:
      - "cancel_event: true"
      - "to_condition: group1: message: &7Hello to people with permissions."
```

The previous event adds a `/test` command that will send a message ONLY to the players that have the `conditionalevents.somepermission` permission.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ajneb97.gitbook.io/conditionalevents/actions/to-actions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
