Lineage 2 Tower Forum

Full Version: Scripts & Plugins synax
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
All scripts and plugins base on Lua language.

Language is simple but for people who know something about programing allow to use other things (like classes, other extensions...)
Lua is language used for making extensions to games, program AI (In WoW, GTA for example.).

Why Lua ? Hmm, it's fast, easy to integrate, works, and lot of people know it.

Links:

  1. http://www.lua.org/manual/5.1/
  2. http://www.rasterbar.com/products/luabind/docs.html
  3. http://lua-users.org/wiki/TutorialDirectory
  4. http://luatut.com/
  5. http://www.ac-web.org/forums/showthread.php?t=70966
  6. http://lua.gts-stolberg.de/en/
  7. http://cpp0x.pl/forum/temat/?id=904

To start create folder named "scripts" in L2Tower directory. And create file *.lua.

Example of script:

Use CH BSOE when HP go lower than 5%.
Code:
repeat
Sleep(100);
until GetMe():GetHpPrecent()<5.0;

if (GetMe():IsAlikeDeath() == false) then
    UseItem(5858);
end;
ShowToClient("Script", "Ups, you have low HP");

Important: Every function listed here what returns * (pointer) to something. Like GetTarget(), may return NULL (nil in lua). GetMe will never return NULL Tongue.
FVector:
Code:
class FVector
{
    float X, Y, Z;
    
    FVector();
    FVector(float X, float Y, float Z);
    bool IsNonZero();
};

L2Buff:
Code:
class L2Buff
{
  enum L2BuffType type;
  int skillId;
  int skillLvl;
  unsigned __int64 endTime;
  unsigned char index;

  bool IsValid() const;
};

User:
Code:
class User {
  const L2Buff* GetBuff(int skillId) const;
  bool GotBuff(int skillId) const;
  bool IsValid();
  bool IsPlayer();
  bool IsMyPartyMember();
  bool IsFriend();
  bool IsMe();
  bool IsNpc();
  bool IsMyClanMember();
  bool IsMyClanMemberMaster();
  bool IsMyAllianceMember();
  bool IsWalking();
  bool IsSiting();
  bool IsEnemy();
  bool IsPvPFlag();
  bool IsPvPFlagBlink();
  bool IsAlikeDeath();
  bool IsSpoiled();
  bool IsPet();
  bool IsMyPet();
  bool IsSummon();
  bool IsPetOrSummon();
  bool IsAttacking();
  bool WasAttacked();
  long GetId();
  FVector GetLocation();
  int GetHp();
  int GetMp();
  int GetCp();
  int GetMaxHp();
  int GetMaxMp();
  int GetMaxCp();
  double GetHpPrecent();
  double GetMpPrecent();
  double GetCpPrecent();
  int GetLevel();
  int GetPenaltyLevel();
  int GetSoulLevel();
  L2Race GetRace();
  int GetStatSTR();
  int GetStatDEX();
  int GetStatCON();
  int GetStatINT();
  int GetStatMEN();
  int GetStatWIT();
  int GetNpcId();
  string GetName();
  string GetNickName();
  int GetWeightLimit();
  int GetWeight();
  double GetWeightPrecent();
  int GetStatAccuracy();
  int GetStatCriticalRate();
  int GetStatPhysicalAttack();
  int GetStatAttackSpeed();
  int GetStatPhysicalDefense();
  int GetStatEvasion();
  int GetStatMagicAttack();
  int GetStatMagicDefense();
  int GetStatCastingSpeed();
  int GetClanId();
  int GetClanCrestId();
  int GetAllianceId();
  int GetAllianceCrestId();
  long GetTarget();
  L2Class GetClass();
  string GetMasterName();
  FVector GetDestinationLocation();
  bool IsBlocked(bool incStun);
  long GetPetId();
  long GetMasterId();
  bool IsUsingMagic();
  bool IsUsingBow();
  bool CanSeeMe();
  float GetRangeTo(User *player);
  int GetMonsterTargetCount();
  string GetMasterName();
};



ItemList:
Code:
class ItemList
{
  int maxCount;
  int count;
  list list;

  Item* FindById(int id);
  Item* FindByDisplayId(int id);
};

Skill:
Code:
class Skill
{
  int skillId;
  short skillLvl;
  bool isPassive;        
  string name;
  string description;
  int operTyp;
  int mpConsume;
  int hpConsume;
  int castRange;
  int castStyle;
  double hitTime;
  bool isMagic;

  bool IsSkillAvailable();
  bool CanBeUsed();
};

SkillList:
Code:
class SkillList
{
  int count;
  list<Skill> list;

  Skill* FindById(int id);
};

UserList:
Code:
class UserList
{
   list list;
  
   User* GetByName( const string name );
   User* GetByTitle( const string name );
   int GetCount();
};

Script:
Code:
class Script
{
  void Stop();
  string GetFilename();
  string GetParams();
  bool Log(const string &log);

  void Pause(); //pause script, user need to resume it in html window or with .scriptResume command.
};

HtmlLink:
Code:
class HtmlLink
{
  bool isButton;
  bool isTeleport;
  string text;
  string link;
};

HtmlDialog:
Code:
class HtmlDialog
{
  HtmlDialog();

  string GetHtml();
  string GetLinkForText(const string &title);
  string GetTextForLink(const string &link);

  list links;

  void Update();
  bool HaveLink(const string &link);
};
Utils:
Code:
void Sleep(int time_in_ms);
string L2Race2String(L2Race race);
string L2Class2String(L2Class class);
int GetDistanceInt(int X1, int Y1, int Z1, int X2, int Y2, int Z2);
float GetDistanceFloat(float X1, float Y1, float Z1, float X2, float Y2, float Z2);
float GetDistanceVector(const FVector &v1, const FVector &v2);
unsigned __int64 GetTime();

Commands:
Code:
bool Command(string command);
bool ShowToClient(string name, string text);
bool SendPM(string nick, string text);
bool MoveToNoWait(const FVector &to);
bool MoveToNoWaitF(float X, float Y, float Z);
bool MoveToNoWait(int X, int Y, int Z);
bool MoveTo(const FVector &to, int distance);
bool MoveToF(float X, float Y, float Z, int distance);
bool MoveTo(int X, int Y, int Z, int distance);
bool Action(L2NpcAction action, bool withShift, bool withCtrl);
bool Attack(const int Id, bool withShift);
bool CancelTarget(bool cancelSkillCast);
bool QuestReply (string reply);
bool UseItem(int displayId, int objectId);
bool UseItem(int displayId);
bool UsePetItem(int displayId, int objectId);
bool UsePetItem(int displayId);
bool UseSkill(int skillId, bool shift, bool ctrl);
bool UseSkill(int skillId);
bool TargetMe();
bool TargetPet();
bool Target(int objectId);
bool Target(const User* user);
bool Target(const string &nick);
bool TargetNpc(const string name, int id); //only one needed
void ClearTarget();
void ClearTargets();
bool Talk();
string GetDialogHtml(); // you can use also HtmlDialog object.
bool Click(string link, string text);
bool ClickAndWait(string link, string text);
bool ClickLink(string link);
bool ClickText(string text);
bool ProcessCommand(string command); //internal command call (only l2tower commands)
void WaitForTeleport();
void WaitForNewDialog();
bool PlaySound(string wavFile);

Data access (Inventory, Skills):
You need to know that those functions will return "snapshot" of data.
To get new data you need to call them again.
Code:
ItemList* GetInventory();
ItemList* GetPetInventory();
ItemList* GetPrivateWarehouse();
ItemList* GetClanWarehouse();
ItemList* GetCastleWarehouse();
ItemList* GetEtcWarehouse();
SkillList* GetSkills();

Global info:
Code:
ZoneType GetZoneType();
bool IsLogedIn();
string GetDir();
bool IsPaused();

Data access (Users):
Code:
UserList& GetPlayerList();
UserList& GetNpcList();
UserList& GetPetList();
UserList& GetPartyList();
UserList& GetMonsterList();

User* GetMe();
User* GetPet();
User* GetTarget();
User* GetPartyMaster();

User* GetUserById(int id);
User* GetUserByName(string name);

Globals:
Code:
Script this;
Updated Item class:

    C++ Programming
class Item  {
			public:
			   int objectId;
			   int displayId;
			   string Name;
			   string AdditionalName;
			   string IconName;
			   string IconNameEx1;
			   string IconNameEx2;
			   string IconNameEx3;
			   string IconNameEx4;
			   string ForeTexture;
			   string Description;
			   string DragSrcName;
			   string IconPanel;
			   string MacroCommand;
			   int ItemType;
			   int ItemSubType;
			   __int64 ItemNum;
			   __int64 Price;
			   int Level;
			   int SlotBitType;
			   int Weight;
			   int MaterialType;
			   int WeaponType;
			   int PhysicalDamage;
			   int MagicalDamage;
			   int PhysicalDefense;
			   int MagicalDefense;
			   int ShieldDefense;
			   int ShieldDefenseRate;
			   int Durability;
			   int CrystalType;
			   int RandomDamage;
			   int Critical;
			   int HitModify;
			   int AttackSpeed;
			   int MpConsume;
			   int ArmorType;
			   int AvoidModify;
			   int Damaged;
			   int Enchanted;
			   int MpBonus;
			   int SoulshotCount;
			   int SpiritshotCount;
			   int PopMsgNum;
			   int BodyPart;
			   int RefineryOp1;
			   int RefineryOp2;
			   int CurrentDurability;
			   int CurrentPeriod;
			   __int64 DefaultPrice;
			   int ConsumeType;
			   int Blessed;
			   __int64 AllItemCount;
			   int IconIndex;
			   bool IsEquipped;
			   bool IsRecipe;
			   bool IsArrow;
			   bool IsShowCount;
			   bool IsDisabled;
			   bool IsLock;
			   int AttackAttributeType;
			   int AttackAttributeValue;
			   int DefenseAttributeValueFire;
			   int DefenseAttributeValueWater;
			   int DefenseAttributeValueWind;
			   int DefenseAttributeValueEarth;
			   int DefenseAttributeValueHoly;
			   int DefenseAttributeValueUnholy;
			   int RelatedQuestCnt;
			   int RelatedQuestID[10];
			   int IsBRPremium;
}

1.3:
New global vars (names of images for use in html):
    LUA Programming
HTML_BUTTON_ACTIVE
HTML_BUTTON_NONACTIVE
HTML_BUTTON
HTML_BUTTON_EXTRA_ON
HTML_BUTTON_EXTRA_OFF
HTML_BUTTON_ACTION_ON
HTML_BUTTON_ACTION_OFF
HTML_NEXT_ARROW_UP
HTML_NEXT_ARROW_DOWN
HTML_BACK_ARROW_UP
HTML_BACK_ARROW_DOWN
HTML_MAIN_MENU
HTML_REFRESH
HTML_TAB
HTML_TAB_DOWN
HTML_DELETE
HTML_UP
HTML_DOWN
HTML_PLUS



    C++ Programming
enum HtmlButtonStyle
{
	BUTTON_CUSTOM,
	BUTTON_NO_CLICK,
	BUTTON_ON_OFF,
	BUTTON_EXTRA,
	BUTTON_ACTION,
	BUTTON_TAB
};



    C++ Programming
class HtmlAction
{	
  public:
	HtmlAction(const string &command);
	HtmlAction& AddParam(int param);
	HtmlAction& SetParam(int index, int param);
	string GetAction() const;
	HtmlAction& AddParam(const string &param, bool var);
	HtmlAction& AddParam(const string &param);
	HtmlAction& SetParam(int index, const string &param);
};



    C++ Programming
class HtmlGenerator
{
public:
	HtmlGenerator(const std::wstring &title, bool noPrefix = false);
 
	std::wstring GetString();
 
	void AddButton(const HtmlAction &action, HtmlButtonStyle style, const string& title, 
	bool pressed, const string& msg, const string& img, int width, int height);
	void AddButton(const HtmlAction &action, HtmlButtonStyle style, const int title,
	bool pressed, const string& msg,  const string& img, int width, int height);
	void AddLink(const HtmlAction &action, const string& text, const string& msg);
	void AddLink(const HtmlAction &action, const int text, const string& msg);
	void AddEdit(const string& name, bool isNumber,  int width, int height);
	void AddComboBox(const string& name,  const std::vector<std::wstring> &data, 
	const string& value,  int width, int height);
	void AddMultiEdit(const string& name, int width, int height);
	void AddImage(const string& name, int width, int height);
	void AddHtml(const string& html);
	void Table_Start(bool autoCell, bool rowBreak, int width = 270);
	void Table_SetupPageSpliter(HtmlAction &baseAction, int actionParamIndex, 
	int page, int count, int emptyRowHeight, bool emptyRow, 
	bool allwaysIncludeArrows);
	void Table_End();
	void Table_EndCell();
	void Table_EndRow();
	void Table_AddColumn(int width = 0);
	void Table_AddColumns(int count);
	void AddLine(bool isUp);
	void AddNewLine();
	void AddEmpty();
};

    C++ Programming
class Plugin
{
 public:
  bool IsActive();
  bool GetFileName();
  bool Log(const string &log)
];

    C++ Programming
class Enchant
{
public:
	void setEnchantId(long id);
	long getEnchantId();
 
	void setItemId(long id);
	long getItemId();
 
	void setAuxiliaryStoneId(long id);
	long getAuxiliaryStoneId();
 
	int Enchant();
 
	EnchantResult getLastResult();
 
	void setDelay(long delay);
	long getDelay();
};
 
enum EnchantResult
{
	ENCHANT_NONE,
	ENCHANT_PENDING,
	ENCHANT_SUCCESS,
	ENCHANT_FAILURE,
	ENCHANT_ERROR
};
 
Enchant* GetEnchantManager();

    C++ Programming
CrystallizeItem(int ObjectID);
DeleteItem(int ObjectID,int Amount);



Example:

    LUA Programming
function getItemByName(name)
	invList = GetInventory();
	for item in invList.list do
		if item.Name == name then
			return item.objectId;
		end;
	end;
end;
 
weapon = getItemByName("Adena");
DeleteItem(weapon,100);



===================================================================
===================================================================
    C++ Programming
CraftItem(int recipeID) //RecipeID u can get from recipe-c.dat (use l2fileedit)



Example:

    LUA Programming
function getItemByName(name)
	invList = GetInventory();
	for item in invList.list do
		if item.Name == name then
			return item.ItemNum
		end
	end
return 1;
end
 
while (getItemByName('Varnish') > 4) and (getItemByName('Iron Ore') > 4)  do
CraftItem(30); --steel recipe id / recipe mast exist!!
Sleep(400);    --anty-kick
end;

From .35 all our script functions/classes/methods will be moved to l2tower lib.
So in script you will have to call it like l2tower.GetInventory();
It's needed because there are some other native functions and I don't want mess with them.
Added to User class in 1.4:
    LUA Programming
enum L2ClanRank
	{
                RANK_VAGABOND				= 0,
		RANK_VASSAL					= 1,
		RANK_HEIR					= 2,
		RANK_KNIGHT					= 3,
		RANK_ELDER					= 4,
		RANK_BARON					= 5,
		RANK_VISCOUNT				= 6,
		RANK_COUNT					= 7,
		RANK_MARQUIS				= 8,
		RANK_DUKE					= 9,
		RANK_GRAND_DUKE				= 10,
		RANK_DISTINGUISHED_KING		= 11
	};
 
class FRotator
{
 int Pitch; --Looking up and down (0=Straight Ahead, +Up, -Down).
 int Yaw;   --Rotating around (running in circles), 0=East, +North, -South.
 int Roll;  --Rotation about axis of screen, 0=Straight, +Clockwise, -CCW.
}
 
class User {
...
int GetUserType()   --user type, 0 - player, 1 - npc
int GetSummonType() --summon type, 1 - pet/sevitor
int GetNpcType() --npc type, 0 - npc, 1 - monster
int GetGenderId() --sex, 0 - male, 1 - female
__int64 GetEXP()
int GetMeleAttackRange()
int GetEquip_UnderwearId()
int GetEquip_RightEarringId()
int GetEquip_LeftEarringId()
int GetEquip_NecklaceId()
int GetEquip_LeftRingId()
int GetEquip_RightRingId()
int GetEquip_HelmId()
int GetEquip_TwoHandedWeaponId()
int GetEquip_Unknown1Id()
int GetEquip_Unknown2Id()
int GetEquip_Unknown3Id()
int GetEquip_BraceletId()
int GetEquip_AgationId()
int GetEquip_Talizman1Id()
int GetEquip_Talizman2Id()
int GetEquip_Talizman3Id()
int GetEquip_Talizman4Id()
int GetEquip_Talizman5Id()
int GetEquip_Talizman6Id()
int GetEquip_BeltId()
int GetEquip_GlovesId()
int GetEquip_BodyUpId()
int GetEquip_BodyDownId()
int GetEquip_BootsId()
int GetEquip_CloakId()
int GetEquip_Accessory1Id()
int GetEquip_Accessory2Id()
int GetEquip_WeaponId()
int GetEquip_ShieldId()
int GetTitleColor()
int GetKarma()
int GetRunSpeed()
int GetWalkSpeed()
int GetSwimRunSpeed()
int GetSwimWalkSpeed()
int GetFlRunSpeed()
int GetFlWalkSpeed()
int GetFlyRunSpeed()
int GetFlyWalkSpeed()
int GetSP()
int GetShopStatus()
int GetPKCount()
int GetPvPCount()
L2User_Class GetSubClass()
short GetEvalPointsLeft()
short GetEvalPoints()
short GetInventoryLimit()
int GetWeaponEnchantLevel()
int GetDuelTeam()
bool IsHero()
bool IsNobles()
int GetNickColor()
L2User_ClanRank GetClanRank()
int GetHeadAccessoryId()
int GetMasterId2()
int GetTransformId()
short GetAttribute_AttackType()
short GetAttribute_AttackValue()
short GetAttribute_DefenseFireValue()
short GetAttribute_DefenseWaterValue()
short GetAttribute_DefenseWindValue()
short GetAttribute_DefenseEarthValue()
short GetAttribute_DefenseHolyValue()
short GetAttribute_DefenseUnHolyValue()
bool HasBootsSound()
int GetFlameRestrain()
int GetFlame()
int GetVitality()
int GetTalismanNum()
FVector GetOldLocation()
FVector GetColLocationn()
FVector GetVelocity()
FVector GetAcceleration()
FRotator GetRotation()
}

Pages: 1 2
Reference URL's