Hallo Leute,
Ich schreibe gerade mein Hausystem ums,so dass es in MySQL gespeichert wird
Wenn ich mich einlogge(Ich habe ein Huas gekauft kurz nachdem ich es InGame erstellt habe):
Ich logg mich ein danach werde ich zur drogenfarm geportet dort soll mein Haus sein
/herstellen: Glaube aber hier ist nichts falsch
ocmd:herstellen(playerid,params[])
{
if(!IsAdmin(playerid,4))return SendClientMessage(playerid,COLOR_RED,"Du hast keine rechte um diesen Command auszuführen!");
new preis,hid,Float:ppx,Float:ppy,Float:ppz,lvl,bss[128];
if(sscanf(params,"iiis",preis,hid,lvl,bss))return SendClientMessage(playerid,COLOR_GREEN,"[Benutzung]:{FFFFFF} /herstellen [Preis] [HausID] [Level] [Beschreibung]");
if(hid < 1 || hid > 10)return SendClientMessage(playerid,COLOR_GREY," Falsche HausID!");
if(lvl < 1)return SendClientMessage(playerid,COLOR_GREY," Das Level darf nicht unter 1 sein!");
if(!strlen(bss))return SendClientMessage(playerid,COLOR_GREY," Du musst eine Beschreibung angeben!");
GetPlayerPos(playerid,ppx,ppy,ppz);
CreateHaus(ppx,ppy,ppz,preis,HausInt[hid-1][Interior],HausInt[hid-1][IntX],HausInt[hid-1][IntY],HausInt[hid-1][IntZ],lvl,bss);
SendClientMessage(playerid,COLOR_GREY," Haus wurde erfolgreich erstellt!");
return 1;
}
Laden, Speicher und CreateHaus
stock mysql_CheckHaus(id)
{
new Query[128],count;
format(Query, sizeof(Query), "SELECT * FROM `häuser` WHERE `id` = '%d'", id);
mysql_query(Query);
mysql_store_result();
count = mysql_num_rows();
mysql_free_result();
return count;
}
stock CreateHaus(Float:x,Float:y,Float:z,preis,interior,Float:ex,Float:ey,Float:ez,level,bs[])
{
for(new h = 0;h < MAX_HAUS; h++)
{
if(mysql_CheckHaus(h) == 1)continue;
else if(mysql_CheckHaus(h) == 0){
new query[256],Owner[MAX_PLAYER_NAME],hid[5],string[128];
valstr(hid,h);
mysql_real_escape_string(UNALLOWED_NAME,Owner);
mysql_real_escape_string(bs,bs);
format(query, sizeof(query), "INSERT INTO `häuser` (`hOwner`, `hBeschreibung`) VALUES ('%s', '%s')", Owner, bs);
mysql_query(query);
mysql_SetFloat("häuser","EnterX",x,"id",hid);
mysql_SetFloat("häuser","EnterY",y,"id",hid);
mysql_SetFloat("häuser","EnterZ",z,"id",hid);
mysql_SetFloat("häuser","ExitX",ex,"id",hid);
mysql_SetFloat("häuser","ExitY",ey,"id",hid);
mysql_SetFloat("häuser","ExitZ",ez,"id",hid);
mysql_SetInt("häuser","hInt",interior,"id",hid);
mysql_SetInt("häuser","hPreis",preis,"id",hid);
mysql_SetInt("häuser","hLevel",level,"id",hid);
LoadHaus(h);
HausInfo[h][hPickup] = CreatePickup(1273, 1, x, y, z);
format(string, sizeof(string), "Zu Verkaufen\n%d $\nLevel: %d\nBeschreibung: %s\n '/hkaufen' zum Kaufen", HausInfo[h][hPreis], HausInfo[h][hLevel], HausInfo[h][hBeschreibung]);
HausInfo[h][hLabelID] = Create3DTextLabel(string,COLOR_LIGHTBLUE,x, y, z+1,22.0,0,0);
return 1;
}
}
return 0;
}
stock SaveHaus(hausid)
{
if(mysql_CheckHaus(hausid) == 0)return 0;
new hid[5];
valstr(hid,hausid);
mysql_SetFloat("häuser","EnterX",HausInfo[hausid][EnterX],"id",hid);
mysql_SetFloat("häuser","EnterY",HausInfo[hausid][EnterY],"id",hid);
mysql_SetFloat("häuser","EnterZ",HausInfo[hausid][EnterZ],"id",hid);
mysql_SetFloat("häuser","ExitX",HausInfo[hausid][ExitX],"id",hid);
mysql_SetFloat("häuser","ExitY",HausInfo[hausid][ExitY],"id",hid);
mysql_SetFloat("häuser","ExitZ",HausInfo[hausid][ExitZ],"id",hid);
mysql_SetInt("häuser","hPreis",HausInfo[hausid][hPreis],"id",hid);
mysql_SetInt("häuser","hLocked",HausInfo[hausid][hLocked],"id",hid);
mysql_SetInt("häuser","hAllowrent",HausInfo[hausid][hAllowrent],"id",hid);
mysql_SetInt("häuser","hRent",HausInfo[hausid][hRent],"id",hid);
mysql_SetInt("häuser","hInt",HausInfo[hausid][hInt],"id",hid);
mysql_SetInt("häuser","hOwned",HausInfo[hausid][hOwned],"id",hid);
mysql_SetInt("häuser","hMiete",HausInfo[hausid][hMiete],"id",hid);
mysql_Set("häuser","hOwner",HausInfo[hausid][hOwner],"id",hid);
return 1;
}
stock LoadHaus(hausid)
{
if(mysql_CheckHaus(hausid) == 0)return 0;
new hid[5];
valstr(hid,hausid);
HausInfo[hausid][EnterX] = mysql_GetFloat("häuser", "EnterX", "id", hid);
HausInfo[hausid][EnterY] = mysql_GetFloat("häuser", "EnterY", "id", hid);
HausInfo[hausid][EnterZ] = mysql_GetFloat("häuser", "EnterZ", "id", hid);
HausInfo[hausid][ExitX] = mysql_GetFloat("häuser", "ExitX", "id", hid);
HausInfo[hausid][ExitY] = mysql_GetFloat("häuser", "ExitY", "id", hid);
HausInfo[hausid][ExitZ] = mysql_GetFloat("häuser", "ExitZ", "id", hid);
HausInfo[hausid][hPreis] = mysql_GetInt("häuser", "hPreis", "id", hid);
HausInfo[hausid][hLocked] = mysql_GetInt("häuser", "hLocked", "id", hid);
HausInfo[hausid][hAllowrent] = mysql_GetInt("häuser", "hAllowrent", "id", hid);
HausInfo[hausid][hLevel] = mysql_GetInt("häuser", "hLevel", "id", hid);
HausInfo[hausid][hRent] = mysql_GetInt("häuser", "hRent", "id", hid);
HausInfo[hausid][hInt] = mysql_GetInt("häuser", "hInt", "id", hid);
HausInfo[hausid][hMiete] = mysql_GetInt("häuser", "hMiete", "id", hid);
HausInfo[hausid][hOwned] = mysql_GetInt("häuser", "hOwned", "id", hid);
format(HausInfo[hausid][hBeschreibung],128,"%s",mysql_Get("häuser","hBeschreibung","id",hid));
format(HausInfo[hausid][hOwner],32,"%s",mysql_Get("häuser","hOwner","id",hid));
return 1;
}
Hier noch die mysql stocks:
stock mysql_GetInt(Table[], Field[], Where[], Is[])
{
new query[128];
mysql_real_escape_string(Table, Table);
mysql_real_escape_string(Field, Field);
mysql_real_escape_string(Where, Where);
mysql_real_escape_string(Is, Is);
format(query, 128, "SELECT `%s` FROM `%s` WHERE `%s` = '%s'", Field, Table, Where, Is);
mysql_query(query);
mysql_store_result();
new sqlint = mysql_fetch_int();
mysql_free_result();
return sqlint;
}
stock mysql_Get(Table[], Field[], Where[], Is[])
{
new query[128], Get[128];
mysql_real_escape_string(Table, Table);
mysql_real_escape_string(Field, Field);
mysql_real_escape_string(Where, Where);
mysql_real_escape_string(Is, Is);
format(query, 128, "SELECT `%s` FROM `%s` WHERE `%s` = '%s'", Field, Table, Where, Is);
mysql_query(query);
mysql_store_result();
mysql_fetch_row(Get);
mysql_free_result();
return Get;
}
stock Float:mysql_GetFloat(Table[], Field[], Where[], Is[])
{
new query[128], Float:sqlfloat;
mysql_real_escape_string(Table, Table);
mysql_real_escape_string(Field, Field);
mysql_real_escape_string(Where, Where);
mysql_real_escape_string(Is, Is);
format(query, 128, "SELECT `%s` FROM `%s` WHERE `%s` = '%s'", Field, Table, Where, Is);
mysql_query(query);
mysql_store_result();
mysql_fetch_float(sqlfloat);
mysql_free_result();
return sqlfloat;
}
stock mysql_SetInt(Table[], Field[], To, Where[], Where2[])
{
new query[128];
mysql_real_escape_string(Table, Table);
mysql_real_escape_string(Field, Field);
mysql_real_escape_string(Where, Where);
mysql_real_escape_string(Where2, Where2);
format(query, 128, "UPDATE `%s` SET `%s` = '%d' WHERE `%s` = '%s'", Table, Field, To, Where, Where2);
mysql_query(query);
return true;
}
stock mysql_Set(Table[], Field[], To[], Where[], Where2[])
{
new query[128];
mysql_real_escape_string(Table, Table);
mysql_real_escape_string(Field, Field);
mysql_real_escape_string(To, To);
mysql_real_escape_string(Where, Where);
mysql_real_escape_string(Where2, Where2);
format(query, 128, "UPDATE `%s` SET `%s` = '%s' WHERE `%s` = '%s'", Table, Field, To, Where, Where2);
mysql_query(query);
return true;
}
stock mysql_SetFloat(Table[], Field[], Float:To, Where[], Where2[])
{
new query[128];
mysql_real_escape_string(Table, Table);
mysql_real_escape_string(Field, Field);
mysql_real_escape_string(Where, Where);
mysql_real_escape_string(Where2, Where2);
format(query, 128, "UPDATE `%s` SET `%s` = '%f' WHERE `%s` = '%s'", Table, Field, To, Where, Where2);
mysql_query(query);
return true;
}