A bit help in zcmd. -
DeeadPool - 16.08.2016
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-
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.
Re: A bit help in zcmd. -
DeeadPool - 17.08.2016
Help please....
Re: A bit help in zcmd. -
jlalt - 17.08.2016
try this sir
PHP код:
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", OMedkit);
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;
}
forward mdestroy(My_objectID);
public mdestroy(My_objectID)
{
DestroyObject(My_objectID);
return 1;
}
Re: A bit help in zcmd. -
Vince - 17.08.2016
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.
Re: A bit help in zcmd. -
DeeadPool - 17.08.2016
THank you it works! +Rep
Re: A bit help in zcmd. -
DeeadPool - 17.08.2016
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.
Re: A bit help in zcmd. -
jlalt - 17.08.2016
here you go sir
PHP код:
new PlastObject[MAX_PLAYERS], PObjectTimer[MAX_PLAYERS];
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++)
{
if(PlastObject[playerid])
{
DestroyObject(PlastObject[playerid]);
PlastObject[playerid] = 0;
KillTimer(PObjectTimer[playerid]);
}
OMedkit = CreateObject(11738, x, y, z, 0, 0, 0);
PlastObject[playerid] = OMedkit;
PObjectTimer[playerid] = SetTimerEx("mdestroy", 15000, false, "ii", playerid, OMedkit);
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;
}
forward mdestroy(playerid, My_objectID);
public mdestroy(playerid, My_objectID)
{
DestroyObject(My_objectID);
PlastObject[playerid] = 0;
return 1;
}
Re: A bit help in zcmd. -
DeeadPool - 17.08.2016
Do I have to replace My_objectID with anything?
Re: A bit help in zcmd. -
jlalt - 17.08.2016
Quote:
Originally Posted by DeeadPool
Do I have to replace My_objectID with anything?
|
nope sir.