Gender Check on NPC

Results 1 to 5 of 5
  1. #1
    Account Upgraded | Title Enabled! KerningCity is offline
    MemberRank
    Jan 2012 Join Date
    294Posts

    Gender Check on NPC

    I need to use this gender check:
    PHP Code:
    if(cm.getPlayer().isMale()) { 
    with this NPC script:
    PHP Code:
    /* NPC created by Stevie of Kerning City v83
    */
    var status;

    function 
    start() {
        
    status = -1;
        
    action(100);
    }

    function 
    action(modetypeselection) {
        if (
    mode == -1)
            
    cm.dispose();
        else {
            if (
    mode == 1)
                
    status++;
            else
                
    status--;
                
                if (
    status == 0) { 
                    
    cm.sendNext("You're grounded again! And this time, we're going to make sure that you're grounded #runtil you graduate from high school! #kThat's right, buster, you're going to be sitting in your room #bfor the next three years #kso you can figure out how to act like a normal person!");
                    } else if (
    status == 1) {
                    
    cm.sendNext("You guys are being so unreasonable! All I did was sneak out so I could see my #dgirlfriend #kbecause I love her so much!" ,3);
                    } else if (
    status == 2) {
                    
    cm.sendNext("We already told you that you #baren't allowed to even have a girlfriend! #kWhat do we have to do to get this information through your thick, stubborn skull? If #rforcing you to sit in your room for the next three years #kwill teach you a lesson, then you better believe that we aren't kidding around here!");
                    } else if (
    status == 3) {
                    
    cm.sendNext("Whatever, we'll see about that!" ,3);
                    } else if (
    status == 4) {
                    
    cm.sendOk("#eWhat the fuck did you just mutter under your breath? \r\n#nGet up to your room right now, and #rprepare yourself for a mighty beatdown #kin a few minutes to teach you not to talk back to us like that!");
                    } else if (
    status == 5) {
                    
    cm.warp(300010);
                    
    cm.dispose()
    }
    }

    and where it says:
    PHP Code:
    cm.sendNext("You guys are being so unreasonable! All I did was sneak out so I could see my #dgirlfriend #kbecause I love her so much!" ,3); 
    I need it to say boyfriend instead of girlfriend if I use else but this is all very confusing to me. Any help?


  2. #2
    Member Checkthisuzi is offline
    MemberRank
    Dec 2009 Join Date
    75Posts

    Re: Gender Check on NPC

    i would try using

    Code:
    if (cm.getChar().getGender() == 0)
    This, where 0 means male and 1 means female.

    this should work.


    The complete code updated with gender check:

    Code:
    /* NPC created by Stevie of Kerning City v83 
    */ 
    var status; 
    
    function start() { 
        status = -1; 
        action(1, 0, 0); 
    } 
    
    function action(mode, type, selection) { 
        if (mode == -1) 
            cm.dispose(); 
        else { 
            if (mode == 1) 
                status++; 
            else 
                status--; 
                 
                if (status == 0) {  
                    cm.sendNext("You're grounded again! And this time, we're going to make sure that you're grounded #runtil you graduate from high school! #kThat's right, buster, you're going to be sitting in your room #bfor the next three years #kso you can figure out how to act like a normal person!"); 
                    } else if (status == 1 && cm.getChar().getJob() == 0) { //Male
                    cm.sendNext("You guys are being so unreasonable! All I did was sneak out so I could see my #dgirlfriend #kbecause I love her so much!" ,3);
                    } else if (status == 1 && cm.getChar().getJob() == 1) { //Female 
                    cm.sendNext("You guys are being so unreasonable! All I did was sneak out so I could see my #dboyfriend #kbecause I love her so much!" ,3);  
                    } else if (status == 2 && cm.getChar().getJob() == 0) { 
                    cm.sendNext("We already told you that you #baren't allowed to even have a girlfriend! #kWhat do we have to do to get this information through your thick, stubborn skull? If #rforcing you to sit in your room for the next three years #kwill teach you a lesson, then you better believe that we aren't kidding around here!");
                    } else if (status == 2 && cm.getChar().getJob() == 1) { 
                    cm.sendNext("We already told you that you #baren't allowed to even have a boyfriend! #kWhat do we have to do to get this information through your thick, stubborn skull? If #rforcing you to sit in your room for the next three years #kwill teach you a lesson, then you better believe that we aren't kidding around here!"); 
                    } else if (status == 3) { 
                    cm.sendNext("Whatever, we'll see about that!" ,3); 
                    } else if (status == 4) { 
                    cm.sendOk("#eWhat the fuck did you just mutter under your breath? \r\n#nGet up to your room right now, and #rprepare yourself for a mighty beatdown #kin a few minutes to teach you not to talk back to us like that!"); 
                    } else if (status == 5) { 
                    cm.warp(30001, 0); 
                    cm.dispose() 
    } 
    } 
    }

    Please like if this code solves your problem! :)
    Last edited by Checkthisuzi; 13-01-13 at 10:46 PM.

  3. #3
    Account Upgraded | Title Enabled! KerningCity is offline
    MemberRank
    Jan 2012 Join Date
    294Posts

    Re: Gender Check on NPC

    This is the error I get:
    PHP Code:
    java.lang.reflect.UndeclaredThrowableException
            at $Proxy1
    .action(Unknown Source)
            
    at scripting.npc.NPCScriptManager.action(NPCScriptManager.java:91)
            
    at net.server.handlers.channel.NPCMoreTalkHandler.handlePacket(NPCMoreTa
    lkHandler
    .java:71)
            
    at net.MapleServerHandler.messageReceived(MapleServerHandler.java:129)
            
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.mess
    ageReceived
    (DefaultIoFilterChain.java:716)
            
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessage
    Received
    (DefaultIoFilterChain.java:434)
            
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(Def
    aultIoFilterChain
    .java:46)
            
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.mes
    sageReceived
    (DefaultIoFilterChain.java:796)
            
    at org.apache.mina.filter.codec.ProtocolCodecFilter$ProtocolDecoderOutpu
    tImpl
    .flush(ProtocolCodecFilter.java:427)
            
    at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(Prot
    ocolCodecFilter
    .java:245)
            
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessage
    Received
    (DefaultIoFilterChain.java:434)
            
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(Def
    aultIoFilterChain
    .java:46)
            
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.mes
    sageReceived
    (DefaultIoFilterChain.java:796)
            
    at org.apache.mina.core.filterchain.IoFilterAdapter.messageReceived(IoFi
    lterAdapter
    .java:119)
            
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessage
    Received
    (DefaultIoFilterChain.java:434)
            
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.fireMessageRece
    ived
    (DefaultIoFilterChain.java:426)
            
    at org.apache.mina.core.polling.AbstractPollingIoProcessor.read(Abstract
    PollingIoProcessor.java:715)
            
    at org.apache.mina.core.polling.AbstractPollingIoProcessor.process(Abstr
    actPollingIoProcessor
    .java:668)
            
    at org.apache.mina.core.polling.AbstractPollingIoProcessor.process(Abstr
    actPollingIoProcessor
    .java:657)
            
    at org.apache.mina.core.polling.AbstractPollingIoProcessor.access$600(Ab
    stractPollingIoProcessor
    .java:68)
            
    at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run
    (AbstractPollingIoProcessor.java:1141)
            
    at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnabl
    e
    .java:64)
            
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
            
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
            
    at java.lang.Thread.run(Unknown Source)
    Caused byjava.security.PrivilegedActionExceptionjavax.script.ScriptException
    sun.org.mozilla.javascript.internal.EcmaErrorTypeErrorCannot find function
     
    getChar in object scripting.npc.NPCConversationManager@2ef2be. (<Unknown source
    >#21) in <Unknown source> at line number 21
            
    at java.security.AccessController.doPrivileged(Native Method)
            
    at com.sun.script.util.InterfaceImplementor$InterfaceImplementorInvocati
    onHandler
    .invoke(Unknown Source)
            ... 
    25 more
    Caused by
    javax.script.ScriptExceptionsun.org.mozilla.javascript.internal.Ecm
    aError
    TypeErrorCannot find function getChar in object scripting.npc.NPCConve
    rsationManager
    @2ef2be. (<Unknown source>#21) in <Unknown source> at line number
    21
            at com
    .sun.script.javascript.RhinoScriptEngine.invoke(Unknown Source)
            
    at com.sun.script.javascript.RhinoScriptEngine.invokeFunction(Unknown So
    urce
    )
            
    at com.sun.script.util.InterfaceImplementor$InterfaceImplementorInvocati
    onHandler
    $1.run(Unknown Source)
            ... 
    27 more
    Caused by
    sun.org.mozilla.javascript.internal.EcmaErrorTypeErrorCannot find
     
    function getChar in object scripting.npc.NPCConversationManager@2ef2be. (<Unkno
    wn source
    >#21)
            
    at sun.org.mozilla.javascript.internal.ScriptRuntime.constructError(Unkn
    own Source
    )
            
    at sun.org.mozilla.javascript.internal.ScriptRuntime.constructError(Unkn
    own Source
    )
            
    at sun.org.mozilla.javascript.internal.ScriptRuntime.typeError(Unknown S
    ource
    )
            
    at sun.org.mozilla.javascript.internal.ScriptRuntime.typeError2(Unknown
    Source
    )
            
    at sun.org.mozilla.javascript.internal.ScriptRuntime.notFunctionError(Un
    known Source
    )
            
    at sun.org.mozilla.javascript.internal.ScriptRuntime.getPropFunctionAndT
    hisHelper
    (Unknown Source)
            
    at sun.org.mozilla.javascript.internal.ScriptRuntime.getPropFunctionAndT
    his
    (Unknown Source)
            
    at sun.org.mozilla.javascript.internal.Interpreter.interpretLoop(Unknown
     Source
    )
            
    at sun.org.mozilla.javascript.internal.Interpreter.interpret(Unknown Sou
    rce
    )
            
    at sun.org.mozilla.javascript.internal.InterpretedFunction.call(Unknown
    Source
    )
            
    at sun.org.mozilla.javascript.internal.ContextFactory.doTopCall(Unknown
    Source
    )
            
    at com.sun.script.javascript.RhinoScriptEngine$1.superDoTopCall(Unknown
    Source
    )
            
    at com.sun.script.javascript.RhinoScriptEngine$1.doTopCall(Unknown Sourc
    e
    )
            
    at sun.org.mozilla.javascript.internal.ScriptRuntime.doTopCall(Unknown S
    ource
    )
            
    at sun.org.mozilla.javascript.internal.InterpretedFunction.call(Unknown
    Source
    )
            ... 
    30 more
    Error
    NPC 9201003. UndeclaredThrowableException
    plus you wrote .GetJob instead of .GetGender

    FIXED IT, with your help!

    The correct gender check was actually:
    PHP Code:
    cm.getPlayer().getGender() == 
    not

    PHP Code:
    cm.getChar().getGender() == 
    and fixed it! Thanks a lot man.

  4. #4
    Ass > Tits Lapje is offline
    MemberRank
    Feb 2009 Join Date
    nullLocation
    1,879Posts

    Re: Gender Check on NPC

    Do thank me.

    PHP Code:
    /* NPC created by Stevie of Kerning City v83 
    */ 
    var status

    function 
    start() { 
        
    status = -1
        
    action(100); 


    function 
    action(modetypeselection) { 
        if (
    mode == -1
            
    cm.dispose(); 
        else { 
            if (
    mode == 1
                
    status++; 
            else 
                
    status--; 
        }
        if (
    status == 0) {  
            
    cm.sendNext("You're grounded again! And this time, we're going to make sure that you're grounded #runtil you graduate from high school! #kThat's right, buster, you're going to be sitting in your room #bfor the next three years #kso you can figure out how to act like a normal person!"); 
        } else if (
    status == 1) { 
            
    cm.sendNext("You guys are being so unreasonable! All I did was sneak out so I could see my #d" cm.getPlayer().getGender() == "girlfriend" "boyfriend" "#kbecause I love " cm.getPlayer().getGender() == "her" "him" "so much!"3); 
        } else if (
    status == 2) { 
            
    cm.sendNext("We already told you that you #baren't allowed to even have a " cm.getPlayer().getGender() == "girlfriend" "boyfriend" "#kWhat do we have to do to get this information through your thick, stubborn skull? If #rforcing you to sit in your room for the next three years #kwill teach you a lesson, then you better believe that we aren't kidding around here!"); 
        } else if (
    status == 3) { 
            
    cm.sendNext("Whatever, we'll see about that!" ,3); 
        } else if (
    status == 4) { 
            
    cm.sendOk("#eWhat the fuck did you just mutter under your breath? \r\n#nGet up to your room right now, and #rprepare yourself for a mighty beatdown #kin a few minutes to teach you not to talk back to us like that!"); 
        } else if (
    status == 5) { 
            
    cm.warp(300010); 
            
    cm.dispose() 
        } 

    Edit: Ninja'd. Only read that you fixed it after posting.

  5. #5
    Account Upgraded | Title Enabled! KerningCity is offline
    MemberRank
    Jan 2012 Join Date
    294Posts

    Re: Gender Check on NPC

    Quote Originally Posted by Lapje View Post
    Do thank me.

    PHP Code:
    /* NPC created by Stevie of Kerning City v83 
    */ 
    var status

    function 
    start() { 
        
    status = -1
        
    action(100); 


    function 
    action(modetypeselection) { 
        if (
    mode == -1
            
    cm.dispose(); 
        else { 
            if (
    mode == 1
                
    status++; 
            else 
                
    status--; 
        }
        if (
    status == 0) {  
            
    cm.sendNext("You're grounded again! And this time, we're going to make sure that you're grounded #runtil you graduate from high school! #kThat's right, buster, you're going to be sitting in your room #bfor the next three years #kso you can figure out how to act like a normal person!"); 
        } else if (
    status == 1) { 
            
    cm.sendNext("You guys are being so unreasonable! All I did was sneak out so I could see my #d" cm.getPlayer().getGender() == "girlfriend" "boyfriend" "#kbecause I love " cm.getPlayer().getGender() == "her" "him" "so much!"3); 
        } else if (
    status == 2) { 
            
    cm.sendNext("We already told you that you #baren't allowed to even have a " cm.getPlayer().getGender() == "girlfriend" "boyfriend" "#kWhat do we have to do to get this information through your thick, stubborn skull? If #rforcing you to sit in your room for the next three years #kwill teach you a lesson, then you better believe that we aren't kidding around here!"); 
        } else if (
    status == 3) { 
            
    cm.sendNext("Whatever, we'll see about that!" ,3); 
        } else if (
    status == 4) { 
            
    cm.sendOk("#eWhat the fuck did you just mutter under your breath? \r\n#nGet up to your room right now, and #rprepare yourself for a mighty beatdown #kin a few minutes to teach you not to talk back to us like that!"); 
        } else if (
    status == 5) { 
            
    cm.warp(300010); 
            
    cm.dispose() 
        } 

    Edit: Ninja'd. Only read that you fixed it after posting.
    I like your method better, it looks a lot neater instead of separating the checks. Thanks man!



Advertisement