Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Old Scripting Engine (GS1)
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 07-31-2017, 12:44 AM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,743
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
Help me weed out bad practices.

So I was scripting in an online editor and was annoyed by the people popping into the level to see what I was working on. So I scripted a system to remove players froma level in the offline editor in GS1. As part of my practice learning GS2 I want input on mistakes I made, how to make the script more efficient, design security for the NPC, and finally convert the script into GS2. Any advice is appreciated.

PHP Code:
// Script to add/remove players from ban list
if (playerchats) {
  if (
strequals(#a,maximus_asinus)) {
    
if (startswith(/add,#c)) {
      
tokenize #c;
      
this.duplicate false;
      if (
strequals(#t(1),#a)) {
        
setplayerprop #c,You cannot ban yourself.;
      
}
      else {
        for (
i=0;i<sarraylen(server.warp);i++;) {
          if (
strequals(#I(server.warp,i),#t(1))) {
            
this.duplicate true;
          }
        }
        if (
this.duplicate == true) {
          
setplayerprop #c,"#t(1)" is already on the ban list.;
        
}
        else {
          
addstring server.warp,#t(1);
          
setplayerprop #c,Added "#t(1)" to the ban list.;
        
}
      }
    }
    if (
startswith(/remove,#c)) {
      
tokenize #c;
      
for (i=0;i<sarraylen(server.warp);i++;) {
        if (
strequals(#I(server.warp,i),#t(1))) {
          
deletestring server.warp,i;
          
setplayerprop #c,Removed "#t(1)" from the ban list.;
        
}
      }
    }
  }

PHP Code:
// Script that removes the player
if (createdtimeout 0.05;
if (
timeout) {
  for (
i=0;i<sarraylen(server.warp);i++;) {
    if (
strequals(#I(server.warp,i),#a)) {
      
setplayerprop #c,You're banned from this level.;
      
setlevel2 onlinestartlocal.nw,30,30;
    }
  }
  
timeout 0.05;

I'm assuming placing a for loop inside a never ending timeout is bad practice and possibly process intensive. Can you manipulate another player's level and coordinates through a script like this? That way I could remove the player when I add them to the list and only have a playerenters check to see if they're on the list which would eliminate the timeout completely. This would also help me understand how you can manipulate other players via script.

Also I think I read that variables can now be assigned text values in GS2 like how strings work in GS1. Can you manipulate those variables in the same way as I am doing it in my script? If so, how?
__________________
Save Classic!
Reply With Quote
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 01:05 PM.


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