Page 1 of 1

Start my class

Posted: Mon Jul 08, 2013 7:37 am
by kshysius123
Hi,
which class start my class method when server start?

Re: Start my class

Posted: Mon Jul 08, 2013 9:54 am
by Arantir
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:

Code: Select all

INSERT INTO `global_tasks` (`task`, `type`, `param1`, `param2`, `param3`) VALUES ('script', 'TYPE_FIXED_SHEDULED', '1', '0', 'MyScript.java');
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)

Re: Start my class

Posted: Mon Jul 08, 2013 5:42 pm
by kshysius123
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:

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

Re: Start my class

Posted: Mon Jul 08, 2013 7:58 pm
by Arantir
kshysius123 wrote: and insert to global_tasks

clan_level TYPE_FIXED_SHEDULED 0 1 100000 example.java
Arantir wrote:task - what to to. "stript" means to run one from /game/data/scripts/cron/
The task column is not for custom values. Server doesn't know what to do for a task "clan_level"...
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());
Only these are supported.
The one runs your cron script is "script" task, as I had written in previous post.