Hi,
which class start my class method when server start?
Start my class
Forum rules
READ NOW: L2j Forums Rules of Conduct
READ NOW: L2j Forums Rules of Conduct
-
- Posts: 151
- Joined: Wed Jan 04, 2012 7:10 pm
Re: Start my class
Actually, nothing calls your class method when server starts. Server doesn't even know about your classes.
Server calls its own methods, which ones you can use to run your classes. Or you can write own code in server core to force program to run desirable classes. But if you can do this you don't create such thread, yes?
There is a pretty notice in /game/data/scripts/cron/documentation.txt =)
So, if you aren't going to modify core (recompile the server) you can add some script, let say 'MyScript.java',to /game/data/scripts/cron/ directory and then insert this row to your gameserver database:
task - what to to. "stript" means to run one from /game/data/scripts/cron/
param1 - delay in milliseconds after server start. 1 means almost immediately after start
param2 - interval in milliseconds (or time of day like 12:00:00) for repeating the script. 0 means don't repeat anymore after first run.
param3 - script file name (in this case)
Server calls its own methods, which ones you can use to run your classes. Or you can write own code in server core to force program to run desirable classes. But if you can do this you don't create such thread, yes?
There is a pretty notice in /game/data/scripts/cron/documentation.txt =)
So, if you aren't going to modify core (recompile the server) you can add some script, let say 'MyScript.java',to /game/data/scripts/cron/ directory and then insert this row to your gameserver database:
Code: Select all
INSERT INTO `global_tasks` (`task`, `type`, `param1`, `param2`, `param3`) VALUES ('script', 'TYPE_FIXED_SHEDULED', '1', '0', 'MyScript.java');
param1 - delay in milliseconds after server start. 1 means almost immediately after start
param2 - interval in milliseconds (or time of day like 12:00:00) for repeating the script. 0 means don't repeat anymore after first run.
param3 - script file name (in this case)
-
- Posts: 22
- Joined: Sat Jun 29, 2013 4:55 pm
Re: Start my class
so... i need help wit code whi don't work?
so i just test update in mysql clan_level
i open example.java file in /server/game/data/script/corn and insert this code:
and insert to global_tasks
clan_level TYPE_FIXED_SHEDULED 0 1 100000 example.java
P.S i create clan in game and clan id 268484370
when i start server in mysql clan_data -> clan_level not update :s
so i just test update in mysql clan_level
i open example.java file in /server/game/data/script/corn and insert this code:
Code: Select all
package cron; import java.sql.Connection;import java.sql.PreparedStatement; import com.l2jserver.L2DatabaseFactory; public class example{ public static void main(String[] args) { try (Connection con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET clan_level=? WHERE clan_id=?")) { ps.setInt(1, 1); ps.setInt(2, 268484370); ps.execute(); } catch (Exception e) { } }}
clan_level TYPE_FIXED_SHEDULED 0 1 100000 example.java
P.S i create clan in game and clan id 268484370
when i start server in mysql clan_data -> clan_level not update :s
-
- Posts: 151
- Joined: Wed Jan 04, 2012 7:10 pm
Re: Start my class
kshysius123 wrote: and insert to global_tasks
clan_level TYPE_FIXED_SHEDULED 0 1 100000 example.java
The task column is not for custom values. Server doesn't know what to do for a task "clan_level"...Arantir wrote:task - what to to. "stript" means to run one from /game/data/scripts/cron/
Here is cut from the core:
Code: Select all
registerTask(new TaskBirthday()); registerTask(new TaskClanLeaderApply()); registerTask(new TaskCleanUp()); registerTask(new TaskDailySkillReuseClean()); registerTask(new TaskGlobalVariablesSave()); registerTask(new TaskJython()); registerTask(new TaskOlympiadSave()); registerTask(new TaskRaidPointsReset()); registerTask(new TaskRecom()); registerTask(new TaskRestart()); registerTask(new TaskScript()); registerTask(new TaskSevenSignsUpdate()); registerTask(new TaskShutdown());
The one runs your cron script is "script" task, as I had written in previous post.