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

Post Reply 
 
Thread Rating:
  • 83 Vote(s) - 3.14 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Plugins API
Author Message
ClockMan Offline
All Mighty
*******

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

Global info
Plugins are created and started before user login, and (in future there will be able to use them as "auto login".
You can use menu options or command .pluginReload to reload some plugin for testing proposes for example.
All errors from plugin will show up in Loader Right Button -> Running Games -> Pid -> ... -> Logs.
Because some data isn't available all time, make use of functions: bool IsLogedIn(); and bool IsPaused();

If plugin name is in yellow color in menu = some error occurs.
First number in menu is number of found events in plugin.
Delete are events from file what you not using, it will make game faster.
Plugins work in main game thread, so if you will do there something what need lot of processor time, your game will hang, and thats why Sleep is not allowed.

Plugins have to be located in "plugins" subdirectory.

Functions what are NOT allowed to be used in plugin :
Sleep
MoveTo
MoveToF
UseSkill
TargetMe
TargetPet
Target
TargetNpc
Talk
WaitForTeleport
WaitForNewDialog
ClickLink
ClickText
ClickAndWait
Click

There will be added some replacement functions...
You still can create new thread in Lua and call that function from this thread like this:
    LUA Programming
CUseSkill = coroutine.create(
       function (skillId)
           UseSkill(skillId);
       end);
 
  coroutine.resume(CUseSkill, 2333);



Sample plugin:
    LUA Programming
function OnCreate()
	--Event called after plugin is loaded, you should setup here any default vars,
	--and register to any commands or [/b]other things.
end;
 
function OnDestroy()
	--Event called before plugin gets destroy, make sure you kill any threads what you created.
end;
 
function OnTick()
	--Event called very 100ms, you can use it to check anything, don't put lot of code here.
	--Event is called always, some data maybe unavaible when no user is logged in.
	--Also calling some functions can make game crash (or force you to diconnect).
end;
 
function OnLTick()
	--Event called very 100ms, you can use it to check anything, don't put lot of code here.
	--This event is called only if user is loged in.
end;
 
function OnTick500ms()
	--Event called very 500ms, you can use it to check anything, don't put lot of code here.
	--Event is called always, some data maybe unavaible when no user is logged in.
	--Also calling some functions can make game crash (or force you to diconnect).
end;
 
function OnLTick500ms()
	--Event called very 500ms, you can use it to check anything, don't put lot of code here.
	--This event is called only if user is loged in.
end;
 
function OnTick1s()
	--Event called very 1s, you can use it to check anything, don't put lot of code here.
	--Event is called always, some data maybe unavaible when no user is logged in.
	--Also calling some functions can make game crash (or force you to diconnect).
end;
 
function OnLTick1s()
	--Event called very 1s, you can use it to check anything, don't put lot of code here.
	--This event is called only if user is loged in.
end;
 
function OnLogin(username)
	--Event called after user login	
end;
 
function OnLogout()
	--Event called before user logout
end;
 
function OnAttackCanceled(user)
	--Event called when some player/npc cancel his attack.
end;
 
function OnAttack(user, target)
	--Event called when some player/npc attack other.
end;
 
function OnAttacked(user, target)
	--Event called when some player/npc attacked other.
end;
 
function OnAutoAttackStart(user, target)
	--Event called when some player/npc activate auto attack.
end;
 
function OnUserInfo(user)
	--Event called when we get some info about ourself
end;
 
function OnCharInfo(player)
	--Event called when we get some info about someother players (he spawn)
end;
 
function OnNpcInfo(npc)
	--Event called when we get some info about some npc/monster (he spawn)
end;
 
function OnDeleteUser(user)
	--Event called when some npc/player/user dissaper from map.
end;
 
function OnDie(user, spoiled)
	--Event called when some npc/player/user die.
end;
 
function OnRevive(user)
	--Event called when some npc/player/user revive.
end;
 
function OnMagicSkillCanceled(user)
	--Event called when some npc/player/user cancel magic skill.
end;
 
function OnMagicSkillLaunched(user, target, skillId)
	--Event called when some npc/player/user casted magic skill on someone other. 
	--For AOE skills this event will be called for every target.
end;
 
function OnMagicSkillUse(user, target, skillId)
	--Event called when some npc/player/user start cast magic skill on someone other. 
end;
 
function OnTargetSelected(user, target)
	--Event called when some npc/player/user select target.
end;
 
function OnMyTargetSelected(target)
	--Event called when our target got change.
end;
 
function OnTargetUnselected(user)
	--Event called when some npc/player/we cancel target.
end;
 
function OnChangeMoveType(user)
	--Event called when some npc/player/we change move type from walk to run for example.
end;
 
function OnChangeWaitType(user)
	--Event called when some npc/player/we change wait type from sit to stand for example.
end;
 
function OnChatUserMessage(chatType, nick, msg)
	--Event called someone say something on chat. chatType is a EChatType enum.
end;
 
function OnChatSystemMessage(id, msg)
	--Event called some system message show up on chat (id - integer, msg - string).
end;



Attached File(s)
.lua  sample.lua (Size: 3.93 KB / Downloads: 439)

[Image: owner.gif]
(This post was last modified: 05-01-2011 16:49 PM by ClockMan.)
05-01-2011 16:49 PM
Visit this user's website Find all posts by this user Quote this message in a reply
amiroooo Offline
Beta Tester

Posts: 1,270
Joined: Sep 2011
Reputation: 412
Version: 1.4.2.142
Post: #2
RE: Plugins API

if i try coroutine example on Target() I still get client crash.
    LUA Programming
CTarget = coroutine.create(
       function (objectid)
           Target(objectid);
       end);
 
  coroutine.resume(CTarget, TargetNewMob():GetId());

12-14-2011 18:10 PM
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
RE: Plugins API

since 1.4.1.67:

    LUA Programming
function OnCreate()
	this:RegisterCommand("ass", CommandChatType.CHAT_ALLY, CommandAccessLevel.ACCESS_ME);
end;
 
function OnCommand_ass(vCommandChatType, vNick, vCommandParam)
	ShowToClient("ass", vNick .. " typed command on chat " .. tostring(vCommandChatType) .. " and params count is " .. tostring(vCommandParam:GetCount()));
end;


[Image: owner.gif]
12-15-2011 19:31 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: Plugins API

//this thread is out of date,

details can be found in ScriptEditor Help

[Image: owner.gif]
12-25-2011 12:29 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
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
  Scripts & Plugins synax ClockMan 18 133,139 07-27-2013 01:13 AM
Last Post: OxenteBahia



User(s) browsing this thread: 1 Guest(s)