A bit help in zcmd.
#1

So actually i made a medkit system which heals the player in specific area.

here is the script, the problem is that the object does not get destroyed when the timer ends.

script:-
at the top-
Код:
new OMedkit;
the command script :-
Код:
CMD:medkit(playerid, parmas[])
{

	new Float:x,
		Float:y,
		Float:z;
	
	new Float:ox,
		Float:oy,
		Float:oz;

    new Float:MHealth;
		
	GetPlayerPos(playerid, x, y, z);
	if(Medkit[playerid] == 0) return SendClientMessage(playerid, -1, "You are not carrying any medkit! Please visit the shop to one.");
	Medkit[playerid] = 0;
	for(new i = 0; i < MAX_PLAYERS; i++)
	  {
		 OMedkit = CreateObject(11738, x, y, z, 0, 0, 0);
		 SetTimerEx("mdestroy", 15000, false, "i", objectid);
	     GetObjectPos(OMedkit, ox,oy, oz);
		 GetPlayerHealth(i, MHealth);
		 if(gTeam[i] == gTeam[playerid])
		   {
			  if(IsPlayerInRangeOfPoint(i, 10.0, ox, oy, oz))
				 {
					 if(MHealth < 60.0)
						 {
                              SetPlayerHealth(i, 100.0);
					          SendClientMessage(i, -1, "You have been healed by a deployed medkit!");
				          }
		         }
	      }

     }
return 1;
}
the timer ending :-
Код:
forward mdestroy(playerid);
public mdestroy(playerid)
{
   DestroyObject(OMedkit);
return 1;
}
Need help ASAP.
Reply
#2

Help please....
Reply
#3

try this sir
PHP код:
CMD:medkit(playeridparmas[])
{
    new 
Float:x,
        
Float:y,
        
Float:z;
    new 
Float:ox,
        
Float:oy,
        
Float:oz;
    new 
Float:MHealth;
    
GetPlayerPos(playeridxyz);
    if(
Medkit[playerid] == 0) return SendClientMessage(playerid, -1"You are not carrying any medkit! Please visit the shop to one.");
    
Medkit[playerid] = 0;
    for(new 
0MAX_PLAYERSi++)
      {
         
OMedkit CreateObject(11738xyz000);
         
SetTimerEx("mdestroy"15000false"i"OMedkit);
         
GetObjectPos(OMedkitox,oyoz);
         
GetPlayerHealth(iMHealth);
         if(
gTeam[i] == gTeam[playerid])
           {
              if(
IsPlayerInRangeOfPoint(i10.0oxoyoz))
                 {
                     if(
MHealth 60.0)
                         {
                              
SetPlayerHealth(i100.0);
                              
SendClientMessage(i, -1"You have been healed by a deployed medkit!");
                          }
                 }
          }
     }
return 
1;
}
forward mdestroy(My_objectID);
public 
mdestroy(My_objectID)
{
   
DestroyObject(My_objectID);
   return 
1;

Reply
#4

The CreateObject should not be inside the loop otherwise you'll be creating a MAX_PLAYERS amount of objects (possibly a thousand if you didn't redefine MAX_PLAYERS) instead of just the one.

It is also rather silly that you use GetObjectPos right after creating the object. You already know its position because you just told the game to create the object at that position. So x, y and z are equal to ox, oy and oz respectively.
Reply
#5

THank you it works! +Rep
Reply
#6

But now, the problem is that if i use /medkit command again, the object dose not appears. need help please I don't know how to fix it.

Help please.
Reply
#7

here you go sir
PHP код:
new PlastObject[MAX_PLAYERS], PObjectTimer[MAX_PLAYERS];
CMD:medkit(playeridparmas[])
{
    new 
Float:x,
        
Float:y,
        
Float:z;
    new 
Float:ox,
        
Float:oy,
        
Float:oz;
    new 
Float:MHealth;
    
GetPlayerPos(playeridxyz);
    if(
Medkit[playerid] == 0) return SendClientMessage(playerid, -1"You are not carrying any medkit! Please visit the shop to one.");
    
Medkit[playerid] = 0;
    for(new 
0MAX_PLAYERSi++)
      {
         if(
PlastObject[playerid])
         {
             
DestroyObject(PlastObject[playerid]);
              
PlastObject[playerid] = 0;
              
KillTimer(PObjectTimer[playerid]);
         }
         
OMedkit CreateObject(11738xyz000);
         
PlastObject[playerid] = OMedkit;
         
PObjectTimer[playerid] = SetTimerEx("mdestroy"15000false"ii"playeridOMedkit);
         
GetObjectPos(OMedkitox,oyoz);
         
GetPlayerHealth(iMHealth);
         if(
gTeam[i] == gTeam[playerid])
           {
              if(
IsPlayerInRangeOfPoint(i10.0oxoyoz))
                 {
                     if(
MHealth 60.0)
                         {
                              
SetPlayerHealth(i100.0);
                              
SendClientMessage(i, -1"You have been healed by a deployed medkit!");
                          }
                 }
          }
     }
return 
1;
}
forward mdestroy(playeridMy_objectID);
public 
mdestroy(playeridMy_objectID)
{
   
DestroyObject(My_objectID);
   
PlastObject[playerid] = 0;
   return 
1;

Reply
#8

Do I have to replace My_objectID with anything?
Reply
#9

Quote:
Originally Posted by DeeadPool
Посмотреть сообщение
Do I have to replace My_objectID with anything?
nope sir.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)