[Add-On]Lotto System

Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Account Inactive denisp2 is offline
    InactiveRank
    Mar 2010 Join Date
    66Posts

    [Add-On]Lotto System

    [Add-On]Lotto System
    I'm not a pro coder, but check it out. I made that lotto system yesterday. You may fix my mistakes, and suggest things.
    I didn't check that but someone told me that it works.
    *** I dont care if you dont like my way, I care if it's wrong.
    Run in MySql:
    PHP Code:
    ALTER TABLE `charactersADD COLUMN `lottonumberint(11NOT NULL DEFAULT '0'
    Create Lotto.java class in Client:
    PHP Code:
    package net.sf.odinms.client;

    import java.sql.ResultSet;
    import java.sql.SQLException;
    import net.sf.odinms.database.DatabaseConnection;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import net.sf.odinms.net.MaplePacket;
    import net.sf.odinms.tools.MaplePacketCreator;
    /**
     *
     * @author Avishay - denisp2
     */
    public class Lotto {
    MapleCharacter player;
    private 
    int lottonu;
    private 
    int didwon;
    boolean win false;

        public 
    void makeZero() {
            try {
                
    Connection con DatabaseConnection.getConnection();
                
    PreparedStatement ps con.prepareStatement("UPDATE characters SET lottonumber=0  where lottonumber>0");
                
    ResultSet rs ps.executeQuery();
                while(
    rs.next())
                {
                
    ps.executeUpdate();
                
    ps.close();
                }
            }
            catch (
    SQLException ch)
            {
            }
        }
        public 
    void generateWinner() {
                    try {
                        
    int players 0;
                        
    int lottowin = (int) Math.random()*500+1;
                        
    String name "";
                
    Connection con DatabaseConnection.getConnection();
                
    PreparedStatement ps con.prepareStatement("SELECT name,lottonumber,mesos FROM characters  where lottonumber>=0");
                
    ResultSet rs ps.executeQuery();
                while(
    rs.next())
                {
                                
    players++;
                                
    lottonu rs.getInt("lottonumber");
                                if (
    lottonu == lottowin) {
                                    
    win true;
                                    
    name rs.getString("name");
                                    
    int mesos rs.getInt("mesos");
                                     
    int prize = (int) Math.random()*150000000+9999999;
                                    
    MaplePacket packet MaplePacketCreator.serverNotice(6"Congrats! "+name+" has won " prize " Mesos in the lottery!");
                                    
    PreparedStatement ps con.prepareStatement("UPDATE characters WHERE mesos = ?");
                                                
    ps.setInt(1mesos+prize);
                                                
    ps.executeUpdate();
                                                
    ps.close();
                            }
                        if (
    win == false) {
                            
    MaplePacket packet MaplePacketCreator.serverNotice(6"Nobody has won in the lottery, Dont worry! Maybe you will be the winner next time :)");
                        }
                     
    win false;
            }
            }
                catch (
    SQLException lol)
                    {
                }
        }
        public 
    void sumbitLotto(int number) {
            try {
                
    Connection con DatabaseConnection.getConnection();
                
    PreparedStatement ps con.prepareStatement("UPDATE characters SET Lotto = ?");
                
    ps.setInt(1number);
                
    ps.executeUpdate();
                
    ps.close();
            }
            catch (
    SQLException bz)
            {
            }
        }
        public 
    String didLotto() {
             
    String did "";
            try {
                
    Connection con DatabaseConnection.getConnection();
                
    PreparedStatement ps con.prepareStatement("SELECT lottonumber FROM characters");
                
    ResultSet rs ps.executeQuery();
                if (
    rs.getInt("lottonumber") >= 1) {
                    
    did "yes";
                } else {
                    
    did "no";
                }
            }
                    catch (
    SQLException bz)
            {
            }
            return 
    did;
        }

    Add import in NPCConversationManager:
    PHP Code:
    import net.sf.odinms.client.Lotto
    Add in privates:
    PHP Code:
    private Lotto lott
    And add these:
    PHP Code:
        public String didLotto() {
            return 
    lott.didLotto();
        }

        public 
    void sumbitLotto(int number) {
            
    lott.sumbitLotto(number);
        } 

    Add in your gm commands:
    PHP Code:
            } else if(splitted[0].equals("!lotto")) {
                
    lott.generateWinner();
                
    lott.makeZero(); 
    And don't forget the import:
    PHP Code:
    import net.sf.odinms.client.Lotto
    Add in privates:
    PHP Code:
    private Lotto lott

    If there's long list in your file, then add this:
    PHP Code:
                new CommandDefinition("lotto"3), 
    And now, the NPC:
    PHP Code:
    var status 0;

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

    function 
    action(modetypeselection) {
        if (
    mode == -1) {
            
    cm.dispose();
            }
            if (
    mode == 1)
                
    status++;
            else
                
    status--;
            if (
    status == 0) {
            if(
    cm.didLotto() == "no") {
                
    cm.sendGetText("#eHey I'm the lotto NPC in that server :)/r/nIf you want to join to the next lotto, chosse a number between #r1-1000#k ***Make sure you have 10K***");
            } else {
            
    cm.sendOk("#eI see that you already sumbitted your lotto this time, Try again later!");
            
    cm.dispose();
            }
            } else if (
    status == 1) {
                if(
    cm.getText() >= && cm.getText() <= 1000) {
                if(
    cm.getMeso() >= 10000) {
                    
    cm.sumbitLotto(cm.getText());
                    
    cm.sendOk("Thanks! Your number sumbitted!");
                } else {
                
    cm.sendOk("#eDude you don't have 10K...");
                
    cm.dispose();
                } else {
                    
    cm.sendOk("#eMake sure you choosed number between 1-1000");
                    
    cm.dispose();
                }
                
    cm.dispose();
            }
        }

    And that's all! :)
    Credit to me.
    Last edited by denisp2; 15-03-11 at 04:47 PM. Reason: Fixing


  2. #2
    Account Inactive Aprentice is offline
    InactiveRank
    Feb 2011 Join Date
    MarylandLocation
    28Posts

    re: [Add-On]Lotto System

    fANTASTIC jOB.

  3. #3
    return null; mertjuh is offline
    True MemberRank
    Dec 2008 Join Date
    The NetherlandsLocation
    1,269Posts

    re: [Add-On]Lotto System

    Hmm, Lotto

  4. #4
    Account Inactive denisp2 is offline
    InactiveRank
    Mar 2010 Join Date
    66Posts

    re: [Add-On]Lotto System

    Quote Originally Posted by mertjuh View Post
    Hmm, Lotto
    I made another one, it's not the same

  5. #5
    You'll never know what th AskHugo is offline
    True MemberRank
    Jun 2010 Join Date
    The InternetLocation
    234Posts

    re: [Add-On]Lotto System

    Yeah, you're right. Your Lotto system is completely different. Good work!

    By the way, in netbeans you can just do ctrl + shift + i to fix imports. No need to manually add them in.

  6. #6
    Why you look? johnnyrocks is offline
    True MemberRank
    Nov 2007 Join Date
    393Posts

    re: [Add-On]Lotto System

    They have different methods so I can't complain :)

  7. #7
    Alpha Member Soulfist is offline
    Alpha MaleRank
    Dec 2010 Join Date
    a hovelLocation
    1,835Posts

    re: [Add-On]Lotto System

    I actually thinks its pretty good, since your not a pro coder. But your right, it isnt THAT hard to do.


    @First Poster


    This isnt that spectacular, geez, overreacting much...

  8. #8
    Interesting... SharpAceX is offline
    Alpha MaleRank
    Oct 2008 Join Date
    2,009Posts

    re: [Add-On]Lotto System

    The coding seems solid. I'd have to say good job on this because this isn't another repack or CMS.

    Some screens would be nice though.

  9. #9
    Gamma Sparrow is offline
    GammaRank
    Mar 2009 Join Date
    SydneyLocation
    2,960Posts

    re: [Add-On]Lotto System

    Looks great, good job! I'd love to see screenshots. If I use this when I make my server I'll make an auto event script for it.

  10. #10
    Account Inactive xPerpetual is offline
    InactiveRank
    Mar 2011 Join Date
    17Posts

    re: [Add-On]Lotto System

    I doubt this will work properly, using SQL to change the lotto numbers and giving meso to the winner won't work for the players that are online atm.
    and you have a mistake here:
    Code:
    PreparedStatement pss = con.prepareStatement("UPDATE characters WHERE mesos = ?");
                                                ps.setInt(1, mesos+prize);
    You called the preparedstatement pss and changed the Integer for ps.

  11. #11
    Account Inactive TheTestCoder is offline
    InactiveRank
    Mar 2011 Join Date
    34Posts

    re: [Add-On]Lotto System

    Its a good job. I'm not a pro coder, but to me you're pretty good.

    On-Topic: Great job. (:

  12. #12
    Account Inactive denisp2 is offline
    InactiveRank
    Mar 2010 Join Date
    66Posts

    re: [Add-On]Lotto System

    Thanks for the comments guys! I dont have own server, so I need someone to check it XD
    Soon I will get new computer and I will create my own server :)

  13. #13
    Smoke & Fly Kars is offline
    GammaRank
    Apr 2008 Join Date
    The NetherlandsLocation
    3,383Posts

    re: [Add-On]Lotto System

    This isn't new. Yours is completely different from the one i've seen so, good job.

  14. #14
    Account Inactive anitawu is offline
    InactiveRank
    Feb 2011 Join Date
    25Posts

    re: [Add-On]Lotto System

    Thanks for your sharing ~~

  15. #15
    Gamma Xerixe is offline
    GammaRank
    Apr 2008 Join Date
    MalaysiaLocation
    3,605Posts

    Re: [Add-On]Lotto System

    Imo, you should make a check if they have max mesos or not, otherwise it'll just make their mesos go "negative".

    Also, shouldn't this
    Code:
    MaplePacket packet = MaplePacketCreator.serverNotice(6, "Congrats! "+name+" has won 50 Mesos in the lottery!");
    be

    Code:
    MaplePacket packet = MaplePacketCreator.serverNotice(6, "Congrats! "+name+" has won " + prize + " Mesos in the lottery!");
    But anyway, nice release (:
    “To live is the rarest thing in the world. Most people exist, that is all.”



Page 1 of 2 12 LastLast

Advertisement