Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-15-2013, 03:39 PM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
Baddie Script Review

I have attached my server's baddie script, and as discussed in the playerworld forums, I had questions about IOS scripts involving baddies.

I want to know how well/poor, organized, etc. this is coded in the goal of putting it in a mobile server.

Original Question Post:
http://forums.graalonline.com/forums...hp?t=134268621


What needs to be changed? Or does it totally need to be re-done.
I am not an expert GS2 coder as I switched from GML (Gamemaker language)
Constructive criticism would be nice
Attached Files
File Type: txt baddie.txt (6.6 KB, 157 views)
Reply With Quote
  #2  
Old 08-15-2013, 07:38 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
The whole thing seems to be a mess of different scheduled events. You should clean that up a lot. Also, the minimum timeout/scheduleEvent time on serverside is 0.1, not 0.05. You seem to be scheduling events even in areas where you don't need to wait (e.g. when adding experience, why not just call the function instead of scheduling it for 0.1 seconds in the future?)

I don't understand why you need a timeout checking if the baddy is dead every 0.1 seconds. Just check if it's dead when it gets attacked and handle it then.

There are also a lot of random errors like in onAttack where you loop through the players (with temp.p) but then use the player variable, which is going to either be unset or set to an arbitrary player.

I also noticed some typos like this.aggressive / this.agressive.

I didn't look very closely but there are a lot of big problems.
__________________
Reply With Quote
  #3  
Old 08-15-2013, 08:29 PM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
Quote:
Originally Posted by cbk1994 View Post
The whole thing seems to be a mess of different scheduled events. You should clean that up a lot. Also, the minimum timeout/scheduleEvent time on serverside is 0.1, not 0.05. You seem to be scheduling events even in areas where you don't need to wait (e.g. when adding experience, why not just call the function instead of scheduling it for 0.1 seconds in the future?)

I don't understand why you need a timeout checking if the baddy is dead every 0.1 seconds. Just check if it's dead when it gets attacked and handle it then.

There are also a lot of random errors like in onAttack where you loop through the players (with temp.p) but then use the player variable, which is going to either be unset or set to an arbitrary player.

I also noticed some typos like this.aggressive / this.agressive.

I didn't look very closely but there are a lot of big problems.

I understand.. Now that I look it over it is pretty unacceptable.
Reply With Quote
  #4  
Old 08-15-2013, 10:20 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
also try to get familiar with the move() function, will help you a lot
__________________
MEEP!
Reply With Quote
  #5  
Old 08-16-2013, 02:31 AM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
Quote:
Originally Posted by callimuc View Post
also try to get familiar with the move() function, will help you a lot
Can you give me an example of using the move() function?
Reply With Quote
  #6  
Old 08-16-2013, 04:07 AM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by i8bit View Post
Can you give me an example of using the move() function?
using scripthelp:
TServerNPC.move(float, float, float, int) - moves the npc smoothly, parameters are delta x, delta y, time and options: cache type (0, 1-cache, 2-append) + blockcheck(4) + eventwhendone(8) + applydir(16)

example:
Graal Script Code:
function onCreated() {
  
this.image "block.png";
  
this.this.30;
  echo(
"Starting to move...");
    
//Move NPC by 2 tiles in the x, 2 tiles in the y within 0.5 secs
    //While the last parameter is 8 (check description above script example)
    //The event 'onMovementFinished()' will be called
  
move(220.58);
}
function 
onMovementFinished() {
  echo(
"Done moving!");

With some maths you can tweak around the delta x/y and have it move around the player easy.


Ps: This move example replaced something like this which does lag more on the server
Graal Script Code:
function onCreated() {
  
this.image "block.png";
  
this.this.30;
  echo(
"Starting to move...");
  
temp.time = (0.05/0.5); //steps divided by the time it should take
  
for (temp.i=0;temp.i<2;temp.i+=temp.time) {
    
this.+= temp.time;
    
this.+= temp.time;
  }
  echo(
"Done moving!");

__________________
MEEP!
Reply With Quote
  #7  
Old 08-16-2013, 01:17 PM
Cubical Cubical is offline
Banned
Join Date: Feb 2007
Posts: 1,348
Cubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant future
On an unrelated note you may want to create some getter and setter functions instead of doing things such as

Graal Script Code:
clientr.exp += this.expgain
It helps if you want to add some validation or a new variable to how it's calculated later on such as experience potions or checks to make sure they do not level past the max level. The main reason you would want to use getter and setter functions is if you need to go change something such as the flag name or whatever formula you use to calculate the experience you wont need to go back and modify every line of code that adds experience. I'm at work so if it doesn't make too much sense I can reexplain later if Chris Vimes hasn't already answered your questions

join the player to a class called player_functions or whatever you want to call it doing player.join("player_functions"); Then within that class do something similar to the following

Graal Script Code:
function addExp(amount){
  
clientr.exp += amount;

then whenever you need to add experience you can do

Graal Script Code:
player.addExp(8675039); 
Then if you want to add checks later you can just do the following in player_functions instead of going back and modifying 100 times in all your code

Graal Script Code:
public function addExp(amount){
  
temp.exptable = { 0102040,75100 };
  if (
clientr.exp amount <= temp.exptable[clientr.level]){
    
clientr.exp += amount;
  } else 
player.levelUp();
}

function 
levelUp(){
  
clientr.level++;
  
clientr.exp 0;

This also helps prevent unneeded code duplication

Last edited by Cubical; 08-16-2013 at 09:16 PM..
Reply With Quote
  #8  
Old 08-16-2013, 07:34 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by Cubical View Post
Graal Script Code:
function addExp(amount){
  
clientr.exp += amount;

...
Graal Script Code:
function addExp(amount){
  
temp.exptable = { 0102040,75100 };
  if (
clientr.exp amount <= temp.exptable[clientr.level]){
    
clientr.exp += amount;
  } else 
player.levelUp();
}

function 
levelUp(){
  
clientr.level++;
  
clientr.exp 0;

the addExp() function needs to be a public function
__________________
MEEP!
Reply With Quote
  #9  
Old 08-16-2013, 09:16 PM
Cubical Cubical is offline
Banned
Join Date: Feb 2007
Posts: 1,348
Cubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant future
whoops and fixed
Reply With Quote
  #10  
Old 08-16-2013, 10:07 PM
MysticalDragon MysticalDragon is offline
Global Administration
MysticalDragon's Avatar
Join Date: Oct 2002
Location: Lynn Ma
Posts: 883
MysticalDragon is just really niceMysticalDragon is just really nice
Send a message via AIM to MysticalDragon Send a message via MSN to MysticalDragon
To answer your question, it has to be completely redone. The code is terrible, and your abusing schduleevent as if it was a timeout :/. I might release delterias Baddie system on the forums soon. You could probably at least learn from it.

Graal Script Code:
//Can be Used for Baddies
public function addMobExperience(temp.mob_leveltemp.mob_base_exp) {
  
// Find XP multiplier
  
temp.curr_level this._get("pve_level");  //Player Level (clientr.pve_level)
  
temp.level_difference temp.mob_level temp.curr_level//Mob Level
  
temp.difference max(-5min(temp.level_difference5)); //Difference
  
temp.multiplier = (temp.difference/5); //Multiplier

  // Add experience  
  
addExperience(temp.mob_base_exp temp.multiplier);
}

//Can be used for Quests etc
public function addExperience(temp.amount) {
  
temp.amount *= 1;  //Incase you have events like double EXP
  
temp.curr_exp this._get("pve_exp");  //clientr.pve_exp
  
temp.curr_exp += temp.amount;
  
// Check if we reached a new level
  
if (temp.curr_exp >= this._get("pve_nextlevelexp")) {
  
/* Only used on Delteria
    // Add enchantment point when leveling up
    temp.enchantment_points = this._get("enchantment_points");
    this._set("enchantment_points", temp.enchantment_points + 1);
  */
    
temp.new_level this._get("pve_level") + 1//clientr.pve_level + 1;
   /* If you want them to still gain EXP for extra things like CMD Points after     max level (25)
    if (temp.new_level >= 26) {
      // reset experience points so they can get more enchantment points
      this._set("pve_exp", 0);
      return;
    }
  */
    
this._set("pve_level"temp.new_level); //clientr.pve_level = temp.new_level;
    
this._set("pve_exp"0); //clientr.pve_exp = 0;
    
this._set("pve_nextlevelexp"1000 temp.new_level); //clientr.pve_nextlevelexp = 1000 * temp.new_level

    //Floating Text to Display player leveling up
    
this.triggerclient("weapon""Player/DamageDisplay""text2",
      
player.random(01),
      
player.random( -.51),
      
"Level Up! (" SPC clientr.pve_level SPC ")",
      
25512800"blue"
    
);
    
this.updateProperties(); //Updat properties (only used on Delteria)
  
} else {
    
this._set("pve_exp"temp.curr_exp);
    
this.sendNotification("You gained" SPC  temp.amount SPC "experience!"1"expicon.png""");//Iphone Notification
  
}

__________________
~Delteria Support
~Playerworld Support
~PWA Chief
http://support.toonslab.com
[email protected]




Last edited by MysticalDragon; 08-16-2013 at 10:19 PM..
Reply With Quote
  #11  
Old 08-17-2013, 12:08 AM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
Quote:
The code is terrible
Well I mind as well give up.. lol

I really am trying. Fact of the matter is I am not a good programmer haha.

But I appreciate all the tips.

Perhaps I just need to re-learn GS2 from scratch, and broadin my knowledge of different functions.
Reply With Quote
  #12  
Old 08-17-2013, 12:11 AM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is a jewel in the roughTricxta is a jewel in the rough
Quote:
Originally Posted by i8bit View Post
Well I mind as well give up.. lol

I really am trying. Fact of the matter is I am not a good programmer haha.

But I appreciate all the tips.
Don't be disheartened, it's rare for someone to master a language straight off the bat without some kind of code review. Just stick with it.
__________________
Quote:
Originally Posted by Crono View Post
No look at it, Stefan is totally trolling Thor. Calling Classic a "playerworld" (something it's not supposed to be) is the ultimate subtle insult to a true fan.

It's genius.
Reply With Quote
  #13  
Old 08-17-2013, 02:10 PM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
For the baddie being hit, could I just use the default onwas.Hit() function as long as the player's ani is something_sword. Or trigger in manually?

Also, does the default onwas.Hit() work when a player hits a player?
Reply With Quote
Reply

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 09:03 AM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright (C) 1998-2008 Linux cyberjoueurs All Rights Reserved.