Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Level Updater Scanner (https://forums.graalonline.com/forums/showthread.php?t=83174)

[email protected] 12-15-2008 08:38 PM

Level Updater Scanner
 
So, I'm trying to do a check on every level uploaded to the server. However, It's coming out with some weird things when I am wanting to write the lines back. Here's the script, basically what it is doing is running through each line in the level uploaded and checking if it's got anything illegal in it, if it does it deletes that entire NPC [from 'NPC image x y' to 'NPCEND'], here's what I have so far...

HTML Code:

function onLevelFileUpdated(file){
  temp.lines.loadlines("levels/" @ temp.file);
  temp.newlines.loadlines("levels/" @ temp.file);
 
  temp.illegal = {"item", "client", "rupee", "player"};

  for (temp.i: temp.lines) {
    temp.currentline++;
    if (i.starts("BOARD")) continue;
    if (i.starts("GLEV")) continue;
    if (i.starts("LINK")) continue;
   
    if (i == "NPCEND") {
      if (temp.bad == true) {
        temp.total = temp.currentline - temp.count;
        for (temp.t = temp.count; temp.t < (temp.count + temp.total); temp.t++)
          temp.newlines.delete(t);
        temp.currentline = count - 1;
        temp.bad = false;
        continue;
      }
    }
   
    if (i.starts("NPC")) temp.count = temp.currentline;
    for (temp.scan: temp.illegal) {
      if (i.lower().pos(scan) != -1) temp.bad = true;
    } 
  }
  temp.newlines.savelines("levels/" @ temp.file, 0);
}


LoneAngelIbesu 12-15-2008 09:51 PM

What error are you experiencing? You never mentioned.

RozenMaiden 12-16-2008 12:10 AM

Also I might add that I think such a thing could be easily avoided
e.g.
PHP Code:

player.(@ "rup" "ees" ) = 10


Crow 12-16-2008 03:31 PM

Quote:

Originally Posted by RozenMaiden (Post 1449609)
Also I might add that I think such a thing could be easily avoided
e.g.
PHP Code:

player.(@ "rup" "ees" ) = 10


I think in this case, Andy wants to remove old, unused scripting gibberish. Might be wrong though.

[email protected] 12-16-2008 07:16 PM

Quote:

Originally Posted by LoneAngelIbesu (Post 1449579)
What error are you experiencing? You never mentioned.

oh, sorry

Well, it's cutting out scripts, here's the original level
HTML Code:

NPC - 49 17
this.join("env-tree");
NPCEND
NPC era_image-tree-02.png 18 49
this.join("env-tree");
NPCEND
NPC - 35 43
this.join("env-tree");
NPCEND
NPC - 23 33
if (playerchats&&strequals(#c,:in)) {
playerx=22.5;
playery=33;
}
if (playerchats&&strequals(#c,:out)) {
playerx=30;
playery=30;
}
NPCEND
NPC era_flower-1_1a.png 30 33
function onCreated() {
  this.item = "Yellow_Mum";
  this.join("env-flower");
}
NPCEND
NPC era_flower-1_1a.png 30 35
function onCreated() {
  this.item = "Yellow_Mum";
  this.join("env-flower");
}
NPCEND
NPC era_flower-1_1a.png 35 35
function onCreated() {
  this.item = "Yellow_Mum";
  this.join("env-flower");
}
NPCEND
NPC era_flower-1_1a.png 35 35
function onCreated() {
  this.item = "Yellow_Mum";
  this.join("env-flower");
}
NPCEND
NPC era_flower-1_1a.png 35 35
function onCreated() {
  this.item = "Yellow_Mum";
  this.join("env-flower");
}
NPCEND
NPC era_flower-1_1a.png 35 35
function onCreated() {
  this.item = "Yellow_Mum";
  this.join("env-flower");
}
NPCEND
NPC - 37 53
this.join("env-outsidemall");
NPCEND
NPC - 57 59
this.join("test_treadmill");
NPCEND
NPC - 54 52
function onCreated() {
  this.setShape(1, 112, 64);
  this.join("shop_seashells");
}
//#CLIENTSIDE
function onCreated() {
  this.setShape(1, 112, 64);
}
NPCEND
NPC - 56 49
if (created) {
  showcharacter;
  setcharprop #3,head42.png;
  setcharprop #C0,black;
  setcharprop #C1,black;
  setcharprop #P1,era_rare-pinkNoLand.png;
  setcharprop #C2,pink;
  setcharprop #C3,darkblue;
  setcharprop #C4,pink;
  setcharprop #8,body16.png;
  setcharprop #n,Sarah;
  setcharprop #2,no-shield.gif;
  dir = 2;
  setcharani idle,;
}
NPCEND
NPC - 0 0
function onCreated() {
  this.addItem();
  this.rupees += 30;
}
NPCEND

Here's what it outputs...
HTML Code:

NPC - 49 17
this.join("env-tree");
NPCEND
NPC era_image-tree-02.png 18 49
this.join("env-tree");
NPCEND
NPC - 35 43
this.join("env-tree");
NPCEND
NPC - 23 33
}
  this.join("env-flower");
NPC era_flower-1_1a.png 35 35
  this.item = "Yellow_Mum";
}
NPCEND
this.join("env-outsidemall");
NPC - 57 59
NPCEND
function onCreated() {
  this.join("shop_seashells");
//#CLIENTSIDE
  this.setShape(1, 112, 64);
NPCEND
if (created) {
  showcharacter;
  setcharprop #3,head42.png;
  setcharprop #C0,black;
  setcharprop #C1,black;
  setcharprop #P1,era_rare-pinkNoLand.png;
  setcharprop #C2,pink;
  setcharprop #C3,darkblue;
  setcharprop #C4,pink;
  setcharprop #n,Sarah;
  dir = 2;
}
NPC - 0 0
  this.addItem();
  this.rupees += 30;
}
NPCEND


RozenMaiden 12-16-2008 08:26 PM

Quote:

Originally Posted by Crow (Post 1449852)
I think in this case, Andy wants to remove old, unused scripting gibberish. Might be wrong though.

Ah, I thought it was like a check for player houses or stuff like that

xXziroXx 12-16-2008 09:03 PM

Probably because you're deleting entrys in an array currently used for the loop, thus messing it up. You should never manipulate the same array as the loop uses, use a copy of it and update the original after the loop :p


PHP Code:

temp.array = { "foo""bar""baz" };
for (
temp.entrytemp.array) {
  echo(
temp.entry);
  if (
temp.entry == "foo"temp.array.delete(temp.var);
  
temp.var ++;


Echoes "foo" and "baz" since by deleting an entry, you shorten the array, thus skipping "bar".

Instead, do something like:

PHP Code:

temp.array = { "foo""bar""baz" };
temp.loopArray temp.array;
for (
temp.entrytemp.array) {
  echo(
temp.entry);
  if (
temp.entry == "foo"temp.loopArray.delete(temp.var);
  
temp.var ++;
}
temp.array = temp.loopArray

:D

[email protected] 12-16-2008 09:29 PM

i don't think i am, or am i? o_O

xXziroXx 12-16-2008 09:32 PM

Quote:

Originally Posted by [email protected] (Post 1450145)
i don't think i am, or am i? o_O

Oh, my bad, I failed to notice that you were deleting from newlines. It does sound like this would be the problem though. :noob:

[email protected] 12-16-2008 09:37 PM

damn!! try fix it plz ziro, i have faith in u!! :D

xXziroXx 12-16-2008 09:46 PM

Quote:

Originally Posted by [email protected] (Post 1450148)
damn!! try fix it plz ziro, i have faith in u!! :D

Zzzz fine, but that means I gotta copy & paste it into a script on Mal, gimme a few mins :mad:

xXziroXx 12-16-2008 10:34 PM

Sorry, Angelu kept me busy on client :p

I didn't quite fix yours, but I did make a version that works. Feel free to use it, or whatever.

PHP Code:

function onLevelFileUpdated(file)
{
  
temp.lines.loadlines("levels/" temp.file);
  
temp.newLines.loadlines("levels/" temp.file);
  
  
temp.illegal = {"item""client""rupee""player"};
  
  
temp.var = -1;
  for (
temp.linetemp.lines) {
    
temp.var ++;
    
    if (
temp.line.starts("BOARD")) continue;
    if (
temp.line.starts("GLEV")) continue;
    if (
temp.line.starts("LINK")) continue;
    if (
temp.line == "" && !temp.isNPC) continue;
       
    if (
temp.line.starts("NPC") && temp.line != "NPCEND") {
      
temp.isNPC true;
      
temp.startPos = var;
    }
    
    else if (
temp.line == "NPCEND") {
      
temp.endPos temp.var;
      
      if (
temp.bad && temp.isNPC) {
        for (
temp.temp.startPostemp.<= temp.endPostemp.++) {
          
temp.newLines.delete(temp.temp.deleteCount);
          
temp.deleteCount ++;
        }
        
        
temp.bad false;
        
temp.isNPC false;
      }
    }
    
    else if (
temp.isNPC && !temp.bad) {
      for (
temp.scantemp.illegal) {
        if (
temp.line.lower().pos(temp.scan) > -1temp.bad true;
      }
    }
  }
  
  
temp.newLines.saveLines("levels/" temp.file0);



[email protected] 12-17-2008 07:12 PM

yay llove u long time xxxxxxxxx


All times are GMT +2. The time now is 04:26 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.