Liberty Unleashed

Scripting => Script Help => Topic started by: rwwpl on July 22, 2015, 10:23:14 am

Title: PutToCar all players in derby problem.
Post by: rwwpl on July 22, 2015, 10:23:14 am
Function:

Code: [Select]
function PutToCar()
{
foreach(ii,p in Players)
{
if (p && InDerby[p.ID])
{
local v = GetClosestVehicle(p);
if (v) p.Vehicle = v;
}
}
}

Error line:
Code: [Select]
if (v) p.Vehicle = v;

Error:

Code: [Select]
<22/07/2015 - 11:02:29>
AN ERROR HAS OCCURED [invalid instance type]

<22/07/2015 - 11:02:29>
CALLSTACK

<22/07/2015 - 11:02:29> *FUNCTION [PutToCar()] Scripts/Glowny/Funkcje.nut line [1239]

<22/07/2015 - 11:02:29>
LOCALS

<22/07/2015 - 11:02:29> [vehicle] INSTANCE

<22/07/2015 - 11:02:29> [p] INSTANCE

<22/07/2015 - 11:02:29> [ii] 1

<22/07/2015 - 11:02:29> [this] TABLE
Title: Re: PutToCar all players in derby problem.
Post by: Ankris on July 22, 2015, 11:46:22 am
Could u post the code when "PutToCar()" it's called pls?
Title: Re: PutToCar all players in derby problem.
Post by: rwwpl on July 22, 2015, 12:43:19 pm
Code: [Select]
function CheckDerby()
{
DerbyZapisy = false;
if (DerbyGracze > 1)
{
DerbyCash = DerbyGracze * 300;
Derby = true;
PutToCar();
NewTimer("DerbyOdlicz",0,1,"3");
NewTimer("DerbyOdlicz",1000,1,"2");
NewTimer("DerbyOdlicz",2000,1,"1");
NewTimer("DerbyOdlicz",3000,1,"0");
NewTimer("MessageLang",3000,1,"* Derby wystartowaly! Graczy [#ffaa00][ "+DerbyGracze+" ][#beff0a] / Wygrana [#ffaa00][ $"+DerbyCash+" ]!","* Derby has started! Players [#ffaa00][ "+DerbyGracze+" ][#beff0a] / Prize [#ffaa00][ $"+DerbyCash+" ]!",190,255,10);
}
else CloseDerby();
}
Title: Re: PutToCar all players in derby problem.
Post by: Ankris on July 22, 2015, 02:04:12 pm
dat code doesn't help ...

Code: [Select]
function PutToCar()
{
foreach(ii,p in Players)
{
if (p && InDerby[p.ID])
{
local v = GetClosestVehicle(p);
if (v) {
print(v);
print(p);
p.Vehicle = v;
}
}
}
}

Tell me what prints.
Title: Re: PutToCar all players in derby problem.
Post by: rwwpl on July 22, 2015, 02:31:01 pm
(http://i62.tinypic.com/izyjrr.png)

Code: [Select]
<22/07/2015 - 15:29:49> Banshee
<22/07/2015 - 15:29:49> rwwpl
<22/07/2015 - 15:29:49> rwwpl2 <- bugged...
<22/07/2015 - 15:29:49> rwwpl2
Title: Re: PutToCar all players in derby problem.
Post by: Ankris on July 22, 2015, 02:36:32 pm
i meant
Code: [Select]
print(v);
print(p);

not the error.
Title: Re: PutToCar all players in derby problem.
Post by: rwwpl on July 22, 2015, 02:59:51 pm
Code: [Select]
<22/07/2015 - 15:29:49> Banshee
<22/07/2015 - 15:29:49> rwwpl
<22/07/2015 - 15:29:49> rwwpl2 <- bugged...
<22/07/2015 - 15:29:49> rwwpl2
Title: Re: PutToCar all players in derby problem.
Post by: Ankris on July 22, 2015, 03:13:51 pm
noice bug.
Code: [Select]
function PutToCar()
{
foreach(ii,p in Players)
{
if (InDerby[ii])
{
local v = GetClosestVehicle(p);
p = FindPlayer(ii);
if (v)
{
p.Pos = v.Pos;
p.Vehicle = v;
}
}
}
}

btw, as you are using the Vortrex loop method (not Shadow. loop method, it's different), go to "onPlayerPart" event and replace the line
Code: [Select]
Players[p.ID] <- null;
to
Code: [Select]
Players.rawdelete(p.ID);
Rawdelete will remove the player ID slot from table, and you never will need check if exists or not the slot.
Title: Re: PutToCar all players in derby problem.
Post by: rwwpl on July 22, 2015, 03:25:01 pm
Error is line

Code: [Select]
p.Vehicle = v;

(http://i58.tinypic.com/35jj77k.png)
Title: Re: PutToCar all players in derby problem.
Post by: Ankris on July 22, 2015, 03:33:47 pm
omg, the var 'p' never can be changed

Code: [Select]
function PutToCar()
{
foreach(ii,p in Players)
{
if (InDerby[ii])
{
local v = GetClosestVehicle(p), p = FindPlayer(ii);
if (v && p)
{
p.Pos = v.Pos;
p.Vehicle = v;
}
}
}
}
Title: Re: PutToCar all players in derby problem.
Post by: rwwpl on July 22, 2015, 03:57:09 pm
(http://i61.tinypic.com/2u7o9ra.png)
Title: Re: PutToCar all players in derby problem.
Post by: Ankris on July 22, 2015, 04:27:12 pm
* starts to hate 'for each' loop *

Code: [Select]
function PutToCar()
{
foreach(ii,iv in Players)
{
if (InDerby[ii])
{
local player = FindPlayer(ii), vehicle = GetClosestVehicle(player);
if (vehicle && player)
{
player.Pos = vehicle.Pos;
player.Vehicle = vehicle;
}
}
}
}
Title: Re: PutToCar all players in derby problem.
Post by: rwwpl on July 22, 2015, 04:37:46 pm
Error here:
Code: [Select]
vehicle = GetClosestVehicle(player);

when I replace to iv in GetClosestVehicle, it worked, but error in player.Pos = vehicle.Pos;

Code: [Select]
<22/07/2015 - 17:30:40>
AN ERROR HAS OCCURED [parameter 1 has an invalid type 'integer' ; expected: 'instance']

<22/07/2015 - 17:30:40>
CALLSTACK

<22/07/2015 - 17:30:40> *FUNCTION [PutToCar()] Scripts/Glowny/Funkcje.nut line [1238]

<22/07/2015 - 17:30:40> *FUNCTION [CheckDerby()] Scripts/Glowny/Funkcje.nut line [1222]

<22/07/2015 - 17:30:40>
LOCALS

<22/07/2015 - 17:30:40> [player] 1

<22/07/2015 - 17:30:40> [iv] INSTANCE

<22/07/2015 - 17:30:40> [ii] 1

<22/07/2015 - 17:30:40> [this] TABLE

<22/07/2015 - 17:30:40> [this] TABLE
Title: Re: PutToCar all players in derby problem.
Post by: Ankris on July 22, 2015, 06:48:58 pm
Code: [Select]
function PutToCar()
{
foreach(ii,iv in Players)
{
if (InDerby[ii])
{
local player = FindPlayer(ii), vehicle = GetClosestVehicle(player);
if (vehicle && type(player) == "instance")
{
player.Pos = vehicle.Pos;
player.Vehicle = vehicle;
}
}
}
}
fu...
Title: Re: PutToCar all players in derby problem.
Post by: rwwpl on July 22, 2015, 07:04:20 pm
No Errors but


(http://i62.tinypic.com/atpx21.png)

Only player with id 0 has put to car.
Title: Re: PutToCar all players in derby problem.
Post by: Ankris on July 22, 2015, 07:43:36 pm
Explain me a thing: Why the local "player" changes to integer 1 when shouldn't be changed?
Title: Re: PutToCar all players in derby problem.
Post by: Vortrex on July 22, 2015, 09:34:11 pm
I notice a problem though. You don't need to create a new player variable in the foreach loop. This is because the "ii" and "iv" are index AND value. When I first created that loop, I used the abbreviation "ii" as "iterator index" and "iv" as "iterator value". I think I should've mentioned that before but I don't think I ever did. It was just for readability purposes.

If you use "iv" as your player variable while inside the loop, then it should work. The "iv" is a pointer to the instance for the player and can be used just like any "player" instance.

Example:
iv.Skin = 1;

Does the exact same thing as this:
local player = FindPlayer( ii );
player.Skin = 1;

Title: Re: PutToCar all players in derby problem.
Post by: rwwpl on July 23, 2015, 01:05:48 pm
And how to fix that? Maybe there's a different way? I tired that, but it still doesn't work...