CreatureEvent
CreatureEvent Interface
There are many types of events for the CreatureEvent interface, here is a list.
    1.
    You can create a CreatureEvent script in data/creaturescripts/scripts folder, but
    2.
    You must register CreatureEvents in data/creaturescripts/creaturescripts.xml, here is an example
    1
    <event type="login" name="PlayerLogin" script="login.lua" />
    Copied!
    3.
    Alternatively you can use revscript method to register via lua, by saving a .lua file in data/scripts folder.
    4.
    Any CreatureEvent that is not onLogin, must be registered to the creature before it will be used by the creature.

onLogin(player)

onLogin is an event of the interface CreatureEvent
    player -- 1st arg/parameter /userdata/ = The player who is trying to login
onLogin is called whenever any player tries to log in, its a great spot to register other CreatureEvents to players.
After you have registered your event in creaturescripts.xml you can call the event in a script like so:
1
local firstItems = {2050, 2382} --- table with items for new player
2
3
function onLogin(player)
4
if player:getLastLoginSaved() == 0 then --- player has never logged in before
5
for i = 1, #firstItems do
6
player:addItem(firstItems[i], 1) -- we give 1 of each item in table above to player
7
end
8
player:addItem(ITEM_BAG, 1) -- we give the player a bag too
9
end
10
return true --- we must return true to allow player to login, false or no return will keep player from logging in.
11
end
Copied!
Always remember to return true if you wish to allow player login, returning false or not returning true will block player from logging in!

onLogout(player)

onLogout is an event of the interface CreatureEvent
    player -- 1st arg/parameter /userdata/ = The player who is trying to logout
onLogout is called whenever any player tries to logout, its a great spot to unregister other CreatureEvents to players.
After you have registered your event in creaturescripts.xml you can call the event in a script like so:
1
function onLogout(player)
2
if player:isPzLocked() then
3
player:sendTextMessage(MESSAGE_INFO_DESCR,"You must not be pz-locked, in order to logout")
4
return false --- here we block player from logging out
5
end
6
--- if we made it to this point, player must not be pzlocked, so lets let him logout
7
return true --- player logs out successfully
8
end
Copied!
Always remember to return true if you wish to allow player logout, returning false or not returning true will block player from logging out!
Last modified 1mo ago