Revscriptsys
Revscriptsys:
Revscriptsys
Revscriptsys is a new alternative way to register scripts so that you don't need to do it via XML. You just need to place your lua scripts inside data/scripts/, or any subfolder of it if you want. Monster scripts are, however, placed in a different path: data/monster/ (or any subfolder of it, like before). This system supports the usage of different metatables in the same script (Actions, MoveEvents, GlobalEvents...). This comes in hand if you do prolonged quests (for example), which otherwise would need separate files for each metatable. The script must contain a header and footer, as shown in the following example:
local testAction = Action() -- this is our header, the first thing we have to write (except for configuration tables and such)
function testAction.onUse(player, item, fromPosition, target, toPosition, isHotkey) -- now we can design the action itself
return print("We used this item: " .. item.itemid)
end
testAction:id(2550) -- the item is a scythe
testAction:register() -- this is our footer, it has to be the last function executedAvailable metatables:
Action()
CreatureEvent("name")
GlobalEvent("name")
MonsterType("name")
MoveEvent()
Spell("name")
TalkAction("words")
Weapon(WEAPON_TYPE)Credits: Evil Hero.
Actions:
Actions
Action()
Interfaces:
onUse
Methods:
Example:
local action = Action()
function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if target.itemid == 2739 then
target:transform(2737)
target:decay()
Game.createItem(2694, 1, toPosition)
return true
end
return destroyItem(player, target, toPosition)
end
action:id(2550)
action:register()Action:id(ids)
Description:
Registers the Action by chosen itemid(s)
Parameters:
id(s)
Returns: N/A
Example:
local action = Action()
action:id(1000) -- only registering one itemid
action:id(1000,1001,1002,...) -- registering several itemids
action:register()Action:aid(ids)
Description:
Registers the Action by chosen actionid(s)
Parameters:
aid(s)
Returns: N/A
Example:
local action = Action()
action:aid(1000) -- only registering one actionid
action:aid(1000,1001,1002,...) -- registering several actionids
action:register()Action:uid(ids)
Description:
Registers the Action by chosen uniqueid(s)
Parameters:
uid(s)
Returns: N/A
Example:
local action = Action()
action:uid(1000) -- only registering one uniqueid
action:uid(1000,1001,1002,...) -- registering several uniqueids
action:register()Action:allowFarUse(bool)
Description:
Determines whether the item can be used on a target from a distance or not.
default: false
Parameters:
boolean value (true or false)
Returns: N/A
Example:
local action = Action()
action:allowFarUse(true)
action:register()Action:blockWalls(bool)
Description:
Determines whether the item can be used on a target even if there is a wall between the Player and the target.
default: true
Parameters:
boolean value (true or false)
Returns: N/A
Example:
local action = Action()
action:blockWalls(false)
action:register()Action:checkFloor(bool)
Description:
Determines whether the item must be used on a target which is on the same floor level as the Player's.
default: true
Parameters:
boolean value true/false
Returns: N/A
Example:
local action = Action()
action:checkFloor(false)
action:register()CreatureEvents:
CreatureEvents
CreatureEvent("name")
Interfaces:
Methods:
none
Example:
local creatureevent = CreatureEvent("example")
function creatureevent.onLogin(player)
player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "Welcome!")
return true
end
creatureevent:register()CreatureEvent("name").onLogout(player)
Interface:
onLogout(player)
Example:
local creatureevent = CreatureEvent("example")
function creatureevent.onLogout(player)
player:getPosition():sendMagicEffect(CONST_ME_POFF)
return true
end
creatureevent:register()CreatureEvent("name").onThink(creature, interval)
Interface:
onThink(creature, interval)
Example:
local creatureevent = CreatureEvent("example")
function creatureevent.onThink(creature, interval)
return true
end
creatureevent:register()CreatureEvent("name").onPrepareDeath(creature, killer)
Interface:
onPrepareDeath(creature, killer)
Example:
local creatureevent = CreatureEvent("example")
function creatureevent.onPrepareDeath(creature, killer)
return true
end
creatureevent:register()CreatureEvent("name").onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
Interface:
onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
Example:
local creatureevent = CreatureEvent("example")
function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
return true
end
creatureevent:register()CreatureEvent("name").onKill(creature, target)
Interface:
onKill(creature, target)
Example:
local creatureevent = CreatureEvent("example")
function creatureevent.onKill(creature, target)
return true
end
creatureevent:register()CreatureEvent("name").onAdvance(player, skill, oldLevel, newLevel)
Interface:
onAdvance(player, skill, oldLevel, newLevel)
Example:
local creatureevent = CreatureEvent("example")
function creatureevent.onAdvance(player, skill, oldLevel, newLevel)
return true
end
creatureevent:register()CreatureEvent("name").onModalWindow(player, modalWindowId, buttonId, choiceId)
Interface:
onModalWindow(player, modalWindowId, buttonId, choiceId)
Example:
local creatureevent = CreatureEvent("example")
function creatureevent.onModalWindow(player, modalWindowId, buttonId, choiceId)
return true
end
creatureevent:register()CreatureEvent("name").onTextEdit(player, item, text)
Interface:
onTextEdit(player, item, text)
Example:
local creatureevent = CreatureEvent("example")
function creatureevent.onTextEdit(player, item, text)
return true
end
creatureevent:register()CreatureEvent("name").onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
Interface:
onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
Example:
local creatureevent = CreatureEvent("example")
function creatureevent.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
creatureevent:register()CreatureEvent("name").onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
Interface:
onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
Example:
local creatureevent = CreatureEvent("example")
function creatureevent.onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
creatureevent:register()CreatureEvent("name").onExtendedOpCode(player, opcode, buffer)
Interface:
onExtendedOpCode(player, opcode, buffer)
Example:
local creatureevent = CreatureEvent("example")
function creatureevent.onExtendedOpCode(player, opcode, buffer)
return true
end
creatureevent:register()GlobalEvents:
GlobalEvents
GlobalEvent("name")
Interfaces:
Methods:
Example:
local globalevent = GlobalEvent("example")
function globalevent.onThink(...)
return true
end
globalevent:interval(1000) -- will be executed every 1000ms
globalevent:register()GlobalEvent("name").onTime(interval)
Interface:
onTime(interval)
Example:
local globalevent = GlobalEvent("example")
function globalevent.onTime(interval)
broadcastMessage("Good morning!", MESSAGE_STATUS_DEFAULT)
return true
end
globalevent:time("08:00") -- will be executed each day on 8am
globalevent:register()GlobalEvent("name").onStartup()
Interface:
onStartup()
Example:
local globalevent = GlobalEvent("example")
function globalevent.onStartup()
broadcastMessage("Server started!", MESSAGE_STATUS_DEFAULT)
return true
end
globalevent:register()GlobalEvent("name").onShutdown()
Interface:
onShutdown()
Example:
local globalevent = GlobalEvent("example")
function globalevent.onShutdown()
broadcastMessage("Shutting down, see you soon!", MESSAGE_STATUS_DEFAULT)
return true
end
globalevent:register()GlobalEvent("name").onRecord(current, old)
Interface:
onRecord(current, old)
Example:
local globalevent = GlobalEvent("example")
function globalevent.onRecord(current, old)
return true
end
globalevent:register()Monstertypes:
Monstertypes
MonsterType("name")
Description:
We have created a table masking system, in order to make MonsterTypes easier to maintain/create example
Interfaces:
onThink(...)
onAppear(...)
onDisappear()
onMove(...)
onSay(...)
Methods:
Create a new MonsterType:
Game.createMonsterType(name)
Boolean functions:
isAttackable(bool)
isConvinceable(bool)
isSummonable(bool)
isIllusionable(bool)
isHostile(bool)
isPushable(bool)
isHealthHidden(bool)
canPushItems(bool)
canPushCreatures(bool)
canPushCreatures(bool)
Integer Functions:
health(health)
maxHealth(maxHealth)
experience(exp)
addElement(type, percent)
maxSummons(ammount)
armor(armor)
defense(defense)
corpseId(id)
manaCost(mana)
baseSpeed(speed)
light(color, level)
staticAttackChance(chance)
targetDistance(distance)
yellChance(chance)
yellSpeedTicks(ticks)
changeTargetChance(chance)
changeTargetSpeed(interval)
String Functions:
name(name)
nameDescription(description)
combatImmunity(immunity)
conditionImmunity(immunity)
addVoice(sentence, interval, chance, yell)
registerEvent(name)
addSummonname, interval, chance)
race(race)
Get Functions:
getAttackList()
getDefenseList()
getElementList()
getVoices()
getLoot()
getCreatureEvents()
getSummonList()
Userdata Functions:
addAttack(monsterspell)
addDefense(monsterspell)
addLoot(loot)
outfit(outfit)
How to create a MonsterType from scratch.
Example:
MoveEvents:
MoveEvents
MoveEvent()
Interfaces:
onEquip(player, item, slot, isCheck)
onDeEquip(player, item, slot, isCheck)
onStepIn(creature, item, position, fromPosition)
onStepOut(creature, item, position, fromPosition)
onAddItem(moveitem, tileitem, position)
onRemoveItem(moveitem, tileitem, position)
Methods:
level(lvl)
magiclevel(lvl)
slot(slot)
id(ids)
aid(ids)
uid(ids)
position(positions)
premium(bool)
vocation(vocName[, showInDescription = false, lastVoc = false])
Example:
MoveEvent().onEquip(player, item, slot, isCheck)
Interface:
onEquip(player, item, slot, isCheck)
Example:
MoveEvent().onDeEquip(player, item, slot, isCheck)
Interface:
onDeEquip(player, item, slot, isCheck)
Example:
MoveEvent().onStepIn(creature, item, position, fromPosition)
Interface:
onStepIn(creature, item, position, fromPosition)>
Example:
MoveEvent().onStepOut(creature, item, position, fromPosition)
Interface:
onStepOut(creature, item, position, fromPosition)>
Example:
MoveEvent().onAddItem(moveitem, tileitem, position)
Interface:
onAddItem(moveitem, tileitem, position)>
Example:
MoveEvent().onRemoveItem(moveitem, tileitem, position)
Interface:
onAddItem(moveitem, tileitem, position)>
Returns: N/A
Example:
MoveEvent:level(lvl)
Description:
Registers the MoveEvent by chosen level
Parameters:
id(s)
Returns: N/A
Example:
MoveEvent:magiclevel(lvl)
Description:
Registers the MoveEvent by chosen magic level
Parameters:
id(s)
Returns: N/A
Example:
MoveEvent:id(ids)
Description:
Registers the MoveEvent by chosen itemid(s)
Parameters:
id(s)
Returns: N/A
Example:
MoveEvent:aid(ids)
Description:
Registers the MoveEvent by chosen actionid(s)
Parameters:
aid(s)
Returns: N/A
Example:
MoveEvent:uid(ids)
Description:
Registers the MoveEvent by chosen uniqueid(s)
Parameters:
uid(s)
Returns: N/A
Example:
MoveEvent:position(positions)
Description:
Registers the MoveEvent by chosen position(s)
Parameters:
position(s)
Returns: N/A
Example:
MoveEvent:premium(bool)
Description:
Determines whether the MoveEvent will be triggered by premium players or not
default: false
Parameters:
boolean value (true or false)
Returns: N/A
Example:
MoveEvent:vocation(vocName[, showInDescription = false, lastVoc = false])
Description:
Determines whether the MoveEvent will be triggered by a specific vocation. Optional parameters will determine if the vocation specified will be shown in the description and if it is the last vocation shown in description.
Parameters:
vocName (string), showInDescription (boolean), lastVoc
Returns: N/A
Example:
Spells:
Spells
Spell(words, name or id)
Interfaces:
onCastSpell(creature, var, isHotkey)
Methods:
getManaCost(player)
getSoulCost()
isPremium()
isLearnable()
Example:
Spell(words, name or id).onCastSpell(creature, var, isHotkey)
Interface:
onCastSpell(creature, var, isHotkey)
Returns: N/A
Example:
Spell:getManaCost(player)
Description:
Returns the mana that the player will spend when casting the spell
Parameters:
player
Returns: N/A
Example:
Spell:getSoulCost()
Description:
Returns the soul that the player will spend when casting the spell
Parameters:
none
Returns: N/A
Example:
Spell:isPremium()
Description:
Returns whether the player that cast the spell is premium or not
Parameters:
none
Returns: N/A
Example:
Spell:isLearnable()
Description:
Returns whether the player that cast the spell is able to learn the spell or not
Parameters:
none
Returns: N/A
Example: