objects not getting destroyed
#1

What I wanted to do is player writes /activate they get 4 walls and each zombie approaching gets cherried by the walls every 3 seconds for 9 seconds but Im running into bugs: either objects doesnt get destroyed either the cherry thing never stops even when I kill the timer lol
Код:
CMD:activate(playerid)
{
    new Float:x,Float:y,Float:z; // Get Player Coordinate
    {
    if(pInfo[playerid][HasCherryPerk] == 1)
    {
	if(maptime <= 120) // If Map Time is less than 120 seconds (2 Minutes)
	{
	        GetPlayerPos(playerid,Float:x,Float:y,Float:z); // Get Player Position
			if(team[playerid] == TEAM_HUMAN)// if team is Human
			{
					fucktimer[playerid] = SetTimerEx("GetCherried", 3000, false, "i", playerid);
		            CageHuman = CreateObject(971, Float:x+4.0,Float:y+4.0,Float:z+0.0,  0.0, 0.0, 0.0);
		            CageHuman1 = CreateObject(971, Float:x+4.0,Float:y-4.0,Float:z-0.0,  0.0, 0.0, 0.0);
		            CageHuman2 = CreateObject(971, Float:x-1.0,Float:y+0.0,Float:z-0.0,  0.0, 0.0, 90.0);
		            CageHuman3 = CreateObject(971, Float:x+8.0,Float:y+0.0,Float:z-0.0,  0.0, 0.0, 90.0);
		            CageHuman4 = CreateObject(971, Float:x+4.0,Float:y+0.0,Float:z+3.0, 90.0, 0.0, 0.0);
	                uselesstimer[playerid] = SetTimerEx("HideObject971", 9000, false, "i", playerid);
				}
			}
}
}
	return 1;
}
forward GetCherried(playerid);
public GetCherried(playerid)
{
					 new Float:x,Float:y,Float:z,Float:Angle;
				        GetPlayerPos(playerid,Float:x,Float:y,Float:z);
				        GetPlayerFacingAngle(playerid,Float:Angle);

foreach(Player,i)
						{
						    if(team[i] == TEAM_ZOMBIE)
						    {
		    	    				if(GetDistanceBetweenPlayers(playerid,i) < 15.0)
		        	    			{
						    			GetClosestPlayer(i);
										GetPlayerFacingAngle(i,Float:Angle);
										GetPlayerVelocity(i,Float:x,Float:y,Float:z);
										SetPlayerVelocity(i,Float:x+0.3,Float:y+0.3,Float:z+0.2);
										SetPlayerFacingAngle(i,Float:Angle);
										}
										}
										}
										return 1;
										}

forward HideObject971(playerid);
public HideObject971(playerid)
{
DestroyObject(CageHuman);
DestroyObject(CageHuman1);
DestroyObject(CageHuman2);
DestroyObject(CageHuman3);
DestroyObject(CageHuman4);
KillTimer(fucktimer[playerid]);

return 1;
}
yeah I know the code is badly written , I wrote it quickly zz ;(
Reply
#2

Where is created the variable CageHuman? If is global you need to destroy the previos creation of the object before you create . In command replace

If (IsValidObject(CageHuman)) DestroyObject (CageHuman); // do it for all before create

CageHuman = CreateObject(971, Float+4.0,Float:y+4.0,Float:z+0.0, 0.0, 0.0, 0.0);
Reply
#3

Quote:
Originally Posted by Mister0
Посмотреть сообщение
Where is created the variable CageHuman? If is global you need to destroy the previos creation of the object before you create . In command replace

If (IsValidObject(CageHuman)) DestroyObject (CageHuman); // do it for all before create

CageHuman = CreateObject(971, Float+4.0,Float:y+4.0,Float:z+0.0, 0.0, 0.0, 0.0);
I didn't understand it elaborate further how does this make a difference?
Reply
#4

I just spent ages writing a massive post and it said my token had expired because I left the page open too long... so I'm just going to spit some code at you and let you figure it out.

PHP код:
new CherryCount[MAX_PLAYERS];
new 
CageHuman[MAX_PLAYERS][5] = {INVALID_OBJECT_ID, ...};

CMD:activate(playerid)
{
    if(
pInfo[playerid][HasCherryPerk] == 1)
    {    
        if(
maptime <= 120// If Map Time is less than 120 seconds (2 Minutes)
        
{
            new 
Float:xFloat:yFloat:z;
            
GetPlayerPos(playeridFloat:xFloat:yFloat:z); // Get Player Position
            
if(team[playerid] == TEAM_HUMAN)// if team is Human
            
{
                if(
CherryCount[playerid]++ != 0) return SendClientMessage(playerid, -1"You have already enabled this perk.");
                
SetTimerEx("GetCherried"3000false"i"playerid);
                
CageHuman[playerid][0] = CreateObject(971Float:4.0Float:4.0Float:z0.00.00.0);
                
CageHuman[playerid][1] = CreateObject(971Float:4.0Float:4.0Float:z0.00.00.0);
                
CageHuman[playerid][2] = CreateObject(971Float:1.0Float:yFloat:z0.00.090.0);
                
CageHuman[playerid][3] = CreateObject(971Float:8.0Float:yFloat:z0.00.090.0);
                
CageHuman[playerid][4] = CreateObject(971Float:4.0Float:yFloat:3.090.00.00.0);
            }
            
// else SendClientMessage(playerid, -1, "Only Humans can use this perk.");
        
}
        
// else SendClientMessage(playerid, -1, "Map Time is more than 120 seconds.");
    
}
    
// else SendClientMessage(playerid, -1, "You don't have the Cherry perk.");    
    
return 1;
}

forward GetCherried(playerid);
public 
GetCherried(playerid)
{
    new 
Float:xFloat:yFloat:z;
    foreach(new 
Player)
    {
        if(
== playerid || team[i] != TEAM_ZOMBIE) continue;
        if(
GetDistanceBetweenPlayers(playeridi) < 15.0)
        {
            
GetPlayerVelocity(iFloat:xFloat:yFloat:z);
            
SetPlayerVelocity(iFloat:0.3Float:0.3Float:0.2);
        }
    }
    if(!
IsPlayerConnected(playerid) || ++CherryCount[playerid] > 3)
    {
        for(new 
0sizeof(CageHuman[]); j++)
        {
            
DestroyObject(CageHuman[playerid][j]);
            
CageHuman[playerid][j] = INVALID_OBJECT_ID;
        }
        
CherryCount[playerid] = 0;
        return 
1;
    }
    else 
SetTimerEx("GetCherried"3000false"i"playerid);
    return 
1;

Haven't tested, have fun, cya, bye.
Reply
#5

Quote:
Originally Posted by Threshold
Посмотреть сообщение
I just spent ages writing a massive post and it said my token had expired because I left the page open too long... so I'm just going to spit some code at you and let you figure it out.

PHP код:
new CherryCount[MAX_PLAYERS];
new 
CageHuman[MAX_PLAYERS][5] = {INVALID_OBJECT_ID, ...};
CMD:activate(playerid)
{
    if(
pInfo[playerid][HasCherryPerk] == 1)
    {    
        if(
maptime <= 120// If Map Time is less than 120 seconds (2 Minutes)
        
{
            new 
Float:xFloat:yFloat:z;
            
GetPlayerPos(playeridFloat:xFloat:yFloat:z); // Get Player Position
            
if(team[playerid] == TEAM_HUMAN)// if team is Human
            
{
                if(
CherryCount[playerid]++ != 0) return SendClientMessage(playerid, -1"You have already enabled this perk.");
                
SetTimerEx("GetCherried"3000false"i"playerid);
                
CageHuman[playerid][0] = CreateObject(971Float:4.0Float:4.0Float:z0.00.00.0);
                
CageHuman[playerid][1] = CreateObject(971Float:4.0Float:4.0Float:z0.00.00.0);
                
CageHuman[playerid][2] = CreateObject(971Float:1.0Float:yFloat:z0.00.090.0);
                
CageHuman[playerid][3] = CreateObject(971Float:8.0Float:yFloat:z0.00.090.0);
                
CageHuman[playerid][4] = CreateObject(971Float:4.0Float:yFloat:3.090.00.00.0);
            }
            
// else SendClientMessage(playerid, -1, "Only Humans can use this perk.");
        
}
        
// else SendClientMessage(playerid, -1, "Map Time is more than 120 seconds.");
    
}
    
// else SendClientMessage(playerid, -1, "You don't have the Cherry perk.");    
    
return 1;
}
forward GetCherried(playerid);
public 
GetCherried(playerid)
{
    new 
Float:xFloat:yFloat:z;
    foreach(new 
Player)
    {
        if(
== playerid || team[i] != TEAM_ZOMBIE) continue;
        if(
GetDistanceBetweenPlayers(playeridi) < 15.0)
        {
            
GetPlayerVelocity(iFloat:xFloat:yFloat:z);
            
SetPlayerVelocity(iFloat:0.3Float:0.3Float:0.2);
        }
    }
    if(!
IsPlayerConnected(playerid) || ++CherryCount[playerid] > 3)
    {
        for(new 
0sizeof(CageHuman[]); j++)
        {
            
DestroyObject(CageHuman[playerid][j]);
            
CageHuman[playerid][j] = INVALID_OBJECT_ID;
        }
        
CherryCount[playerid] = 0;
        return 
1;
    }
    else 
SetTimerEx("GetCherried"3000false"i"playerid);
    return 
1;

Haven't tested, have fun, cya, bye.
Thanks but theres one little thing I dont understand on this piece of code.
How would you call it to cherry every 3 seconds if its false and how would you call it to destroy the cage after 9 seconds + end cherry effect?
P.S:
new CageHuman[MAX_PLAYERS][5] = {INVALID_OBJECT_ID, ...};
C:\Users\xc0de\Desktop\tst\gamemodes\zm1.pwn(42) : error 029: invalid expression, assumed zero
Reply
#6

There shouldn't be an error on that line as far as I'm concerned. Show the lines above and below that one if you can.

You'll notice that in the GetCherried function, at the bottom there is another SetTimerEx line. This calls the function again instead of having it repeat, and it saves you having to save the timer ID as well. This isn't necessary but I'm a minimalist. There is also a variable 'CherryCount' which keeps track of how many times the function GetCherried has been called, and once it has been executed 3 times it deletes the objects and stops the timer from being called again.
PHP код:
if(!IsPlayerConnected(playerid) || ++CherryCount[playerid] > 3
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)