Skip to content

gameObjectScript

mtanksl edited this page Jun 23, 2024 · 3 revisions

Introduction

Behaviours can be attached during game object creation, using GameObjectScript.

Example

Let's attach a new Behaviour to all the monsters.

public class MonsterScript : GameObjectScript<Monster>
{
    public override void Start(Monster monster)
    {
        if (monster.Metadata.Sentences != null && monster.Metadata.Sentences.Length > 0)
        {
            Context.Server.GameObjectComponents.AddComponent(monster, new CreatureTalkBehaviour(TalkType.MonsterSay, monster.Metadata.Sentences) );
        }
    }

    public override void Stop(Monster monster)
    {

    }
}

Edit the file \mtanksl.OpenTibia.GameData\data\gameobjectscripts\config.lua. If the monster's name is not found in the registration list, the empty name is used instead.

gameobjectscripts = {
    ...
    monsters = {
        { name = "", filename = "OpenTibia.Game.GameObjectScripts.MonsterScript" },
        ...
    },
    ...
}