SA-MP Forums Archive
I was expecting this, loops - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: I was expecting this, loops (/showthread.php?tid=628809)



I was expecting this, loops - AndreiWow - 15.02.2017

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;
                } 



Re: I was expecting this, loops - SyS - 15.02.2017

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


Re: I was expecting this, loops - AndreiWow - 15.02.2017

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.


Re: I was expecting this, loops - SyS - 15.02.2017

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...


Re: I was expecting this, loops - AndreiWow - 15.02.2017

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.


Re: I was expecting this, loops - StrikerZ - 15.02.2017

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.


Re: I was expecting this, loops - SyS - 15.02.2017

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."));  




Re: I was expecting this, loops - AndreiWow - 15.02.2017

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++)


Re: I was expecting this, loops - SyS - 15.02.2017

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...


Re: I was expecting this, loops - AndreiWow - 15.02.2017

worked, thank you.