Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Add-On]Lotto System

Newbie Spellweaver
Joined
Mar 17, 2010
Messages
48
Reaction score
13
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:
ALTER TABLE `characters` ADD COLUMN `lottonumber` int(11) NOT NULL DEFAULT '0';
Create Lotto.java class in Client:
PHP:
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(1, mesos+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(1, number);
            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:
import net.sf.odinms.client.Lotto;
Add in privates:
PHP:
private Lotto lott;
And add these:
PHP:
    public String didLotto() {
        return lott.didLotto();
    }

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

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

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

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

function action(mode, type, selection) {
    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() >= 1 && 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:
Junior Spellweaver
Joined
Jun 2, 2010
Messages
105
Reaction score
63
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.
 
Legendary Battlemage
Loyal Member
Joined
Dec 13, 2010
Messages
649
Reaction score
140
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...
 
Custom Title Activated
Loyal Member
Joined
Mar 17, 2009
Messages
1,911
Reaction score
538
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.
 
Newbie Spellweaver
Joined
Mar 13, 2011
Messages
17
Reaction score
12
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.
 
Newbie Spellweaver
Joined
Mar 12, 2011
Messages
11
Reaction score
3
Its a good job. I'm not a pro coder, but to me you're pretty good.

On-Topic: Great job. :)
 
Newbie Spellweaver
Joined
Mar 17, 2010
Messages
48
Reaction score
13
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 :)
 
Smoke & Fly
Loyal Member
Joined
Apr 21, 2008
Messages
1,190
Reaction score
76
This isn't new. Yours is completely different from the one i've seen so, good job.
 
Custom Title Activated
Loyal Member
Joined
Apr 29, 2008
Messages
1,297
Reaction score
509
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 :)
 
Newbie Spellweaver
Joined
Mar 17, 2010
Messages
48
Reaction score
13
pps
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 :)
Oops, you're right :) I forget about it. Fixed!
 
Back
Top