- Joined
- Dec 16, 2010
- Messages
- 304
- Reaction score
- 164
Bored. Made what I like to call a 'Super' Gachapon. It's very adaptable to high and low rate servers, simply follow the directions in the comments. It's also adaptable in the fact that you can choose whether or not you want players to be able to gain more than 1 of the same item from the Gachapon.
Read the comments, I think I left enough.
NPC Script:
(Make sure you put your item IDs in the array)
Methods you'll need in the source (which are also useful in plenty of other situations):
Shoutout to Nemesis <3 Thanks for helping!
If Nemesis decides to post on this thread, thank him
Oh, and Soulfist deserves some credit as well.
Feel free to flame me <3
Read the comments, I think I left enough.
NPC Script:
(Make sure you put your item IDs in the array)
PHP:
/**
*
* @author Sharky
* Special shoutout to Nemesis <3 Thanks for helping bud :)
*/
highRate = true; // set this to false and uncomment the 'for low-rate', and comment the 'for high-rate' stuff to change it for a low-rate server
var currency = 4030002; // for high-rates
//var mesos = 10000000; // for low-rates
function start() {
cm.sendNext("I am the #rSuper Gachapon#k, want to take the chance? I will take #b" + (highRate == true ? "one of your #t"+ currency +"#" : mesos + " mesos") + "#k and give you a random item with random stats! Good luck!");
}
function action(m,t,s){
cm.dispose();
if(m > 0) {
if(cm.haveItem(currency)) { // for high-rates
cm.gainItem(currency, -1); // for high-rates : loses the currency item
//if(cm.getMeso() >= mesos) { // for low-rates
//cm.gainMeso(-mesos); // for low-rates
//You have to put your IDs in the array!!!! Example (not real item IDs): var Prizes = [[1072344], [2340199], [2839028], [1827400, 2844709]];
var Prizes = [["common prizes"], ["standard prizes"], ["rare prizes"], ["extremely rare prizes"]];
var random1 = Math.floor(Math.random() * 100); // this is the number that will determine which section they get (common, standard, rare, extremely rare)
var section = random1 < 6 ? 3 : random1 >= 6 && random1 < 18 ? 2 : random1 >= 18 && random1 < 50 ? 1 : 0; // Determines what section the item they win will be in
var random2 = Math.floor(Math.random() * Prizes[section].length); // This determines the item from the section in the array that they will get
var statConstant = section == 0 ? 100 : section == 1 ? 400 : section == 2 ? 1000 : section == 3 ? 4000 : -1; // for high-rates : This determines the stats the item will recieve (varies with section)
//var statConstant = section == 0 ? 10 : section == 1 ? 20 : section == 2 ? 35 : section == 3 ? 50; // for low-rates : This determines the stats the item will recieve (varies with section)
var newitem;
newitem = Prizes[section][random2];
// If you want don't want players getting more than 1 of the same item from Gachapon, uncomment the stuff below
/*if(cm.haveItem(newitem)) {
for(var a = 0; a < item[section].length; a++) {
if(!cm.haveItem(Prizes[section][a])) {
newitem = Prizes[section][a];
break;
}
}
}*/
var newstat = Math.floor(Math.random() * statConstant) + statConstant;
var slot = cm.gainItemRetPos(newitem); // gains the item AND declares the variable for stat editing
cm.editEquipById(slot, -1, newstat, true); // check the method to see how it works
cm.reloadChar(); // reloads your character so the item's stats are successfully editted
cm.serverNotice("[Super Gachapon]: "+ cm.getPlayer().getName() +" has won a "+ newstat +" stat "+ Packages.server.MapleItemInformationProvider.getInstance().getName(newitem) +" from the Super Gachapon!"); // server notice for the entire world to see
}
}
}
Methods you'll need in the source (which are also useful in plenty of other situations):
MapleInventoryManipulator:
MapleCharacter:
NPCConversationManager:
PHP:
public static void editEquipById(MapleCharacter chr, int itemid, byte stat, short value) {
editEquipById(chr, itemid, stat, value, false);
}
public static void editEquipById(MapleCharacter chr, int input, byte stat, short value, boolean superGacha) {
Equip equip = null;
if (superGacha) {
equip = (Equip) chr.getInventory(MapleInventoryType.EQUIP).getItem((byte)input);
equip.setStr(value);
equip.setDex(value);
equip.setInt(value);
equip.setLuk(value);
equip.setWatk(value);
return;
}
equip = (Equip) chr.getInventory(MapleInventoryType.EQUIP).findById(input);
switch(stat) {
case 1:
equip.setStr(value);
break;
case 2:
equip.setDex(value);
break;
case 3:
equip.setInt(value);
break;
case 4:
equip.setLuk(value);
break;
case 5:
equip.setWatk(value);
break;
}
}
MapleCharacter:
PHP:
public void sendServerNotice(String msg) {
MaplePacket packet = MaplePacketCreator.serverNotice(5, msg);
try {
client.getChannelServer().getWorldInterface().broadcastMessage(name, packet.getBytes());
} catch (RemoteException e) {
getClient().getChannelServer().reconnectWorld();
}
}
NPCConversationManager:
PHP:
public void editEquipById(int input, byte stat, short value, boolean supergacha) {
if(supergacha) {
MapleInventoryManipulator.editEquipById(getPlayer(), input, stat, value, true);
return;
}
MapleInventoryManipulator.editEquipById(getPlayer(), input, stat, value);
}
public void reloadChar() {
getPlayer().getClient().getSession().write(MaplePacketCreator.getCharInfo(getPlayer()));
getPlayer().getMap().removePlayer(getPlayer());
getPlayer().getMap().addPlayer(getPlayer());
}
public byte gainItemRetPos(int itemid) {
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
IItem it = ii.getEquipById(itemid);
byte ret = getPlayer().getInventory(MapleInventoryType.EQUIP).addItem(it);
c.getSession().write(MaplePacketCreator.addInventorySlot(MapleInventoryType.EQUIP, it));
c.getSession().write(MaplePacketCreator.getShowItemGain(itemid, (short)1, true));
c.getSession().write(MaplePacketCreator.enableActions());
return ret;
}
public void serverNotice(String msg) {
getPlayer().sendServerNotice(msg);
}
Shoutout to Nemesis <3 Thanks for helping!
If Nemesis decides to post on this thread, thank him
Oh, and Soulfist deserves some credit as well.
Feel free to flame me <3
Last edited by a moderator: