Newbie Spellweaver
- Joined
- Aug 16, 2009
- Messages
- 49
- Reaction score
- 42
Well user can talk to the npc every 24hour for prize.
NPC Code
MapleCharacter.java
NPCConversationManager.java
Mysql
NPC Code
Code:
var status = 0;
function start() {
cm.sendNext("I'm giving out free smeges to players everyday..");
}
function action(mode, type, selection) {
if (mode == 0) {
cm.sendOk("Fine, I'll give to other players if you don't want it..")
cm.dispose();
}else {
if(mode > 0)
status++;
else if(mode < 0)
cm.dispose();
if (status == 1) {
if (cm.getGiftLog('FreeGift') >= 1) {
cm.sendOk("I'm sorry, You have already received your gift in this account today!! Please come back 24 hours later!!");
cm.dispose();
}else
cm.sendYesNo("Grats, you haven't received your #r#e10#n#k free #v5072000# today, do you want to get your free gift now?");
}else if (status == 2) {
cm.gainItem(5072000, 10);
cm.setBossLog('FreeGift');
cm.sendOk("Congratulation!! You've reveived your #r#e10#n#k free #v5072000#!!");
cm.dispose();
} else
cm.sendOk("Fine, I'll give to other players if you don't want it..")
}
}
MapleCharacter.java
Code:
public int getBossLog(String bossid) {
Connection con1 = DatabaseConnection.getConnection();
try {
int ret_count = 0;
PreparedStatement ps;
ps = con1.prepareStatement("select count(*) from bosslog where characterid = ? and bossid = ? and lastattempt >= subtime(current_timestamp, '1 0:0:0.0')");
ps.setInt(1, id);
ps.setString(2, bossid);
ResultSet rs = ps.executeQuery();
if (rs.next())
ret_count = rs.getInt(1);
else
ret_count = -1;
rs.close();
ps.close();
return ret_count;
} catch (Exception Ex) {
return -1;
}
}
public int getGiftLog(String bossid) {
Connection con1 = DatabaseConnection.getConnection();
try {
int ret_count = 0;
PreparedStatement ps;
ps = con1.prepareStatement("select count(*) from bosslog where accountid = ? and bossid = ? and lastattempt >= subtime(current_timestamp, '1 0:0:0.0')");
ps.setInt(1, accountid);
ps.setString(2, bossid);
ResultSet rs = ps.executeQuery();
if (rs.next())
ret_count = rs.getInt(1);
else
ret_count = -1;
rs.close();
ps.close();
return ret_count;
} catch (Exception Ex) {
return -1;
}
}
//setBossLog module
public void setBossLog(String bossid) {
Connection con1 = DatabaseConnection.getConnection();
try {
PreparedStatement ps;
ps = con1.prepareStatement("insert into bosslog (accountid, characterid, bossid) values (?,?,?)");
ps.setInt(1, accountid);
ps.setInt(2, id);
ps.setString(3, bossid);
ps.executeUpdate();
ps.close();
} catch (Exception Ex) {
}
}
NPCConversationManager.java
Code:
public int getBossLog(String bossid) {
return getPlayer().getBossLog(bossid);
}
public int getGiftLog(String bossid) {
return getPlayer().getGiftLog(bossid);
}
@Override
public void setBossLog(String bossid) {
getPlayer().setBossLog(bossid);
}
Mysql
Code:
CREATE TABLE `bosslog` (
`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`accountid` INTEGER UNSIGNED NOT NULL,
`characterid` INTEGER UNSIGNED NOT NULL,
`bossid` VARCHAR(20) NOT NULL,
`lastattempt` TIMESTAMP NOT NULL,
PRIMARY KEY (`id`)
)
Last edited: