Author Topic: /healall help  (Read 3712 times)

rwwpl

  • Full Member
  • ***
  • Posts: 126
  • Karma: +18/-6
  • LU-DM Team
    • View Profile
    • LU-DM Team
/healall help
« on: April 25, 2014, 02:29:23 pm »
Command /healall is not healing anyone, in addition /getall works on all players, and uses code from
/healall. When I'm alone, nothing is showing up, but when there is 2 persons or more, in console are showing up errors.

Code: [Select]
else if (c=="getall")
{
if (IsNoob(p,c)) return 0;
else if (!p.Spawned) MessagePlayer("** Musisz sie zrespic aby uzyc tej komendy!",p,255,0,0);
else
{
Message("*** "+p.Name+" teleportowal wszystkich graczy do siebie!",0,200,0);
for ( local count = GetPlayers(), id = 0, max = GetMaxPlayers(), plrs; count && id < max; id++ )
{
if ( !( plrs = FindPlayer( id ) ) ) continue;
if (plrs.Spawned) plrs.Pos = p.Pos;
--count;
}
}
}

else if (c=="healall")
{
if (IsNoob(p,c)) return 0;
else if (!p.Spawned) MessagePlayer("** Musisz sie zrespic aby uzyc tej komendy!",p,255,0,0);
else
{
Message("*** "+p.Name+" uzdrowil wszystkich graczy!",0,200,0);
for ( local count = GetPlayers(), id = 0, max = GetMaxPlayers(), plrs; count && id < max; id++ )
{
if ( !( plrs = FindPlayer( id ) ) ) continue;
if (plrs.Spawned) plrs.Health = 100;
--count;
}
}
}

Error is this line
Code: [Select]
if (plrs.Spawned) plrs.Health = 100;
This script from my old vcmp server.
« Last Edit: September 15, 2014, 06:13:39 pm by rwwpl »

SugarD

  • Argonath RPG Dev/Manager
  • Tester
  • Sr. Member
  • ****
  • Posts: 820
  • Karma: +37/-75
  • STOP IN THE NAME OF THE COLESLAW!
    • View Profile
    • Clan Xperience
Re: /healall help
« Reply #1 on: April 25, 2014, 03:26:25 pm »
I'm not sure if this would be of any help prior to you getting an answer, but check out the wiki page on player health in the server's functions, and see if you can spot any typos in your code:
http://www.liberty-unleashed.co.uk/LUWiki/Squirrel/Server/Functions/Players/Health

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: /healall help
« Reply #2 on: April 25, 2014, 04:06:26 pm »
Posting the errors you get is rather useful in trying to fix this for you..

rwwpl

  • Full Member
  • ***
  • Posts: 126
  • Karma: +18/-6
  • LU-DM Team
    • View Profile
    • LU-DM Team
Re: /healall help
« Reply #3 on: April 26, 2014, 12:06:51 pm »
« Last Edit: April 26, 2014, 12:19:33 pm by rwwpl »

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: /healall help
« Reply #4 on: April 26, 2014, 01:21:24 pm »
If I were you I would rewrite that for loop. It has a lot of stuff that isn't needed, and it turns out it doesn't work the way you want it to be.

The error in your script is the fact plrs isn't being set to a player instance, but to an integer.

rwwpl

  • Full Member
  • ***
  • Posts: 126
  • Karma: +18/-6
  • LU-DM Team
    • View Profile
    • LU-DM Team
Re: /healall help
« Reply #5 on: September 15, 2014, 06:11:09 pm »
/healall problem is back

Error
Code: [Select]
AN ERROR HAS OCCURED [trying to set 'integer']
<15/09/2014 - 18:01:34>
CALLSTACK
<15/09/2014 - 18:01:34> *FUNCTION [onPlayerCommand()] Scripts/0xSkrypt/0x844411.nut line [2547]
<15/09/2014 - 18:01:34>
LOCALS
<15/09/2014 - 18:01:34> [plrs] 1
<15/09/2014 - 18:01:34> [i] 1
<15/09/2014 - 18:01:34> [veh] NULL
<15/09/2014 - 18:01:34> [i] NULL
<15/09/2014 - 18:01:34> [plr] INSTANCE
<15/09/2014 - 18:01:34> [c] "healall"
<15/09/2014 - 18:01:34> [temp] NULL
<15/09/2014 - 18:01:34> [t] NULL
<15/09/2014 - 18:01:34> [c] "healall"
<15/09/2014 - 18:01:34> [p] INSTANCE
<15/09/2014 - 18:01:34> [this] TABLE

Command:
Code: [Select]
else if (c == "healall")
{
if (IsNoob(p,c)) return 0;
else
{
Message("*** "+p.Name+" uzdrowil wszystkich na serwerze!",255,0,80);
for(local i = 0; i <= GetMaxPlayers(); i++)
{
local plrs = FindPlayer(i);
if(plrs) plrs.Health = 100;
}
}
}

The error is in this line:
Code: [Select]
plrs.Health = 100;
This is another command that works without a problem.

Code: [Select]
else if (c == "disarmall")
{
if (IsNoob(p,c)) return 0;
else
{
Message("*** "+p.Name+" rozbroil wszystkich graczy na serwerze!",255,0,80);
for(local i = 0; i <= GetMaxPlayers(); i++)
{
local plrs = FindPlayer(i);
if(plrs) plrs.ClearWeapons();
}
}
}

Not know how solve it; x
« Last Edit: September 15, 2014, 08:38:22 pm by rwwpl »

Stoku

  • lck.gudio.eu
  • Full Member
  • ***
  • Posts: 276
  • Karma: +26/-2
  • Liberty City Killers
    • View Profile
    • Liberty City Killers (GTA3/VC Clan)
Re: /healall help
« Reply #6 on: September 16, 2014, 12:23:17 pm »
You're trying to set an integer instead of float, so maybe try:
Code: [Select]
plrs.Health = 100.0;
« Last Edit: September 16, 2014, 12:28:15 pm by Stoku »

rwwpl

  • Full Member
  • ***
  • Posts: 126
  • Karma: +18/-6
  • LU-DM Team
    • View Profile
    • LU-DM Team
Re: /healall help
« Reply #7 on: September 16, 2014, 04:11:46 pm »
You're trying to set an integer instead of float, so maybe try:
Code: [Select]
plrs.Health = 100.0;

The same error.
Code: [Select]
...
AN ERROR HAS OCCURED [trying to set 'integer']
...

++

In VCMP 0.4 script working properly, so I think the error is in the code LU (with health and armour).

« Last Edit: September 16, 2014, 09:12:44 pm by rwwpl »

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: /healall help
« Reply #8 on: September 18, 2014, 11:55:30 am »
As you can see in the locals, plrs is an integer, so you're trying to do this:
1.Health = 100;

This wont work.

Now your code seems fine, so I'm not entirely sure why FindPlayer is returning an integer. How many players were in the server when you were testing this?


Piterus

  • Newbie
  • *
  • Posts: 17
  • Karma: +8/-2
    • View Profile
Re: /healall help
« Reply #9 on: September 18, 2014, 05:09:55 pm »
How many players were in the server when you were testing this?
3-4

rwwpl

  • Full Member
  • ***
  • Posts: 126
  • Karma: +18/-6
  • LU-DM Team
    • View Profile
    • LU-DM Team
Re: /healall help
« Reply #10 on: September 18, 2014, 06:37:33 pm »
Now what? I need this command for events etc...

Vortrex

  • Full Member
  • ***
  • Posts: 267
  • Karma: +54/-73
    • View Profile
Re: /healall help
« Reply #11 on: September 18, 2014, 10:40:14 pm »
I haven't used a for loop to get players in a long time. Is there a preceding "i" variable somewhere in your command script? The locals say you have two, one is NULL and the other is 1.

A bit off topic, but it might help:
Instead of looping through the maximum players, why don't you just create a table, and store all the players in that?

Here is what I use when scripting:
Code: [Select]
function onScriptLoad( )
{
Players <- { };
}

function onPlayerConnect( player )
{
Players[ player.ID ] <- player;
}

function onPlayerPart( player , reason )
{
Players[ player.ID ] <- null;
}

THEN, when you need to grab all the players and set health, you just loop through the table:
Code: [Select]
foreach( ii , iv in Players )
{
iv.Health = 100;
}

xMerkel

  • Newbie
  • *
  • Posts: 34
  • Karma: +1/-12
  • Cpp
    • View Profile
Re: /healall help
« Reply #12 on: September 19, 2014, 05:56:43 pm »
Code: [Select]
local i = 0;
for ( ; i <= GetMaxPlayers ( ); i++ ) {

local pPlayer = FindPlayer ( i );

if ( pPlayer ) {

pPlayer.Health = 100;
}
}

Vortrex

  • Full Member
  • ***
  • Posts: 267
  • Karma: +54/-73
    • View Profile
Re: /healall help
« Reply #13 on: September 19, 2014, 07:36:23 pm »
Code: [Select]
local i = 0;
for ( ; i <= GetMaxPlayers ( ); i++ ) {

local pPlayer = FindPlayer ( i );

if ( pPlayer ) {

pPlayer.Health = 100;
}
}

Merkel, that is a horrible way to do it. If you have a 128 player capacity and 10 players online, why does the loop need to keep running 118 more times? You're holding up the main thread by doing this, which is wasting resources.

The method in my previous post is more efficient.

xMerkel

  • Newbie
  • *
  • Posts: 34
  • Karma: +1/-12
  • Cpp
    • View Profile
Re: /healall help
« Reply #14 on: September 19, 2014, 07:39:16 pm »
Code: [Select]
local i = 0;
for ( ; i <= GetMaxPlayers ( ); i++ ) {

local pPlayer = FindPlayer ( i );

if ( pPlayer ) {

pPlayer.Health = 100;
}
}

Merkel, that is a horrible way to do it. If you have a 128 player capacity and 10 players online, why does the loop need to keep running 118 more times? You're holding up the main thread by doing this, which is wasting resources.

The method in my previous post is more efficient.

LU never had more of 50 plrs. For the moment loops.

@rwwpl, server throws the error 'trying to set 'integer'' bcs "plrs" already exists as integer (Local with Players playing?)
« Last Edit: September 19, 2014, 07:41:29 pm by xMerkel »

 

© Liberty Unleashed Team.