All conditions and their parameters are not set using any
player
value (his level etc.).
They should be created and configured above
function addonBonus.onLogin(player)
ex.
Lua:
-- Define different conditions
local conditions = {
mage = Condition(CONDITION_ATTRIBUTES),
noble = Condition(CONDITION_ATTRIBUTES),
Citizen = Condition(CONDITION_ATTRIBUTES),
hunter = Condition(CONDITION_ATTRIBUTES),
Knight = Condition(CONDITION_ATTRIBUTES),
Summoner = Condition(CONDITION_ATTRIBUTES),
Warrior = Condition(CONDITION_ATTRIBUTES),
Barbarian = Condition(CONDITION_ATTRIBUTES),
Druid = Condition(CONDITION_ATTRIBUTES),
Wizard = Condition(CONDITION_ATTRIBUTES),
Oriental = Condition(CONDITION_ATTRIBUTES),
Custom = Condition(CONDITION_ATTRIBUTES)
}
-- Set parameters for each condition
conditions.noble:setParameter(CONDITION_PARAM_TICKS, -1)
conditions.noble:setParameter(CONDITION_PARAM_SKILL_SHIELD, 15)
conditions.noble:setParameter(CONDITION_PARAM_STAT_MAGICPOINTS, 50)
conditions.noble:setParameter(CONDITION_PARAM_SKILL_DISTANCE, 50)
conditions.noble:setParameter(CONDITION_PARAM_SKILL_MELEE, 50)
conditions.noble:setParameter(CONDITION_PARAM_SKILL_FIST, 50)
-- HERE rest of conditions
function addonBonus.onLogin(player)
-- HERE code related to player starts:
-- Getting the player's outfit directly
local outfit = player:getOutfit()
local lookType = outfit.lookType
local lookAddons = outfit.lookAddons
All code inside function addonBonus.onLogin(player)
is executed every time player logins into game. So it creates 12 new conditions in C++, set their values and then only add some of them or none in ex.
player:addCondition(conditions.Knight)
. At end of execution of
addonBonus.onLogin
it will remove them all from Lua (they are
local
inside that function). I'm not sure, if it will remove these Conditions from C++ at all!
Code above
function addonBonus.onLogin(player)
is executed only once at server start (also on
/reload xx
), so making it create variables saves a lot of CPU.
You can apply same
condition
to multiple players using
player:addCondition(conditions.Knight)
. That's what all Spells do with Conditions and Combats.
EDIT:
To make it easier to understand. Your Lua script may look like this:
Lua:
local loginMessage = CreatureEvent("LoginMessage")
local loginCounter = 0
function loginMessage.onLogin(player)
loginCounter = loginCounter + 1
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Players logins into game " .. loginCounter)
return true
end
loginMessage:register()
whenever any player relogs, it will increase count +1. Variable is outside "callback"
function
, it's shared between
function
executions.
You don't have to understand C++. From Lua point of view (what C++ "does"): when new player logins, it executes in Lua (imagine it's pasted at end of your .lua file):
Lua:
local playerLoggingIn = Player(123)
loginMessage:onLogin(playerLoggingIn)
Second player with GUID 567 logins, it executes:
Code:
local playerLoggingIn = Player(567)
loginMessage:onLogin(playerLoggingIn)
Third player with GUID 789 logins, it executes:
Code:
local playerLoggingIn = Player(789)
loginMessage:onLogin(playerLoggingIn)
so everytime some player logins into game, it defines new local variables at end of file ex.
local playerLoggingIn = Player(567)
and pass it as parameter to your function ex.
loginMessage.onLogin(playerLoggingIn)
.