I was expecting this, loops
#1

Code:
PHP код:
else if(!strcmp(param"hire"))
    {
        new 
Float:xFloat:yFloat:zFloat:prot;
        
GetPlayerPos(playeridxyz);
        
GetPlayerFacingAngle(playeridprot);
        for(new 
iMAX_DLABSi++)
        {
            if(
IsPlayerInRangeOfPoint(playerid300.0DrugLabs[i][ExitX], DrugLabs[i][ExitY], DrugLabs[i][ExitZ]))
            {
                if(
DrugLabs[i][OwnerID] == PlayerInfo[playerid][ID])
                {
                    new 
DB_Query[150];
                    
LabCooker[i] = CreateActor(70xyzprot);
                    
ApplyActorAnimation(LabCooker[i], "BD_FIRE""wash_up"4.110000);
                    
SetActorVirtualWorld(LabCooker[i], DrugLabs[i][VirtualWorld]);
                    
                    
mysql_format(DatabaseDB_Querysizeof(DB_Query), "UPDATE `DrugLabs` SET `ActorSkin` = 70, `ActorPosX` = %f, `ActorPosY` = %f, `ActorPosZ` = %f, `ActorRot` = %f WHERE `ID` = %d"
                    
xyzprotDrugLabs[i][ID]);
                    
mysql_tquery(DatabaseDB_Query);
                    
                    
SendClientMessage(playeridCOLOR_WHITE"Hired!");
                    break;
                }
                else
                {
                    if(
PlayerInfo[playerid][pLanguage] == 1)
                    {
                        
SCM(playeridCOLOR_GREY"You don't own this place.");
                        break;
                    }
                    else
                    {
                        
SCM(playeridCOLOR_GREY"Nu ai cheie.");
                        break;
                    }
                }
            }
            else
            {
                if(
PlayerInfo[playerid][pLanguage] == 1)
                {
                    
SCM(playeridCOLOR_GREY"You are not inside a druglab.");
                    break;
                }
                else
                {
                    
SCM(playeridCOLOR_GREY"Nu esti intr-un druglab.");
                    break;
                }
            }
        }
    } 
Alright so..
it will loop through all the druglabs and then check if the player is close to the /exit point, thats how I check if the player is inside, then it will check if the player is the owner by checking if OwnerID si the same as ID from the player, unique database ID, and if they both match nothing is happening, this code is not executing:
PHP код:
if(DrugLabs[i][OwnerID] == PlayerInfo[playerid][ID])
                {
                    new 
DB_Query[150];
                    
LabCooker[i] = CreateActor(70xyzprot);
                    
ApplyActorAnimation(LabCooker[i], "BD_FIRE""wash_up"4.110000);
                    
SetActorVirtualWorld(LabCooker[i], DrugLabs[i][VirtualWorld]);
                    
                    
mysql_format(DatabaseDB_Querysizeof(DB_Query), "UPDATE `DrugLabs` SET `ActorSkin` = 70, `ActorPosX` = %f, `ActorPosY` = %f, `ActorPosZ` = %f, `ActorRot` = %f WHERE `ID` = %d"
                    
xyzprotDrugLabs[i][ID]);
                    
mysql_tquery(DatabaseDB_Query);
                    
                    
SendClientMessage(playeridCOLOR_WHITE"Hired!");
                    break;
                } 
Reply
#2

You put break in all conditions. How will then loop iterate?
Reply
#3

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
You put break in all conditions. How will then loop iterate?
I removed the break from here:
PHP код:
if(DrugLabs[i][OwnerID] == PlayerInfo[playerid][ID])
                {
                    new 
DB_Query[150];
                    
LabCooker[i] = CreateActor(70xyzprot);
                    
ApplyActorAnimation(LabCooker[i], "BD_FIRE""wash_up"4.110000);
                    
SetActorVirtualWorld(LabCooker[i], DrugLabs[i][VirtualWorld]);
                    
                    
mysql_format(DatabaseDB_Querysizeof(DB_Query), "UPDATE `DrugLabs` SET `ActorSkin` = 70, `ActorPosX` = %f, `ActorPosY` = %f, `ActorPosZ` = %f, `ActorRot` = %f WHERE `ID` = %d"
                    
xyzprotDrugLabs[i][ID]);
                    
mysql_tquery(DatabaseDB_Query);
                    
                    
SendClientMessage(playeridCOLOR_WHITE"Hired!");
                } 
But it still doesn't work.
Reply
#4

Quote:
Originally Posted by AndreiWow
Посмотреть сообщение
I removed the break from here:
PHP код:
if(DrugLabs[i][OwnerID] == PlayerInfo[playerid][ID])
                {
                    new 
DB_Query[150];
                    
LabCooker[i] = CreateActor(70xyzprot);
                    
ApplyActorAnimation(LabCooker[i], "BD_FIRE""wash_up"4.110000);
                    
SetActorVirtualWorld(LabCooker[i], DrugLabs[i][VirtualWorld]);
                    
                    
mysql_format(DatabaseDB_Querysizeof(DB_Query), "UPDATE `DrugLabs` SET `ActorSkin` = 70, `ActorPosX` = %f, `ActorPosY` = %f, `ActorPosZ` = %f, `ActorRot` = %f WHERE `ID` = %d"
                    
xyzprotDrugLabs[i][ID]);
                    
mysql_tquery(DatabaseDB_Query);
                    
                    
SendClientMessage(playeridCOLOR_WHITE"Hired!");
                } 
But it still doesn't work.
I didn't meant to remove break from there but from other parts...
Reply
#5

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
I didn't meant to remove break from there but from other parts...
well if I remove it from the other parts player will receive 200 messages telling him that he is not the owner in case he tries the command and he is not the owner.


also if the player is not inside the interior he will also receive 200 messages telling him that he is not inside the druglab, thats why I used break there.
Reply
#6

Instead of looping every time, get the id of it when player enters it and save it in a variable and reset it when he exists. Use the variable instead of looping every time.
Reply
#7

Try this :
PHP код:
else if(!strcmp(param"hire"))  
{  
    new 
i
    for( 
i=0MAX_DLABSi++)  
        if(
IsPlayerInRangeOfPoint(playerid300.0DrugLabs[i][ExitX], DrugLabs[i][ExitY], DrugLabs[i][ExitZ]))  
           break; 
                 
    if(
== MAX_DLABS)  
        
SCM(playeridCOLOR_GREY,(PlayerInfo[playerid][pLanguage] == 1)?( "You are not inside a druglab."):("Nu esti intr-un druglab."));  
  
     else if(
DrugLabs[i][OwnerID] == PlayerInfo[playerid][ID])  
     {  
        new 
DB_Query[150];  
        
LabCooker[i] = CreateActor(70xyzprot);  
        
ApplyActorAnimation(LabCooker[i], "BD_FIRE""wash_up"4.110000);  
        
SetActorVirtualWorld(LabCooker[i], DrugLabs[i][VirtualWorld]);  
        
mysql_format(DatabaseDB_Querysizeof(DB_Query), "UPDATE `DrugLabs` SET `ActorSkin` = 70, `ActorPosX` = %f, `ActorPosY` = %f, `ActorPosZ` = %f, `ActorRot` = %f WHERE `ID` = %d"  
        
xyzprotDrugLabs[i][ID]);  
        
mysql_tquery(DatabaseDB_Query);  
        
SendClientMessage(playeridCOLOR_WHITE"Hired!");  
      
     }  
    else  
        
SCM(playeridCOLOR_GREY, (PlayerInfo[playerid][pLanguage] == 1)?("You don't own this place."):("Nu ai cheie."));  

Reply
#8

C:\Users\andrei\Desktop\Scripting SA-MP\Basic RP Script Scratch FIX\gamemodes\U1.pwn(3725) : warning 215: expression has no effect


for( i; i < MAX_DLABS; i++)
Reply
#9

Quote:
Originally Posted by AndreiWow
Посмотреть сообщение
C:\Users\andrei\Desktop\Scripting SA-MP\Basic RP Script Scratch FIX\gamemodes\U1.pwn(3725) : warning 215: expression has no effect


for( i; i < MAX_DLABS; i++)
for( i=0; i < MAX_DLABS; i++)

My bad...
Reply
#10

worked, thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)