Liberty Unleashed
Scripting => Script Help => Topic started by: rwwpl on July 22, 2015, 10:23:14 am
-
Function:
function PutToCar()
{
foreach(ii,p in Players)
{
if (p && InDerby[p.ID])
{
local v = GetClosestVehicle(p);
if (v) p.Vehicle = v;
}
}
}
Error line:
if (v) p.Vehicle = v;
Error:
<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
-
Could u post the code when "PutToCar()" it's called pls?
-
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();
}
-
dat code doesn't help ...
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.
-
(http://i62.tinypic.com/izyjrr.png)
<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
-
i meant
print(v);
print(p);
not the error.
-
<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
-
noice bug.
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
Players[p.ID] <- null;
to
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.
-
Error is line
p.Vehicle = v;
(http://i58.tinypic.com/35jj77k.png)
-
omg, the var 'p' never can be changed
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;
}
}
}
}
-
(http://i61.tinypic.com/2u7o9ra.png)
-
* starts to hate 'for each' loop *
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;
}
}
}
}
-
Error here:
vehicle = GetClosestVehicle(player);
when I replace to iv in GetClosestVehicle, it worked, but error in player.Pos = vehicle.Pos;
<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
-
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...
-
No Errors but
(http://i62.tinypic.com/atpx21.png)
Only player with id 0 has put to car.
-
Explain me a thing: Why the local "player" changes to integer 1 when shouldn't be changed?
-
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;
-
And how to fix that? Maybe there's a different way? I tired that, but it still doesn't work...