00:00
00:00
Newgrounds Background Image Theme

Zpredojev just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Rpg Ai Help! 2006-08-08 11:42:22


I'm currently making an RPG game and I relly need help on making enimies who will randomly move around but when they get a certain distace close to you they attack you with a random attack. Plz help!

Response to Rpg Ai Help! 2006-08-08 11:52:44


At 8/8/06 11:42 AM, narutofan02472 wrote: I'm currently making an RPG game and I relly need help on making enimies who will randomly move around but when they get a certain distace close to you they attack you with a random attack. Plz help!

You know you're basically asking us to make a whole game for you ! ill give you some code to work off (a random movement script) but i'm not gona make your whole goddamn game, just learn actionscript yourself.

onClipEvent (load) {
function getXY() {
myX=random(550), myY=random(400);
speedX=(_x-myX)/200, speedY=(_y-myY)/200;
}
setInterval(getXY, 2000);
getXY();
}
onClipEvent (enterFrame) {
_x += speedX, _y += speedY;
if (_x>=550 || _x<=0) {
speedX = -speedX;
}
if (_y>=400 || _y<=0) {
speedY = -speedY;
}
}

Response to Rpg Ai Help! 2006-08-08 11:52:47


This is really easy. You should be able to do this by yourself.

Assuming that this is tile based with square tiles...
function moveRandom() {
switch(Math.floor(Math.random()*4)) {
case 0:
//move up
break;
case 1:
//move left
break;
case 2:
//move down
break;
case 3:
//move right
break;
default:
throw new Error("Should never be reached.");
break;
}
//If occupies same space as player
//Make random attack using Math.floor(Math.random()*numberOfDifferent
Attacks)
}

And call that function for each enemy whenever they need it.

And next time, please give us a better description of your game's mechanics before asking for code.

Response to Rpg Ai Help! 2006-08-08 11:59:59


At 8/8/06 11:52 AM, Fat_Lifeguard wrote: This is really easy. You should be able to do this by yourself.

Assuming that this is tile based with square tiles...
function moveRandom() {
switch(Math.floor(Math.random()*4)) {
case 0:
//move up
break;
case 1:
//move left
break;
case 2:
//move down
break;
case 3:
//move right
break;
default:
throw new Error("Should never be reached.");
break;
}
//If occupies same space as player
//Make random attack using Math.floor(Math.random()*numberOfDifferent
Attacks)
}

wtf dude that wont help him at all, just saying //move left. He's gona copy and paste that see it dosent work and not bother with it, your just gona put him off actionscript for life putting that gobeldy gook in his face.

Response to Rpg Ai Help! 2006-08-08 14:05:56


uhh.. actually i'm not that clueless about actionscrip and i can tell that fat lifeguard's code is practically all comments, i know how to measure distance but im more interested in loading random frames.

Response to Rpg Ai Help! 2006-08-08 14:31:35


At 8/8/06 02:05 PM, narutofan02472 wrote: uhh.. actually i'm not that clueless about actionscrip and i can tell that fat lifeguard's code is practically all comments, i know how to measure distance but im more interested in loading random frames.

It's hard to give people code that's definitely going to work if you don't know much about the game mechanics.

Anyway, to stop at random frames:

gotoAndStop(Math.floor(Math.random()*(rang
e+1))+min)

range being the spread of the frames (i.e. the range between 6 and 10 is 10-6, or 4) and min being the lower limit (in the previous example, 6).

Response to Rpg Ai Help! 2006-08-08 14:58:18


At 8/8/06 11:52 AM, Fat_Lifeguard wrote: throw new Error("Should never be reached.");

please do not teach people to throw errors if you arent going to set up a try and catch first.
that is not only terrible coding habits, but you are making things complicated for new ASers.


BBS Signature

Response to Rpg Ai Help! 2006-08-08 15:02:26


At 8/8/06 02:58 PM, authorblues wrote: that is not only terrible coding habits, but you are making things complicated for new ASers.

Explain, AB, explain. What is throw new error?


BBS Signature

Response to Rpg Ai Help! 2006-08-08 15:04:26


At 8/8/06 03:02 PM, -Toast- wrote:
At 8/8/06 02:58 PM, authorblues wrote: that is not only terrible coding habits, but you are making things complicated for new ASers.
Explain, AB, explain. What is throw new error?

I've never heared of it myself, but it seems to be one of them things you dont need and you can just do it some other way, or else i'd have heard about it i guess. Am i right?

Response to Rpg Ai Help! 2006-08-08 15:10:41


At 8/8/06 03:04 PM, -reelbigcheese- wrote:
At 8/8/06 03:02 PM, -Toast- wrote: Explain, AB, explain. What is throw new error?
I've never heared of it myself, but it seems to be one of them things you dont need and you can just do it some other way, or else i'd have heard about it i guess. Am i right?

its not unnecessary, but generally speaking, a person will never use it.
its only implimented to create an easier way to handle user-thrown errors

AS: Try and Catch by me


BBS Signature

Response to Rpg Ai Help! 2006-08-08 15:18:30


At 8/8/06 03:10 PM, authorblues wrote: AS: Try and Catch by me

Didn't get it :P. What is it used for?


BBS Signature

Response to Rpg Ai Help! 2006-08-08 15:23:13


At 8/8/06 03:18 PM, -Toast- wrote:
At 8/8/06 03:10 PM, authorblues wrote: AS: Try and Catch by me
Didn't get it :P. What is it used for?

I think I got it up to the vit where I got bored and stopped reading because the next bit of code looked long and scary (about halfway through). It's a method for error handling... or something?


BBS Signature