Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-15-2008, 08:38 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
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);
}
Reply With Quote
  #2  
Old 12-15-2008, 09:51 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
What error are you experiencing? You never mentioned.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #3  
Old 12-16-2008, 12:10 AM
RozenMaiden RozenMaiden is offline
Registered User
Join Date: Dec 2008
Posts: 27
RozenMaiden is on a distinguished road
Also I might add that I think such a thing could be easily avoided
e.g.
PHP Code:
player.(@ "rup" "ees" ) = 10
Reply With Quote
  #4  
Old 12-16-2008, 03:31 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by RozenMaiden View Post
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.
Reply With Quote
  #5  
Old 12-16-2008, 07:16 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
Quote:
Originally Posted by LoneAngelIbesu View Post
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
Reply With Quote
  #6  
Old 12-16-2008, 08:26 PM
RozenMaiden RozenMaiden is offline
Registered User
Join Date: Dec 2008
Posts: 27
RozenMaiden is on a distinguished road
Quote:
Originally Posted by Crow View Post
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
Reply With Quote
  #7  
Old 12-16-2008, 09:03 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
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


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
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #8  
Old 12-16-2008, 09:29 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
i don't think i am, or am i? o_O
Reply With Quote
  #9  
Old 12-16-2008, 09:32 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by [email protected] View Post
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.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #10  
Old 12-16-2008, 09:37 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
damn!! try fix it plz ziro, i have faith in u!!
Reply With Quote
  #11  
Old 12-16-2008, 09:46 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by [email protected] View Post
damn!! try fix it plz ziro, i have faith in u!!
Zzzz fine, but that means I gotta copy & paste it into a script on Mal, gimme a few mins
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #12  
Old 12-16-2008, 10:34 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Sorry, Angelu kept me busy on client

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);

__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #13  
Old 12-17-2008, 07:12 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
yay llove u long time xxxxxxxxx
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 02:09 PM.


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