Help in Scripting!

Joined
Mar 7, 2013
Messages
670
Reaction score
43
hi , I could help me as I can add a change of music in eventscript ?

i have this...

Code:
importPackage(java.lang);
importPackage(Packages.tools.packet);


[COLOR=#212121]
[/COLOR]function scheduledTimeout(eim,player) {

player.getClient().getSession().write(CField.musicChange("nameMusic"));


eim.broadcastPlayerMsg(6, "Music Change");


}



but cant work u.u , show message in console:

Code:
Event nameMYQUEST, Instance name : Quest142, method Name : scheduledTimeout:
javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: TypeError: Cannot call method "getClient" of undefined



need help, thank you :D
 
Thanks guys! :D



cant work guys

i use this:

Code:
function scheduledTimeout(eim) {


eim.changeMusic("Bgm00/Florallife"); 
}

and show this problem:


Code:
Event nameMIQUEST, Instance name : Quest142, method Name : scheduledTimeout:
javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: TypeError: Cannot find function changeMusic in object scripting.EventInstanceManager@59c9491. (<Unknown source>#123) in <Unknown source>

so i create the function in EventInstanceM

Code:
public void changeMusic(final MapleCharacter chr) {
         //"Bgm00/Florallife"
       chr.getClient().getSession().write(CField.musicChange(name));
    }

bump...
 
Last edited:
Upvote 0
dont work.... :c
Code:
Event nameMIQUEST, Instance name : Quest142, method Name : scheduledTimeout:
javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "CField" is not defined. (<Unknown source>#119)

use this:

Code:
function scheduledTimeout(eim) {
eim.broadcastPacket(CField.musicChange(Bgm08/PlotOfPixie));
}
 
Upvote 0
Code:
public void changeMusic(final MapleCharacter chr) {
         //"Bgm00/Florallife"
       chr.getClient().getSession().write(CField.musicChange(name));
    }

That will never ever work. Where is name comming from? You don't specify a var for text.

Code:
public void changeMusic(final MapleCharacter chr, String name) {
         //"Bgm00/Florallife"
       chr.getClient().getSession().write(CField.musicChange(name));
    }

followed by eim.changeMusic(chr, name);

also make sure you indeed import the proper packages. Why doesn't your compiler throw these issues?

EDIT as for doing it without an internal addition (the void musicChange) i think simply importing MapleCharacter in the script on your first post should do the trick... At least on java 7
 
Upvote 0
AbstractPlayerInteraction has:
PHP:
    public final void changeMusic(final String songName) {
        getPlayer().getMap().broadcastMessage(CField.musicChange(songName)); }
So you can use with npc/reactor/portal(cm/rm/pi).changeMusic("Bgm00/Florallife") because they extends AbstractPlayerInteraction but EventInstanceManager does not.

@Novak
Do you know what the differences are?
EventInstanceManager:
PHP:
    public final void changeMusic(final MapleCharacter chr, final String songName) {
        //chr.getClient().getSession().write(CField.musicChange(songName)); whats the difference?
        chr.getMap().broadcastMessage(CField.musicChange(songName)); }

Event Script:
1.
PHP:
importPackage(Packages.client.MapleCharacter);
function scheduledTimeout(eim) {
eim.changeMusic(chr, CField.musicChange("Bgm00/Florallife"));
eim.broadcastPlayerMsg(6, "Music Change"); }

Is better than these?
2.
PHP:
importPackage(Packages.client.MapleCharacter);
function scheduledTimeout(eim) {
        //chr.getClient().getSession().write(CField.musicChange("Bgm00/Florallife")); whats the difference?
        chr.getMap().broadcastMessage(CField.musicChange("Bgm00/Florallife"));
        eim.broadcastPlayerMsg(6, "Music Change"); }
3.
PHP:
function scheduledTimeout(eim) {
eim.broadcastPacket(CField.musicChange("Bgm00/Florallife"));
eim.broadcastPlayerMsg(6, "Music Change"); }

4. add "player"?
https://forum.ragezone.com/f566/help-scripting-1079480-post8502078/#post8502078 or?
4.1. add "player"?
PHP:
  public void timeOut(final long delay, final EventInstanceManager eim, final MapleCharacter player) {
...
em.getIv().invokeFunction("scheduledTimeout", eim, player); }

    public void restartEventTimer(long time, MapleCharacter player) {
        ...
            timeOut(time, this, player); }

    public void startEventTimer(long time, MapleCharacter player) {
        restartEventTimer(time, player); }
PHP:
function scheduledTimeout(eim, player) {
eim.changeMusic(player, CField.musicChange("Bgm00/Florallife"));
eim.broadcastPlayerMsg(6, "Music Change"); }

5. add "mapid"
PHP:
  public void timeOut(final long delay, final EventInstanceManager eim, final int mapid) {
...
em.getIv().invokeFunction("scheduledTimeout", eim, mapid); }

    public void restartEventTimer(long time, int mapid) {
        ...
            timeOut(time, this, mapid); }

    public void startEventTimer(long time, int mapid) {
        restartEventTimer(time, mapid); }
PHP:
function scheduledTimeout(eim, mapid) {
var map = eim.getMapInstance(mapid);
//or var map = getMap(eim);?
//or var map = em.getChannelServer().getMapFactory().getMap(mapid);?
map.broadcastMessage(CField.musicChange("Bgm00/Florallife"));
eim.broadcastPlayerMsg(6, "Music Change"); }
 
Last edited:
Upvote 0
Ok, i try when go my home n.n



hi,thanks for replys, when use import


Code:
[COLOR=#0000BB]importPackage[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]Packages[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]client[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]MapleCharacter[/COLOR][COLOR=#007700]);
[/COLOR]



have error when loading server...

i try use this:

Code:
function scheduledTimeout(eim,player) {
eim.changeMusic(player, "Bgm08/PlotOfPixie");
eim.broadcastPlayerMsg(6, "Music Change");
}
[COLOR=#007700]
[/COLOR]
 public final void changeMusic(final MapleCharacter chr, final String songName) {
        chr.getMap().broadcastMessage(CField.musicChange(songName));
    }

have this problem now:
Code:
Event nameMIQUEST, Instance name : Quest142, method Name : scheduledTimeout:
javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: Can't find method scripting.EventInstanceManager.changeMusic(sun.org.mozilla.javascript.internal.Undefined,string).
[COLOR=#007700]
[/COLOR]

 
Last edited:
Upvote 0
use this (as I mentioned)
Code:
importPackage(java.lang);
importPackage(Packages.tools.packet);

function scheduledTimeout(eim) {
    eim.broadcastPacket(CField.musicChange("Bgm08/PlotOfPixie"));
    eim.broadcastPlayerMsg(6, "Music Change");
}
I tested it and worked fine.

------
~~~
Code:
Event nameMIQUEST, Instance name : Quest142, method Name : scheduledTimeout:
javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: Can't find method scripting.EventInstanceManager.changeMusic(sun.org.mozilla.javascript.internal.[B]Undefined[/B],string).
[COLOR=#007700]
[/COLOR]
Of course you'll get this error because you haven't defined "MapleCharacter(player)".
Code:
function scheduledTimeout(eim[B],player[/B]) {
eim.changeMusic(player, "Bgm08/PlotOfPixie");
eim.broadcastPlayerMsg(6, "Music Change");
}
There is no
Code:
scheduledTimeout(eim[B],player[/B])
just
Code:
em.getIv().invokeFunction("scheduledTimeout", eim);
so if you want to do that, then you have to add "player"
Code:
em.getIv().invokeFunction("scheduledTimeout", eim[B], player[/B]);
Code:
  public void timeOut(final long delay, final EventInstanceManager eim[B], MapleCharacter player[/B]) {
 
Upvote 0
Thanks so much! work now! n.n



@Yuuroido

bro, how to use other method in maplecharacter, but example.

i have this method in maplecharacter

Code:
public void StageT(){
            if (getMonsterCount(getMapId())== 0) {
            //action...1
//but example show new message
               dropMessage(-1,"Hi i am action 1");
            } else {
               //action 2
             dropMessage(-1,"Sorry i am action 2");
            }
       
    }

use this??

Code:
function scheduledTimeout(eim) {


eim.broadcastPacket(StageT()); 


}

already use in npcConversation

cm.StageT();

and work fine n.n! but i dont know how to use in EventManager
 
Upvote 0
no, eim.broadcastPacket(); is only used for packet(bytes)
Code:
function scheduledTimeout(eim) {
    var players = eim.getPlayers();
    for (i = 0; i < players.size(); i++) {
        players.get(i).StageT();
    }
}

sorry if I am very confused , but never had encoded EventScript, i understand, but how to use this method in eventscript?
//MapleCharacter defined
public final void STAGE_Start(){
getMap().spawnMonsterOnGroudBelow(MapleLifeFactory.getMonster(9801016),new Point(88, 78));
}
 
Last edited:
Upvote 0
//MapleCharacter defined
public final void STAGE_Start(){
getMap().spawnMonsterOnGroudBelow(MapleLifeFactory.getMonster(9801016),new Point(88, 78));
}
...You really want to use it?
in eventscript
PHP:
function setup() {//depends on startInstance(EventManager)
    var eim = em.newInstance(/*eventName*/);
    var map = eim.setInstanceMap(/*mapID*/);//register the map to EventInstanceManager
    var mob = em.getMonster(9801016);//return MapleLifeFactory.getMonster(id)
    eim.registerMonster(mob);//register the monster to EventInstanceManager
    map.spawnMonsterOnGroudBelow(mob,new java.awt.Point(88, 78));
}
 
Last edited:
Upvote 0
AbstractPlayerInteraction has:
PHP:
    public final void changeMusic(final String songName) {
        getPlayer().getMap().broadcastMessage(CField.musicChange(songName)); }
So you can use with npc/reactor/portal(cm/rm/pi).changeMusic("Bgm00/Florallife") because they extends AbstractPlayerInteraction but EventInstanceManager does not.

@Novak
Do you know what the differences are?
EventInstanceManager:
PHP:
    public final void changeMusic(final MapleCharacter chr, final String songName) {
        //chr.getClient().getSession().write(CField.musicChange(songName)); whats the difference?
        chr.getMap().broadcastMessage(CField.musicChange(songName)); }

You mean the difference between
chr.getClient().getSession().write(CField.musicChange(songName));
and
chr.getMap().broadcastMessage(CField.musicChange(songName));
?

Since it's really simple, one grabs the player, finds the connected client that player belongs to, and sends this packet to just that client, meaning the music will only change for that 1 specific player.

The other will literrally broadcast, it get's the map the character is on, finds all the clients that have a character in that channel/world on that map, and broadcasts the packet to all of them. The result is music changing for all players on said map.

As for which one to use, that depends on what you want to achieve. Do you want everyone in the map to hear it? Or just one person? Most of the time in a event you'll just use the one that sends it to the entire map, picking out one character cab be a bit more annoying.
 
Upvote 0
Back