PDA

View Full Version : Trouble updating level tiles using script..


DarkIceX
07-05-2008, 03:54 PM
I'm trying to create a system which allows you to copy a level to your current level so that your level becomes a near exact replica (no NPCs)..

It's been done before, but It's good practice.

Anyways, I'm having a problem with the tiles resetting back to the normal tiles after a few minutes. The level is by default a level of all grass. When I copy a level, It'll update the board for a few minutes then pop back to all grass.

Wondering what's causing this.


function onCreated()
{
setshape(1,32,32);
}

function onActionspy()
{
temp.levelname = params[0];
temp.y = 0;

for (temp.x = -1; temp.x < 65; temp.x++)
{
tiles[temp.x,temp.y] = findlevel(temp.levelname).tiles[temp.x,temp.y];
if (temp.x == 64 && temp.y < 64)
{
temp.x = -1;
temp.y++;
}
}
updateboard(0,0,64,64);

for (a: allplayers)
{
if (a.level.name == temp.levelname)
{
if (a.level.name == "") continue;
temp.players.add(a.account);
}
}
echo(temp.players.size() SPC "players in" SPC temp.levelname);
echo(temp.players);
echo("Getting player attributes");

for (p: temp.players)
{
if (findplayer(p).communityname == "")
{
temp.account = findplayer(p).account;
}
else temp.account = findplayer(p).communityname;
temp.x = findplayer(p).x;
temp.y = findplayer(p).y;
temp.head = findplayer(p).headimg;
temp.body = findplayer(p).bodyimg;
temp.shield = findplayer(p).shieldimg;
temp.colors_0 = findplayer(p).colors[0];
temp.colors_1 = findplayer(p).colors[1];
temp.colors_2 = findplayer(p).colors[2];
temp.colors_3 = findplayer(p).colors[3];
temp.colors_4 = findplayer(p).colors[4];
temp.colors_5 = findplayer(p).colors[5];
echo(temp.account @ ": (" @ temp.x @ "," @ temp.y @ ")" SPC temp.head @ "," SPC temp.body @ "," SPC temp.shield @ "," SPC temp.colors_0 @ "," SPC temp.colors_1 @ "," SPC temp.colors_2 @ "," SPC temp.colors_3 @ "," SPC temp.colors_4 @ "," SPC temp.colors_5);
}
echo("Attribute fetching completed for" SPC temp.levelname);
}

//#CLIENTSIDE

function onPlayerChats()
{
if (player.chat.starts("/spy"))
{
temp.level = player.chat.tokenize()[1];
player.chat = temp.level;
triggeraction(x,y,"spy",temp.level);
}
}


This may not be the best or most efficient way of doing it, but I'm still learning, so if you know a better way It'd also be appreiciated if you could point me in the right direction.

Thanks :D

07-05-2008, 05:13 PM
technically, your best bet is to do it all clientside. the only purpose to you doing it all serverside is so that others see it, if you're creating a spy level make it clientside.
I made one serverside for Era, I'll post the script when I find it ^^

DarkIceX
07-05-2008, 06:31 PM
technically, your best bet is to do it all clientside. the only purpose to you doing it all serverside is so that others see it, if you're creating a spy level make it clientside.
I made one serverside for Era, I'll post the script when I find it ^^

Actually, I'd would do it clientside, but one of the points is for other people to be able to see it aswell.

Much more useful to have it serverside from the beginning instead of needing each person to set it to the right level or such.

xXziroXx
07-05-2008, 06:50 PM
Actually, I'd would do it clientside, but one of the points is for other people to be able to see it aswell.

If you do it clientsided all players in the level will see the same thing if the data is the same for everyone. :noob:

DarkIceX
07-05-2008, 06:56 PM
If you do it clientsided all players in the level will see the same thing if the data is the same for everyone. :noob:

I'll try it...

Edit: Tried it clientside, it still does the same thing. I also tried using updateboard2 and it STILL changes back to grass.

zokemon
07-06-2008, 12:38 AM
try level.tilelayers[0].tiles[x,y] instead of just tiles[x,y].

I don't know if it will help but it seemed to help me.

DarkIceX
07-06-2008, 02:09 AM
All fixed. The finished product is a level NPC that just copies the level and takes the attributes of the players in the level and echoes them to RC..
Probably not the most efficient or easy, but it works:


function onCreated()
{
setTimer(0.5);
setshape(1,32,32);
this.levelname = null;
}

function onActionspy()
{
this.levelname = params[0];
this.spying = true;

for (a: allplayers)
{
if (a.level.name == this.levelname)
{
if (a.level.name == "") continue;
temp.players.add(a.account);
}
}
echo(temp.players.size() SPC "players in" SPC this.levelname);
echo(temp.players);
echo("Getting player attributes");

for (p: temp.players)
{
if (findplayer(p).communityname == "")
{
temp.account = findplayer(p).account;
}
else temp.account = findplayer(p).communityname;
temp.x = findplayer(p).x;
temp.y = findplayer(p).y;
temp.head = findplayer(p).headimg;
temp.body = findplayer(p).bodyimg;
temp.shield = findplayer(p).shieldimg;
temp.colors_0 = findplayer(p).colors[0];
temp.colors_1 = findplayer(p).colors[1];
temp.colors_2 = findplayer(p).colors[2];
temp.colors_3 = findplayer(p).colors[3];
temp.colors_4 = findplayer(p).colors[4];
temp.colors_5 = findplayer(p).colors[5];
echo(temp.account @ ": (" @ temp.x @ "," @ temp.y @ ")" SPC temp.head @ "," SPC temp.body @ "," SPC temp.shield @ "," SPC temp.colors_0 @ "," SPC temp.colors_1 @ "," SPC temp.colors_2 @ "," SPC temp.colors_3 @ "," SPC temp.colors_4 @ "," SPC temp.colors_5);
}
echo("Attribute fetching completed for" SPC this.levelname);
}

function onTimeout()
{
if (this.spying == true && this.levelname != null)
{
temp.y = 0;
for (temp.x = -1; temp.x < 65; temp.x++)
{
level.tilelayers[0].tiles[temp.x,temp.y] = findlevel(this.levelname).tiles[temp.x,temp.y];
if (temp.x == 64 && temp.y < 64)
{
temp.x = -1;
temp.y++;
}
}
updateboard(0,0,64,64);
}
setTimer(0.5);
}

//#CLIENTSIDE

function onCreated()
{
setshape(1,32,32);
setTimer(0.05);
dontblock();
}

function onPlayerChats()
{
if (player.chat.starts("/spy"))
{
temp.levelname = player.chat.tokenize()[1];
player.chat = temp.levelname;
triggeraction(x,y,"spy",temp.levelname);
}
}


If there's anything I can improve on or so more easily than what I have here, It's appreiciated if you could shout it out so I know next time.