J'ai ce qu'il te faut pour la position, mais je suis en train de faire celui pour les pvs.
Crée un script de nom biblio par exemple :
#include "aps_include"
/*
CREATE TABLE player (
playerId bigint(20) NOT NULL auto_increment,
name varchar(255) NOT NULL default '',
charecter varchar(255) NOT NULL default '',
storedLoc varchar(255) NOT NULL default '',
PRIMARY KEY (playerId)
) TYPE=MyISAM;
*/
//charge la position du joueur
void LoadPlayer(object oPC);
//sauvegarde la position d'un joueur
void SavePlayer(object oPC);
//sauvegarde les positions de tous les joueurs
void SaveAllPlayers();
void LoadPlayer(object oPC)
{
int rc = 0;
string playerName, charecterName;
string query;
if (GetIsPC(oPC))
{
charecterName = GetName(oPC);
playerName = GetPCPlayerName(oPC);
query = "SELECT playerId, storedLoc FROM player " +
"WHERE name='" + playerName + "' "+
"AND charecter='"+ charecterName +"' ";
SQLExecDirect(query);
rc = SQLFirstRow();
if (rc == SQL_ERROR)
{
query = "INSERT INTO player (name, charecter) VALUES " +
"('" + playerName + "', '"+ charecterName +"')";
SQLExecDirect(query);
}
else
{
SetLocalInt(oPC, "playerId", StringToInt(SQLGetData(1)));
DelayCommand(5.0, AssignCommand(oPC, JumpToLocation(StringToLocation(SQLGetData(2)))));
}
}
}
void SavePlayer(object oPC) {
string query;
string charecterName;
int playerId = 0;
playerId = GetLocalInt(oPC, "playerId");
if (playerId > 0) {
charecterName = GetName(oPC);
/*
query = "UPDATE player "+
"SET storedLoc='"+ LocationToString(GetLocation(oPC)) +"' "+
"WHERE playerId='" + IntToString(GetLocalInt(oPC, "playerId")) + "' ";
*/
query = "UPDATE player "+
"SET storedLoc='"+ LocationToString(GetLocalLocation(oPC, "currentLoc")) +"' "+
"WHERE playerId='" + IntToString(GetLocalInt(oPC, "playerId")) + "' ";
SQLExecDirect(query);
}
}
void SaveAllPlayers() {
object oPC = OBJECT_INVALID;
oPC = GetFirstPC();
while (oPC != OBJECT_INVALID) {
PrintString("Sauvegarde des joueurs effectuee");
if (GetIsObjectValid(GetArea(oPC)) == TRUE) {
SavePlayer(oPC);
}
oPC = GetNextPC();
}
}
Remarque : j'ai mis en commentaires la table que tu dois crée.
Ensuite ceci dans le OnHearthBeat :
#include "biblio"
void main()
{
int player_hb_counter = 0;
object oPC = OBJECT_INVALID;
oPC = GetFirstPC();
while (oPC != OBJECT_INVALID)
{
if (GetIsObjectValid(GetArea(oPC)) == TRUE)
{
SetLocalLocation(oPC, "currentLoc", GetLocation(oPC));
}
oPC = GetNextPC();
}
player_hb_counter = GetLocalInt(OBJECT_SELF, "player_hb_counter");
player_hb_counter++;
// la tu peux personnaliser le temps entre chaque save
if (player_hb_counter >= 10) {
player_hb_counter = 0;
SaveAllPlayers();
}
SetLocalInt(OBJECT_SELF, "player_hb_counter", player_hb_counter);
}
et enfin Met les fonction adéquates dans le OnEnter et OnLeave (respectivement LoadPC(oPC) et SavePC(oPC))
PS : Pour Zunder :
- SetPersistentInt(object oPC, string sVarName, int iValue, int iExpiration=0, string sTable="pwdata");
- SetPersistentString(object oPC, string sVarName, string sValue, int iExpiration=0, string sTable="pwdata");
- SetPersistentFloat(object oPC, string sVarName, float fValue, int iExpiration=0, string sTable="pwdata");
- SetPersistentVetor(object oPC, string sVarName, vector vValue, int iExpiration=0, string sTable="pwdata");
et
- GetPersistentInt(object oPC, string sVarName, string sTable="pwdata");
- GetPersistentString(object oPC, string sVarName, string sTable="pwdata");
- GetPersistentFloat(object oPC, string sVarName, string sTable="pwdata");
- GetPersistentVector(object oPC, string sVarName, string sTable="pwdata");
et puis il y a les autres fonctions pour jouer avec les tables mysql