• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

Lua define function

Kahras

Member
Joined
Aug 6, 2012
Messages
97
Reaction score
7
Location
Warsaw
You can guide me on how to define a doCreateMonster that was used in the onKill function so that I can define this function in onLogout?

Lua:
function onKill(player, target)
        a = doCreateMonster(xxxx)
return true
end

function onLogout(player)
doRemoveCreature(a)
return true
end


local variable doesn't work, global variable is a problem when 2 players run the script
 

amatria

Well-Known Member
Joined
May 15, 2021
Messages
74
Solutions
6
Reaction score
78
Location
Spain
GitHub
amatria
You can store a table of key-value pairs where the key is the player's CID and the value is the monster created for each player online.

Proof of concept:
Lua:
player_monster_table = {}

player_a_cid = 17
player_b_cid = 19

-- onKill player_a
-- foo = doCreateMonster(...)
player_monster_table[player_a_cid] = "foo"
-- onKill player_b
-- bar = doCreateMonster(...)
player_monster_table[player_b_cid] = "bar"

-- onLogout player_b
-- doRemoveCreature(player_monster_table[player_b_cid])
player_monster_table[player_b_cid] = nil

-- final key-value state
for key, value in pairs(player_monster_table) do
  print(key, value)
end
 
Last edited:
Top