Command Doesn't do anything
#1

The command only prints (Done?) which is under
PHP код:
CMD:buycar(playeridparams[])
{
    new 
bool:in_range false;
    new 
bool:notIn false;
    new 
bool:noMoney false;
    new 
bool:AlreadyHas false;
    new 
bool:NotForSale false;
    for(new 
1<= MAX_VEHICLESa++)
    {
        new 
Float:vxFloat:vyFloat:vz;
        
GetVehiclePos(avxvyvz);
        if(
IsPlayerInRangeOfPoint(playerid3.0vxvyvz))
        {
            if(
CarInDb[a] == false) { notIn true; }
        }
    }
    if(
notIn == true) return SendClientMessage(playeridCOLOR_RED"This is a server-car!");
    for(new 
0!= CarsLoad;i++)
    {
        if(
IsPlayerInRangeOfPoint(playerid3.0CarInfo[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(Smoneysizeof(Smoney), "SELECT pMoney FROM users WHERE pName='%s'",CarInfo[i][owner]);
                            
mysql_query(1Smoney);
                            
format(UMoneysizeof(UMoney), "UPDATE users SET pMoney='%i' WHERE username='%s'",money+CarInfo[i][CarPrice], CarInfo[i][owner]);
                            
mysql_query(1UMoney);
                        }
                        new 
query[200];
                        
format(querysizeof(query), "UPDATE cars SET owner='%s', owned='1', cSale='0' WHERE id='%i'",PlayerName(playerid), CarInfo[i][CarID]);
                        
mysql_query(1query);
                        
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(playeridCOLOR_RED"You aren't near any for-sale car!");
    if(
noMoney == true) return SendClientMessage(playeridCOLOR_RED"You don't have enough money!");
    if(
AlreadyHas == true) return SendClientMessage(playeridCOLOR_RED"You already have two cars!");
    if(
NotForSale == true) return SendClientMessage(playeridCOLOR_RED"This vehicle isn't for sale!");
    print(
"Done?");
    return 
1;

PHP код:
CarsLoad clamp(cache_get_row_count(), 0sizeof CarInfo 1); 
I'm making it on this way to prevent messages spamming in loops but it doesn't do anything :/
Reply
#2

After debugging
PHP код:
CMD:buycar(playeridparams[])
{
    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!= CarsLoad;i++)
    {
        print(
"loop started!");
        if(
IsPlayerInRangeOfPoint(playerid3.0CarInfo[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(Smoneysizeof(Smoney), "SELECT pMoney FROM users WHERE pName='%s'",CarInfo[i][owner]);
                            
mysql_query(1Smoney);
                            
format(UMoneysizeof(UMoney), "UPDATE users SET pMoney='%i' WHERE username='%s'",money+CarInfo[i][CarPrice], CarInfo[i][owner]);
                            
mysql_query(1UMoney);
                            print(
"Give money to player checked!");
                        }
                        new 
query[200];
                        
format(querysizeof(query), "UPDATE cars SET owner='%s', owned='1', cSale='0' WHERE id='%i'",PlayerName(playerid), CarInfo[i][CarID]);
                        
mysql_query(1query);
                        
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(playeridCOLOR_RED"You aren't near any for-sale car!");
    if(
noMoney == true) return SendClientMessage(playeridCOLOR_RED"You don't have enough money!");
    if(
AlreadyHas == true) return SendClientMessage(playeridCOLOR_RED"You already have two cars!");
    if(
NotForSale == true) return SendClientMessage(playeridCOLOR_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?
Reply
#3

Bump...
Reply
#4

Check this
PHP код:
CMD:buycar(playeridparams[])
{
    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!= CarsLoad;i++)
    {
        print(
"loop started!");
        if(
IsPlayerInRangeOfPoint(playerid3.0CarInfo[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(Smoneysizeof(Smoney), "SELECT pMoney FROM users WHERE pName='%s'",CarInfo[i][owner]);
                            
mysql_query(1Smoney);
                            
format(UMoneysizeof(UMoney), "UPDATE users SET pMoney='%i' WHERE username='%s'",money+CarInfo[i][CarPrice], CarInfo[i][owner]);
                            
mysql_query(1UMoney);
                            print(
"Give money to player checked!");
                        }
                        new 
query[200];
                        
format(querysizeof(query), "UPDATE cars SET owner='%s', owned='1', cSale='0' WHERE id='%i'",PlayerName(playerid), CarInfo[i][CarID]);
                        
mysql_query(1query);
                        
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(playeridCOLOR_RED"You aren't near any for-sale car!");
    if(
noMoney == true) return SendClientMessage(playeridCOLOR_RED"You don't have enough money!");
    if(
AlreadyHas == true) return SendClientMessage(playeridCOLOR_RED"You already have two cars!");
    if(
NotForSale == true) return SendClientMessage(playeridCOLOR_RED"This vehicle isn't for sale!");
    print(
"Done?");
    return 
1;

Reply
#5

What did you change?!
Reply
#6

At
PHP код:
for(new 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 iCarsLoad;i++) 
Reply
#7

Nothing changed
Reply
#8

Quote:
Originally Posted by nezo2001
Посмотреть сообщение
Nothing changed
What does it show in console now ?
And please show me where CarsLoad is declared.
Reply
#9

Console shows as above and CarsLoad is declared up just check the post again.
Reply
#10

I'm really in-need of it :/
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)