Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

How to modify properties of C structs from Lua #7

@pancelor

Description

@pancelor

I want to teleport a random enemy to the starting room when I press the bomb button.

Here's my mod:

necrolua.hook("c_Player::p_UseBomb", function(func, self)
  print "c_Player::p_UseBomb"

  print "inside mod 1"
  local m_GetRandomEnemy = necrolua.get("c_Enemy::m_GetRandomEnemy")
  print "inside mod 2"
  local enemy = m_GetRandomEnemy()
  print "inside mod 3"
  enemy.x = 0
  enemy.y = 0
  print "inside mod 4"
  func(self)
end)

When I press the bomb button, it crashes:

c_Player::p_UseBomb
inside mod 1
calling nl_symbol("c_Enemy::m_GetRandomEnemy")
[←[33mNecroLuaAPI.dll←[0m][←[32mLua←[0m] nl_luainit.lua:429: nl_get :: cast("__cdecl c_Enemy* (*)()", 20917504)
inside mod 2
inside mod 3
mods\0luatest\lua\init.lua:22: 'struct c_Enemy' has no member named 'x'
stack traceback:
        mods\0luatest\lua\init.lua:22: in function <mods\0luatest\lua\init.lua:14>
        [C]: in function 'xpcall'
        nl_luainit.lua:456: in function <nl_luainit.lua:455>
[←[33mNecroLuaAPI.dll←[0m] nl_payload.c:176: Mod API finalized.
[NecroLua.exe] nl_launcher.c: 58: Done with exit code 0x00000001

I seem to have successfully called GetRandomEnemy from lua, but I don't know what to do now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions