Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-17-2011, 03:39 AM
skillmaster19 skillmaster19 is offline
Registered User
Join Date: Oct 2010
Posts: 392
skillmaster19 will become famous soon enough
Looking for feedback on smartbaddy BETA

I created a smartbaddy, using gbaddy3.0 to help me a little. This baddy is supposed to simulate how a player would fight. This baddy runs around the player and sometimes charges rather than charging 100% of the time, to create a challenge. In addition, the baddy has a 0.1-0.4 second delay before swinging its sword to show it is not a perfect computer that can hit right away. This script may be used for learning purposes, and feel free to upload it to your server to play with it. However, this script may not be used in the final content of a server. I might give away permission to this script if I get good feedback. I wouldn't use this on your server anyways, as I am sure it is not very efficient. Also, I had a bit of trouble with the triggering of the npc when hit, so if someone could tell me how to fix it, that will be appreciated.
PHP Code:
function onCreated()

{
   
this.outsidetargetmodes = {"targetingup","targetingdown","targetingleft","targetingright","charge"};
  
showcharacter();
  
  
swordimg "sword1.png";
  
this.hp 10;
  
this.movementSpeed 1;
swordpower 1;
  
setTimer(0.9);

}

function 
onTimeOut()
{
this.swordfreezetime--;
if (
players.size() > 0)
    
setTimer(0.1);
  else
    
setTimer(0);

if (
this.hp 0)
{


this.ani "walk";
  
this.closestplayer findnearestplayer(this.xthis.y);
  
this.plyr this.closestplayer;
if (!
getMode){
  if(
int(random(0,100)) <30)
  {
  
this.mode ="charge";
  }
  else
  {


 
temp.wheretoattack int(random(0,100));
 if(
temp.wheretoattack >=50 )
 {
 if(
this.dir || this.dir 2)
 {
 
this.mode "targetingright";
 }
 if(
this.dir || this.dir 3){
  
this.mode "targetingdown";
  }
  else if(
temp.wheretoattack <=49){
  if(
this.dir || this.dir 2){
  
this.mode "targetingleft";
  }
  if(
player.dir || player.dir 3){
  
this.mode "targetingup";
  }
  }
  }
  }
  }
this.toright this.plyr.x+5;
  
this.todown this.plyr.y+5;
  
this.toup this.plyr.-5;
  
this.toleft this.plyr.x-5;
 switch(
this.mode){


   case 
"targetingleft":
 
this.targetx this.toleft;
  
this.targetythis.plyr.y;
 break;

  case 
"targetingright":
  
this.targetx this.toright;
 
this.targety=this.plyr.y;
  break;

  case 
"targetingdown":
  
this.targety this.todown;
  
this.targetx this.plyr.x;
  break;
  case 
"targetingup":
   
this.targety this.toup;
  
this.targetx this.plyr.x;
  break;
  case 
"charge":
   
this.targetx this.plyr.x;
  
this.targety this.plyr.y;
  break;
}
  

  
this.distx = (this.targetx) - this.x;
  
this.disty this.targety this.y;
  
this.plyrdistx this.plyr.-this.x;
  
this.plyrdisty this.plyr.y-this.y;

  
this.len = (this.distx this.distx this.disty this.disty) ^ 0.5;
  
this.movex = (this.distx this.len);
  
this.fixed_x this.1.5;
    
this.fixed_y this.2;
  
this.movey = (this.disty this.len);

if (!
checkBlockedTile(this.movex+this.fixed_xthis.fixed_y+this.movey)) {
     if(
this.distx <20 && this.disty <20){
     
this.+= this.movex * (this.movementSpeed);
  
this.+= this.movey * (this.movementSpeed);
}
}
else 
this.ani "idle";


}

  if (
abs(this.distx) > abs(this.disty))
  {
    if (
this.distx 0)
      
this.dir 3;
    else
      
this.dir 1;
  }
  else
  {
    if (
this.disty 0)
      
this.dir 2;

    else
      
this.dir 0;

  }
 if(
this.swordfreezetime <=0)
        {
     if (
abs(this.plyrdistx) < && abs(this.plyrdisty) < 2){
   
this.scheduleevent(random(0.1,0.4),"hurtCharacter",0);
    }
     if (
abs(this.plyrdistx) < && abs(this.plyrdisty) < 4){
        
this.scheduleevent(random(0.1,0.4),"hurtCharacter",0);
    }
    }
    }
function 
getMode(){
if(
this.mode in this.outsidetargetmodes)
return 
true;
else
return 
false;
}



function 
checkBlockedTile(xValueyValue) {
  if (
onwall(xValueyValue) || onwater(xValueyValue))
    return 
true;
  else
    return 
false;
}
function 
onRespawn(ticker) {
      
this.hp 10;
      
this.ani "idle";
      
move(int(random(-0.9999,0.9999)),int(random(-0.9999,0.9999)), 0o);
      
this.chat this.hp;
    }

    function 
onhurtCharacter()
    {
   if (
abs(this.plyrdistx) < && abs(this.plyrdisty) < 4){
   if (
abs(this.plyrdistx) < && abs(this.plyrdisty) < 2){
   
this.mode ="waiting";
    
this.ani "sword";
    
this.scheduleevent(0.1,"StopSwinging",0);
    }
    }


    if(
this.plyr.hearts 0){
    
this.ani="idle";
    }
    }

    function 
onStopSwinging(){
     
this.ani "walk";
     
this.swordfreezetime 10//stops swinging for 10 timeouts
    
}


  function 
onPlayerEnters()
  {
    
onTimeOut();
  }

function 
onWa****(){
this.mode "waiting";
if(
this.hp >0){
    switch(
player.dir){

    case 
"2":
    if (!
checkBlockedTile(this.xthis.y+5)){
    
this.ythis.5;
    }
    break;





case 
"3":


if (!
checkBlockedTile(this.x+5this.y)) {
this.x+=5;
}
break;


    case 
"1":
   if (!
checkBlockedTile(this.x-5this.y)) {

      
this.this.5;
    }

    break;
    case 
"0":
   if (!
checkBlockedTile(this.xthis.y-5)) {
     
this.ythis.5;

    }
break;
}
}
    
this.hp--;

    if (
this.hp >= 0)
    {
      
this.chat this.hp;
    }

    if (
this.hp == 0)
    {
      
this.ani "dead";
    }

    if (
this.hp == 0)
    {
      
clientr.baddykills++;
      
player.chat "I have" SPC clientr.baddykills SPC "baddy kills";
      
this.scheduleevent(50"Respawn"0);
}


Last edited by skillmaster19; 05-18-2011 at 02:46 AM..
Reply With Quote
  #2  
Old 05-17-2011, 03:49 AM
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
PLEASE fix your styling.
__________________
Reply With Quote
  #3  
Old 05-17-2011, 03:51 AM
skillmaster19 skillmaster19 is offline
Registered User
Join Date: Oct 2010
Posts: 392
skillmaster19 will become famous soon enough
Quote:
Originally Posted by cbk1994 View Post
PLEASE fix your styling.
I used /style class, do you know of a better way besides manually doing it? I created this from an older script I made and didn't feel like redoing the whole styling.
Reply With Quote
  #4  
Old 05-17-2011, 03:54 AM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is just really niceTricxta is just really nice
use the tab key on your keyboard and quickly run through your script fixing it up, the script isnt that long... alternatively go into the level editor paste your script there and press the style button in the npc window like the way it use to be done before npc server scripting became the new BIG THING

also....
PHP Code:
    if(this.plyr.hearts 0){ 
    
this.ani="idle"
    } 
    } 
error??? also while = works dont do it!!! instead use this standard

= is for assigning values eg:this.i=4;
== is for comparing values eg:if (this.i==4)

might wanna fix this up

and....
PHP Code:
//#CLIENTSIDE 
function onWa****(){ 
switch(
player.dir){ 

case
"0"
triggeraction(player.x+1.5,player.y-2+1.5,"hit"); 

break; 


case
"1"
triggeraction(player.x-2+1.5,player.y+1.5,"hit"); 
break; 

case
"2"
triggeraction(player.x+1.5,player.y+2+1.5,"hit"); 
break; 

case
"3"
triggeraction(player.x+2+1.5,player.y+1.5,"hit"); 
break; 


learn how to use vecx() and vecy()

triggeraction(player.x+1.5+(vecx(playerdir)*2),pla yer.y+1.5,"hit");

also arent triggeractions ment to have a space for parameters being sent or is this different in gs2?
__________________
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
  #5  
Old 05-17-2011, 03:56 AM
skillmaster19 skillmaster19 is offline
Registered User
Join Date: Oct 2010
Posts: 392
skillmaster19 will become famous soon enough
Quote:
Originally Posted by cbk1994 View Post
PLEASE fix your styling.
fixed. Better?
Reply With Quote
  #6  
Old 05-17-2011, 04:00 AM
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
Quote:
Originally Posted by skillmaster19 View Post
fixed. Better?
I don't see any changes?
__________________
Reply With Quote
  #7  
Old 05-17-2011, 04:08 AM
skillmaster19 skillmaster19 is offline
Registered User
Join Date: Oct 2010
Posts: 392
skillmaster19 will become famous soon enough
Quote:
Originally Posted by cbk1994 View Post
I don't see any changes?
I styled it using a website that people have reccomended and fixed errors. I had a lot of errors because I took an old script I made when I had been scripting for less than a week and built off of it. and trixta yes the single equal sign (=) was an accident.
Reply With Quote
  #8  
Old 05-17-2011, 04:20 AM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is just really niceTricxta is just really nice
you've been scripting for less then a week yet you feel this is code gallery worthy? Uhmmm k bai
__________________
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
  #9  
Old 05-17-2011, 04:20 AM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
you could always try styling your code as you write it
__________________
Reply With Quote
  #10  
Old 05-17-2011, 04:21 AM
skillmaster19 skillmaster19 is offline
Registered User
Join Date: Oct 2010
Posts: 392
skillmaster19 will become famous soon enough
Quote:
Originally Posted by Tricxta View Post
you've been scripting for less then a week yet you feel this is code gallery worthy? Uhmmm k bai
No, I have been scripting for months. Read. I said the original script was made in my first week. I completely redid it today. btw fixed a huge glitch that caused the npc to target the same direction every time. Also nerfed the npcs reaction speed but improved its strategy.

Last edited by skillmaster19; 05-17-2011 at 04:50 AM..
Reply With Quote
  #11  
Old 05-17-2011, 05:39 AM
oo_jazz_oo oo_jazz_oo is offline
Jazz teh Awesome
oo_jazz_oo's Avatar
Join Date: Jul 2006
Location: California
Posts: 596
oo_jazz_oo is a jewel in the roughoo_jazz_oo is a jewel in the rough
Send a message via MSN to oo_jazz_oo
The problem with your styling is that there are huge line gaps, indentation is all wrong.

PHP Code:
function onCreated() {
  if (
player.hearts 5) {
    
this.chat "Hello!";
  }
}
function 
onPlayerTouchsme() {
  if (
player.ap 80) {
    
player.hearts += 1;
    if (
player.hearts >= 10) {
      
this.chat "Thats a lot of hearts!";
    }
  }

Beginning and ending curly braces are on their own line. Code inside said braces is indented more. Any code inside those braces is indented even more.
This makes reading scripts much easier.

Do not use the built in style function on rc, as it tends to muck things up, and it is much better practice to style as you go along, instead of coding a giant wall of text, then attempting to style afterwards.

Beginning braces should be on the same line as the function declaration, and ending braces should be on their own line.
__________________

Reply With Quote
  #12  
Old 05-17-2011, 09:55 AM
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 Tricxta View Post
you've been scripting for less then a week yet you feel this is code gallery worthy? Uhmmm k bai
Stop being an ass.
Reply With Quote
  #13  
Old 05-17-2011, 04:55 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
How to style your script properly with jsbeautifer.org

Copy-paste your code into the code text area.

Settings:
- Indent with 2 spaces
- Braces with control statement
- Un-check all Checkboxes

Click 'Beautify'

Result:

PHP Code:
// Scripted by Skill 

function onActionhit() {
  if (
this.hp 0) {
    switch (
player.dir) {
    case 
"2":
      if (!
checkBlockedTile(this.xthis.5)) {
        
this.this.5;
      }
      break;
    case 
"3":
      if (!
checkBlockedTile(this.5this.y)) {
        
this.+= 5;
      }
      break;
    case 
"1":
      if (!
checkBlockedTile(this.5this.y)) {
        
this.this.5;
      }
      break;
    case 
"0":
      if (!
checkBlockedTile(this.xthis.5)) {
        
this.this.5;
      }
      break;
    }
  }
  
this.hp--;
  if (
this.hp >= 0) {
    
this.chat this.hp;
  }
  if (
this.hp 0) {
    
this.ani "dead";
  }
  if (
this.hp == 0) {
    
clientr.baddykills++;
    
player.chat "I have"
    
SPC clientr.baddykills SPC "baddy kills";
    
this.scheduleevent(50"Respawn"0);
  }
}

function 
onCreated() {
  
this.outsidetargetmodes = {
    
"targetingup""targetingdown""targetingleft""targetingright""charge"
  
};
  
setshape(16464);
  
showcharacter();
  
swordimg "sword1.png";
  
this.hp 10;
  
this.movementSpeed 1;
  
swordpower 1;
  
setTimer(0.1);
}

function 
onTimeOut() {
  
this.swordfreezetime--;
  if (
players.size() > 0setTimer(0.1);
  else 
setTimer(0);
  if (
this.hp 0) {
    
this.ani "walk";
    
this.closestplayer findnearestplayer(this.xthis.y);
    
this.plyr this.closestplayer;
    if (!
getMode) {
      if (
int(random(0100)) < 30) {
        
this.mode "charge";
      } else {
        
temp.wheretoattack int(random(0100));
        if (
temp.wheretoattack >= 50) {
          if (
this.dir || this.dir 2) {
            
this.mode "targetingright";
          }
          if (
this.dir || this.dir 3) {
            
this.mode "targetingdown";
          }
          if (
temp.wheretoattack <= 49) {
            if (
this.dir || this.dir 2) {
              
this.mode "targetingleft";
            }
            if (
player.dir || player.dir 3) {
              
this.mode "targetingup";
            }
          }
        }
      }
    }
    if (
this.mode == "targetingleft") {
      
this.targetx this.toleft;
      
this.targety this.plyr.y;
    }
    if (
this.mode == "targetingright") {
      
this.targetx this.toright;
      
this.targety this.plyr.y;
    }
    if (
this.mode == "targetingdown") {
      
this.targety this.todown;
      
this.targetx this.plyr.x;
    }
    if (
this.mode == "targetingup") {
      
this.targety this.toup;
      
this.targetx this.plyr.x;
    }
    if (
this.mode == "charge") {
      
this.targetx this.plyr.x;
      
this.targety this.plyr.y;
    }
    
this.toright this.plyr.4;
    
this.todown this.plyr.4;
    
this.toup this.plyr.4;
    
this.toleft this.plyr.4;
    
this.distx = (this.targetx) - this.x;
    
this.disty this.targety this.y;
    
this.plyrdistx this.plyr.this.x;
    
this.plyrdisty this.plyr.this.y;
    
this.len = (this.distx this.distx this.disty this.disty) ^ 0.5;
    
this.movex = (this.distx this.len);
    
this.fixed_x this.1.5;
    
this.fixed_y this.2;
    
this.movey = (this.disty this.len);
    if (!
checkBlockedTile(this.movex this.fixed_xthis.fixed_y this.movey)) {
      if (
this.distx 20 && this.disty 20) {
        
this.+= this.movex * (this.movementSpeed);
        
this.+= this.movey * (this.movementSpeed);
      }
    } else 
this.ani "idle";
  }
  if (
abs(this.distx) > abs(this.disty)) {
    if (
this.distx 0this.dir 3;
    else 
this.dir 1;
  } else {
    if (
this.disty 0this.dir 2;
    else 
this.dir 0;
  }
  if (
this.swordfreezetime <= 0) {
    if (
abs(this.plyrdistx) < && abs(this.plyrdisty) < 3) {
      
this.scheduleevent(random(0.20.6), "hurtCharacter"0);
    }
    if (
abs(this.plyrdistx) < && abs(this.plyrdisty) < 4) {
      
this.scheduleevent(random(0.10.6), "hurtCharacter"0);
    }
  }

  function 
getMode() {
    if (
this.mode in this.outsidetargetmodes) return true;
    else return 
false;
  }

  function 
checkBlockedTile(xValueyValue) {
    if (
onwall(xValueyValue) || onwater(xValueyValue)) return true;
    else return 
false;
  }

  function 
onRespawn(ticker) {
    
this.hp 10;
    
this.ani "idle";
    
move(int(random(-0.99990.9999)), int(random(-0.99990.9999)), 0o);
    
this.chat this.hp;
  }

  function 
onhurtCharacter() {
    
this.mode "waiting";
    
this.ani "sword";
    
this.scheduleevent(0.1"StopSwinging"0);
  }
  if (
this.plyr.hearts 0) {
    
this.ani "idle";
  }
}

function 
onStopSwinging() {
  
this.ani "walk";
  
this.swordfreezetime 10//stops swinging for 10 timeouts 
}

function 
onPlayerEnters() {
  
onTimeOut();
}
//#CLIENTSIDE 

function onWa****() {
  
triggeraction(player.1.5 + (vecx(playerdir) * 2), player.1.5"hit");
}

function 
onCreated() {
  
setshape(16464);

When your code is styled properly, it's now possible to see that you have other functions nested in your timeout function.
Reply With Quote
  #14  
Old 05-18-2011, 02:33 AM
skillmaster19 skillmaster19 is offline
Registered User
Join Date: Oct 2010
Posts: 392
skillmaster19 will become famous soon enough
Many fixes! The baddy currently doesn't work on gmaps at the time, I had to remove this to make the hit detection better.
Reply With Quote
  #15  
Old 05-18-2011, 02:40 AM
Messiah Messiah is offline
Professional Rebel
Join Date: Mar 2011
Posts: 131
Messiah will become famous soon enough
Quote:
Originally Posted by Tricxta View Post
you've been scripting for less then a week yet you feel this is code gallery worthy? Uhmmm k bai
Who are you to judge others? Hes looking for feedback, not someone to tell him his code isn't "worthy" of posting on a goddamn forum.
Reply With Quote
  #16  
Old 05-18-2011, 11:08 PM
skillmaster19 skillmaster19 is offline
Registered User
Join Date: Oct 2010
Posts: 392
skillmaster19 will become famous soon enough
Fixes, and it wont let me edit my original post.
PHP Code:
function onCreated() {
  
this.outsidetargetmodes = {
    
"targetingup""targetingdown""targetingleft""targetingright""charge"
  
};
  
showcharacter();
  
swordimg "sword1.png";
  
this.hp 10;
  
this.movementSpeed 1;
  
swordpower 1;
  
setTimer(0.9);
}

function 
onTimeOut() {
  
this.resettarget++;
  if (
this.resettarget 30) {
    
this.mode "waiting";
    
this.resettarget 0;
  }
  
this.swordfreezetime--;
  if (
players.size() > 0setTimer(0.1);
  else 
setTimer(0);
  if (
this.hp 0) {
    
this.ani "walk";
    
this.closestplayer findnearestplayer(this.xthis.y);
    
this.plyr this.closestplayer;
    if (!
getMode) {
      if (
int(random(0100)) < 30) {
        
this.mode "charge";
      } else {
        
temp.wheretoattack int(random(0100));
        if (
temp.wheretoattack >= 50) {
          if (
this.dir || this.dir 2) {
            
this.mode "targetingright";
          }
          if (
this.dir || this.dir 3) {
            
this.mode "targetingdown";
          }
        }
        if (
temp.wheretoattack <= 49) {
          if (
this.dir || this.dir 2) {
            
this.mode "targetingleft";
          }
          if (
this.dir || this.dir 3) {
            
this.mode "targetingup";
          }
        }
      }
    }
    
this.toright this.plyr.5;
    
this.todown this.plyr.5;
    
this.toup this.plyr.5;
    
this.toleft this.plyr.5;
    switch (
this.mode) {
    case 
"targetingleft":
      
this.targetx this.toleft;
      
this.targety this.plyr.y;
      break;
    case 
"targetingright":
      
this.targetx this.toright;
      
this.targety this.plyr.y;
      break;
    case 
"targetingdown":
      
this.targety this.todown;
      
this.targetx this.plyr.x;
      break;
    case 
"targetingup":
      
this.targety this.toup;
      
this.targetx this.plyr.x;
      break;
    case 
"charge":
      
this.targetx this.plyr.x;
      
this.targety this.plyr.y;
      break;
    }
    
this.distx = (this.targetx) - this.x;
    
this.disty this.targety this.y;
    
this.plyrdistx this.plyr.this.x;
    
this.plyrdisty this.plyr.this.y;
    
this.len = (this.distx this.distx this.disty this.disty) ^ 0.5;
    
this.movex = (this.distx this.len);
    
this.fixed_x this.1.5;
    
this.fixed_y this.2;
    
this.movey = (this.disty this.len);
    if (!
checkBlockedTile(this.movex this.fixed_xthis.fixed_y this.movey)) {
      if (
this.distx 20 && this.disty 20) {
        
this.+= this.movex * (this.movementSpeed);
        
this.+= this.movey * (this.movementSpeed);
      }
    } else 
this.ani "idle";
  }
  if (
abs(this.distx) > abs(this.disty)) {
    if (
this.distx 0this.dir 3;
    else 
this.dir 1;
  } else {
    if (
this.disty 0this.dir 2;
    else 
this.dir 0;
  }
  if (
this.swordfreezetime <= 0) {
    if (
abs(this.plyrdistx) < && abs(this.plyrdisty) < 2) {
      
this.scheduleevent(random(0.10.4), "hurtCharacter"0);
    }
    if (
abs(this.plyrdistx) < && abs(this.plyrdisty) < 4) {
      
this.scheduleevent(random(0.10.4), "hurtCharacter"0);
    }
  }
}

function 
getMode() {
  if (
this.mode in this.outsidetargetmodes) return true;
  else return 
false;
}

function 
checkBlockedTile(xValueyValue) {
  if (
onwall(xValueyValue) || onwater(xValueyValue)) return true;
  else return 
false;
}

function 
onRespawn(ticker) {
  
this.hp 10;
  
this.ani "idle";
  
move(int(random(-0.99990.9999)), int(random(-0.99990.9999)), 0o);
  
this.chat this.hp;
}

function 
onhurtCharacter() {
  if (
abs(this.plyrdistx) < && abs(this.plyrdisty) < 4) {
    if (
abs(this.plyrdistx) < && abs(this.plyrdisty) < 2) {
      if (
abs(this.plyrdistx) > abs(this.plyrdisty)) {
        if (
this.plyrdistx 0this.dir 3;
        else 
this.dir 1;
      } else {
        if (
this.plyrdisty 0this.dir 2;
        else 
this.dir 0;
      }
      
this.mode "waiting";
      
this.ani "sword";
      
this.scheduleevent(0.1"StopSwinging"0);
    }
  }
  if (
this.plyr.hearts 0) {
    
this.ani "idle";
  }
}

function 
onStopSwinging() {
  
this.ani "walk";
  
this.swordfreezetime 10//stops swinging for 10 timeouts
}

function 
onPlayerEnters() {
  
onTimeOut();
}

function 
onWa****() {
  
this.mode "waiting";
  if (
this.hp 0) {
    switch (
player.dir) {
    case 
"2":
      if (!
checkBlockedTile(this.xthis.5)) {
        
this.this.5;
      }
      break;
    case 
"3":
      if (!
checkBlockedTile(this.5this.y)) {
        
this.+= 5;
      }
      break;
    case 
"1":
      if (!
checkBlockedTile(this.5this.y)) {
        
this.this.5;
      }
      break;
    case 
"0":
      if (!
checkBlockedTile(this.xthis.5)) {
        
this.this.5;
      }
      break;
    }
  }
  
this.hp--;
  if (
this.hp >= 0) {
    
this.chat this.hp;
  }
  if (
this.hp == 0) {
    
this.ani "dead";
  }
  if (
this.hp == 0) {
    
clientr.baddykills++;
    
player.chat "I have"
    
SPC clientr.baddykills SPC "baddy kills";
    
this.scheduleevent(50"Respawn"0);
  }


Last edited by skillmaster19; 05-18-2011 at 11:27 PM..
Reply With Quote
  #17  
Old 05-18-2011, 11:10 PM
Soala Soala is offline
Ideas on Fire
Soala's Avatar
Join Date: Jun 2007
Location: In my head
Posts: 3,208
Soala is a jewel in the roughSoala is a jewel in the rough
srry can't read
Reply With Quote
  #18  
Old 05-18-2011, 11:11 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Im not a scripter myself, and i don't know a lot about it. So tell me if i am wrong, but does the style of the script and the layout actually effect the script in any way in terms of its functionality?
__________________
Reply With Quote
  #19  
Old 05-18-2011, 11:29 PM
skillmaster19 skillmaster19 is offline
Registered User
Join Date: Oct 2010
Posts: 392
skillmaster19 will become famous soon enough
Quote:
Originally Posted by Emera View Post
Im not a scripter myself, and i don't know a lot about it. So tell me if i am wrong, but does the style of the script and the layout actually effect the script in any way in terms of its functionality?
No, but by making the script look organized, others(and yourself!) can understand the script better and find errors easier. An example of this is when I originally had an unorganized script, which fowlplay then styled, who discovered several functions were "nested" in another function.(that is bad)
Reply With Quote
  #20  
Old 05-18-2011, 11:47 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Ok thanks for that. I learn something new everyday.
__________________
Reply With Quote
  #21  
Old 05-20-2011, 12:38 AM
skillmaster19 skillmaster19 is offline
Registered User
Join Date: Oct 2010
Posts: 392
skillmaster19 will become famous soon enough
The baddy is now more efficient, by moving some things out of the timeout.I fixed many bugs causing it to keep charging, and it changes targets at the correct time now(when hit, when it hits, etc) I also fixed the styling
btw, how good or bad is this CPU time? 0.073447624 % npcs[2] (in level skills_sample_level.nw at pos (30.9, 6.1)) (skill_insidebaddy)
PHP Code:
function onCreated() {
  
showcharacter();
  
// change these to the attributes that you want
  
headimg "head10.gif";
  
bodyimg "body.png";
  
shieldimg "shield1.png";
  
swordimg "sword1.png";
  
this.maxhp 10;
  
this.movementSpeed 1;
  
colors[0] = "black"//skin color
  
colors[1] = "black"// coat color
  
colors[2] = "black"// sleeves color
  
colors[3] = "black"// shoes color
  
colors[4] = "black"// belt color
  //dont change past this point if you don't know what you are doing
  
this.outsidetargetmodes = {
    
"targetingup""targetingdown""targetingleft""targetingright""charge"
  
};
  
swordpower 1;
  
setTimer(0.1);
  
this.hp this.maxhp;
}

function 
onTimeOut() {
    if (!
getMode) {
    
getTarget();
  }
  
this.swordfreezetime--;
  if (
players.size() > 0setTimer(0.1);
  else 
setTimer(0);
  if (
this.hp 0) {
    
this.ani "walk";
    
this.closestplayer findnearestplayer(this.xthis.y);
    
this.plyr this.closestplayer;
    
this.toright this.plyr.6;
    
this.todown this.plyr.6;
    
this.toup this.plyr.6;
    
this.toleft this.plyr.6;
    switch (
this.mode) {
    case 
"targetingleft":
      
this.targetx this.toleft;
      
this.targety this.plyr.y;
      break;
    case 
"targetingright":
      
this.targetx this.toright;
      
this.targety this.plyr.y;
      break;
    case 
"targetingdown":
      
this.targety this.todown;
      
this.targetx this.plyr.x;
      break;
    case 
"targetingup":
      
this.targety this.toup;
      
this.targetx this.plyr.x;
      break;
    case 
"charge":
      
this.targetx this.plyr.x;
      
this.targety this.plyr.y;
      break;
    }
    
this.distx = (this.targetx) - this.x;
    
this.disty this.targety this.y;
    
this.plyrdistx this.plyr.this.x;
    
this.plyrdisty this.plyr.this.y;
    
this.len = (this.distx this.distx this.disty this.disty) ^ 0.5;
    
this.movex = (this.distx this.len);
    
this.fixed_x this.1.5;
    
this.fixed_y this.2;
    
this.movey = (this.disty this.len);
    if (!
checkBlockedTile(this.movex this.fixed_xthis.fixed_y this.movey)) {
      if (
this.distx 20 && this.disty 20) {
        
this.+= this.movex * (this.movementSpeed);
        
this.+= this.movey * (this.movementSpeed);
      }
    } else 
this.ani "idle";
  }
  if (
abs(this.distx) > abs(this.disty)) {
    if (
this.distx 0this.dir 3;
    else 
this.dir 1;
  } else {
    if (
this.disty 0this.dir 2;
    else 
this.dir 0;
  }
  if (
this.swordfreezetime <= 0) {
    if (
abs(this.plyrdistx) < && abs(this.plyrdisty) < 2) {
      
this.scheduleevent(random(0.10.4), "hurtCharacter"0);
    }
    if (
abs(this.plyrdistx) < && abs(this.plyrdisty) < 4) {
      
this.scheduleevent(random(0.10.4), "hurtCharacter"0);
    }
  }
}

function 
getMode() {
  if (
this.mode in this.outsidetargetmodes) return true;
  else return 
false;
}

function 
checkBlockedTile(xValueyValue) {
  if (
onwall(xValueyValue) || onwater(xValueyValue)) return true;
  else return 
false;
}

function 
onRespawn(ticker) {
  
this.hp this.maxhp;
  
this.ani "idle";
  
move(int(random(-0.99990.9999)), int(random(-0.99990.9999)), 0o);
  
this.chat this.hp;
}

function 
onhurtCharacter() {
  if (
abs(this.plyrdistx) < && abs(this.plyrdisty) < 4) {
    if (
abs(this.plyrdistx) < && abs(this.plyrdisty) < 2) {
      if (
abs(this.plyrdistx) > abs(this.plyrdisty)) {
        if (
this.plyrdistx 0this.dir 3;
        else 
this.dir 1;
      } else {
        if (
this.plyrdisty 0this.dir 2;
        else 
this.dir 0;
      }
      
this.swordfreezetime 10//stops swinging for 10 timeouts
      
this.mode "waiting";
      
this.ani "sword";
      
this.scheduleevent(0.3"StopSwinging"0);
    }
  }
  if (
this.plyr.hearts == 0) {
    
this.ani "idle";
  }
}

function 
onStopSwinging() {
  
this.ani "idle";
}

function 
onPlayerEnters() {
  
onTimeOut();
}

function 
getTarget() {
  if (
int(random(0100)) < 30) {
    
this.mode "charge";
  } else {
    
temp.wheretoattack int(random(0100));
    if (
temp.wheretoattack >= 50) {
      if (
this.dir || this.dir 2) {
        
this.mode "targetingright";
      }
      if (
this.dir || this.dir 3) {
        
this.mode "targetingdown";
      }
    }
    if (
temp.wheretoattack <= 49) {
      if (
this.dir || this.dir 2) {
        
this.mode "targetingleft";
      }
      if (
this.dir || this.dir 3) {
        
this.mode "targetingup";
      }
    }
  }
}

function 
onWa****() {
  
this.mode "waiting";
  if (
this.hp 0) {
    switch (
player.dir) {
    case 
"2":
      if (!
checkBlockedTile(this.xthis.5)) {
        
this.this.5;
      }
      break;
    case 
"3":
      if (!
checkBlockedTile(this.5this.y)) {
        
this.+= 5;
      }
      break;
    case 
"1":
      if (!
checkBlockedTile(this.5this.y)) {
        
this.this.5;
      }
      break;
    case 
"0":
      if (!
checkBlockedTile(this.xthis.5)) {
        
this.this.5;
      }
      break;
    }
  }
  
this.hp--;
  if (
this.hp >= 0) {
    
this.chat this.hp;
  }
  if (
this.hp == 0) {
    
this.ani "dead";
  }
  if (
this.hp == 0) {
    
clientr.baddykills++;
    
player.chat "I have"
    
SPC clientr.baddykills SPC "baddy kills";
    
this.scheduleevent(50"Respawn"0);
  }


Last edited by skillmaster19; 05-20-2011 at 12:51 AM..
Reply With Quote
  #22  
Old 05-20-2011, 12:57 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
-: if (!getMode) {
+: if (!getMode()) {

You're still using a 0.1 second timeout for a baddy and that is very troubling for something you plan to have a lot. Aim for 0.5 second minimum timeout.
Reply With Quote
  #23  
Old 05-20-2011, 01:04 AM
skillmaster19 skillmaster19 is offline
Registered User
Join Date: Oct 2010
Posts: 392
skillmaster19 will become famous soon enough
Quote:
Originally Posted by fowlplay4 View Post
-: if (!getMode) {
+: if (!getMode()) {

You're still using a 0.1 second timeout for a baddy and that is very troubling for something you plan to have a lot. Aim for 0.5 second minimum timeout.
How else am I supposed to update the position frequently? the low timeouts are necessary to have the baddy fight well.
Reply With Quote
  #24  
Old 05-20-2011, 01:30 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by skillmaster19 View Post
How else am I supposed to update the position frequently? the low timeouts are necessary to have the baddy fight well.
With move(). Sure you can do it your way and use interpolation on the client-side to smoothen out the movement but that's a bit more complicated.

I made a post about this similar situation a while back:
http://forums.graalonline.com/forums...25&postcount=5
Reply With Quote
  #25  
Old 05-20-2011, 01:53 AM
skillmaster19 skillmaster19 is offline
Registered User
Join Date: Oct 2010
Posts: 392
skillmaster19 will become famous soon enough
Quote:
Originally Posted by fowlplay4 View Post
With move(). Sure you can do it your way and use interpolation on the client-side to smoothen out the movement but that's a bit more complicated.

I made a post about this similar situation a while back:
http://forums.graalonline.com/forums...25&postcount=5
Thanks, but the point of this baddy was to be action based, and keep the baddies response times amazing. If I lowered the timeout to 1 second, the whole targeting system would be pointless, because the player is constantly moving. I logged onto zodiac to find out while the baddies move very smoothly, but if you run from them they take about a second to respond, same as when you enter their aggro area. of course this kind of adaptation has to be done to Zodiac because it has hundreds of monsters being fought at once,but I plan to just use this baddy for part of a quest that will occasionally be played by new players.(there won't be hundreds of them being actively fought, that would crash the server)
Reply With Quote
  #26  
Old 06-09-2011, 01:57 AM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
The timeout value is quite intensive. I could only think that maybe you could leverage some of it clientside i.e. place the intended target in an attr[] serverside and have it move at a slower rate whilst smoothing out the movement clientside.
Reply With Quote
  #27  
Old 09-07-2011, 06:06 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
0.1 is fine as long as the baddy is only moving when there are players around.
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 07:30 PM.


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