Guten Tag liebe Breadfisher,
Habe ein Problem undswar wen ich ein Haus erstelle ist alles schön und gut nur wen man das Haus Kauft sind da 2Pickups und 2 Texte.
Hier nochmal das Enum:
enum houseEnum{
h_id,
h_besitzer[MAX_PLAYER_NAME],
Float:h_x,
Float:h_y,
Float:h_z,
Float:h_ix,
Float:h_iy,
Float:h_iz,
h_int,
h_preis,
h_locked,
h_pickup,
Text3D:h_text
};
new hInfo[100][houseEnum];
Und hier das komplette um zu zeigen was falsch ist
updateHaus(id)
{
new string[128];
if(hInfo[id][h_pickup])
{
DestroyPickup(hInfo[id][h_pickup]);
}
if(hInfo[id][h_text])
{
Delete3DTextLabel(hInfo[id][h_text]);
}
if(!strlen(hInfo[id][h_besitzer]))
{
hInfo[id][h_pickup]=CreatePickup(1273, 1, hInfo[id][h_x], hInfo[id][h_y], hInfo[id][h_z], -1);
format(string,128, "~[***Haus***]~\nZum Verkauf\nKosten: %i$\n/hauskaufen", hInfo[id][h_preis]);
hInfo[id][h_text] = Create3DTextLabel(string, COLOR_LIME, hInfo[id][h_x], hInfo[id][h_y], hInfo[id][h_z], 10, 0, 1);
}
else
{
hInfo[id][h_pickup]=CreatePickup(1239, 1, hInfo[id][h_x], hInfo[id][h_y], hInfo[id][h_z], -1);
format(string,128, "~[***Haus***]~\nBesitzer: %s\n/enter", hInfo[id][h_besitzer]);
hInfo[id][h_text]=Create3DTextLabel(string, COLOR_WHITE, hInfo[id][h_x], hInfo[id][h_y], hInfo[id][h_z], 10, 0, 1);
}
return 1;
}
OnGameModeInit
new query[128];
format(query, sizeof(query), "SELECT * FROM houses");
mysql_function_query(Handle, query, true, "OnHausesLoad", "");
public OnHausesLoad()
{
new num_fields,num_rows;
cache_get_data(num_rows,num_fields,Handle);
if(!num_rows)return 1;
for(new i=0; i<num_rows; i++)
{
new id=getFreeHausID();
hInfo[id][h_x]=cache_get_field_content_float(i, "X", Handle);
hInfo[id][h_y]=cache_get_field_content_float(i, "Y", Handle);
hInfo[id][h_z]=cache_get_field_content_float(i, "Z", Handle);
hInfo[id][h_ix]=cache_get_field_content_float(i, "IX", Handle);
hInfo[id][h_iy]=cache_get_field_content_float(i, "IY", Handle);
hInfo[id][h_iz]=cache_get_field_content_float(i, "IZ", Handle);
hInfo[id][h_int]=cache_get_field_content_int(i, "Interior", Handle);
new tmp_name[MAX_PLAYER_NAME];
cache_get_field_content(i, "Besitzer", tmp_name, Handle);
strmid(hInfo[id][h_besitzer], tmp_name, 0, sizeof(tmp_name), sizeof(tmp_name));
hInfo[id][h_id]=cache_get_field_content_int(i, "id", Handle);
hInfo[id][h_preis]=cache_get_field_content_int(i, "Preis", Handle);
hInfo[id][h_locked]=cache_get_field_content_int(i, "Locked", Handle);
updateHaus(id);
}
return 1;
}
updateHaus(id)
{
new string[128];
if(hInfo[id][h_pickup])
{
DestroyPickup(hInfo[id][h_pickup]);
}
if(hInfo[id][h_text])
{
Delete3DTextLabel(hInfo[id][h_text]);
}
if(!strlen(hInfo[id][h_besitzer]))
{
hInfo[id][h_pickup]=CreatePickup(1273, 1, hInfo[id][h_x], hInfo[id][h_y], hInfo[id][h_z], -1);
format(string,sizeof(string), "~~[**Haus**]~~\nZum Verkauf\nKosten: %i$\n/hauskaufen", hInfo[id][h_preis]);
hInfo[id][h_text]=Create3DTextLabel(string, COLOR_WHITE, hInfo[id][h_x], hInfo[id][h_y], hInfo[id][h_z], 10, 0, 1);
}
else
{
hInfo[id][h_pickup]=CreatePickup(1239, 1, hInfo[id][h_x], hInfo[id][h_y], hInfo[id][h_z], -1);
format(string,sizeof(string), "~~[**Haus**]~~\nBesitzer: %s\n/enter", hInfo[id][h_besitzer]);
hInfo[id][h_text]=Create3DTextLabel(string, COLOR_BLUE, hInfo[id][h_x], hInfo[id][h_y], hInfo[id][h_z], 10, 0, 1);
}
return 1;
}
getFreeHausID()
{
for(new i=0; i<sizeof(hInfo); i++)
{
if(hInfo[i][h_id]==0)return i;
}
return 0;
}
Befehle mit ocmd:
ocmd:setpreis(playerid, params[])
{
if(pInfo[playerid][pAdmin] >= 3)return SendClientMessage(playerid, COLOR_RED, "Dein Adminrang ist zu niedrig.");
new tmp_preis;
if(sscanf(params, "i", tmp_preis))return SendClientMessage(playerid, COLOR_RED, "INFO: /setpreis [preis]");
for(new i=0; i<sizeof(hInfo); i++)
{
if(!hInfo[i][h_id])continue;
if(!IsPlayerInRangeOfPoint(playerid, 5, hInfo[i][h_x], hInfo[i][h_y], hInfo[i][h_z]))continue;
hInfo[i][h_preis] = tmp_preis;
saveHaus(i);
updateHaus(i);
return 1;
}
return 1;
}
ocmd:deletehaus(playerid, params[])
{
if(pInfo[playerid][pAdmin] >= 3)return SendClientMessage(playerid, COLOR_RED, "Dein Adminrang ist zu niedrig.");
for(new i=0; i<sizeof(hInfo); i++)
{
if(!hInfo[i][h_id])continue;
if(!IsPlayerInRangeOfPoint(playerid, 5, hInfo[i][h_x], hInfo[i][h_y], hInfo[i][h_z]))continue;
new query[128];
format(query,sizeof(query), "DELETE FROM houses WHERE id='%i'", hInfo[i][h_id]);
mysql_function_query(Handle, query, false, "", "");
hInfo[i][h_x]=0.0;
hInfo[i][h_y]=0.0;
hInfo[i][h_z]=0.0;
hInfo[i][h_ix]=0.0;
hInfo[i][h_iy]=0.0;
hInfo[i][h_iz]=0.0;
hInfo[i][h_id]=0;
hInfo[i][h_preis]=0;
hInfo[i][h_int]=0;
updateHaus(i);
return 1;
}
return 1;
}
ocmd:createhaus(playerid, params[])
{
if(pInfo[playerid][pAdmin] >= 3)return SendClientMessage(playerid, COLOR_RED, "Dein Adminrang ist zu niedrig.");
new Float:xc, Float:yc, Float:zc;
GetPlayerPos(playerid, xc, yc, zc);
new id=getFreeHausID();
hInfo[id][h_x]=xc;
hInfo[id][h_y]=yc;
hInfo[id][h_z]=zc;
hInfo[id][h_ix]=0.0;
hInfo[id][h_iy]=0.0;
hInfo[id][h_iz]=0.0;
hInfo[id][h_int]=0;
strmid(hInfo[id][h_besitzer], "", 0, MAX_PLAYER_NAME, MAX_PLAYER_NAME);
hInfo[id][h_preis]=1;
updateHaus(id);
//In Datenbank abspeichern
new query[256];
format(query, sizeof(query), "INSERT INTO houses (X, Y, Z, IX, IY, IZ, Interior, Preis, Locked) VALUES ('%f', '%f', '%f', '0.0', '0.0', '0.0', '0', '1', '1')", xc, yc, zc);
mysql_function_query(Handle, query, true, "OnHausCreated", "i", id);
return 1;
}
ocmd:hausverkaufen(playerid, params[])
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
for(new i=0; i<sizeof(hInfo); i++)
{
if(!hInfo[i][h_id])continue;
if(!IsPlayerInRangeOfPoint(playerid, 5,
hInfo[i][h_x], hInfo[i][h_y], hInfo[i][h_z]))continue;
if(!strlen(hInfo[i][h_besitzer]))continue;
if(!strcmp(hInfo[i][h_besitzer], name, true))
{
hInfo[i][h_preis]=hInfo[i][h_preis]/2;
GivePlayerMoney(playerid, hInfo[i][h_preis]);
strmid(hInfo[i][h_besitzer], "", 0, MAX_PLAYER_NAME, MAX_PLAYER_NAME);
updateHaus(i);
saveHaus(i);
return 1;
}
}
return 1;
}
ocmd:hauskaufen(playerid, params[])
{
if(hatPlayerHaus(playerid))return SendClientMessage(playerid, COLOR_RED, "Du hast bereits ein Haus.");
for(new i=0; i<sizeof(hInfo); i++)
{
if(!hInfo[i][h_id])continue;
if(!IsPlayerInRangeOfPoint(playerid, 5, hInfo[i][h_x], hInfo[i][h_y], hInfo[i][h_z]))continue;
if(!strlen(hInfo[i][h_besitzer]))
{
if(GetPlayerMoney(playerid)<hInfo[i][h_preis])return SendClientMessage(playerid, COLOR_RED, "Du hast nicht genügend Geld.");
GivePlayerMoney(playerid, -hInfo[i][h_preis]);
strmid(hInfo[i][h_besitzer], getPlayerName(playerid), 0, MAX_PLAYER_NAME, MAX_PLAYER_NAME);
updateHaus(i);
saveHaus(i);
return 1;
}
return SendClientMessage(playerid, COLOR_RED, "Das Haus steht nicht zum Verkauf.");
}
return 1;
}
hatPlayerHaus(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
for(new i=0; i<sizeof(hInfo); i++)
{
if(!hInfo[i][h_id])continue;
if(!strlen(hInfo[i][h_besitzer]))continue;
if(!strcmp(name, hInfo[i][h_besitzer], true))return 1;
}
return 0;
}
saveHaus(id)
{
new query[128];
format(query, sizeof(query), "UPDATE houses SET Besitzer='%s', Preis='%i', X='%f', Y='%f', Z='%f', IX='%f', IY='%f', IZ='%f', Interior='%i' WHERE id='%i'", hInfo[id][h_besitzer], hInfo[id][h_preis], hInfo[id][h_x], hInfo[id][h_y], hInfo[id][h_z], hInfo[id][h_ix], hInfo[id][h_iy], hInfo[id][h_iz], hInfo[id][h_int],hInfo[id][h_id]);
mysql_function_query(Handle, query, false, "", "");
return 1;
}
Hoffe ihr könnt mir helfen.
Liebe Grüße,
SkoMe