Liberty Unleashed

Scripting => Script Help => Topic started by: rwwpl on April 25, 2014, 01:29:23 pm

Title: /healall help
Post by: rwwpl on April 25, 2014, 01: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.
Title: Re: /healall help
Post by: SugarD on April 25, 2014, 02: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 (http://www.liberty-unleashed.co.uk/LUWiki/Squirrel/Server/Functions/Players/Health)
Title: Re: /healall help
Post by: Thijn on April 25, 2014, 03:06:26 pm
Posting the errors you get is rather useful in trying to fix this for you..
Title: Re: /healall help
Post by: rwwpl on April 26, 2014, 11:06:51 am
(http://i59.tinypic.com/23vyd89.png)
Title: Re: /healall help
Post by: Thijn on April 26, 2014, 12: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.
Title: Re: /healall help
Post by: rwwpl on September 15, 2014, 05: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
Title: Re: /healall help
Post by: Stoku on September 16, 2014, 11:23:17 am
You're trying to set an integer instead of float, so maybe try:
Code: [Select]
plrs.Health = 100.0;
Title: Re: /healall help
Post by: rwwpl on September 16, 2014, 03: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).

Title: Re: /healall help
Post by: Thijn on September 18, 2014, 10: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?

Title: Re: /healall help
Post by: Piterus on September 18, 2014, 04:09:55 pm
How many players were in the server when you were testing this?
3-4
Title: Re: /healall help
Post by: rwwpl on September 18, 2014, 05:37:33 pm
Now what? I need this command for events etc...
Title: Re: /healall help
Post by: Vortrex on September 18, 2014, 09: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;
}
Title: Re: /healall help
Post by: xMerkel on September 19, 2014, 04:56:43 pm
Code: [Select]
local i = 0;
for ( ; i <= GetMaxPlayers ( ); i++ ) {

local pPlayer = FindPlayer ( i );

if ( pPlayer ) {

pPlayer.Health = 100;
}
}
Title: Re: /healall help
Post by: Vortrex on September 19, 2014, 06: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.
Title: Re: /healall help
Post by: xMerkel on September 19, 2014, 06: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?)
Title: Re: /healall help
Post by: Vortrex on September 19, 2014, 06:43:00 pm
You're not getting my point. Hell, even if you had a maximum of 50 players that could connect, you are still looking for players that aren't connected (unless the server is full).

128 was just an example number. It's actually the default amount unless you set it otherwise.
Title: Re: /healall help
Post by: rwwpl on September 20, 2014, 08:50:33 am
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;
}

This code works ;) Thanks