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!

Modified gainItem(), accomodates pets.

Status
Not open for further replies.
Master Summoner
Loyal Member
Joined
Nov 30, 2007
Messages
511
Reaction score
0
Using Leifde's pet patch requires that you modify certain things, the gainItem() function included, when pets are involved. If you don't use this fix, your client will crash if you ever use the gainItem() function for pets due to the whole database shabang not being applied to that pet. Here we go:

In AbstractPlayerInteraction.java, replace the gainItem() function with this:
PHP:
public void gainItem(int id, short quantity) {
            MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
                        if (id >= 5000000 && id <= 5000045) {
            try {
                Connection con = (Connection) DatabaseConnection.getConnection();
                PreparedStatement ps = (PreparedStatement) con.prepareStatement("INSERT INTO pets (name, level, closeness, fullness) VALUES (?, ?, ?, ?)");
                ps.setString(1, ii.getName(id));
                ps.setInt(2, 1);
                ps.setInt(3, 0);
                ps.setInt(4, 100);
                ps.executeUpdate();
                ResultSet rs = ps.getGeneratedKeys();
                rs.next();
                //c.getPlayer().equipChanged();
                MapleInventoryManipulator.addById(c, id, (short) quantity, c.getPlayer().getName() + " receieved pet, ID " + id + ", from a scripted PlayerInteraction. (Quantity: " + quantity + ")", null, rs.getInt(1));
                rs.close();
                ps.close();
            } catch (SQLException ex) {
                java.util.logging.Logger.getLogger(AbstractPlayerInteraction.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
        if (quantity >= 0) {
            StringBuilder logInfo = new StringBuilder(c.getPlayer().getName());
            logInfo.append(" received ");
            logInfo.append(quantity);
            logInfo.append(" from a scripted PlayerInteraction (");
            logInfo.append(this.toString());
            logInfo.append(")");
            MapleInventoryManipulator.addById(c, id, quantity, logInfo.toString());
                
        } else {
            MapleInventoryManipulator.removeById(c, MapleItemInformationProvider.getInstance().getInventoryType(id), id, -quantity, true, false);
                    }
                }
        c.getSession().write(MaplePacketCreator.getShowItemGain(id, quantity, true));
    }

That's about it. You'll need a bunch of imports, but if you're using Netbeans and haven't noticed by now that it gives you the option of adding in all missing imports then you should shoot yourself, sorry.
 
Last edited:
Experienced Elementalist
Joined
Jun 8, 2008
Messages
275
Reaction score
4
Re: [Release] Modified gainItem(), accomodates pets.

i should shoot myself :< :p, jk good work bro.
 
Experienced Elementalist
Joined
May 28, 2007
Messages
264
Reaction score
2
Re: [Release] Modified gainItem(), accomodates pets.

what does this do exactly? can't you just use gainitem, and equip it to your pet.
 
Master Summoner
Loyal Member
Joined
Nov 30, 2007
Messages
511
Reaction score
0
Re: [Release] Modified gainItem(), accomodates pets.

what does this do exactly? can't you just use gainitem, and equip it to your pet.
Read the top of the post. <__<
 
Master Summoner
Joined
May 31, 2008
Messages
524
Reaction score
1
Re: [Release] Modified gainItem(), accomodates pets.

So... This will stop your server from crashing by the gainItem function... Right?
 
Junior Spellweaver
Joined
Apr 24, 2008
Messages
153
Reaction score
0
Re: [Release] Modified gainItem(), accomodates pets.

YESHH!!! Pet Evolver Will Work Great Now! Thanks ill release my script soon =)
 
Newbie Spellweaver
Joined
Jul 13, 2008
Messages
81
Reaction score
0
Re: [Release] Modified gainItem(), accomodates pets.

Wow nice!

i like it thank you alot
 
Experienced Elementalist
Joined
May 28, 2007
Messages
264
Reaction score
2
Re: [Release] Modified gainItem(), accomodates pets.

Oh, then great release lol.
 
Master Summoner
Loyal Member
Joined
Nov 30, 2007
Messages
511
Reaction score
0
Re: [Release] Modified gainItem(), accomodates pets.

So... This will stop your server from crashing by the gainItem function... Right?
Yes, it fixes client crashes when the gainItem() function is used.


YESHH!!! Pet Evolver Will Work Great Now! Thanks ill release my script soon =)
Yeah, I saw your post in the pets topic and I knew why you had that problems so I here this is. ;o
 
Experienced Elementalist
Joined
Jun 8, 2008
Messages
275
Reaction score
4
Re: [Release] Modified gainItem(), accomodates pets.

in case some noobies out their don't know what to replace just replace this.

PHP:
public void gainItem(int id, short quantity) {
		if (quantity >= 0) {
			StringBuilder logInfo = new StringBuilder(c.getPlayer().getName());
			logInfo.append(" received ");
			logInfo.append(quantity);
			logInfo.append(" from a scripted PlayerInteraction (");
			logInfo.append(this.toString());
			logInfo.append(")");
			MapleInventoryManipulator.addById(c, id, quantity, logInfo.toString());
		} else {
			MapleInventoryManipulator.removeById(c, MapleItemInformationProvider.getInstance().getInventoryType(id), id, -quantity, true, false);
		}
		c.getSession().write(MaplePacketCreator.getShowItemGain(id,quantity, true));
	}
 
Junior Spellweaver
Joined
Apr 24, 2008
Messages
153
Reaction score
0
Re: [Release] Modified gainItem(), accomodates pets.

I Lovee yooh =) im cleaning up the script =O its sooo messy
 
Newbie Spellweaver
Joined
Jan 5, 2006
Messages
87
Reaction score
26
Re: [Release] Modified gainItem(), accomodates pets.

[...]That's about it. You'll need a bunch of imports, but if you're using Netbeans and haven't noticed by now that it gives you the option of adding in all missing imports then you should shoot yourself, sorry.
*Shoots shelf* Ah well, manually doing it FTW.
 
Experienced Elementalist
Joined
Jun 8, 2008
Messages
275
Reaction score
4
Re: [Release] Modified gainItem(), accomodates pets.

Code:
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import java.rmi.RemoteException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import net.sf.odinms.client.MapleCharacter;
import net.sf.odinms.client.MapleClient;
import net.sf.odinms.client.MapleInventory;
import net.sf.odinms.client.MapleInventoryType;
import net.sf.odinms.client.MapleQuestStatus;
import net.sf.odinms.database.DatabaseConnection;
import net.sf.odinms.net.channel.ChannelServer;
import net.sf.odinms.net.world.MapleParty;
import net.sf.odinms.net.world.MaplePartyCharacter;
import net.sf.odinms.net.world.guild.MapleGuild;
import net.sf.odinms.server.MapleInventoryManipulator;
import net.sf.odinms.server.MapleItemInformationProvider;
import net.sf.odinms.server.MaplePortal;
import net.sf.odinms.server.maps.MapleMap;
import net.sf.odinms.server.quest.MapleQuest;
import net.sf.odinms.tools.MaplePacketCreator;

those are all the imports, those aren't all that i added but yeah for people that dont know how to use netbeans to get imports.
 
Newbie Spellweaver
Joined
Jul 13, 2008
Messages
19
Reaction score
0
Re: [Release] Modified gainItem(), accomodates pets.

Code:
init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\Compaq_Owner\Desktop\StarLightMS Pack\odinms\build\classes
C:\Documents and Settings\Compaq_Owner\Desktop\StarLightMS Pack\StarLightMS RePack\StarLightMS RePack\src\net\sf\odinms\scripting\AbstractPlayerInteraction.java:127: cannot find symbol
symbol  : method addById(net.sf.odinms.client.MapleClient,int,short,java.lang.String,<nulltype>,int)
location: class net.sf.odinms.server.MapleInventoryManipulator
                MapleInventoryManipulator.addById(c, id, (short) quantity, "Cash Item was purchased.", null, rs.getInt(1));
1 error
BUILD FAILED (total time: 0 seconds)

Anyone can help me with this error please?
 
Master Summoner
Loyal Member
Joined
Nov 30, 2007
Messages
511
Reaction score
0
Re: [Release] Modified gainItem(), accomodates pets.

Updated, changed the addById() function to fit the situation:
PHP:
MapleInventoryManipulator.addById(c, id, (short) quantity, c.getPlayer().getName() + " receieved pet, ID " + id + ", from a scripted PlayerInteraction. (Quantity: " + quantity, null, rs.getInt(1));
 
Experienced Elementalist
Joined
Jun 8, 2008
Messages
275
Reaction score
4
Re: [Release] Modified gainItem(), accomodates pets.

Right Click>Clean And Build
 
Banned
Banned
Joined
Apr 6, 2008
Messages
80
Reaction score
0
Re: [Release] Modified gainItem(), accomodates pets.

could be the fix for why players just sometimse cc with pets (equiped) and then get bugged and cant ever log back on their chars? :S xD
 
Master Summoner
Loyal Member
Joined
Nov 30, 2007
Messages
511
Reaction score
0
Re: [Release] Modified gainItem(), accomodates pets.

PHP:
MapleInventoryManipulator.addById(c, id, (short) quantity, c.getPlayer().getName() + " receieved pet, ID " + id + ", from a scripted PlayerInteraction. (Quantity: " + quantity + ")", null, rs.getInt(1));
 
Master Summoner
Loyal Member
Joined
Apr 20, 2008
Messages
578
Reaction score
76
Re: [Release] Modified gainItem(), accomodates pets.

could be the fix for why players just sometimse cc with pets (equiped) and then get bugged and cant ever log back on their chars? :S xD

You need to add this in ChangeChannelHandler.java..

Code:
import net.sf.odinms.net.channel.handler.SpawnPetHandler;

at the imports.

Then find

Code:
		if (c.getPlayer().getTrade() != null) {
			MapleTrade.cancelTrade(c.getPlayer());
		}

And add under it.
Code:
		if (c.getPlayer().getPet() != null) {
			SpawnPetHandler pethandler = new SpawnPetHandler();
			pethandler.unequipPet(c);
		}
 
Junior Spellweaver
Joined
Apr 24, 2008
Messages
153
Reaction score
0
Re: [Release] Modified gainItem(), accomodates pets.

i posted my npc scripts on dragon evolving/replacing lmao
 
Status
Not open for further replies.
Back
Top