Command Doesn't do anything -
nezo2001 - 29.08.2015
The command only prints (Done?) which is under
PHP код:
CMD:buycar(playerid, params[])
{
new bool:in_range = false;
new bool:notIn = false;
new bool:noMoney = false;
new bool:AlreadyHas = false;
new bool:NotForSale = false;
for(new a = 1; a <= MAX_VEHICLES; a++)
{
new Float:vx, Float:vy, Float:vz;
GetVehiclePos(a, vx, vy, vz);
if(IsPlayerInRangeOfPoint(playerid, 3.0, vx, vy, vz))
{
if(CarInDb[a] == false) { notIn = true; }
}
}
if(notIn == true) return SendClientMessage(playerid, COLOR_RED, "This is a server-car!");
for(new i = 0; i != CarsLoad;i++)
{
if(IsPlayerInRangeOfPoint(playerid, 3.0, CarInfo[i][CarX], CarInfo[i][CarY], CarInfo[i][CarY]))
{
if(GetPlayerMoney(playerid) < CarInfo[i][CarPrice])
{
if(PlayerInfo[playerid][pHasCar] > 2)
{
if(CarInfo[i][cSale] == 0)
{
if(strcmp(CarInfo[i][owner], "None"))
{
new UMoney[128];
new Smoney[128];
new money = format(Smoney, sizeof(Smoney), "SELECT pMoney FROM users WHERE pName='%s'",CarInfo[i][owner]);
mysql_query(1, Smoney);
format(UMoney, sizeof(UMoney), "UPDATE users SET pMoney='%i' WHERE username='%s'",money+CarInfo[i][CarPrice], CarInfo[i][owner]);
mysql_query(1, UMoney);
}
new query[200];
format(query, sizeof(query), "UPDATE cars SET owner='%s', owned='1', cSale='0' WHERE id='%i'",PlayerName(playerid), CarInfo[i][CarID]);
mysql_query(1, query);
PlayerInfo[playerid][pHasCar]++;
GivePlayerMoney(playerid, -CarInfo[i][CarPrice]);
}
else { NotForSale = true; }
} else { AlreadyHas = true; }
} else { noMoney = true; }
} else { notIn = true; }
}
if(in_range == true) return SendClientMessage(playerid, COLOR_RED, "You aren't near any for-sale car!");
if(noMoney == true) return SendClientMessage(playerid, COLOR_RED, "You don't have enough money!");
if(AlreadyHas == true) return SendClientMessage(playerid, COLOR_RED, "You already have two cars!");
if(NotForSale == true) return SendClientMessage(playerid, COLOR_RED, "This vehicle isn't for sale!");
print("Done?");
return 1;
}
PHP код:
CarsLoad = clamp(cache_get_row_count(), 0, sizeof CarInfo - 1);
I'm making it on this way to prevent messages spamming in loops but it doesn't do anything :/
Re: Command Doesn't do anything -
nezo2001 - 29.08.2015
After debugging
PHP код:
CMD:buycar(playerid, params[])
{
new bool:in_range = false;
new bool:notIn = false;
new bool:noMoney = false;
new bool:AlreadyHas = false;
new bool:NotForSale = false;
/*for(new a = 1; a <= MAX_VEHICLES; a++)
{
new Float:vx, Float:vy, Float:vz;
GetVehiclePos(a, vx, vy, vz);
if(IsPlayerInRangeOfPoint(playerid, 3.0, vx, vy, vz))
{
if(CarInDb[a] == false) { notIn = true; }
}
}*/
print("Bools set!");
//if(notIn == true) return SendClientMessage(playerid, COLOR_RED, "This is a server-car!");
print("loop is starting!");
for(new i; i != CarsLoad;i++)
{
print("loop started!");
if(IsPlayerInRangeOfPoint(playerid, 3.0, CarInfo[i][CarX], CarInfo[i][CarY], CarInfo[i][CarY]))
{
print("In range checked!");
if(GetPlayerMoney(playerid) < CarInfo[i][CarPrice])
{
print("Money checked!");
if(PlayerInfo[playerid][pHasCar] > 2)
{
print("Player has a car checked!");
if(CarInfo[i][cSale] == 0)
{
print("Car is for sale checked!");
if(strcmp(CarInfo[i][owner], "None"))
{
new UMoney[128];
new Smoney[128];
new money = format(Smoney, sizeof(Smoney), "SELECT pMoney FROM users WHERE pName='%s'",CarInfo[i][owner]);
mysql_query(1, Smoney);
format(UMoney, sizeof(UMoney), "UPDATE users SET pMoney='%i' WHERE username='%s'",money+CarInfo[i][CarPrice], CarInfo[i][owner]);
mysql_query(1, UMoney);
print("Give money to player checked!");
}
new query[200];
format(query, sizeof(query), "UPDATE cars SET owner='%s', owned='1', cSale='0' WHERE id='%i'",PlayerName(playerid), CarInfo[i][CarID]);
mysql_query(1, query);
PlayerInfo[playerid][pHasCar]++;
GivePlayerMoney(playerid, -CarInfo[i][CarPrice]);
print("Vehicle sold!");
}
else { NotForSale = true; }
} else { AlreadyHas = true; }
} else { noMoney = true; }
} else { notIn = true; }
}
if(in_range == true) return SendClientMessage(playerid, COLOR_RED, "You aren't near any for-sale car!");
if(noMoney == true) return SendClientMessage(playerid, COLOR_RED, "You don't have enough money!");
if(AlreadyHas == true) return SendClientMessage(playerid, COLOR_RED, "You already have two cars!");
if(NotForSale == true) return SendClientMessage(playerid, COLOR_RED, "This vehicle isn't for sale!");
print("Done?");
return 1;
}
Код:
[20:22:25] Bools set!
[20:22:25] loop is starting!
[20:22:25] Done?
Re: Command Doesn't do anything -
nezo2001 - 29.08.2015
Bump...
Re: Command Doesn't do anything -
Trollerz - 29.08.2015
Check this
PHP код:
CMD:buycar(playerid, params[])
{
new bool:in_range = false;
new bool:notIn = false;
new bool:noMoney = false;
new bool:AlreadyHas = false;
new bool:NotForSale = false;
/*for(new a = 1; a <= MAX_VEHICLES; a++)
{
new Float:vx, Float:vy, Float:vz;
GetVehiclePos(a, vx, vy, vz);
if(IsPlayerInRangeOfPoint(playerid, 3.0, vx, vy, vz))
{
if(CarInDb[a] == false) { notIn = true; }
}
}*/
printa("Bools set!");
//if(notIn == true) return SendClientMessage(playerid, COLOR_RED, "This is a server-car!");
print("loop is starting!");
for(new i; i != CarsLoad;i++)
{
print("loop started!");
if(IsPlayerInRangeOfPoint(playerid, 3.0, CarInfo[i][CarX], CarInfo[i][CarY], CarInfo[i][CarY]))
{
print("In range checked!");
if(GetPlayerMoney(playerid) < CarInfo[i][CarPrice])
{
printf("Money checked!");
if(PlayerInfo[playerid][pHasCar] > 2)
{
print("Player has a car checked!");
if(CarInfo[i][cSale] == 0)
{
print("Car is for sale checked!");
if(strcmp(CarInfo[i][owner], "None"))
{
new SMoney[128];
new Umoney[128];
new money = format(Smoney, sizeof(Smoney), "SELECT pMoney FROM users WHERE pName='%s'",CarInfo[i][owner]);
mysql_query(1, Smoney);
format(UMoney, sizeof(UMoney), "UPDATE users SET pMoney='%i' WHERE username='%s'",money+CarInfo[i][CarPrice], CarInfo[i][owner]);
mysql_query(1, UMoney);
print("Give money to player checked!");
}
new query[200];
format(query, sizeof(query), "UPDATE cars SET owner='%s', owned='1', cSale='0' WHERE id='%i'",PlayerName(playerid), CarInfo[i][CarID]);
mysql_query(1, query);
PlayerInfo[playerid][pHasCar]++;
GivePlayerMoney(playerid, -CarInfo[i][CarPrice]);
print("Vehicle sold!");
}
else { NotForSale = true; }
} else { AlreadyHas = true; }
} else { noMoney = true; }
} else { notIn = true; }
}
if(in_range == true) return SendClientMessage(playerid, COLOR_RED, "You aren't near any for-sale car!");
if(noMoney == true) return SendClientMessage(playerid, COLOR_RED, "You don't have enough money!");
if(AlreadyHas == true) return SendClientMessage(playerid, COLOR_RED, "You already have two cars!");
if(NotForSale == true) return SendClientMessage(playerid, COLOR_RED, "This vehicle isn't for sale!");
print("Done?");
return 1;
}
Re: Command Doesn't do anything -
nezo2001 - 29.08.2015
What did you change?!
Re: Command Doesn't do anything -
Ahmad45123 - 29.08.2015
At
PHP код:
for(new i; i != CarsLoad;i++)
What is this.. IDk what is CarsLoad var but thats the issue.. Depending in your debugging it means that the loop didn't work.
Try doing it as:
PHP код:
for(new i; i < CarsLoad;i++)
Re: Command Doesn't do anything -
nezo2001 - 29.08.2015
Nothing changed
Re: Command Doesn't do anything -
Ahmad45123 - 29.08.2015
Quote:
Originally Posted by nezo2001
Nothing changed
|
What does it show in console now ?
And please show me where CarsLoad is declared.
Re: Command Doesn't do anything -
nezo2001 - 29.08.2015
Console shows as above and CarsLoad is declared up just check the post again.
Re: Command Doesn't do anything -
nezo2001 - 29.08.2015
I'm really in-need of it :/