guys, in main.nut, i see that /goto and /heal without timer, anyone can give me a example that replace the command with new /heal and /goto command?
You need to add a timer using NewTimer. Use the search or the wiki to learn more
Quote from: umar4911 on Dec 16, 2017, 10:12 AMYou need to add a timer using NewTimer. Use the search or the wiki to learn more
hmmm.........
NewTimer( "ClientMessageToAll", 1000, 1, "-> 3",28, 255, 11 );
{
if(cmd == "heal")
{
local hp = player.Health;
if(hp == 100) Message("[#FF3636]Error - [#8181FF]Use this command when you have less than 100% hp !");
else {
player.Health = 100.0;
MessagePlayer( "[#FFFF81]---> You have been healed !", player );
}
}
where to put timer?
to make a heal cmd with timer, first get to know the about timer
NewTimer( func, time, repeat, ... );
string func - the function to call when the timer ends (in a string format)
int time - the time before the function call
int repeat - how many times to repeat the process (1 just to execute once)
... - function (func) parameters
Copied from wiki
OK make a heal cmd
{
if(cmd == "heal")
{
local hp = player.Health;
if(hp == 100) Message("[#FF3636]Error - [#8181FF]Use this command when you have less than 100% hp !");
else {
MessagePlayer("You need to wait 5 seconds to heal", player);
NewTimer(heal, 1, 5000, player);
}
}
Added NewTimer that make a timer that after 5 seconds play the function heal with parameters player and only play once.
Now make a heal function to work
function heal(player)
{
local plr = FindPlayer(player); //It can happen that player left the game while healing so need to check that is player available.
if(plr)
{
plr.Health = 100;
MessagePlayer("Healed!", plr);
}
}
Quote from: umar4911 on Dec 16, 2017, 02:10 PMto make a heal cmd with timer, first get to know the about timer
NewTimer( func, time, repeat, ... );
string func - the function to call when the timer ends (in a string format)
int time - the time before the function call
int repeat - how many times to repeat the process (1 just to execute once)
... - function (func) parameters
Copied from wiki
OK make a heal cmd
{
if(cmd == "heal")
{
local hp = player.Health;
if(hp == 100) Message("[#FF3636]Error - [#8181FF]Use this command when you have less than 100% hp !");
else {
MessagePlayer("You need to wait 5 seconds to heal", player);
NewTimer(heal, 1, 5000, player);
}
}
Added NewTimer that make a timer that after 5 seconds play the function heal with parameters player and only play once.
Now make a heal function to work
function heal(player)
{
local plr = FindPlayer(player); //It can happen that player left the game while healing so need to check that is player available.
if(plr)
{
plr.Health = 100;
MessagePlayer("Healed!", plr);
}
}
That'd crash the server because you cannot pass instances in timers of the native plugin.
i have healall cmd
This code heal all > for (local i=0; i<GetMaxPlayers(); i++)
if ( cmd == "healall" )
{
if ( player.Name == "umar491" || player.Name == "ForOver" )
{
Message( "[#FF0000]**[#FFFFFF] Admin[#FF0000] " + player.Name+ "[#FFFFFF] healed All Players");
for (local i=0; i<GetMaxPlayers(); i++)
{
local p=FindPlayer(i);
if(p)
p.Health = 100.0;
}
}
else MessagePlayer( "[#FF0000] You're not allowed to use this command. " , player )
}
Quote from: =RK=MarineForce on Dec 16, 2017, 04:32 PMi have healall cmd
This code heal all > for (local i=0; i<GetMaxPlayers(); i++)
if ( cmd == "healall" )
{
if ( player.Name == "umar491" || player.Name == "ForOver" )
{
Message( "[#FF0000]**[#FFFFFF] Admin[#FF0000] " + player.Name+ "[#FFFFFF] healed All Players");
for (local i=0; i<GetMaxPlayers(); i++)
{
local p=FindPlayer(i);
if(p)
p.Health = 100.0;
}
}
else MessagePlayer( "[#FF0000] You're not allowed to use this command. " , player )
}
At least read the topic word to word before posting.
Quote from: Xmair on Dec 16, 2017, 02:49 PMQuote from: umar4911 on Dec 16, 2017, 02:10 PMto make a heal cmd with timer, first get to know the about timer
NewTimer( func, time, repeat, ... );
string func - the function to call when the timer ends (in a string format)
int time - the time before the function call
int repeat - how many times to repeat the process (1 just to execute once)
... - function (func) parameters
Copied from wiki
OK make a heal cmd
{
if(cmd == "heal")
{
local hp = player.Health;
if(hp == 100) Message("[#FF3636]Error - [#8181FF]Use this command when you have less than 100% hp !");
else {
MessagePlayer("You need to wait 5 seconds to heal", player);
NewTimer(heal, 1, 5000, player);
}
}
Added NewTimer that make a timer that after 5 seconds play the function heal with parameters player and only play once.
Now make a heal function to work
function heal(player)
{
local plr = FindPlayer(player); //It can happen that player left the game while healing so need to check that is player available.
if(plr)
{
plr.Health = 100;
MessagePlayer("Healed!", plr);
}
}
That'd crash the server because you cannot pass instances in timers of the native plugin.
Then what should be used?
Quote from: umar4911 on Dec 22, 2017, 12:31 PMThen what should be used?
Pass the playerID and then inside function use the FindPlayer method to get the instance.
NewTimer( "CalledFunction", 1000, 1, player.ID );
function CalledFunction( playerID )
{
local player = FindPlayer( playerID );
if ( !player ) return;
bla
bla
}