L2Tower Discord Let's keep the community alive with discord. Discussions about plugins and scripts L2Tower Discord

Post Reply 
 
Thread Rating:
  • 103 Vote(s) - 2.58 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scripts & Plugins synax
Author Message
ClockMan Offline
All Mighty
*******

Posts: 2,886
Joined: Jan 2011
Reputation: 499
Version: 1.4.3.143
Post: #1
Scripts & Plugins synax

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.

[Image: owner.gif]
(This post was last modified: 04-01-2011 09:08 AM by ClockMan.)
03-29-2011 09:27 AM
Visit this user's website Find all posts by this user Quote this message in a reply
ClockMan Offline
All Mighty
*******

Posts: 2,886
Joined: Jan 2011
Reputation: 499
Version: 1.4.3.143
Post: #2
Classes

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);
};

[Image: owner.gif]
(This post was last modified: 04-30-2011 17:35 PM by ClockMan.)
03-31-2011 17:26 PM
Visit this user's website Find all posts by this user Quote this message in a reply
ClockMan Offline
All Mighty
*******

Posts: 2,886
Joined: Jan 2011
Reputation: 499
Version: 1.4.3.143
Post: #3
Global functions

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;

[Image: owner.gif]
(This post was last modified: 04-07-2011 08:39 AM by ClockMan.)
03-31-2011 19:51 PM
Visit this user's website Find all posts by this user Quote this message in a reply
ClockMan Offline
All Mighty
*******

Posts: 2,886
Joined: Jan 2011
Reputation: 499
Version: 1.4.3.143
Post: #4
RE: Scripts & Plugins synax

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;
}


[Image: owner.gif]
04-30-2011 17:39 PM
Visit this user's website Find all posts by this user Quote this message in a reply
ClockMan Offline
All Mighty
*******

Posts: 2,886
Joined: Jan 2011
Reputation: 499
Version: 1.4.3.143
Post: #5
RE: Scripts & Plugins synax

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();
};


[Image: owner.gif]
(This post was last modified: 05-01-2011 14:45 PM by ClockMan.)
05-01-2011 14:44 PM
Visit this user's website Find all posts by this user Quote this message in a reply
ClockMan Offline
All Mighty
*******

Posts: 2,886
Joined: Jan 2011
Reputation: 499
Version: 1.4.3.143
Post: #6
RE: Scripts & Plugins synax

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


[Image: owner.gif]
05-01-2011 16:20 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Geddys Offline
Administrator
*******

Posts: 265
Joined: Dec 2010
Reputation: 89
Version: 1.4.1.93
Post: #7
RE: Scripts & Plugins synax

    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();

(This post was last modified: 06-12-2011 15:42 PM by Geddys.)
06-12-2011 15:38 PM
Find all posts by this user Quote this message in a reply
Sakaszli Offline
I'm too pro to be pro.
*******

Posts: 1,189
Joined: Jan 2011
Reputation: 484
Version: 1.4.2.134.5b
Post: #8
RE: Scripts & Plugins synax

    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;

(This post was last modified: 07-12-2011 21:02 PM by Sakaszli.)
06-15-2011 19:25 PM
Visit this user's website Find all posts by this user Quote this message in a reply
ClockMan Offline
All Mighty
*******

Posts: 2,886
Joined: Jan 2011
Reputation: 499
Version: 1.4.3.143
Post: #9
RE: Scripts & Plugins synax

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.

[Image: owner.gif]
06-15-2011 22:32 PM
Visit this user's website Find all posts by this user Quote this message in a reply
ClockMan Offline
All Mighty
*******

Posts: 2,886
Joined: Jan 2011
Reputation: 499
Version: 1.4.3.143
Post: #10
RE: Scripts & Plugins synax

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()
}


[Image: owner.gif]
(This post was last modified: 07-24-2011 19:02 PM by ClockMan.)
07-24-2011 19:02 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
Star help with multibox +tower scripts buybuy 2 4,421 11-13-2015 21:00 PM
Last Post: TheQQmaster
Rainbow GUIDE Very helpful to the beginners. [GUIDEs/ SCRIPTs/ PLUGINs] AStark 57 205,699 05-16-2015 11:08 AM
Last Post: krums
  How to Install Plugins? SinnedK 1 7,473 10-02-2013 08:46 AM
Last Post: l2syrena
Photo Error running Scripts samlong 0 3,586 03-30-2013 06:29 AM
Last Post: samlong
  Plugins API ClockMan 3 17,413 12-25-2011 12:29 PM
Last Post: ClockMan



User(s) browsing this thread: