Shop Tutorial?
- Studs
- Geschlossen
- Erledigt
-
-
mysql_format(handle, query, sizeof(query), "SELECT * FROM Houses WHERE owner = '%e'", SpielerName(playerid));
mysql_pquery(handle, query, "OnHouseLoad", "d", playerid);In OnHouseLoad kannst du dann alles für das Haus des Spielers abarbeiten.
Sprich:
cache_get_value_name_int(0, "shopid", OwnedShop[playerid]);
cache_get_value_name_int(0, "insuranced", ShopInfo[OwnedShop[playerid]][insuranced]);
cache_get_value_name_int(0, "insurancetime", bisversichert);
(oder anstatt der 0 eine Schleife mit "i", allerdings habe ich es so verstanden, dass der Spieler nur ein Haus haben kann, daher reicht 0, die erste Zeile des Results.) -
Lädt irgendwie nicht, bekomme immer die nachricht mein shop seie nicht versichert,
Code
Alles anzeigenif(hatPlayerShop(playerid))//autoban { new query[256]; mysql_format(handle, query, sizeof(query), "SELECT * FROM Houses WHERE owner = '%e'", GetName(playerid)); mysql_pquery(handle, query, "OnHouseLoad", "d", playerid); new bisversichert; //new id=getFreeShopID(); cache_get_value_name_int(OwnedShop[playerid], "insuranced", ShopInfo[OwnedShop[playerid]][insuranced]); cache_get_value_name_int(OwnedShop[playerid], "insurancetime", bisversichert); // PlayerInfo[playerid][pBanDauer] = bisgebannt; if(ShopInfo[OwnedShop[playerid]][insuranced]>=1) { if(gettime() < bisversichert) { new timebanned = bisversichert-gettime(); new tage = timebanned / 86400; timebanned -= tage * 86400; new stunden = timebanned / 3600; timebanned -= stunden * 3600; new minuten = timebanned / 60; timebanned -= minuten * 60; new sekunden = timebanned; new str[128]; if(tage > 0) format(str,sizeof(str),"Your Insurance for your Shop expands in %i Days, %i Hours, %i Minutes and %i Seconds!",tage,stunden,minuten,sekunden); else if(stunden > 0) format(str,sizeof(str),"Your Insurance for your Shop expands in %i Hours, %i Minutes and %i Seconds!",stunden,minuten,sekunden); else if(minuten > 0) format(str,sizeof(str),"Your Insurance for your Shop expands in %i Minutes and %i Seconds!",minuten,sekunden); else format(str,sizeof(str),"Your Insurance for your Shop expands in %i Seconds!",sekunden); SendClientMessage(playerid,-1,str); return 1; } else { SendClientMessage(playerid,-1,"Your Insurance is expanded! You won't be protected against Robbers now!"); // ShopInfo[id][insuranced] = 0; ShopInfo[OwnedShop[playerid]][insuranced] = 0; ShopInfo[OwnedShop[playerid]][insurancetime] = 0; // ShopInfo[id][insurancetime] = 0; // new query[128]; mysql_format(handle, query, sizeof(query), "UPDATE Houses SET insuranced='0', insurancetime = '0' WHERE shopid = '%d'", ShopInfo[OwnedShop[playerid]][shopid],ShopInfo[OwnedShop[playerid]][shopid]); mysql_pquery(handle, query, "ShopsSave"); return 1; } } else { return SendClientMessage(playerid,COOLRED,"Your Shop isn't insuranced! You won't be protected against Robbers!"); } }
Code
Alles anzeigenstock hatPlayerShop(playerid) { new name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, sizeof(name)); for(new i=0; i<sizeof(ShopInfo); i++) { if(!ShopInfo[i][shopid])continue; if(!strlen(ShopInfo[i][owner]))continue; if(!strcmp(name, ShopInfo[i][owner], true)) return 1; } return 0; }
Code
Alles anzeigenforward OnHouseLoad(playerid); public OnHouseLoad(playerid) { new num_rows; cache_get_row_count(num_rows); if(!num_rows)return 1; for(new i; i<num_rows; i++) { cache_get_value_name_int(0, "shopid", OwnedShop[playerid]); // cache_get_value_name_int(0, "insuranced", ShopInfo[OwnedShop[playerid]][insuranced]); } return 1; }
-
Alles was nach dem mysql_pquery bezüglich der Versicherung kommt, muss in das Callback OnHouseLoad.
Erst dort hast du die Werte aus der Datenbank zur Verfügung. -
Das mit dem Laden funktioniert ja schonmal hab ich auch in den mysql logs gecheckt,
jedoch wird mir weiterhin gesagt ich wäre nicht versichert, irgendwas stimmt mit den beiden
werten beim zuordnen oder so nicht, sieht doch alles korrekt aus?
Code
Alles anzeigenif(hatPlayerShop(playerid))//autoban { new query[256]; mysql_format(handle, query, sizeof(query), "SELECT * FROM Houses WHERE owner = '%e'", GetName(playerid)); mysql_pquery(handle, query, "OnHouseLoad", "d", playerid); new bisversichert = ShopInfo[OwnedShop[playerid]][insurancetime]; //new id=getFreeShopID(); // cache_get_value_name_int(OwnedShop[playerid], "insuranced", ShopInfo[OwnedShop[playerid]][insuranced]); // cache_get_value_name_int(OwnedShop[playerid], "insurancetime", bisversichert); // PlayerInfo[playerid][pBanDauer] = bisgebannt; if(ShopInfo[OwnedShop[playerid]][insuranced]==1) { if(gettime() < bisversichert) { new timebanned = bisversichert-gettime(); new tage = timebanned / 86400; timebanned -= tage * 86400; new stunden = timebanned / 3600; timebanned -= stunden * 3600; new minuten = timebanned / 60; timebanned -= minuten * 60; new sekunden = timebanned; new str[128]; if(tage > 0) format(str,sizeof(str),"Your Insurance for your Shop expands in %i Days, %i Hours, %i Minutes and %i Seconds!",tage,stunden,minuten,sekunden); else if(stunden > 0) format(str,sizeof(str),"Your Insurance for your Shop expands in %i Hours, %i Minutes and %i Seconds!",stunden,minuten,sekunden); else if(minuten > 0) format(str,sizeof(str),"Your Insurance for your Shop expands in %i Minutes and %i Seconds!",minuten,sekunden); else format(str,sizeof(str),"Your Insurance for your Shop expands in %i Seconds!",sekunden); SendClientMessage(playerid,-1,str); return 1; } else { SendClientMessage(playerid,-1,"Your Insurance is expanded! You won't be protected against Robbers now!"); // ShopInfo[id][insuranced] = 0; ShopInfo[OwnedShop[playerid]][insuranced] = 0; ShopInfo[OwnedShop[playerid]][insurancetime] = 0; // ShopInfo[id][insurancetime] = 0; // new query[128]; mysql_format(handle, query, sizeof(query), "UPDATE Houses SET insuranced='0', insurancetime = '0' WHERE shopid = '%d'", ShopInfo[OwnedShop[playerid]][shopid],ShopInfo[OwnedShop[playerid]][shopid]); mysql_pquery(handle, query, "ShopsSave"); return 1; } } else { return SendClientMessage(playerid,COOLRED,"Your Shop isn't insuranced! You won't be protected against Robbers!"); } }
Code
Alles anzeigenforward OnHouseLoad(playerid); public OnHouseLoad(playerid) { new num_rows; cache_get_row_count(num_rows); if(!num_rows)return 1; for(new i; i<num_rows; i++) { cache_get_value_name_int(i, "shopid", OwnedShop[playerid]); cache_get_value_name_int(i, "insuranced", ShopInfo[OwnedShop[playerid]][insuranced]); cache_get_value_name_int(i, "insurancetime", ShopInfo[OwnedShop[playerid]][insurancetime]); } return 1; }
-
Wie gesagt, alles was nach dem mysql_pquery kommt, muss in das Callback, heißt auch die Prüfung ob eine Versicherung existiert oder nicht. Die Werte werden erst im Callback geladen, diese stehen direkt nach mysql_pquery noch nicht zur Verfügung, deshalb wird dir immer gesagt, dass du keine Versicherung hast.
Also: Alles aus obigem Code, was nach mysql_pquery steht, muss ins Callback.
-
achso, jetzt versteh ich das erst, danke geht
-
breadfish.de
Hat das Thema geschlossen.