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] Super Gachapon

Skilled Illusionist
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)
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:
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 :p
Oh, and Soulfist deserves some credit as well.


Feel free to flame me <3
 
Last edited by a moderator:
Custom Title Activated
Loyal Member
Joined
Nov 27, 2009
Messages
1,905
Reaction score
948
Why do people even bother to use switch, it's dumb.
 
Skilled Illusionist
Joined
Dec 16, 2010
Messages
304
Reaction score
164
Why do people even bother to use switch, it's dumb.
Switch / case is faster than if / else >_>
In some languages and programming environments, the use of a case or switch statement is considered superior to an equivalent series of if-else statements because it is:

* easier to debug (e.g. setting breakpoints on code vs. a call table, if the debugger has no conditional breakpoint capability)
* easier to read (subjective)
* easier to understand and therefore
* easier to maintain

Additionally, as mentioned above, an optimized implementation may:

* execute much faster than the alternative, because it is often implemented by using an indexed branch table

For example, deciding program flow based on a single character's value, if correctly implemented, is vastly more efficient than the alternative, reducing instruction path lengths considerably.

@magelight: They are rofl. And I answered your npc prob on my thread.
 
Last edited:
Joined
Jun 5, 2010
Messages
567
Reaction score
598
reloadChar is useless, there's a packet to update equip stats. There's a packet to update character appearance too.

Also switch isn't faster than if in Java

edit:
lol
* execute much faster than the alternative, because it is often implemented by using an indexed branch table

For example, deciding program flow based on a single character's value, if correctly implemented, is vastly more efficient than the alternative, reducing instruction path lengths considerably.
This is not done here, and you can probably do this using if/else too
 
Last edited:
Skilled Illusionist
Joined
Dec 16, 2010
Messages
304
Reaction score
164
reloadChar is useless, there's a packet to update equip stats. There's a packet to update character appearance too.

Also switch isn't faster than if in Java

edit:
lol

This is not done here, and you can probably do this using if/else too
What packet might that be?
And thanks for the info on if/else and switch.
 
Custom Title Activated
Loyal Member
Joined
Aug 21, 2009
Messages
1,149
Reaction score
598
I don't see the "Super" part of this, this one just gave me more reasons to sleep...
 
Junior Spellweaver
Joined
Jan 30, 2011
Messages
106
Reaction score
21
hmmm, nice release =D I'll tell you if it has any problem with it
 
Legendary Battlemage
Loyal Member
Joined
Dec 13, 2010
Messages
649
Reaction score
140
So you did release it chris, good job o-o.


@Osiris, "Super Gachapon" was my name for it because I made a rough draft. It was his idea tho ;)
 
Joined
Jun 5, 2010
Messages
567
Reaction score
598
It's more organized and you don't have to put in tons of }else if(){

Well that's true, but you have a fat list of lines of case and breaks. I use switch sometimes since it's a little easier to read but if statements are more powerful. What if you wanted a range of numbers: so 1-100 would return 1, 101-2400 would return 2, otherwise return -1? Then you'd use if. Switch looks better in some cases such as if (x==1||x==3||x==100|x==235||x=25) {}
 
may web.very maple.pls.
Loyal Member
Joined
Aug 12, 2009
Messages
1,810
Reaction score
606
PHP:
var Prizes = [["common prizes"], ["standard prizes"], ["rare prizes"], ["extremely rare prizes"]];
should be:
PHP:
var Prizes = ["common prizes", "standard prizes", "rare prizes", "extremely rare prizes"];

I don't see whats the point of the extra brackets
 
Legendary Battlemage
Loyal Member
Joined
Dec 13, 2010
Messages
649
Reaction score
140
PHP:
var Prizes = [["common prizes"], ["standard prizes"], ["rare prizes"], ["extremely rare prizes"]];
should be:
PHP:
var Prizes = ["common prizes", "standard prizes", "rare prizes", "extremely rare prizes"];

I don't see whats the point of the extra brackets


Like i said, the very base of this NPC is mine. I did that because instead of handling it in seperate arrays, you could set it up like [rare], [common], etc etc. You could randomize each array seperately, that was the original intent. If you did it like your suggesting Akira, it would completely defeat the purpose :(:

Either way. I too find the methods more useful *copy pastes* :D:
 
Skilled Illusionist
Joined
Dec 16, 2010
Messages
304
Reaction score
164
PHP:
var Prizes = [["common prizes"], ["standard prizes"], ["rare prizes"], ["extremely rare prizes"]];
should be:
PHP:
var Prizes = ["common prizes", "standard prizes", "rare prizes", "extremely rare prizes"];

I don't see whats the point of the extra brackets
4 separate classifications of item IDs, so I used 4 separate arrays.
PHP:
[[lvl 30 claw id, lvl 30 sword id], [lvl 50 claw id, lvl 50 sword id], [lvl 100 gear, more lvl 100 gear], [timeless poop, timeless poop]];
Just as an example.
If you had reviewed the whole script you probably would have gotten your answer.
 
Newbie Spellweaver
Joined
Jan 30, 2009
Messages
7
Reaction score
0
First of all, very nice release!
So if I want the luck to be balanced out instead of common, rare, and etc.
What do I delete?
 
Newbie Spellweaver
Joined
May 10, 2011
Messages
27
Reaction score
1
I don't get why is everyone complaining. The guy has put some effort to it, didn't he?
This is a very nice release, very organized. I think that's the main pro of it. :)
 
Skilled Illusionist
Joined
Dec 16, 2010
Messages
304
Reaction score
164
I don't get why is everyone complaining. The guy has put some effort to it, didn't he?
This is a very nice release, very organized. I think that's the main pro of it. :)
Lol, thanks, but this release really isn't that good. And it didn't even work correctly for like a month after I posted it. I'm just gonna try to find out how to close the thread because someone bumped this really late and I don't really want people commenting more on old work.
 
Back
Top