Jump to content
La fin ?! Elle est là ! ×
×
×
  • Create New...

[JAVA] Système de Jail


Manghao
 Share

Recommended Posts

Salut, alors voilà j'ai fait un système anti téléportation ainsi qu'une commande pour JAIL et UNJAIL un personnage.

 

Ce système consiste à bloquer les téléportations des personnages quand ils sont en prison, avant il fallait les muter pour ne pas qu'ils utilisent les commande de téléportation mais les potions de téléportation marchaient.

 

Fini avec ce système, les personnages pourront parler mais pas ce téléporter.

 

Pour ce faire tapez:

JAIL [mapid] [cellid] [pseudo]

UNJAIL [pseudo]

 

Passons au code.

 

Dans commands.java mettez ceci dans le GM Level de votre choix:

 

code
if(command.equalsIgnoreCase("JAIL"))
{
short mapID = -1;
int cellID = -1;
try
{
mapID = Short.parseShort(infos[1]);
cellID = Integer.parseInt(infos[2]);
}catch(Exception e){};
if(mapID == -1 || cellID == -1 || World.getCarte(mapID) == null)
{
String str = "MapID ou cellID invalide";
SocketManager.GAME_SEND_CONSOLE_MESSAGE_PACKET(_out,str);
return;
}
if(World.getCarte(mapID).getCase(cellID) == null)
{
String str = "MapID ou cellID invalide";
SocketManager.GAME_SEND_CONSOLE_MESSAGE_PACKET(_out,str);
return;
}
Personnage target = _perso;
if(infos.length > 3)//Si un nom de perso est spécifié
{
target = World.getPersoByName(infos[3]);
if(target == null || target.get_fight() != null)
{
String str = "Le personnage n'a pas ete trouve ou est en combat";
SocketManager.GAME_SEND_CONSOLE_MESSAGE_PACKET(_out,str);
return;
}
}
target.teleport(mapID, cellID);
String str = "Le joueur a ete envoye en prison";
SocketManager.GAME_SEND_CONSOLE_MESSAGE_PACKET(_out,str);
SocketManager.GAME_SEND_MESSAGE_TO_ALL("Le joueur "+target.get_name()+" viens d'être envoyé en prison par "+_perso.get_name()+" ! Ses droits de téléportation lui on été retirés !", ManghaoEMU.COLOR_RED);
SQLManager.JAIL(target.get_GUID());
SQLManager.UPDATE_PERSO(target, target.get_GUID());
SQLManager.REFRESH_PERSO(target);
}else if(command.equalsIgnoreCase("UNJAIL"))
{
Personnage target = _perso;

String name = null;
try
{
name = infos[1];
}catch(Exception e){};

target = World.getPersoByName(name);
if(target == null)
{
String mess = "Le personnage n'existe pas.";
SocketManager.GAME_SEND_CONSOLE_MESSAGE_PACKET(_out,mess);
return;
}
target.warpToSavePos();
String mess = "Vous avez unjail "+target.get_name();
SocketManager.GAME_SEND_CONSOLE_MESSAGE_PACKET(_out,mess);
SocketManager.GAME_SEND_MESSAGE_TO_ALL("Le joueur "+target.get_name()+" viens d'être désemprisonné par "+_perso.get_name()+" ! Ses droits de téléportation lui sont redonné", ManghaoEMU.COLOR_RED);
SQLManager.UNJAIL(target.get_GUID());
SQLManager.UPDATE_PERSO(target, target.get_GUID());
SQLManager.REFRESH_PERSO(target);

if(!target.isOnline())
{
mess = "(Le personnage "+target.get_name()+" n'etait pas connecte)";
SocketManager.GAME_SEND_CONSOLE_MESSAGE_PACKET(_out,mess);
}
}else

 

dans Ancestra.java ou l'équivalent renommé selon les émulateurs ajoutez:

public static String COLOR_RED = "F7230C";
 
Puis dans SQLManager.java:
 
code

public static void JAIL(int persoID)
{ String query = "UPDATE `personnages` SET jail='1' WHERE `guid`=" + persoID +
";";
try {
PreparedStatement p = newTransact(query, othCon);
p.execute();
} catch (SQLException e) {
GameServer.addToLog("Game: SQL ERROR: " + e.getMessage());
GameServer.addToLog("Game: Query: " + query);
}
}
public static void UNJAIL(int persoID)
{ String query = "UPDATE `personnages` SET jail='0' WHERE `guid`=" + persoID +
";";
try {
PreparedStatement p = newTransact(query, othCon);
p.execute();
} catch (SQLException e) {
GameServer.addToLog("Game: SQL ERROR: " + e.getMessage());
GameServer.addToLog("Game: Query: " + query);
}
}
public static void UPDATE_PERSO(Personnage P,int persoID)
{
String baseQuery = "UPDATE `personnages` SET "+
"`jail` = ?,"+
" WHERE guid = "+ persoID + ";";

try {
PreparedStatement p = newTransact(baseQuery, othCon);
p.setInt(1, P.getJail());
p.execute();
closePreparedStatement(p);
} catch (SQLException e) {
GameServer.addToLog("Game: SQL ERROR: "+e.getMessage());
GameServer.addToLog("Game: Query: "+baseQuery);
}
}
public static Personnage REFRESH_PERSO(Personnage toRefresh)
{
try
{
ResultSet RS = SQLManager.executeQuery("SELECT * from personnages WHERE `guid` = '"+toRefresh.get_GUID()+"';",ManghaoEMU.OTHER_DB_NAME);

while(RS.next())
{
toRefresh.setJail(RS.getInt("jail"));

}
closeResultSet(RS);
return toRefresh;
}catch(SQLException e)
{
RealmServer.addToLog("SQL ERROR: "+e.getMessage());
e.printStackTrace();
return toRefresh;
}
}

 

 

Dans Personnages.java mettez:

//JAIL
private int _jail = 0;
 

Cherchez:

public Personnage
 

après:

int wifeGuid
 

mettez:

,int jail
 

en dessous de:

this._wife = wifeGuid;
 

ajoutez:

this._jail = jail;
 

ajoutez:

public void setJail(int jail)
{
	this._jail = jail;
}

public int getJail()
{
	return this._jail;
}
 

en dessous de:

public int get_capital() {
return _capital;
}
 

Vous aurez une erreur ici :

public static Personnage CREATE_PERSONNAGE
 

au dessus de:

perso._sorts = Constants.getStartSorts(classe);
 

vous avez:

);
 

rajoutez donc:

0
 

ce qui donne:

0
);
 

 

n'oubliez pas de mettre une virgule sur la ligne au dessus = voir screen

 

screen:

 

code

jail.png

 

puis cherchez:

public void teleport
 

vous aurez:

PrintWriter PW = null;
if(_compte.getGameThread() != null)
{
PW = _compte.getGameThread().get_out();
}
if(World.getCarte(newMapID) == null)
{
GameServer.addToLog("Game: INVALID MAP : "+newMapID);
return;
}
...
 

rajoutez au dessus de:

PrintWriter PW = null;
 
if(getJail() == 1 && _compte.get_gmLvl() < 1)
{
return;
}else{
if(getJail() == 0)
{
 

ce qui donne:

public void teleport(short newMapID, int newCellID)
{
if(getJail() == 1 && _compte.get_gmLvl() < 1)
{
return;
}else{
if(getJail() == 0)
{
PrintWriter PW = null;
....
 

Dans SQLManager de nouveau ou vous aurez les erreurs sur les personnages rajoutez:

RS.getInt("jail")
 

n'oubliez pas la virgule sur la ligne d'avant pour avoir (vous n'avez pas forecement wife avant):

RS.getInt("wife"),
RS.getInt("jail")
 

J'ai fait ce code vite fait, il peut être amélioré, si vous l'améliorez partagez le si vous le souhaitez.

 

Par contre je souhaite que ce tuto reste sur Funky-Emu.

 

Un merci vaux un +1.

 

Cordialement Dextouxe

 

PS: désolé pour l'intendation.

 

Edited by Funky Emulation
Core X - External 2 Internal
  • J'adore 1

Partages :

Projets :

Link to comment
Share on other sites

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

T'es sérieux ? Tout ça ? Tu mets une commande jail, tu vas dans Personnage.teleport() si t'es dasn la ma pque t'as configuré pour ta commande tu mets un return pour le teleport ... 5 lignes de code xD.

Link to comment
Share on other sites

 Share



Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.