SA-MP Forums Archive
one question (cmd for all) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: one question (cmd for all) (/showthread.php?tid=591548)



one question (cmd for all) - xTURBOx - 13.10.2015

I want to know how to make a command that does it to all players.
Example: /healall
I want it to heal all players
SetPlayerHealth(playerid, 100.0); <--- what do I replace playerid if I want it for all players??


Re: one question (cmd for all) - Sjn - 13.10.2015

Loop through all the players, check if the player is connected or not, then heal. Something like

PHP код:
CMD:healall(playeridparams[])
{
    for (new 
0MAX_PLAYERSi++)
    {
        if (
IsPlayerConnected(i))
        {
            
SetPlayerHealth(i100.0);
        }
    }
    return 
1;

This is a very basic example, it just heals all the players that are online in-game and anyone can use this command. Ofcourse, you will have to modify the command to make it the way you want it and fit in your server.


Re: one question (cmd for all) - bgedition - 13.10.2015

- Delete -


Re: one question (cmd for all) - Logic_ - 13.10.2015

I prefer foreach

PHP код:
CMD:healall(playeridparams[])
{
    foreach(
Playeri)
    {
            
SetPlayerHealth(i100.0);
        }
    return 
1;




Re: one question (cmd for all) - HydraHumza - 13.10.2015

Quote:
Originally Posted by ALiScripter
Посмотреть сообщение
I prefer foreach

PHP код:
CMD:healall(playeridparams[])
{
    foreach(
Playeri)
    {
            
SetPlayerHealth(i100.0);
        }
    return 
1;

if he is using new version of then new syntax of foreach loop is

Код:
foreach(new i : Player)



Re: one question (cmd for all) - Logic_ - 13.10.2015

Quote:
Originally Posted by Humza
Посмотреть сообщение
if he is using new version of then new syntax of foreach loop is

Код:
foreach(new i : Player)
my bad xD that i am using a older version, where can i find the new version


Re: one question (cmd for all) - Sjn - 13.10.2015

Quote:
Originally Posted by ALiScripter
Посмотреть сообщение
I prefer foreach

PHP код:
CMD:healall(playeridparams[])
{
    foreach(
Playeri)
    {
            
SetPlayerHealth(i100.0);
        }
    return 
1;

Well, he didn't even know the default looping method, so i wouldn't recommend him using foreach since its an addon to the server.


Re: one question (cmd for all) - xTURBOx - 13.10.2015

Quote:
Originally Posted by Sjn
Посмотреть сообщение
Loop through all the players, check if the player is connected or not, then heal. Something like

PHP код:
CMD:healall(playeridparams[])
{
    for (new 
0MAX_PLAYERSi++)
    {
        if (
IsPlayerConnected(i))
        {
            
SetPlayerHealth(i100.0);
        }
    }
    return 
1;

This is a very basic example, it just heals all the players that are online in-game and anyone can use this command. Ofcourse, you will have to modify the command to make it the way you want it and fit in your server.
Thanks just what I was looking for +rep