- 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 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:
Create Lotto.java class in Client:
Run in MySql:
PHP:
ALTER TABLE `characters` ADD COLUMN `lottonumber` int(11) NOT NULL DEFAULT '0';
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:
And add these:
PHP:
import net.sf.odinms.client.Lotto;
Add in privates:
PHP:
private Lotto lott;
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.
Credit to me.
Last edited: