Guten Morgen
Ich habe gestern gemerkt das beim Registrieren die Werte zwar übergeben werden aber nach dem Logout nicht so ganz gespeichert werdern.
Sobald man sich wieder Einloggt sind die werte wie: Geld,Level,Adminlevel,Fraktion,Rang und Spawnchange auf 0
Mein Code sieht wie folgt aus:
#define DIALOG_REGISTER
#define DIALOG_LOGIN
forward carSavedToDB(carid);
forward OnPlayerCarsLoad(playerid);
enum playerInfo{
eingeloggt,
level,
db_id,
alevel,
fraktion,
rang,
spawnchange
}
enum autoEnum{
id_x,
model,
besitzer,
Float:c_x,
Float:c_y,
Float:c_z,
Float:c_r,
db_id
}
new sInfo[MAX_PLAYERS][playerInfo];
new aInfo[50][autoEnum];
//mysql:
#define db_host "85.190.160.205"
#define db_user "ni515543_2_DB"
#define db_pass "xxxxxxx"
#define db_db "ni515543_2_DB"
new dbhandle;
public OnGameModeExit()
{
mysql_close(dbhandle);
}
public OnUserCheck(playerid)
{
new num_rows,num_fields;
cache_get_data(num_rows,num_fields,dbhandle);
if(num_rows==0)
{
//Register
ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Account Erstellung","Gebe bitte nun dein gewünschtes Passwort ein!","Registrieren","Abbrechen");
}
else
{
//Login
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Anmelden","Gebe bitte dein Passwort ein.","Anmleden","Abbrechen");
}
return 1;
}
public OnPlayerConnect(playerid)
{
if(IsPlayerNPC(playerid)) return 1;
new nachricht[128];
format(nachricht,sizeof(nachricht),"Du bist mit der ID %i verbunden.",playerid);
SendClientMessage(playerid,rot,nachricht);
//Login/Register:
new name[MAX_PLAYER_NAME],query[128];
GetPlayerName(playerid,name,sizeof(name));
format(query,sizeof(query),"SELECT id FROM user WHERE username='%s' ",name);
mysql_function_query(dbhandle,query,true,"OnUserCheck","i",playerid);
SendClientMessage(playerid,grün,"Willkommen auf Reallife Version 0.1.4! Wir wünschen euch ein angenehmen Spiel spaß bei uns!");
//textdraws anzeigen:
TextDrawShowForPlayer(playerid,Text:uhrzeitLabel);
TextDrawShowForAll(Jahr);
SetPlayerColor(playerid,weiß);
sInfo[playerid][level]=1;
SetPlayerScore(playerid,sInfo[playerid][level]);
return 1;
}
savePlayer(playerid)
{
if(sInfo[playerid][eingeloggt]==0)return 1;
//Speichern level,money
new query[256];
format(query,sizeof(query),"UPDATE user SET level='%i',money='%i',alevel='%i',fraktion='%i,rang='%i',spawnchange='%i' WHERE id='%i'",sInfo[playerid][level],GetPlayerMoney(playerid),sInfo[playerid][alevel],sInfo[playerid][fraktion],sInfo[playerid][rang],sInfo[playerid][spawnchange],sInfo[playerid][db_id]);
mysql_function_query(dbhandle,query,false,"","");
return 1;
}
resetPlayer(playerid)
{
for(new i=0; i<sizeof(sInfo[]); i++)
{
sInfo[playerid][playerInfo:i]=0;
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
for(new i=0; i<sizeof(aInfo); i++)
{
if(aInfo[i][id_x]==0)continue;
if(aInfo[i][besitzer]!=sInfo[playerid][db_id])continue;
GetVehiclePos(aInfo[i][id_x],aInfo[i][c_x],aInfo[i][c_y],aInfo[i][c_z]);
GetVehicleZAngle(aInfo[i][id_x],aInfo[i][c_r]);
new query[156];
format(query,sizeof(query),"UPDATE user SET level='%i',money='%i',alevel='%i',fraktion='%i,rang='%i' WHERE id='%i'",sInfo[playerid][level],
GetPlayerMoney(playerid),sInfo[playerid][alevel],sInfo[playerid][fraktion],sInfo[playerid][rang],sInfo,sInfo[playerid][db_id]);
mysql_function_query(dbhandle,query,false,"","");
DestroyVehicle(aInfo[i][id_x]);
aInfo[i][id_x]=0;
break;
}
savePlayer(playerid);
resetPlayer(playerid);
loadPlayerCars(playerid);
return 1;
}
public carSavedToDB(carid)
{
aInfo[carid][db_id]=cache_insert_id(dbhandle);
return 1;
}
saveCarToDB(playerid,carid)
{
new query[128];
format(query,sizeof(query),"INSERT INTO autos(besitzer,model,x,y,z,r) VALUES('%i','%i','%f','%f','%f','%f')",sInfo[playerid][db_id],aInfo[carid][model],aInfo[carid][c_x],aInfo[carid][c_y],aInfo[carid][c_z],aInfo[carid][c_r]);
mysql_function_query(dbhandle,query,true,"carSavedToDB","i",carid);
return 1;
}
createPlayerCar(playerid,modelid,Float:x,Float:y,Float:z,Float:r)
{
for(new i=0; i<sizeof(aInfo); i++)
{
if(aInfo[i][id_x]!=0)continue;
aInfo[i][besitzer]=sInfo[playerid][db_id];
aInfo[i][c_x] =x;
aInfo[i][c_y] =y;
aInfo[i][c_z] =z;
aInfo[i][c_r] =r;
aInfo[i][model] =modelid;
aInfo[i][id_x] = CreateVehicle(modelid,x,y,z,r,-1,-1,-1);
new string[128];
format(string,sizeof(string),"Das Auto aInfo[%i]wurde erstellt",i);
SendClientMessageToAll(duneklhelblau,string);
saveCarToDB(playerid,i);
return 1;
}
return 1;
}
ocmd:spawnchange(playerid,params[])
{
if(isPlayerInFrakt(playerid,0)) return SendClientMessage(playerid,rot,"Du bist in keiner Fraktion.");
if(sInfo[playerid][spawnchange] == 0)
{
sInfo[playerid][spawnchange] = 1;
}
else
{
sInfo[playerid][spawnchange] = 0;
}
savePlayer(playerid);
SendClientMessage(playerid,grün,"Spawn geändert");
return 1;
} für die Fraktionen!
ocmd:einladen(playerid,params[])
{
if(isPlayerInFrakt(playerid, 0))return SendClientMessage(
playerid, helblau, "Du bist in keiner Fraktion.");
if(sInfo[playerid][rang] < 6)return SendClientMessage(
playerid, helblau, "Dein Rang ist zu niedrig.");
new pID, fID;
fID = sInfo[playerid][fraktion];
if(sscanf(params, "u", pID))return SendClientMessage(
playerid, gelb, "INFO: /invite [playerid]");
if(!isPlayerInFrakt(pID, 0))return SendClientMessage(
playerid, gelb, "Spieler ist kein Zivilist.");
new string[128];
format(string,sizeof(string), "%s hat dich in die Fraktion %s eingeladen.",
getPlayerName(playerid), fInfo[fID][f_name]);
SendClientMessage(pID, gelb, string);
SendClientMessage(pID, gelb,
"Zum akzeptieren /accept invite eingeben.");
SetPVarInt(pID, "inv_fraktid", fID);
SetPVarInt(pID, "inv_inviter", playerid);
return 1;
}
ocmd:annehmen(playerid, params[])
{
new item[64];
if(sscanf(params,"s[64]",item))return SendClientMessage(
playerid, gelb, "INFO: /accept [invite]");
if(!strcmp(item, "invite", false))
{
if(GetPVarInt(playerid, "inv_fraktid") == 0)return SendClientMessage(
playerid, grün, "Du wurdest in keine Fraktion eingeladen.");
new fID = GetPVarInt(playerid, "inv_fraktid");
sInfo[playerid][fraktion] = fID;
sInfo[playerid][rang] = 1;
new string[128];
format(string,sizeof(string), "Du bist der Fraktion %s beigetreten.",
fInfo[fID][f_name]);
SendClientMessage(playerid, grün, string);
format(string,sizeof(string), "%s ist der Fraktion beigetreten.",
getPlayerName(playerid));
SendClientMessage(GetPVarInt(playerid, "inv_inviter"), grün,
string);
SetPVarInt(playerid, "inv_fraktid", 0);
return 1;
}
return 1;
}
ocmd:Leadererstellen(playerid,params[])
{
if(!isAdmin(playerid,5))return SendClientMessage(playerid,grün,"Du hast keine Berechtigung dazu!");
new pID, fID;
if(sscanf(params,"ui",pID,fID))return SendClientMessage(playerid,rot,"INFO: /Leadererstellen[playerid][fraktid]");
if(fID>= sizeof(fInfo))return SendClientMessage(playerid,rot,"Fraktion existiert nicht.");
sInfo[pID][fraktion] = fID;
sInfo[pID][rang] = 6;
new string[128];
format(string,sizeof(string),"%s hat dich zum Leader der Fraktion %s gemacht",getPlayerName(playerid),fInfo[fID][f_name]);
SendClientMessage(pID,gelb,string);
SendClientMessage(playerid,grün,"Du hast einen Spieler zum Leader gemacht.");
return 1;
}
ocmd:autoentfernen(playerid, params[])
{
new vID = GetPlayerVehicleID(playerid);
if(!IsPlayerInAnyVehicle(playerid))return SendClientMessage(playerid, hellgrün, "Du bist in kein Auto!");
for (new i = 0; i < sizeof(aInfo); i++)
{
if(vID == aInfo[i] [id_x])
{
if(!strcmp(aInfo[i][besitzer], SpielerName(playerid)))
{
new query[128];
format(query, sizeof(query), "DELETE FROM autos WHERE id='%i'",aInfo[i][db_id]);
mysql_function_query(dbhandle,query,false," "," ");
DestroyVehicle(aInfo[i][besitzer]);
aInfo[i] [id_x] = 0;
SendClientMessage(playerid, hellgrün, "Du hast dein Auto entfernt.");
return 1;
}
break;
}
}
return SendClientMessage(playerid, hellgrün, "Du sitzt nicht in deinem Auto!");
}
ocmd:adminerstellen(playerid,params[])
{
if(!isAdmin(playerid,6))
return SendClientMessage(playerid,grün,"Dein Adminrang ist nicht hochgenug!");
new pID,a_level;
if(sscanf(params,"ui",pID,a_level))
return SendClientMessage(playerid,dunkelblau,"INFO: /adminerstellen [playerid][adminleve]");
sInfo[pID][alevel]=a_level;
savePlayer(pID);
SendClientMessage(pID,helblau,"Sie wurden erfolgreich befördert!");
SendClientMessage(playerid,helblau,"Du hast den Adminrang geändert!");
return 1;
}
public OnPlayerCarsLoad(playerid)
{
new num_fields,num_rows;
cache_get_data(num_rows,num_fields,dbhandle);
if(!num_rows)return 1;
for(new i=0; i<num_rows; i++)
{
new id=getFreeCarID();
aInfo[id][model]=cache_get_field_content_int(i,"model",dbhandle);
aInfo[id][besitzer]=cache_get_field_content_int(i,"besitzer",dbhandle);
aInfo[id][c_x]=cache_get_field_content_float(i,"x",dbhandle);
aInfo[id][c_y]=cache_get_field_content_float(i,"y",dbhandle);
aInfo[id][c_z]=cache_get_field_content_float(i,"z",dbhandle);
aInfo[id][c_r]=cache_get_field_content_float(i,"r",dbhandle);
aInfo[id][db_id]=cache_get_field_content_int(i,"id",dbhandle);
aInfo[id][id_x]=CreateVehicle(aInfo[id][model],aInfo[id][c_x],aInfo[id][c_y],aInfo[id][c_z],aInfo[id][c_r],-1,-1,-1);
}
return 1;
}
loadPlayerCars(playerid)
{
new query[128];
format(query,sizeof(query),"SELECT * FROM autos WHERE besitzer='%i'",sInfo[playerid][db_id]);
mysql_function_query(dbhandle,query,true,"OnPlayerCarsLoad","i",playerid);
return 1;
}
public OnPasswordResponse(playerid)
{
new num_rows,num_fields;
cache_get_data(num_rows,num_fields,dbhandle);
if(num_rows==1)
{
//passwort Richtig
sInfo[playerid][eingeloggt] = 1;
sInfo[playerid][level] = cache_get_field_content_int(0,"level",dbhandle);
SetPlayerScore(playerid,sInfo[playerid][level]);
sInfo[playerid][db_id] = cache_get_field_content_int(0,"id",dbhandle);
SetPlayerMoney(playerid,cache_get_field_content_int(0,"money",dbhandle));
sInfo[playerid][alevel] = cache_get_field_content_int(0,"alevel",dbhandle);
sInfo[playerid][fraktion] = cache_get_field_content_int(0,"fraktion",dbhandle);
sInfo[playerid][rang] = cache_get_field_content_int(0,"rang",dbhandle);
sInfo[playerid][spawnchange] = cache_get_field_content_int(0,"spawnchange",dbhandle);
SetPlayerScore(playerid,sInfo[playerid][level]);
loadPlayerCars(playerid);
}
else
{
//Passwort Falsch
SendClientMessage(playerid,grün,"Du hast dein Passwort falsch eingetippt. Versuche es nochmal!");
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login","Gibt bitte dein Passwort ein:","Anmelden","Abbrechen");
}
return 1;
}
Dialoge:
if(dialogid==DIALOG_LOGIN)
{
if(response)
{
new name[MAX_PLAYER_NAME],query[128],passwort[35];
GetPlayerName(playerid,name,sizeof(name));
if(strlen(inputtext)>0)
{
mysql_escape_string(inputtext,passwort,dbhandle);
format(query,sizeof(query),"SELECT * FROM user WHERE username='%s' AND passwort=MD5('%s')",name,passwort);
mysql_function_query(dbhandle,query,true,"OnPasswordResponse","i",playerid);
}
else
{
//Keine Eingabe
SendClientMessage(playerid,grün,"Gibt bitte dein Passwort ein.");
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login","Gibt bitte dein Passwort ein:","Anmelden","Abbrechen");
}
}
else
{
Kick(playerid);
}
}
if(dialogid==DIALOG_REGISTER)
{
if(response)
{
new name[MAX_PLAYER_NAME],query[128],passwort[35];
GetPlayerName(playerid,name,sizeof(name));
if(strlen(inputtext)>5)
{
//Registrierungsfunktion
mysql_escape_string(inputtext,passwort,dbhandle);
format(query,sizeof(query),"INSERT INTO user (username,passwort) VALUES ('%s',MD5('%s')) ",name,passwort);
mysql_function_query(dbhandle,query,false,"","");
sInfo[playerid][level]=1;
SetPlayerScore(playerid,sInfo[playerid][level]);
}
else
{
//Kleiner als 4 Zeichen
SendClientMessage(playerid,helblau,"Dein Passwort muss mindestens 6 Zeichen lang sein.");
ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Account Erstellung","Gebe bitte nun dein gewünschtes Passwort ein!","Erstellen","Abbrechen");
}
}
else
{
Kick(playerid);
}
}
if(dialogid== DIALOG_Autosystem)
{
if(response)
{
if(listitem==0)
{
if(!IsPlayerInAnyVehicle(playerid))return
SendClientMessage(playerid,rot,"Sie sind nicht im Fahrzeug");
//motorfunktion
if(GetPlayerState(playerid)!=PLAYER_STATE_DRIVER)
{
SendClientMessage(playerid,blau,"Sie sind nicht der Fahrer dieses Fahrzeuges");
}
new vID=GetPlayerVehicleID(playerid), motor, licht, alarm, tueren, bonnet, boot, objective;
//Motor an/ausschalten:
GetVehicleParamsEx(vID,motor,licht,alarm,tueren,bonnet,boot,objective);
if(motor==1) motor = 0;
else motor = 1;
SetVehicleParamsEx(vID,motor,licht,alarm,tueren,bonnet,boot,objective);
SendClientMessage(playerid,blau,"Sie haben den Motor Ihres Fahrzeuges angeschlaten/ausgeschalten!");
}
}
if(listitem==1)
{
if(!IsPlayerInAnyVehicle(playerid))return
SendClientMessage(playerid,rot,"Sie sind nicht im Fahrzeug");
if(GetPlayerState(playerid)!=PLAYER_STATE_DRIVER)
return SendClientMessage(playerid,blau,"Sie befinden sich nicht in Ihr Fahrzeug");
new vID=GetPlayerVehicleID(playerid),
motor,
licht,
alarm,
tueren,
bonnet,
boot,
objective;
//licht an/ausschalten:
GetVehicleParamsEx(vID,motor,licht,alarm,tueren,bonnet,boot,objective);
if(licht==1){
licht = 0;
}
else
{
licht = 1;
}
SetVehicleParamsEx(vID,motor,licht,alarm,tueren,bonnet,boot,objective);
SendClientMessage(playerid,blau,"Du hast das Licht an eingeschalten/ausgeschalten");
}
if(listitem==2)
{
new motor,
licht,
alarm,
tueren,
bonnet,
boot,
objective;
new vID = INVALID_VEHICLE_ID;
if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
{
new Float:Pos[3];
for(new i=0;i<MAX_VEHICLES; i++)
{
GetVehiclePos(i, Pos[0], Pos[1], Pos[2]);
if(IsPlayerInRangeOfPoint(playerid, 5.0, Pos[0], Pos[1], Pos[2]))
{
vID = i;
break;
}
}
}
else if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
vID = GetPlayerVehicleID(playerid);
}
if(vID == INVALID_VEHICLE_ID)
{
SendClientMessage(playerid, 0xFF0000FF, "Error: Nicht nahe oder in einem Fahrzeug.");
}
//abschliessen:
GetVehicleParamsEx(vID,motor,licht,alarm,tueren,bonnet,boot,objective);
if(tueren==1)
{
tueren = 0;
}
else
{
tueren = 1;
}
SetVehicleParamsEx(vID,motor,licht,alarm,tueren,bonnet,boot,objective);
SendClientMessage(playerid,blau,"Sie haben die Türen Ihres Fahrzeuges abgeschlossen/aufgeschlossen!");
}
if(listitem==3)
{
new vID = GetPlayerVehicleID(playerid);
if(!IsPlayerInAnyVehicle(playerid))return SendClientMessage(playerid, hellgrün, "Du bist in kein Auto!");
for (new i = 0; i < sizeof(aInfo); i++)
{
if(vID == aInfo[i] [id_x])
{
if(aInfo[i][besitzer] == sInfo[playerid][db_id])
{
new query[256];
GetVehiclePos(vID, aInfo[i][c_x],aInfo[i][c_y],aInfo[i][c_z]);
GetVehicleZAngle(vID,aInfo[i][c_r]);
format(query, sizeof(query), "UPDATE Autos SET x='%f',y='%f',z='%f',r='%f' WHERE id='%i'",aInfo[i] [c_x],aInfo[i] [c_y],aInfo[i] [c_z],aInfo[i] [c_r],aInfo[i] [db_id]);
mysql_function_query(dbhandle,query,false," "," ");
SendClientMessage(playerid, hellgrün, "Du hast dein Auto geparkt.");
return 1;
}
break;
}
}
return SendClientMessage(playerid, hellgrün, "Sie sitzen nicht in Ihr Fahrze!");
}
} für das sind die sachen fürs Autoparken und so.
Warum es nun rumbuggt weiß ich leider nicht. Es erstellt sich auch nicht mals eine MySQL.log datei um zu sehen woran es liegen könnte