NPC game multi-action lua script design

I need to put script NPC in my currect game project. The project itself was developed in C ++. I will use Luabind to bind lua and C ++.

I need to call an NPC function when a specific NPC or timer is activated in order to do something. I am currently stuck between two NPC script projects.

  • Using the npcname_action view to differentiate each NPC.
    It is kind of troublesome to give a name to every other NPC.
    I am still thinking how to implement this in my project.
    Example:

    HotelBellboy12_Click() { .. }  
    HotelBellboy12_TimerAction() { .. }
    
  • Using the function name.
    Each npc has its own lua file.
    I am thinking of loading a script into memory and, if necessary, loading into luaStateusing luaL_loadbuffer
    Example:

    OnClick() { .. }
    OnTimerAction() { .. }
    

?

+3
2

- , - # 2. , Lua, NPC; script, NPC.

NPC , Lua . NPC NPC , (, Merchant Commoner), NPC. , . NPC, OnClick(), .

, , .

+1

.

, .

, npc - , NPC. - NPC, - . , . , , , , :

npc.bob.click = function () jump() end
npc.alice.timer = function () cry() end
+3

Source: https://habr.com/ru/post/1787920/


All Articles