That guy with a beard
|
 |
Join Date: May 2004
Location: Ontario, Canada
Posts: 819
|
|
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.
|
|
|