Skip to content
Engels Quintero edited this page Oct 9, 2024 · 11 revisions

LUA is used as an extension scripting language to handle the interactions between NPC and player.

SRO LUA
v188 5.1
v230+ 5.3

Compiler

Decompiler

API Functions

LuaInsertQuest

Registers a function to be used for quests

LuaInsertQuest(type_id,file_name,func_name)
  • PARAMETERS :
    • type_id (int) ─ ? (1)
    • file_name (string) ─ Filename where is allocated the function to register
    • func_name (string) ─ Function name to register

Example

LuaInsertQuest(1,"quest.sct","QNO_SD_RE_001")

LuaInsertEvent

Registers a function to be used as an event

LuaInsertEvent(type_id,file_name,func_name)
  • PARAMETERS :
    • type_id (int) ─ ? (1)
    • file_name (string) ─ Filename where is allocated the function to register
    • func_name (string) ─ Function name to register

Example

LuaInsertEvent(1,"event.sct","QEV_LEVEL_CH_POTION")

LuaInsertNpc

Links the NPC to execute the current function process

LuaInsertNpc(count,codenames)
  • PARAMETERS :
    • count (int) ─ Number of NPC to be linked
    • codenames (*args as string) ─ Codenames from NPC

Example

LuaInsertNpc(3,"NPC_CH_EVENT_KISAENG1","NPC_CH_EVENT_KISAENG2","NPC_CH_EVENT_KISAENG3")

LuaInsertDropItem

Registers an item drop globally for all monsters

LuaInsertDropItem(count,codenames,chances)
  • PARAMETERS :
    • count (int) ─ Number of items to be set
    • codenames (*args as string) ─ Codename from item
    • chances (*args as int in [0, 100]) ─ Chance of drop the item in percent

Example

LuaInsertDropItem(2,"ITEM_ETC_MOON_GEM",100,"ITEM_ETC_MOON_POT",100)

SetEventOne

Set text from the first action at npc talk

SetEventOne(event_id,codename,unk1,unk2,unk3)
  • PARAMETERS :
    • event_id (int) ─ Unique identifier for the event
    • codename (string) ─ Codename from text reference
    • unk1 (int) ─ ? (1)
    • unk2 (int) ─ ? (1)
    • unk3 (int) ─ ? (0, 1)

Example

EventID = 40008
SetEventOne(EventID,"SN_QEV_LEVEL_CH_POTION",1,1,0)

SetEventTwo

Sets a text list from all possible actions at npc talk

SetEventTwo(count,codenames)
  • PARAMETERS :
    • count (int) ─ Number of codenames to be set
    • codenames (*args as string) ─ Codenames from the text references

Example

SetEventTwo(2,
  "SN_TALK_QEV_LEVEL_CH_POTION_B",
  "SN_TALK_COMMON_EXIT"
)

InsertPayItemCodeName

Registers the items that gonna be rewarded or exchanged in the process

InsertPayItemCodeName(count,codenames)
  • PARAMETERS :
    • count (int in [0, 120]) ─ Number of codenames to be set
    • codenames (*args as string) ─ Codenames from items

Example

InsertPayItemCodeName(3,
  "ITEM_ETC_E051123_AGILITY_SCROLL",
  "ITEM_ETC_E051123_EVATION_SCROLL",
  "ITEM_ETC_E051123_HIT_SCROLL"
)

InsertPayItemRatio

Registers the reward ratio for the items registered with InsertPayItemCodeName

InsertPayItemRatio(count,ratios)
  • PARAMETERS :
    • count (int) ─ Number of ratios to be set
    • ratios (*args as float) ─ Percent values, the sum should give 100

Example

InsertPayItemRatio(3,32.5,32.5,35)

InsertMenuStringList

Links NPC dialog texts to the results from action events at the current function process

InsertMenuStringList(npc_codename,event_count,event_codename,dialog_codename)
  • PARAMETERS :
    • npc_codename (int) ─ Codename from NPC to link
    • event_count (int) ─ Number of event results to be set
    • event_codename (*args as string) ─ Codename from event result
    • text_codename (*args as string) ─ Codename from text reference to show

Example

InsertMenuStringList("NPC_CH_EVENT_KISAENG1", 5,
  "EVENT_MENUSTRING_GREETING","SN_NPC_CH_EVENT_KISAENG1_QS",
  "EVENT_MENUSTRING_REQUEST_ACCEPT_QUEST","SN_TALK_QEV_CH_EVENT_KISAENG_GLOBAL2011_2_A",
  "EVENT_MENUSTRING_NOT_ACHIEVED","SN_TALK_QEV_CH_EVENT_KISAENG_GLOBAL2011_2_E",
  "EVENT_MENUSTRING_INVENTORY_FULL","SN_TALK_QEV_CH_EVENT_KISAENG_GLOBAL2011_2_D",
  "EVENT_MENUSTRING_ACHIEVED","SN_TALK_QEV_CH_EVENT_KISAENG_GLOBAL2011_2_C"
)

LuaInsertFunctionStringList

Register a callback function which handles the talking process from npc

LuaInsertFunctionStringList(unk1,unk2,callback_name)
  • PARAMETERS :
    • unk1 (int) ─ ? (1)
    • unk2 (string) ─ ? ("CONVERSATION_SINGLE")
    • callback_name (string) ─ Name of the callback function from first action

Example

CONVERSATION_SINGLE = 0
LuaInsertFunctionStringList(1,"CONVERSATION_SINGLE","KISAENG_LETTER_THANKS_Conversation")

-- ...

function KISAENG_LETTER_THANKS_Conversation(conversation_state,npc_codename)
  --- code here
end

LuaNpcHandlerNum

Returns the unique id from NPC which is executing the current process

LuaNpcHandlerNum()
  • RETURNS : (int) ─ Unique identifier of NPC

Example

npcId = LuaNpcHandlerNum()

LuaSetCurPage

Sets the page number to track the loop process through the callback function from LuaInsertFunctionStringList

LuaSetCurPage(number)
  • PARAMETERS :
    • number (int) ─ Page number to be set

Example

pageNum = 1
LuaSetCurPage(pageNum)

LuaGetCurPage

Gets the page number to track the loop process through the callback function from LuaInsertFunctionStringList

LuaGetCurPage()
  • RETURNS : (int) ─ Last page number being set

Example

currentPage = LuaGetCurPage()
if currentPage == 1 then
-- code here
elseif currentPage == 2 then
-- code here
else
-- code here
end

LuaShowMenu

Sets the dialog and the actions from menu to be shown at the next callback from LuaInsertFunctionStringList

LuaShowMenu(type,actionlist_index_begin,actionlist_size,npc_id)
  • PARAMETERS :
    • type (int) ─ Type of dialog event to be shown
      • 5 = GREETING
      • 3 = ACHIEVED
      • 1 = NOT_ACHIEVED
    • actionlist_index_begin (int) ─ Actions list index from SetEventTwo
    • actionlist_size (int) ─ Actions list size
    • npc_id (int) ─ Unique identifier of NPC

Example

SetEventTwo(3,
  "SN_TALK_QEV_LEVEL_CH_POTION_A", -- index: 0
  "SN_TALK_QEV_LEVEL_CH_POTION_B", -- index: 1
  "SN_TALK_COMMON_EXIT" -- index: 2
)

-- ...

MENU_TYPE_GREETING = 5
-- [ SN_TALK_QEV_LEVEL_CH_POTION_B, SN_TALK_COMMON_EXIT ]
idx = 1
size = 2
LuaShowMenu(MENU_TYPE_GREETING,EventID,idx,size,LuaNpcHandlerNum())

LuaGetEventMenuResponse

Gets the player actions response using the menu

LuaGetEventMenuResponse()
  • RETURNS : (int) ─ Index from response (using an unusual offset)

Example

SetEventTwo(3,
  "SN_TALK_QEV_LEVEL_CH_POTION_A",
  "SN_TALK_QEV_LEVEL_CH_POTION_B",
  "SN_TALK_COMMON_EXIT"
)

-- ...

function GetTalkResponse()
  return LuaGetEventMenuResponse()-TALK_RESPONSE_LIST_BASE
end
  
-- ...

talkResponse = GetTalkResponse()
if talkResponse == 0 then -- SN_TALK_QEV_LEVEL_CH_POTION_A
  -- code here
elseif talkResponse == 1 then -- SN_TALK_QEV_LEVEL_CH_POTION_B
  -- code here
else -- SN_TALK_COMMON_EXIT
  -- code here
end

LuaTerminateMenu

Stop the NPC talking loop from the callbacks at LuaInsertFunctionStringList

LuaTerminateMenu()

LuaEventInQuireSameItem

Check inventory items from player talking, used also to count them

LuaEventInQuireSameItem(unk1,codename,type,unk2)
  • PARAMETERS :
    • unk1 (int) ─ ? (0)
    • codename (string) ─ Codename of the item to search
    • type (int) ─ Type of the searching method
      • 0 = INQUIRE_SAMEITEM_OP_FIND_FIRST_SLOT ─ First inventory slot to be found
      • 1 = INQUIRE_SAMEITEM_OP_COUNT_FIRST_ITEM ─ Count the stack from first inventory slot found
      • 2 = INQUIRE_SAMEITEM_OP_COUNT_ALL_SAMEITEM ─ Count all inventory items found
    • unk2 (int) ─ ? (0,-1, Maybe default return value?)
  • RETURNS : (int) ─ Slot or count, depends on searching method

Example

function GetSlotFromItem(codename)
  return LuaEventInQuireSameItem(0,codename,INQUIRE_SAMEITEM_OP_FIND_FIRST_SLOT,-1)
end

-- ...

slot = GetSlotFromItem("ITEM_CH_BLADE_01_A")
if slot >= 0 then
  -- item found
end

LuaDelItem_EXT

Delete an inventory item from player talking

LuaDelItem_EXT(unk1,slot,amount,reason_id,unk2)
  • PARAMETERS :
    • unk1 (int) ─ ? (0)
    • slot (int) ─ Slot from item
    • amount (int) - Amount of items to delete
    • reason_id (int) ─ System operation reason identifier
      • 0 = SYSOP_REASON_QUEST
      • 1 = SYSOP_REASON_EVENT
      • 2 = SYSOP_REASON_DRAINED
      • 3 = SYSOP_REASON_WITHDRAW
      • 4 = SYSOP_REASON_ALCHEMY_REINFORCE
      • 5 = SYSOP_REASON_FLEAMARKET_NETWORK
      • 6 = SYSOP_REASON_SIEGE
      • 255 = SYSOP_REASON_INVALID
    • unk2 (int) ─ ? (0)

Example

slot = GetSlotFromItem("ITEM_CH_BLADE_01_A")
if slot >= 0 then
  -- item found
  LuaDelItem_EXT(0,slot,1,SYSOP_REASON_DRAINED,0)
end

LuaAddItem_EXT

Add an item to the inventory from player talking

LuaAddItem_EXT(event_id,unk1,amount,reason_id,randomize_stats,unk2,payitem_index)
  • PARAMETERS :
    • event_id (int) ─ Unique identifier for the event
    • unk1 (int) ─ ? (0)
    • amount (int) ─ Amount of items to add
    • reason_id (int) ─ System operation reason identifier
      • 0 = SYSOP_REASON_QUEST
      • 1 = SYSOP_REASON_EVENT
      • 2 = SYSOP_REASON_DRAINED
      • 3 = SYSOP_REASON_WITHDRAW
      • 4 = SYSOP_REASON_ALCHEMY_REINFORCE
      • 5 = SYSOP_REASON_FLEAMARKET_NETWORK
      • 6 = SYSOP_REASON_SIEGE
      • 255 = SYSOP_REASON_INVALID
    • randomize_stats (int in [0,1]) ─ Set random stats if the item is equipable
    • unk2 (int) ─ ? (Maybe plus if item is equipable?)
    • payitem_index (int) ─ Index of the item list set at InsertPayItemCodeName (LUA list index paradigm starts from 1)

Example

InsertPayItemCodeName(3,
  "ITEM_ETC_E051123_AGILITY_SCROLL", -- index: 1
  "ITEM_ETC_E051123_EVATION_SCROLL", -- index: 2
  "ITEM_ETC_E051123_HIT_SCROLL" -- index: 3
)

-- ...

-- Add (5) pieces of "ITEM_ETC_E051123_EVATION_SCROLL"
idx = 2
amount = 5
LuaAddItem_EXT(EventID,0,amount,SYSOP_REASON_EVENT,0,0,idx)

LuaGetPlayerLevel

Gets the current level from the player talking

LuaGetPlayerLevel()
  • RETURNS : (int) ─ Current level of the player

LuaGetPlayerGender

Gets the gender from the player talking

LuaGetPlayerGender()
  • RETURNS : (int) ─ Gender type of the player
    • 0 = Female
    • 1 = Male
Clone this wiki locally