Why objects are not destroying?
#1

Hi

Why objects are not destroying??

Top code:
Code:
new p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20,p21,p22,p23,p24,p25,p26,p27,p28,p29,p30,p31,p32,p33,p34,p35,p36;
Main code:
Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_YES)
    {
		if(IsPlayerInRangeOfPoint(playerid, 2.0, -1756.19006, 768.19061, 168.47099))
  		{
  		    if(DJ[playerid]==1)
  		    {
  		        for(new i = 0;i<MAX_PLAYERS;i++)
  		        {
	  		        p1=CreatePlayerObject(i,2780, -1763.72510, 780.92908, 174.22932,   88.00000, 2.00000, -6.00000);
					p2=CreatePlayerObject(i,2780, -1752.37158, 780.15802, 174.22932,   88.00000, 2.00000, -6.00000);
					p3=CreatePlayerObject(i,2780, -1744.06750, 779.74738, 174.22932,   88.00000, 2.00000, -6.00000);
					p4=CreatePlayerObject(i,2780, -1766.28955, 764.69904, 168.54120,   0.00000, 0.00000, -179.00000);
					p5=CreatePlayerObject(i,2780, -1743.22437, 764.93964, 168.54120,   0.00000, 0.00000, -179.00000);
					p6=CreatePlayerObject(i,2780, -1766.28955, 764.69904, 168.54120,   0.00000, 0.00000, -179.00000);
					p7=CreatePlayerObject(i,2780, -1743.22437, 764.93964, 168.54120,   0.00000, 0.00000, -179.00000);
					p8=CreatePlayerObject(i,2780, -1774.05896, 774.17719, 168.39337,   0.00000, 0.00000, 84.00000);
					p9=CreatePlayerObject(i,2780, -1774.03223, 784.32123, 168.39337,   0.00000, 0.00000, 84.00000);
					p10=CreatePlayerObject(i,2780, -1774.00366, 794.26978, 168.39337,   0.00000, 0.00000, 84.00000);
					p11=CreatePlayerObject(i,2780, -1774.07361, 805.47406, 168.39337,   0.00000, 0.00000, 84.00000);
					p12=CreatePlayerObject(i,2780, -1766.94690, 795.36481, 166.59729,   -88.00000, 0.00000, 0.00000);
					p13=CreatePlayerObject(i,2780, -1767.67834, 789.19318, 166.59729,   -88.00000, 0.00000, 0.00000);
					p14=CreatePlayerObject(i,2780, -1767.58838, 782.20294, 166.59729,   -88.00000, 0.00000, 0.00000);
					p15=CreatePlayerObject(i,2780, -1742.22107, 795.15344, 166.60779,   -98.00000, 0.00000, 0.00000);
					p16=CreatePlayerObject(i,2780, -1742.22778, 789.51678, 166.60779,   -98.00000, 0.00000, 0.00000);
					p17=CreatePlayerObject(i,2780, -1742.17041, 782.18506, 166.60779,   -98.00000, 0.00000, 0.00000);
					p18=CreatePlayerObject(i,2780, -1734.08972, 806.35828, 168.23134,   0.00000, 3.00000, -99.00000);
					p19=CreatePlayerObject(i,2780, -1733.98816, 796.45825, 168.23134,   0.00000, 3.00000, -99.00000);
					p20=CreatePlayerObject(i,2780, -1734.02966, 785.73511, 168.23134,   0.00000, 3.00000, -99.00000);
					p21=CreatePlayerObject(i,2780, -1734.39221, 773.08496, 168.23134,   0.00000, 3.00000, -99.00000);
					p22=CreatePlayerObject(i,2780, -1755.33472, 803.83698, 166.60779,   -98.00000, 0.00000, 0.00000);
					p23=CreatePlayerObject(i,2780, -1746.55688, 801.01849, 174.27007,   90.00000, 0.00000, 0.00000);
					p24=CreatePlayerObject(i,2780, -1752.35779, 801.12927, 174.27007,   90.00000, 0.00000, 0.00000);
					p25=CreatePlayerObject(i,2780, -1748.36548, 789.42651, 166.60779,   -98.00000, 0.00000, 0.00000);
					p26=CreatePlayerObject(i,2780, -1761.39917, 789.22473, 166.59729,   -88.00000, 0.00000, 0.00000);
					p27=CreatePlayerObject(i,2780, -1766.02844, 815.00385, 167.98318,   0.00000, 0.00000, 0.00000);
					p28=CreatePlayerObject(i,2780, -1753.73547, 814.99573, 167.98318,   0.00000, 0.00000, 0.00000);
					p29=CreatePlayerObject(i,2780, -1744.25513, 815.03125, 167.98318,   0.00000, 0.00000, 0.00000);
					p30=CreatePlayerObject(i,2780, -1748.68921, 795.19330, 166.60779,   -98.00000, 0.00000, 0.00000);
					p31=CreatePlayerObject(i,2780, -1761.43872, 795.26221, 166.59729,   -88.00000, 0.00000, 0.00000);
					p32=CreatePlayerObject(i,2780, -1761.31079, 782.31293, 166.59729,   -88.00000, 0.00000, 0.00000);
					p33=CreatePlayerObject(i,2780, -1748.67859, 782.21063, 166.60779,   -98.00000, 0.00000, 0.00000);
					p34=CreatePlayerObject(i,2780, -1753.37720, 794.05072, 174.23012,   88.00000, 2.00000, -6.00000);
					p35=CreatePlayerObject(i,2780, -1753.27991, 787.92670, 174.34773,   88.00000, 2.00000, -6.00000);
					p36=CreatePlayerObject(i,2780, -1755.48560, 768.98016, 166.96951,   0.00000, -1.00000, 170.00000);
					Update3DTextLabelText(smoke, 0x2222FFFF, "Press 'N' to stop smoke!");
				}
  		    }
   		}
    }
    if(newkeys & KEY_NO)
    {
		if(IsPlayerInRangeOfPoint(playerid, 2.0, -1756.19006, 768.19061, 168.47099))
  		{
  		    if(DJ[playerid]==1)
  		    {
	        for(new i = 0;i<MAX_PLAYERS;i++)
	        {
                DestroyObject(p1);
                DestroyObject(p2);
                DestroyObject(p3);
                DestroyObject(p4);
                DestroyObject(p5);
                DestroyObject(p6);
                DestroyObject(p7);
                DestroyObject(p8);
                DestroyObject(p9);
                DestroyObject(p10);
                DestroyObject(p11);
                DestroyObject(p12);
                DestroyObject(p13);
                DestroyObject(p14);
                DestroyObject(p15);
                DestroyObject(p16);
                DestroyObject(p17);
                DestroyObject(p18);
                DestroyObject(p19);
                DestroyObject(p20);
                DestroyObject(p21);
                DestroyObject(p22);
                DestroyObject(p23);
                DestroyObject(p24);
                DestroyObject(p25);
                DestroyObject(p26);
                DestroyObject(p27);
                DestroyObject(p28);
                DestroyObject(p29);
                DestroyObject(p30);
                DestroyObject(p31);
                DestroyObject(p32);
                DestroyObject(p33);
                DestroyObject(p34);
                DestroyObject(p35);
                DestroyObject(p36);
				Update3DTextLabelText(smoke, 0x2222FFFF, "Press 'Y' to make smoke!");
	        }
		 }
		}
    }
	return 1;
}
Objects are creating as well.....but not destorying
Reply
#2

DestroyObject is for objects created with CreateObject.

Since you're using CreatePlayerObject, use DestroyPlayerObject.
https://sampwiki.blast.hk/wiki/DestroyPlayerObject
Reply
#3

Quote:
Originally Posted by Arthur Kane
View Post
DestroyObject is for objects created with CreateObject.

Since you're using CreatePlayerObject, use DestroyPlayerObject.
https://sampwiki.blast.hk/wiki/DestroyPlayerObject
Thanks!
Reply
#4

Quote:
Originally Posted by Arthur Kane
View Post
DestroyObject is for objects created with CreateObject.

Since you're using CreatePlayerObject, use DestroyPlayerObject.
https://sampwiki.blast.hk/wiki/DestroyPlayerObject
dude still not working :/

Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_YES)
    {
		if(IsPlayerInRangeOfPoint(playerid, 2.0, -1756.19006, 768.19061, 168.47099))
  		{
  		    if(DJ[playerid]==1)
  		    {
  		        for(new i = 0;i<MAX_PLAYERS;i++)
  		        {
        	  	 	p1=CreatePlayerObject(i,2780, -1763.72510, 780.92908, 174.22932,   88.00000, 2.00000, -6.00000);
					p2=CreatePlayerObject(i,2780, -1752.37158, 780.15802, 174.22932,   88.00000, 2.00000, -6.00000);
					p3=CreatePlayerObject(i,2780, -1744.06750, 779.74738, 174.22932,   88.00000, 2.00000, -6.00000);
					p4=CreatePlayerObject(i,2780, -1766.28955, 764.69904, 168.54120,   0.00000, 0.00000, -179.00000);
					p5=CreatePlayerObject(i,2780, -1743.22437, 764.93964, 168.54120,   0.00000, 0.00000, -179.00000);
					p6=CreatePlayerObject(i,2780, -1766.28955, 764.69904, 168.54120,   0.00000, 0.00000, -179.00000);
					p7=CreatePlayerObject(i,2780, -1743.22437, 764.93964, 168.54120,   0.00000, 0.00000, -179.00000);
					p8=CreatePlayerObject(i,2780, -1774.05896, 774.17719, 168.39337,   0.00000, 0.00000, 84.00000);
					p9=CreatePlayerObject(i,2780, -1774.03223, 784.32123, 168.39337,   0.00000, 0.00000, 84.00000);
					p10=CreatePlayerObject(i,2780, -1774.00366, 794.26978, 168.39337,   0.00000, 0.00000, 84.00000);
					p11=CreatePlayerObject(i,2780, -1774.07361, 805.47406, 168.39337,   0.00000, 0.00000, 84.00000);
					p12=CreatePlayerObject(i,2780, -1766.94690, 795.36481, 166.59729,   -88.00000, 0.00000, 0.00000);
					p13=CreatePlayerObject(i,2780, -1767.67834, 789.19318, 166.59729,   -88.00000, 0.00000, 0.00000);
					p14=CreatePlayerObject(i,2780, -1767.58838, 782.20294, 166.59729,   -88.00000, 0.00000, 0.00000);
					p15=CreatePlayerObject(i,2780, -1742.22107, 795.15344, 166.60779,   -98.00000, 0.00000, 0.00000);
					p16=CreatePlayerObject(i,2780, -1742.22778, 789.51678, 166.60779,   -98.00000, 0.00000, 0.00000);
					p17=CreatePlayerObject(i,2780, -1742.17041, 782.18506, 166.60779,   -98.00000, 0.00000, 0.00000);
					p18=CreatePlayerObject(i,2780, -1734.08972, 806.35828, 168.23134,   0.00000, 3.00000, -99.00000);
					p19=CreatePlayerObject(i,2780, -1733.98816, 796.45825, 168.23134,   0.00000, 3.00000, -99.00000);
					p20=CreatePlayerObject(i,2780, -1734.02966, 785.73511, 168.23134,   0.00000, 3.00000, -99.00000);
					p21=CreatePlayerObject(i,2780, -1734.39221, 773.08496, 168.23134,   0.00000, 3.00000, -99.00000);
					p22=CreatePlayerObject(i,2780, -1755.33472, 803.83698, 166.60779,   -98.00000, 0.00000, 0.00000);
					p23=CreatePlayerObject(i,2780, -1746.55688, 801.01849, 174.27007,   90.00000, 0.00000, 0.00000);
					p24=CreatePlayerObject(i,2780, -1752.35779, 801.12927, 174.27007,   90.00000, 0.00000, 0.00000);
					p25=CreatePlayerObject(i,2780, -1748.36548, 789.42651, 166.60779,   -98.00000, 0.00000, 0.00000);
					p26=CreatePlayerObject(i,2780, -1761.39917, 789.22473, 166.59729,   -88.00000, 0.00000, 0.00000);
					p27=CreatePlayerObject(i,2780, -1766.02844, 815.00385, 167.98318,   0.00000, 0.00000, 0.00000);
					p28=CreatePlayerObject(i,2780, -1753.73547, 814.99573, 167.98318,   0.00000, 0.00000, 0.00000);
					p29=CreatePlayerObject(i,2780, -1744.25513, 815.03125, 167.98318,   0.00000, 0.00000, 0.00000);
					p30=CreatePlayerObject(i,2780, -1748.68921, 795.19330, 166.60779,   -98.00000, 0.00000, 0.00000);
					p31=CreatePlayerObject(i,2780, -1761.43872, 795.26221, 166.59729,   -88.00000, 0.00000, 0.00000);
					p32=CreatePlayerObject(i,2780, -1761.31079, 782.31293, 166.59729,   -88.00000, 0.00000, 0.00000);
					p33=CreatePlayerObject(i,2780, -1748.67859, 782.21063, 166.60779,   -98.00000, 0.00000, 0.00000);
					p34=CreatePlayerObject(i,2780, -1753.37720, 794.05072, 174.23012,   88.00000, 2.00000, -6.00000);
					p35=CreatePlayerObject(i,2780, -1753.27991, 787.92670, 174.34773,   88.00000, 2.00000, -6.00000);
					p36=CreatePlayerObject(i,2780, -1755.48560, 768.98016, 166.96951,   0.00000, -1.00000, 170.00000);
					Update3DTextLabelText(smoke, 0x2222FFFF, "Press 'N' to stop smoke!");
    }
  		    }
   		}
    }
    if(newkeys & KEY_NO)
    {
		if(IsPlayerInRangeOfPoint(playerid, 2.0, -1756.19006, 768.19061, 168.47099))
  		{
  		    if(DJ[playerid]==1)
  		    {
	        for(new i = 0;i<MAX_PLAYERS;i++)
	        {
                DestroyPlayerObject(i,p1);
                DestroyPlayerObject(i,p2);
                DestroyPlayerObject(i,p3);
                DestroyPlayerObject(i,p4);
                DestroyPlayerObject(i,p5);
                DestroyPlayerObject(i,p6);
                DestroyPlayerObject(i,p7);
                DestroyPlayerObject(i,p8);
                DestroyPlayerObject(i,p9);
                DestroyPlayerObject(i,p10);
                DestroyPlayerObject(i,p11);
                DestroyPlayerObject(i,p12);
                DestroyPlayerObject(i,p13);
                DestroyPlayerObject(i,p14);
                DestroyPlayerObject(i,p15);
                DestroyPlayerObject(i,p16);
                DestroyPlayerObject(i,p17);
                DestroyPlayerObject(i,p18);
                DestroyPlayerObject(i,p19);
                DestroyPlayerObject(i,p20);
                DestroyPlayerObject(i,p21);
                DestroyPlayerObject(i,p22);
                DestroyPlayerObject(i,p23);
                DestroyPlayerObject(i,p24);
                DestroyPlayerObject(i,p25);
                DestroyPlayerObject(i,p26);
                DestroyPlayerObject(i,p27);
                DestroyPlayerObject(i,p28);
                DestroyPlayerObject(i,p29);
                DestroyPlayerObject(i,p30);
                DestroyPlayerObject(i,p31);
                DestroyPlayerObject(i,p32);
                DestroyPlayerObject(i,p33);
                DestroyPlayerObject(i,p34);
                DestroyPlayerObject(i,p35);
                DestroyPlayerObject(i,p36);
				Update3DTextLabelText(smoke, 0x2222FFFF, "Press 'Y' to make smoke!");
	        }
		 }
		}
    }
	return 1;
}
Reply
#5

Made an improved version for you. Try it out :
PHP Code:
public OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    new 
SmokeObjectCreated;
    if(
newkeys KEY_YES)
    {
        if(
IsPlayerInRangeOfPoint(playerid2.0, -1756.19006768.19061168.47099))
          {
              if(
DJ[playerid] == )
              {
                    if( 
SmokeObjectCreated == ) return SendClientMessage(playerid, -1"Location already have smokes.");
                    
SmokeObjectCreated 1;
                       
p1 CreateDynamicObject(2780, -1763.72510780.92908174.22932,   88.000002.00000, -6.00000);
                    
p2 CreateDynamicObject(2780, -1752.37158780.15802174.22932,   88.000002.00000, -6.00000);
                    
p3 CreateDynamicObject(2780, -1744.06750779.74738174.22932,   88.000002.00000, -6.00000);
                    
p4 CreateDynamicObject(2780, -1766.28955764.69904168.54120,   0.000000.00000, -179.00000);
                    
p5 CreateDynamicObject(2780, -1743.22437764.93964168.54120,   0.000000.00000, -179.00000);
                    
p6 CreateDynamicObject(2780, -1766.28955764.69904168.54120,   0.000000.00000, -179.00000);
                    
p7 CreateDynamicObject(2780, -1743.22437764.93964168.54120,   0.000000.00000, -179.00000);
                    
p8 CreateDynamicObject(2780, -1774.05896774.17719168.39337,   0.000000.0000084.00000);
                    
p9 CreateDynamicObject(2780, -1774.03223784.32123168.39337,   0.000000.0000084.00000);
                    
p10 CreateDynamicObject(2780, -1774.00366794.26978168.39337,   0.000000.0000084.00000);
                    
p11 CreateDynamicObject(2780, -1774.07361805.47406168.39337,   0.000000.0000084.00000);
                    
p12 CreateDynamicObject(2780, -1766.94690795.36481166.59729,   -88.000000.000000.00000);
                    
p13 CreateDynamicObject(2780, -1767.67834789.19318166.59729,   -88.000000.000000.00000);
                    
p14 CreateDynamicObject(2780, -1767.58838782.20294166.59729,   -88.000000.000000.00000);
                    
p15 CreateDynamicObject(2780, -1742.22107795.15344166.60779,   -98.000000.000000.00000);
                    
p16 CreateDynamicObject(2780, -1742.22778789.51678166.60779,   -98.000000.000000.00000);
                    
p17 CreateDynamicObject(2780, -1742.17041782.18506166.60779,   -98.000000.000000.00000);
                    
p18 CreateDynamicObject(2780, -1734.08972806.35828168.23134,   0.000003.00000, -99.00000);
                    
p19 CreateDynamicObject(2780, -1733.98816796.45825168.23134,   0.000003.00000, -99.00000);
                    
p20 CreateDynamicObject(2780, -1734.02966785.73511168.23134,   0.000003.00000, -99.00000);
                    
p21 CreateDynamicObject(2780, -1734.39221773.08496168.23134,   0.000003.00000, -99.00000);
                    
p22 CreateDynamicObject(2780, -1755.33472803.83698166.60779,   -98.000000.000000.00000);
                    
p23 CreateDynamicObject(2780, -1746.55688801.01849174.27007,   90.000000.000000.00000);
                    
p24 CreateDynamicObject(2780, -1752.35779801.12927174.27007,   90.000000.000000.00000);
                    
p25 CreateDynamicObject(2780, -1748.36548789.42651166.60779,   -98.000000.000000.00000);
                    
p26 CreateDynamicObject(2780, -1761.39917789.22473166.59729,   -88.000000.000000.00000);
                    
p27 CreateDynamicObject(2780, -1766.02844815.00385167.98318,   0.000000.000000.00000);
                    
p28 CreateDynamicObject(2780, -1753.73547814.99573167.98318,   0.000000.000000.00000);
                    
p29 CreateDynamicObject(2780, -1744.25513815.03125167.98318,   0.000000.000000.00000);
                    
p30 CreateDynamicObject(2780, -1748.68921795.19330166.60779,   -98.000000.000000.00000);
                    
p31 CreateDynamicObject(2780, -1761.43872795.26221166.59729,   -88.000000.000000.00000);
                    
p32 CreateDynamicObject(2780, -1761.31079782.31293166.59729,   -88.000000.000000.00000);
                    
p33 CreateDynamicObject(2780, -1748.67859782.21063166.60779,   -98.000000.000000.00000);
                    
p34 CreateDynamicObject(2780, -1753.37720794.05072174.23012,   88.000002.00000, -6.00000);
                    
p35 CreateDynamicObject(2780, -1753.27991787.92670174.34773,   88.000002.00000, -6.00000);
                    
p36 CreateDynamicObject(2780, -1755.48560768.98016166.96951,   0.00000, -1.00000170.00000);
                    
Update3DTextLabelText(smoke0x2222FFFF"Press 'N' to stop smoke!");
              }
           }
    }
    if(
newkeys KEY_NO)
    {
        if(
IsPlayerInRangeOfPoint(playerid2.0, -1756.19006768.19061168.47099))
          {
              if(
DJ[playerid] == 1)
            {
                if( 
SmokeObjectCreated == ) return SendClientMessage(playerid, -1"No smokes here.");
                
SmokeObjectCreated 0;
                
DestroyDynamicObject(p1);
                
DestroyDynamicObject(p2);
                
DestroyDynamicObject(p3);
                
DestroyDynamicObject(p4);
                
DestroyDynamicObject(p5);
                
DestroyDynamicObject(p6);
                
DestroyDynamicObject(p7);
                
DestroyDynamicObject(p8);
                
DestroyDynamicObject(p9);
                
DestroyDynamicObject(p10);
                
DestroyDynamicObject(p11);
                
DestroyDynamicObject(p12);
                
DestroyDynamicObject(p13);
                
DestroyDynamicObject(p14);
                
DestroyDynamicObject(p15);
                
DestroyDynamicObject(p16);
                
DestroyDynamicObject(p17);
                
DestroyDynamicObject(p18);
                
DestroyDynamicObject(p19);
                
DestroyDynamicObject(p20);
                
DestroyDynamicObject(p21);
                
DestroyDynamicObject(p22);
                
DestroyDynamicObject(p23);
                
DestroyDynamicObject(p24);
                
DestroyDynamicObject(p25);
                
DestroyDynamicObject(p26);
                
DestroyDynamicObject(p27);
                
DestroyDynamicObject(p28);
                
DestroyDynamicObject(p29);
                
DestroyDynamicObject(p30);
                
DestroyDynamicObject(p31);
                
DestroyDynamicObject(p32);
                
DestroyDynamicObject(p33);
                
DestroyDynamicObject(p34);
                
DestroyDynamicObject(p35);
                
DestroyDynamicObject(p36);
                
Update3DTextLabelText(smoke0x2222FFFF"Press 'Y' to make smoke!");
            }
         
        }
    }
    return 
1;

Reply
#6

Learn to use for loop with arrays.
Reply
#7

Why using max_players. You can use playerpool or getmaxplayers

Also check if player is connected and if player is not npc if yes skip them that way your loop will be faster
Reply
#8

Quote:
Originally Posted by Whatname
View Post
Why using max_players. You can use playerpool or getmaxplayers

Also check if player is connected and if player is not npc if yes skip them that way your loop will be faster
Please post a code....
Reply
#9

PHP Code:
for(new 0GetMaxPlayers();i++)
{
     if(!
IsPlayerConnected(i) || IsPlayerNPC(i)) continue;
     
//code

Reply
#10

Quote:
Originally Posted by Whatname
View Post
PHP Code:
for(new 0GetMaxPlayers();i++)
{
     if(!
IsPlayerConnected(i) || IsPlayerNPC(i)) continue;
     
//code

Dude I changed the script to dynamic.....as SoFahim said....

But dynamic object not creating
Reply
#11

In server cfg


Add

Code:
plugins streamer
If streamer doesnt load install this: https://www.microsoft.com/en-us/down....aspx?id=48145
Reply
#12

FixED!!


I just used stock funtion to create and destroy and it is working fine!


Thanks for your all support!!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)