Scripting
Script Structure
onLogin(player)
Examplelocal allowed_ips = {"127.0.0.1"} function onLogin(player) -- Whitelisted IP system local ip = player:getIp() if table.contains(allowed_ips, ip) then return true end return false end
onLogout(player)
Examplefunction onLogout(player) -- Custom message for players attempting to log out in a fight if player:hasCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) then player:sendCancelMessage("You may not log out in the middle of a fight.") return false end return true end
onThink(creature, interval)
Examplefunction onThink(creature, interval) -- Remove 1 health from creature at each think interval creature:addHealth(-1) end
onPrepareDeath(creature, killer)
Examplefunction onPrepareDeath(creature, killer) -- If creature name is Delusion, teleport to 1000, 1000, 7, heal back to full health, and take no death penalty if creature:getName() == "Delusion" then creature:teleportTo(Position(1000, 1000, 7)) creature:addHealth(creature:getMaxHealth()) return false end return true end
onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
Examplefunction onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified) -- Increment the number of deaths the player has if creature:isPlayer() then local deaths = creature:getStorageValue(12345) creature:setStorageValue(12345, (deaths == -1 and 0 or deaths) + 1) end end
onKill(creature, target)
Examplefunction onKill(creature, target) -- Increment the number of creature kills the player has if creature:isPlayer() then local kills = creature:getStorageValue(123123) creature:setStorageValue(123123, (kills == -1 and 0 or kills) + 1) end return true end
onAdvance(player, skill, oldLevel, newLevel)
Examplefunction onAdvance(player, skill, oldLevel, newLevel) if skill == SKILL_LEVEL then player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have advanced to level " .. newLevel .. "!") end return true end
onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
Examplefunction onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) -- Creature with the name Delusion will take zero damage from health if creature:getName() == "Delusion" then primaryDamage = 0 secondaryDamage = 0 end return primaryDamage, primaryType, secondaryDamage, secondaryType end
onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
Examplefunction onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) -- Creature with the name Delusion will take zero damage from mana if creature:getName() == "Delusion" then primaryDamage = 0 secondaryDamage = 0 end return primaryDamage, primaryType, secondaryDamage, secondaryType end
onTextEdit(player, item, text)
Examplefunction onTextEdit(player, item, text) -- Allow the item's text to be edited if I'm writing it if player:getName() == "Delusion" then return true end return false end
onModalWindow(player, modalWindowId, buttonId, choiceId)
Examplefunction onModalWindow(player, modalWindowId, buttonId, choiceId) -- Simply log user selection from the modal window print(player:getName() .. " selected Button ID " .. buttonId .. " with choice " .. choiceId) end
onExtendedOpcode(player, opcode, buffer)
Examplefunction onExtendedOpcode(player, opcode, buffer) -- Log the opcode + data received print(player:getName() .. " received opcode " .. opcode .. " with data containing: " .. buffer) end
Notes
Last updated