Well, this is currently just an idea and will take some time to implant. First we'll have to redo some of the current script system in order to support multiple script engines (by compile choice).
So this will be the thread where we can discusse how the Python script shall work. The "lib" will be done in mostly C/C++.
Each script file can handle multiple classes, each class can be extended, or called by other actions. Each action can do for multiple items etc. Or have multiple calls. Python is quite simelar to Lua in many cases, but force you to write nice looking code and is more powerful in many cases.
You can also have multiple things to trigger one action
Actions can trigger other actions
Change player/creature state is easy
Same goes for creatures
Require states to be in action
Static ID, etc NPC
A bigger example for some full script
So this will be the thread where we can discusse how the Python script shall work. The "lib" will be done in mostly C/C++.
Each script file can handle multiple classes, each class can be extended, or called by other actions. Each action can do for multiple items etc. Or have multiple calls. Python is quite simelar to Lua in many cases, but force you to write nice looking code and is more powerful in many cases.
Code:
import tfs
class MyScript(tfs.onUse):
items = (123,576,987)
def action(self):
# Make the player say Hello World
self.who.say("Hello World")
if self.item.id == 123:
# This will tell the user that item is used
self.who.send("This is item 123 in action!")
Code:
import tfs
class MyScript(tfs.onEquip, tfs.onDeEquip):
items = (123)
def action(self):
# Say something when item 123 is equiped and deEquiped
self.who.send("This is item 123 in action!")
Code:
class MyScript(tfs.onEquip, tfs.onDeEquip):
items = (123)
def action(self):
# Say something when item 123 is equiped and deEquiped
self.who.send("This is item 123 in action!")
class MyOtherScript(tfs.onUse):
items = (23423)
def action(self):
# def trigger(self, scriptname, action=0)
self.trigger('MyScript') # Will trigger first action, equip, using same item id and player
self.trigger('MyScript', 'deEquip') # Trigger deEquip
Code:
class MyScript(tfs.onUse):
items = (123) # Super Potion etc
def action(self):
self.who.addMana(500)
self.who.addHealth(500)
self.who.setSpeed(1.5) # 1 means 100% regular, values over etc 10 means static speed
self.who.loseSkill(0) # No skill loose on death
Code:
class MyScript(tfs.onAttack):
creature = (123) # Attacker creature ID, set to 0 or 1 or something for players
def action(self):
self.attacker.setSpeed(1.5)
Code:
class MyScript(tfs.onUse):
items = (123)
def action(self):
if self.who.state('onAttack'):
self.attacker.setSpeed(1.5) # 1 means 100% regular, values over etc 10 means static speed
Code:
class MyScript(tfs.onUse):
items = (123)
def action(self):
# Within 10 fields of creatureID 45554
if self.who.inRange(10, 45554):
self.attacker.addMana(200)
Code:
import tfs
class Script(tfs.onUse, tfs.onAttack, tfs.onAttackEnd)
items = (123) # the holy of holiest!
cache = {}
# Only triggered on use with item = 123
def onUse(self):
self.who.state("holy", 1)
# Triggered always when attacked, even if holy is not active
def onAttack(self):
if self.who.state("holy") and self.who.maxHealth() < 10000:
self.cache[self.who.id] = (self.who.maxHealth(), self.who.maxMana())
self.who.maxHealth(10000)
self.who.maxMana(10000)
self.who.regenHealth(3)
self.who,regenMana(3)
def onAttackEnd(self):
if self.who.state("holy") and self.who.maxHealth() == 10000:
self.who.regenHealth(1)
self.who.regenMana(1)
self.who.maxMana(self.cache[self.who.id][0])
self.who.maxMana(self.cache[self.who.id][1])
Last edited: