Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-02-2007, 08:00 PM
PrinceOfKenshin PrinceOfKenshin is offline
That guy with a beard
PrinceOfKenshin's Avatar
Join Date: May 2004
Location: Ontario, Canada
Posts: 819
PrinceOfKenshin has a spectacular aura aboutPrinceOfKenshin has a spectacular aura about
Help?

Ok how would i script an npc to attack the player with a gun. Also the bodies are custom so there are different parameters. I'm just not 100% sure how to get it to work. What i have is so that it comes out with a random name and walks around
PHP Code:

if (created) {
  
showcharacter;



  
setstring this.namearray,Billy,John,James,Bob,Roger,Tiggus,Homer,Trey,Al,Tiggums,James,John,Robert,Michael,William,David,Richard,Charles,Joseph,Thomas,Christopher,Daniel,Paul,Mark,Donald,George,Kenneth,Steven,Edward,Brian,Ronald,Anthony,Kevin,Jason,Gary,Timothy,Jose,Larry,Jeffery,Frank,Scott,Eric,Stephen,Andrew,Raymond,Gregory,Joshua,Jerry,Dennis,Walter,Patrick,Peter,Harold,Douglas,Henry,Carl,Arthur,Ryan,Roger,Joe,Juan,Jack,Albert,Jonathan,Justin,Gerald,Keith,Samuel,Willie,Ralph,Lawrence,Nicholas,Roy,Benjamin,Bruce,Brandon,Adam,Harry,Fred,Wayne,Billy,Steve,Louis,Jeremy,Aaron,Randy,Howard,Eugene,Carlos,Russell,Bobby,Victor,Martin,Ernest,Phillip,Todd,Jesse,Craig,Alan,Shawn,Clarence,Sean,Philip,Chris,Johnny,Earl,,Jimmy,Antonio,Danny,Bryan,Tony,Luis,Mike,Standley,Leonard,Nathan,Dale,Manuel,Rodney,Curtis,Norman,Allen,Marvin,Vincent,Glenn,Jeffery,Travis,Jeff,Chad,Jacob,Lee,Melvin,Alfred,Kyle,Francis,Bradley,Herbert,Frederick,Bubba,Cletus,Jethro;
  
setstring this.femalenamearray,Nicky,Laura,Vicky,Abigail,Tina,Kara,Ashley,Ronda;
  
setstring this.hatarray,at_newhat-glasses2.png,at_newhat-glasses1.png,at_newhat-glasses3.png,at_newhat-techglass.png,at_newhat-bk-headband.png,at_newhat-mafia1.png,at_newhat-leone3.png,at_newhat-mafialeone2.gif,at_newhat-ecap.png,at_newhat-cap.png,at_newhat-as.png;
  
setstring this.shirtarray,at_leather-jacket1.png,shirt,at_shirt-black1.png,at_shirt-white1.png,at_shirt-suit1.png,at_shirt-suit2.png,at_shirt-suitvest.png,at_west-black1.png,at_stylish-shirt-female.png,at_suit-grayblue2.png,at_shirt-red1.png;
  
setstring this.pantarray,at_pants-cargo4.png,at_pants-cargo3.png,at_pants-cargo2.png,at_pants-grayblue1.png,at_pants-cargo5.png,at_pants-cargo1.png;
  
timeout = .1;
  
randomspot();
  
showchar();
}



function 
showchar() {

  
this.head = int(random(0,20));
  if (
this.head in {10,12,18,19}) this.head = int(random(0,21));
  if (
this.head in {13,15}) set this.female;
  
setcharprop #3,at_newhead#v(this.head).png;
  
setstring this.pant,#R(#s(this.pantarray));
  
setstring this.shirt,#R(#s(this.shirtarray));
  
setstring this.hat,#R(#s(this.hatarray));
  
setcharani at_newidle,#s(this.pant),#s(this.shirt),#s(this.hat);
  
if (!this.female) setstring this.name,#R(#s(this.namearray)); else setstring this.name,#R(#s(this.femalenamearray));

}


//triggeraction x,y,c

if (timeout) {

  
showimg 55,@Arial@bc@#s(this.name),x+1.5,y+3.4;
  
changeimgzoom 55,.7; changeimgvis 55,2;
  
this.randx = int(random(0,60));
  
this.randy = int(random(0,60));
  if (
tiles[this.randx,this.randy] in this.tiles && (this.bob == 1)) {
    
this.wx = this.randx;
    
this.wy = this.randy;
    
warpme();
  }



  
timeout = .1;
}



function 
randomspot() {

  
dir = int(random(0,4));
  
this.tiles = {1092,1093,1094,1095,1108,1109,1110,1111,1124,1125,1126,1127,1140,1141,1142,1143};
  
this.bob = 1;

}
function 
warpme() {
  
x = this.wx - 1.5;
  
y = this.wy - 2;
  
this.bob = 0;
  
this.spotty = 0;
}






if (
created) {
  
this.runcounter = int(random(10,40));
  
this.speed = .6;
  
timeout = .1;
  
this.walkmode = 1;

}


if (
timeout) { // WALKING
  
this.walkpause = int(random(1,100));
  
this.tiles = {1092,1093,1094,1095,1108,1109,1110,1111,1124,1125,1126,1127,1140,1141,1142,1143};
  
setcharani at_newwalk,#s(this.pant),#s(this.shirt),#s(this.hat);
  
newx = x + vecx(dir)*this.speed;
  
newy = y + vecy(dir)*this.speed;
  
this.runcounter--;
  if (
this.walkpause in |70,100|) this.walk = 1;
  if (
this.walk == 1) {
    if (
this.sleeper == 0 && this.walkmode==1) { // RANDOM
      
if (this.runcounter>0) {
        
//      testx = newx + 1.5 + vecx(dir);// && (
        //    testy = newy + 2 + vecy(dir);

        
testx = newx+23/16+2*vecx(dir);
        
testy = newy+31/16+2*vecy(dir);

        if (!
tiles[testx,testy] in this.tiles || onwall(testx,testy)) {
          
dir = (dir+2)%4;//
          // this.runcounter = int(random(10,40));
        
} else {
          
x = newx;
          
y = newy;
        }
      } else {
        
this.runcounter = int(random(10,40));
        
dir = (dir+1+int(random(0,2))*2)%4;
      }
    }
  }else 
setcharani at_newidle,#s(this.pant),#s(this.shirt),#s(this.hat);
  
if (this.sleeper > 0) this.sleeper -=.1;
  if (
this.walk == 1 && check == 0) {
    
check = 1;
    
this.timee = int(random(1,5));
  }
  if (
this.timee > 0) {
    
this.timee -= .1;
    if (
this.timee == 0) this.walk = 0;
  }
  
timeout = .1;
}



if (
actiondoublemouse) this.sleeper = 4;





//#CLIENTSIDE
if (mousedown && rightmousebutton) setplayerprop #c,#v(tiles[mousex,mousey]);
if (created) {
  
setstring this.chat,Howdy.,Go away!,Hiya!;
  
timeout = .05;
  
this.show = 0;
  
this.clicked = 0;

  
setstring this.menuops,Talk,Buy;
}
//mousex in |x,x + 2| && mousey in |y - 1,y+3


if (mousedown && strequals(#p(0),double)) {
  
if (mousex in |x - .5,x+2.5| && mousey in |y - 1.5,y + 3|) {
    if (
this.dist < 15) {

      
this.show = abs(this.show - 1);
    }else 
addstring client.message, You can't talk to them from that far away..;
  }
}



if (timeout) {
  this.dist = ((playerx-x)^2+(playery-y)^2)^.5;


  if (this.show == 1 && this.dist > 15) this.show = 0;
  if (this.show == 1) {
    showimg 10,at_talkmenu.gif,x + 3.5, y + .5;
    this.x = x + 4;
    this.y = y + .9;
    for (g = 0;g < strlen(#s(this.menuops));g ++) {
      showtext 11 + g,this.x, this.y + (g / 1.5),,,#I(this.menuops,g);
      changeimgvis 11 + g,3;
      changeimgzoom 11 + g,.7;
    }
  }else hideimgs 10,15;


  if (this.time == 1) {
    this.timer +=.05;
    if (this.timer == 4.5) {
      hideimg 20;
      this.time = 0;
      this.timer = 0;
    }
  }



  timeout = .05;
}

if (mousedown && leftmousebutton) {

  if (mousex in |this.x + ,this.x + 2| && mousey in |this.y + .1,this.y + .7|) this.clicked = 1;
  elseif (mousex in |this.x,this.x + 2| && mousey in |this.y + .74,this.y + 1.43|) this.clicked = 2; else this.clicked = 0;

  if (mousex in |this.x + 4.4,this.x + 5.5| && mousey in |this.y - .25, this.y + .75|) this.show = 0;


  if (this.clicked == 2) {buy();}
  if (this.clicked == 1) {talk();}

}



function buy() {
  showtext 20,x+1.5,y-1.5,Arial,bc,I'
m not selling anything!;
  
changeimgzoom 20,.7;
  
this.time = 1;
  
this.show = 0;
  
dir = getdir((playerx - x),(playery - y));
}

function 
talk() {
  
showtext 20,x+1.5,y-1.5,Arial,bc,#R(#s(this.chat));
  
changeimgzoom 20,.7;
  
this.time = 1;
  
this.timer = 0;
  
this.show = 0;
  
dir = getdir((playerx - x),(playery - y));

} 
__________________


Quote:
Game Master (Server): Greetings PrinceOfKenshin, there are new posts on the forums that demand your urgent attention! God speed, the fate of the world is in your hands. If you fail, middle earth will forever be in the darkness and your children will be enslaved by McKain.
Reply With Quote
  #2  
Old 06-03-2007, 12:12 AM
PrinceOfKenshin PrinceOfKenshin is offline
That guy with a beard
PrinceOfKenshin's Avatar
Join Date: May 2004
Location: Ontario, Canada
Posts: 819
PrinceOfKenshin has a spectacular aura aboutPrinceOfKenshin has a spectacular aura about
Anyone?
__________________


Quote:
Game Master (Server): Greetings PrinceOfKenshin, there are new posts on the forums that demand your urgent attention! God speed, the fate of the world is in your hands. If you fail, middle earth will forever be in the darkness and your children will be enslaved by McKain.
Reply With Quote
  #3  
Old 06-03-2007, 12:51 AM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
You've used if (created) { two times on the serverside :o

Dunno if that helps..
Oh, I also think this wouldn't work so well on a gs2 server,
some vars in gs1 isn't default as in gs2 (this.chat for example)
__________________
Reply With Quote
  #4  
Old 06-04-2007, 11:55 PM
PrinceOfKenshin PrinceOfKenshin is offline
That guy with a beard
PrinceOfKenshin's Avatar
Join Date: May 2004
Location: Ontario, Canada
Posts: 819
PrinceOfKenshin has a spectacular aura aboutPrinceOfKenshin has a spectacular aura about
Quote:
Originally Posted by Chompy View Post
You've used if (created) { two times on the serverside :o

Dunno if that helps..
Oh, I also think this wouldn't work so well on a gs2 server,
some vars in gs1 isn't default as in gs2 (this.chat for example)
Well i looked at Gambets baddy system and tried to change it to fit me. But because i have a custom bodies its different. And i'm having trouble.
__________________


Quote:
Game Master (Server): Greetings PrinceOfKenshin, there are new posts on the forums that demand your urgent attention! God speed, the fate of the world is in your hands. If you fail, middle earth will forever be in the darkness and your children will be enslaved by McKain.
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 04:08 AM.


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