Event

An **Event** is a custom triggered action determined to be triggered from a condition which will execute the provided callback once said condition is fulfilled.

## Lua scripting

*This section describes game scripting. For more information see the Lua API article*

The event requires some initialization before registering:

```
example\_evhdl = Event:new{
    ref\_name = "example",
    conditions\_fn = function() print("check if conditions are met") end,
    event\_fn = function() print("do something") end,
    title = "Title",
    text = "Detailed description of the event"
}
example\_evhdl:register()

```

The client should display an image if one with the ref\_name of the event is present, see reference name.

Adding receivers is relatively easy, multiple receivers can be passed to the add\_receivers function:

```
texas\_war\_evhdl:add\_receivers(Nation:get("united\_states"), Nation:get("mexico"), Nation:get("texas"))

```

An example event, most of the code is self explanatory:

```
function cake\_test()
    -- Requirements
    local year = get\_year()
    -- "Year must be above 1700"
    if(year <= 1700) then
        return EVENT\_CONDITIONS\_UNMET
    end
    return EVENT\_CONDITIONS\_MET
end

cake\_evhdl = Event:new{
    ref\_name = "cake\_thing",
    conditions\_fn = "cake\_test",
    event\_fn = function(ref\_name)
        cake\_thing:add\_descision(Descision:new{
            ref\_name = "cake\_descision\_0",
            name = "I think i will eat it",
            descision\_fn = function(ref\_name)
                print('Awww, So mean!')
            end,
            effects = "You will throw away the cake"
        })
        cake\_thing:add\_descision(Descision:new{
            ref\_name = "cake\_descision\_1",
            name = "Fuck you",
            descision\_fn = function(ref\_name)
                print('Thanks for accepting <3')
            end,
            effects = "You will eat the cake"
        })
        return EVENT\_DO\_ONE\_TIME
    end,
    title = "A little gift",
    text = "Hi, i baked this cake :3"
}
cake\_evhdl:register()
cake\_evhdl:add\_receivers(Nation:get("my\_nation"))

```

## Dynamic events

If you wish to create a dynamic event that changes text depending on the nation who is firing it - you may want to know that since 0.2.9 there has been Dynamic Event support - in which the ref\_name of the country is passed as a parameter to the function.

```
eapcp\_evhdl = Event:new{
    ref\_name = "eapcp",
    conditions\_fn = function(ref\_name)
        return EVENT\_CONDITIONS\_MET
    end,
    event\_fn = function(ref\_name)
        local nation = Nation:get(ref\_name)
        local canal\_prov = Province:get("colon")
        eapcp\_evhdl.title = "The country of " .. ref\_name
        eapcp\_evhdl.text = "We can decide stuff, what we should do with the country of " .. Nation:get(ref\_name).adjective .. " people?"
        eapcp\_evhdl:update()

        eapcp\_evhdl:add\_descision(Descision:new{
            ref\_name = "dsc0",
            name = "Something very smart",
            descision\_fn = function(ref\_name)
                print("Dec 0: " .. ref\_name)
            end,
            effects = "Smart stuff"
        })
        eapcp\_evhdl:add\_descision(Descision:new{
            ref\_name = "dsc1",
            name = "Something very ambitious",
            descision\_fn = function(ref\_name)
                print("Dec 1: " .. ref\_name)
            end,
            effects = "Ambitious stuff"
        })
        return EVENT\_DO\_ONE\_TIME
    end
}
eapcp\_evhdl:register()
eapcp\_evhdl:add\_receivers(table.unpack(Nation:get\_all()))

```

## Examples

### German Unification

```
unify\_germany\_evhdl = Event:new{
    ref\_name = "unify\_germany",
    conditions\_fn = function(ref\_name)
        return EVENT\_CONDITIONS\_MET
    end,
    event\_fn = function(ref\_name)
        unify\_germany\_evhdl:add\_descision(Descision:new{
            ref\_name = "unify\_germany\_descision\_0",
            name = "Yes",
            descision\_fn = function()
                print('Unifying germany...')
                local prov = Nation:get("germany"):get\_nuclei\_provinces()
                for k, v in pairs(prov) do
                    print(prov.ref\_name)
                    prov:give\_and\_relinquish\_to(Nation:get("germany"))
                end
            end,
            effects = "Prussia acquires all provinces that are a nuclei of Germany"
        })
        unify\_germany\_evhdl:add\_descision(Descision:new{
            ref\_name = "unify\_germany\_descision\_1",
            name = "No",
            descision\_fn = function()
                print('Germany isn\'t going to be a thing :<')
            end,
            effects = "Nothing happens"
        })
        return EVENT\_DO\_ONE\_TIME
    end,
    title = "Unify germany",
    text = "Make germany with magic!"
}
unify\_germany\_evhdl:register()
unify\_germany\_evhdl:add\_receivers(Nation:get("prussia"))

```