Guten Abend,
Ich habe ma so ein Tankstellen system angefangen und wenn ich den Befehl zum erstellen einer Tankstelle eingeben passiert nix.
Wäre net wenn mir einer sagen könnte was ich falsch gemacht habe hir der code:
#include <a_samp>
#include <a_mysql>
#include <ocmd>
#define MAX_TANKSTELLEN 15
#define Gelb 0xFFFF00FF
#define Weiss 0xFFFFFFFF
#define SQL_HOST "localhost"
#define SQL_USER "root"
#define SQL_PASS ""
#define SQL_DATA "tankstelle"
enum Tinf {
Besitzer[MAX_PLAYER_NAME], bool:fExist,
Besetzt, Erpresser[MAX_PLAYER_NAME],
Kasse, KaufPreis,
KaufLevel, TankPreis, fPickup,
fSQLid, Float: TX,Float: TY,Float: TZ,
Text3D:TankText
}
new TankInfo[MAX_TANKSTELLEN][Tinf];
public OnFilterScriptInit()
{
LoadTankst();
Connect_To_Database();
print("\n--------------------------------------");
print(" Test Tankstellen System (c) Fabi.StaR");
print("--------------------------------------\n");
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
ocmd:createtank(playerid, params[])
{
new Level, Preis,string[128],Float:X,Float:Y,Float:Z;
GetPlayerPos(playerid,X,Y,Z);
for(new t = 0; t<sizeof(TankInfo); t++) {
if(IsPlayerAdmin(playerid)) {
new Slot = GetFreeTankstslot();
if(Slot != -1) {
if(sscanf(params,"dd",Level,Preis))return SendClientMessage(playerid,Gelb,"[Benutze]: /createtank [KaufLevel] [KaufPreis]");
TankInfo[Slot][KaufPreis] = Preis;
TankInfo[Slot][KaufLevel] = Level;
TankInfo[Slot][TX] = X;
TankInfo[Slot][TY] = Y;
TankInfo[Slot][TZ] = Z;
mysql_query("SELECT max(id) FROM `tankstellen`");
mysql_store_result();
mysql_fetch_row_format(string);
UpdateFactionCar(Slot);
CreatePickUpofMap(Slot);
}
}
}
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
return 1;
}
return 0;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
return 1;
}
stock GetFreeTankstslot()
{
for(new i = 0; i < sizeof(TankInfo); i++) {
if(TankInfo[i][fExist]==false)return i;
}
return -1;
}
stock LoadTankst()
{
new Load[16], idx;
mysql_query("SELECT * FROM tankstellen");
mysql_store_result();
while(mysql_retrieve_row())
{
mysql_fetch_field_row(Load, "Besitzer");
format(TankInfo[idx][Besitzer],500,Load);
mysql_fetch_field_row(Load, "Erpresser");
format(TankInfo[idx][Erpresser],500,Load);
mysql_fetch_field_row(Load, "Besetzt");
TankInfo[idx][Besetzt] = strval(Load);
mysql_fetch_field_row(Load, "Kasse");
TankInfo[idx][Kasse] = strval(Load);
mysql_fetch_field_row(Load, "X");
TankInfo[idx][TX] = floatstr(Load);
mysql_fetch_field_row(Load, "Y");
TankInfo[idx][TY] = floatstr(Load);
mysql_fetch_field_row(Load, "Z");
TankInfo[idx][TZ] = floatstr(Load);
mysql_fetch_field_row(Load, "TankPreis");
TankInfo[idx][TankPreis] = strval(Load);
mysql_fetch_field_row(Load, "KaufLevel");
TankInfo[idx][KaufLevel] = strval(Load);
mysql_fetch_field_row(Load, "KaufPreis");
TankInfo[idx][KaufPreis] = strval(Load);
mysql_fetch_field_row(Load, "id");
TankInfo[idx][fSQLid] = strval(Load);
CreatePickUpofMap(idx);
idx ++;
}
mysql_free_result();
}
stock UpdateFactionCar(id)
{
new Query[128];
if(TankInfo[id][fExist] == true)
{
format(Query, sizeof(Query), "UPDATE tankstellen SET `Kasse` = '%d' WHERE `id` = '%d'", TankInfo[id][Kasse], TankInfo[id][fSQLid]);
mysql_query(Query);
format(Query, sizeof(Query), "UPDATE tankstellen SET `X` = '%f' WHERE `id` = '%d'", TankInfo[id][TX], TankInfo[id][fSQLid]);
mysql_query(Query);
format(Query, sizeof(Query), "UPDATE tankstellen SET `Y` = '%f' WHERE `id` = '%d'", TankInfo[id][TY], TankInfo[id][fSQLid]);
mysql_query(Query);
format(Query, sizeof(Query), "UPDATE tankstellen SET `Z` = '%f' WHERE `id` = '%d'", TankInfo[id][TZ], TankInfo[id][fSQLid]);
mysql_query(Query);
format(Query, sizeof(Query), "UPDATE tankstellen SET `TankPreis` = '%d' WHERE `id` = '%d'", TankInfo[id][TankPreis], TankInfo[id][fSQLid]);
mysql_query(Query);
format(Query, sizeof(Query), "UPDATE tankstellen SET `KaufLevel` = '%d' WHERE `id` = '%d'", TankInfo[id][KaufLevel], TankInfo[id][fSQLid]);
mysql_query(Query);
format(Query, sizeof(Query), "UPDATE tankstellen SET `KaufPreis` = '%d' WHERE `id` = '%d'", TankInfo[id][KaufPreis], TankInfo[id][fSQLid]);
mysql_query(Query);
}
return 1;
}
stock CreatePickUpofMap(id)
{
if(TankInfo[id][fExist] == true)
{
new str[128];
TankInfo[id][fPickup] = CreatePickup(1339,2, TankInfo[id][TX], TankInfo[id][TY], TankInfo[id][TZ],0);
if(TankInfo[id][Besetzt] != 1)
{
format(str,sizeof(str),"Diese Tankstelle steht zum verkkauf Tipp:/buyTankst ein\nBesitzer: -KEINER-\nKaufPreis: %d\nKaufLevel: %d",TankInfo[id][KaufPreis],TankInfo[id][KaufLevel]);
TankInfo[id][TankText] = Create3DTextLabel(str,Weiss,0,0,0,15,0,1);
}
else
{
format(str,sizeof(str),"%s\nBesitzer: %s\nErpresser: %d\nTankPreis: %d",TankInfo[id][Besitzer],TankInfo[id][Erpresser],TankInfo[id][TankPreis]);
TankInfo[id][TankText] = Create3DTextLabel(str,Weiss,0,0,0,15,0,1);
}
}
return 1;
}
stock Connect_To_Database()
{
mysql_connect(SQL_HOST, SQL_USER, SQL_DATA, SQL_PASS);
if(mysql_ping() == 1)
{
print("<-| [MYSQL] Verbindung zur Datenbank wurde erfolgreich hergestellt!");
return true;
}
else
{
print("<-| [MYSQL] Es konnte keine Verbindung zur Datenbank hergestellt werden!");
print("<-| [MYSQL] Es wird erneut versucht eine Verbindung zur Datenbank herzustellen!");
mysql_connect(SQL_HOST, SQL_USER, SQL_DATA, SQL_PASS);
if(mysql_ping() == 1)
{
print("<-| [MYSQL] Es konnte im 2 Versuch eine Verbindung hergestellt werden!");
return true;
}
else
{
print("<-| [MYSQL] Es konnte keine Verbindung zur Datenbank hergestellt werden!");
print("<-| [MYSQL] Der Server wird nun beendet!");
SendRconCommand("exit");
return true;
}
}
}
stock sscanf(sstring[], format[], {Float,_}:...)
{
#if defined isnull
if (isnull(sstring))
#else
if (sstring[0] == 0 || (sstring[0] == 1 && sstring[1] == 0))
#endif
{
return format[0];
}
#pragma tabsize 4
new
formatPos = 0,
sstringPos = 0,
paramPos = 2,
paramCount = numargs(),
delim = ' ';
while (sstring[sstringPos] && sstring[sstringPos] <= ' ')
{
sstringPos++;
}
while (paramPos < paramCount && sstring[sstringPos])
{
switch (format[formatPos++])
{
case '\0':
{
return 0;
}
case 'i', 'd':
{
new
neg = 1,
num = 0,
ch = sstring[sstringPos];
if (ch == '-')
{
neg = -1;
ch = sstring[++sstringPos];
}
do
{
sstringPos++;
if ('0' <= ch <= '9')
{
num = (num * 10) + (ch - '0');
}
else
{
return -1;
}
}
while ((ch = sstring[sstringPos]) > ' ' && ch != delim);
setarg(paramPos, 0, num * neg);
}
case 'h', 'x':
{
new
num = 0,
ch = sstring[sstringPos];
do
{
sstringPos++;
switch (ch)
{
case 'x', 'X':
{
num = 0;
continue;
}
case '0' .. '9':
{
num = (num << 4) | (ch - '0');
}
case 'a' .. 'f':
{
num = (num << 4) | (ch - ('a' - 10));
}
case 'A' .. 'F':
{
num = (num << 4) | (ch - ('A' - 10));
}
default:
{
return -1;
}
}
}
while ((ch = sstring[sstringPos]) > ' ' && ch != delim);
setarg(paramPos, 0, num);
}
case 'c':
{
setarg(paramPos, 0, sstring[sstringPos++]);
}
case 'f':
{
new changestr[16], changepos = 0, strpos = sstringPos;
while(changepos < 16 && sstring[strpos] && sstring[strpos] != delim)
{
changestr[changepos++] = sstring[strpos++];
}
changestr[changepos] = '\0';
setarg(paramPos,0,_:floatstr(changestr));
}
case 'p':
{
delim = format[formatPos++];
continue;
}
case '\'':
{
new
end = formatPos - 1,
ch;
while ((ch = format[++end]) && ch != '\'') {}
if (!ch)
{
return -1;
}
format[end] = '\0';
if ((ch = strfind(sstring, format[formatPos], false, sstringPos)) == -1)
{
if (format[end + 1])
{
return -1;
}
return 0;
}
format[end] = '\'';
sstringPos = ch + (end - formatPos);
formatPos = end + 1;
}
case 'u':
{
new
end = sstringPos - 1,
id = 0,
bool:num = true,
ch;
while ((ch = sstring[++end]) && ch != delim)
{
if (num)
{
if ('0' <= ch <= '9')
{
id = (id * 10) + (ch - '0');
}
else
{
num = false;
}
}
}
if (num && IsPlayerConnected(id))
{
setarg(paramPos, 0, id);
}
else
{
#if !defined foreach
#define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
#define __SSCANF_FOREACH__
#endif
sstring[end] = '\0';
num = false;
new
name[MAX_PLAYER_NAME];
id = end - sstringPos;
foreach (Player, playerid)
{
GetPlayerName(playerid, name, sizeof (name));
if (!strcmp(name, sstring[sstringPos], true, id))
{
setarg(paramPos, 0, playerid);
num = true;
break;
}
}
if (!num)
{
setarg(paramPos, 0, INVALID_PLAYER_ID);
}
sstring[end] = ch;
#if defined __SSCANF_FOREACH__
#undef foreach
#undef __SSCANF_FOREACH__
#endif
}
sstringPos = end;
}
case 's', 'z':
{
new
i = 0,
ch;
if (format[formatPos])
{
while ((ch = sstring[sstringPos++]) && ch != delim)
{
setarg(paramPos, i++, ch);
}
if (!i)
{
return -1;
}
}
else
{
while ((ch = sstring[sstringPos++]))
{
setarg(paramPos, i++, ch);
}
}
sstringPos--;
setarg(paramPos, i, '\0');
}
default:
{
continue;
}
}
while (sstring[sstringPos] && sstring[sstringPos] != delim && sstring[sstringPos] > ' ')
{
sstringPos++;
}
while (sstring[sstringPos] && (sstring[sstringPos] == delim || sstring[sstringPos] <= ' '))
{
sstringPos++;
}
paramPos++;
}
do
{
if ((delim = format[formatPos++]) > ' ')
{
if (delim == '\'')
{
while ((delim = format[formatPos++]) && delim != '\'') {}
}
else if (delim != 'z')
{
return delim;
}
}
}
while (delim > ' ');
return 0;
}
//EDIT's
- Fehler endekt und behoben aber geht immer noch net