Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
3 more questions
#1
1) Is there a way to delay an action? I know c++ has 'sleep(int)' but it doesnt seem to work for angel script.

2) How can you determine if an attack is coming at you. For example, when Julian's big ball is flying towards you or (henry's arrow, davis ball, bats, etc...)

3) Is there a way to determine the number of enemies on the map? Something like target.num?
Reply
Thanks given by:
#2
(12-18-2013, 12:17 AM)fr33xgames Wrote:  1) Is there a way to delay an action? I know c++ has 'sleep(int)' but it doesn't seem to work for angel script.
Yes, but you'll have to program it yourself, and it is not exactly pretty.
You can define global variables, but to prevent it from being shared between multiple objects you can define an array of size 400, and then only use the index that corresponds to the current object: (yeah this is wasteful as *bleep*)
    C++-Code:
array<int> timers(400,0);
array<int> events(400,0);

Then at the top of id you'd check whether timers[self.num] is bigger than zero. If it is then don't do anything but decrementing it by one. Once it reaches zero you'll carry out whatever action event dictates.
    C++-Code:
void id(){
    up(0); down(0); left(0); right(0); A(0); J(0); D(0);//reset actions
 
    if(timers[self.num]>0){
        if(--timers[self.num] == 0){
            switch(events[self.num]){
                case 1: {
                    //do something
                    break;
                }
                case 2: {
                    //do something else
                    break;
                }
            }
        }
 
        return;
    }
 
    //rest of id here
}

Then to start the timer you'd do something like:
    C++-Code:
timers[self.num] = 10;//wait 10 time units
events[self.num] = 1;//continue combo

Generally though I'd advice against using this stuff, as most of the time you can check the environment to find out whether you can do a combo (and where).

(12-18-2013, 12:17 AM)fr33xgames Wrote:  2) How can you determine if an attack is coming at you. For example, when Julian's big ball is flying towards you or (henry's arrow, davis ball, bats, etc...)
You can loop through the objects and find projectiles that are moving towards you (target.x_velocity).
You can do other checks to see if it will actually hit you but this is the general idea.

(12-18-2013, 12:17 AM)fr33xgames Wrote:  3) Is there a way to determine the number of enemies on the map? Something like target.num?
You'll have to loop through every object in the game and increment a counter whenever an enemy is found.
Something like this should work: (although it is untested)
    C++-Code:
int getEnemyCount(){
    int n = 0;
 
    for(int i = 0;i<400;++i){
        if(loadTarget(i) == 0 && target.team != self.team) ++n;
    }
 
    return n;
}
Age ratings for movies and games (and similar) have never been a good idea.
One can learn a lot from reinventing wheels.
An unsound argument is not the same as an invalid one.
volatile in C++ does not mean thread-safe.
Do not make APIs unnecessarily asynchronous.
Make C++ operator > again
Trump is an idiot.
Reply
Thanks given by: fr33xgames
#3
3 more :P

1) Is there a way to just make an action happen once? For example, if i want john to heal when his dim red health exists. I created an AI for it but he spams the heal skill till the dim red is gone.

2) Can someone show me a template AI of how self.xxx can approach target.xxx? And how to find the distance of an object id()?

3) How do you break out of an if statement with Angel Script? break; doesn't work.

Thanks!
Reply
Thanks given by:
#4
(12-18-2013, 08:53 PM)fr33xgames Wrote:  1) Is there a way to just make an action happen once? For example, if i want john to heal when his dim red health exists. I created an AI for it but he spams the heal skill till the dim red is gone.
My best bet would be to find out where ever the value that stores whether you are being healed is. It isprobably somewhere in an Object structure, which can be accessed by using game.objects[target.num]. There isn't any actual documentation for these files, but if you download the source the structures are stored in "sgame.h" (in pure C structures).
Just simply print out every single unkwn value and see if any of them changes when you activate self heal, and if you find an answer be sure to let me know so I can implement it in the actual DLL.
In a few days I'll be done with school (because christmas holidays wohooo), so if you haven't solved it by then, I'll try to look into it myself.

(12-18-2013, 08:53 PM)fr33xgames Wrote:  2) Can someone show me a template AI of how self.xxx can approach target.xxx? And how to find the distance of an object id()?
I think the id you are referencing is the id (as in identification) and not the id (as in the ego and the id (Freud)/basic ai function). The was this is usually done is by subtracting the position of one from the other (int distancex = target.x-self.x;). If the value is bigger than 0 then target is at the right side of self, and otherwise he is at the left side (or right on top of him :o). If you want the actual distance you'd use the abs() function (abs(distancex) or abs(target.x-self.x)). Same thing goes for distance is y and z direction. If you want the actual distance (as in a line that isn't necessarily parallel to any axis), then I think good old Pythagoras has you covered.
You should be able to do something like:
    C++-Code:
//something like this should work:
int distance = sqrt(xdistance*xdistance+zdistance*zdistance);
//and now that we are at it we may as well go 3d:
int distance = sqrt(xdistance*xdistance+ydistance*ydistance+zdistance*zdistance);
 
//also there could be some problems with doubles and ints, so if the above doesn't work try using double instead of int


I'm beginning to regret calling the AI function for id... probably shouldn't have done that :D
Also Pythagoras may or may not have actually been so good: http://www.youtube.com/watch?v=X1E7I7_r3Cw

(12-18-2013, 08:53 PM)fr33xgames Wrote:  3) How do you break out of an if statement with Angel Script? break; doesn't work.
You don't, just as you don't in C++ (and most other languages).
    C++-Code:
//if you want to do something like the following:
void id(){
    if(something){
        //some code
 
        if(somethingElse) break;
 
        //more code
    }
 
    //rest of code code
}
 
//then you can do this instead:
void id(){
    if(something){
        //some code
 
        if(!somethingElse){
            //more code
        }
    }
 
    //rest of code code
}
 
//or if you don't mind using a hack:
void id(){
    if(something) do {
        //some code
 
        if(somethingElse) break;
 
        //more code
    }while(false);
 
    //rest of code code
}

The reason for why it doesn't just work is the same as in C++. If it did you be unable to break a for/do/while/switch-statement from within an if-statement, as the language wouldn't know whether or not you want to break the if-statement or the loop.
Age ratings for movies and games (and similar) have never been a good idea.
One can learn a lot from reinventing wheels.
An unsound argument is not the same as an invalid one.
volatile in C++ does not mean thread-safe.
Do not make APIs unnecessarily asynchronous.
Make C++ operator > again
Trump is an idiot.
Reply
Thanks given by: fr33xgames
#5
You can still hack through that by conditioning the part of the code you want to break from with something you set before. Or, to not "waste" memory, a for loop which runs once with "continue;" instead of break.
[Image: signature.png]
A-Engine: A new beat em up game engine inspired by LF2. Coming soon

A-Engine Dev Blog - Update #8: Timeout

Reply
Thanks given by:
#6
So I looked into the data structures and found that healing is stored on is Object+0xe0, which corresponds to Object::unkwn7[3 through 6].
unkwn7 is stored as an array of bytes (char in C, and int8), and thus has to be converted to an integer, which can be done like this:
    C++-Code:
int heal = uint8(game.objects[self.num].unkwn7[3])+(uint8(game.objects[self.num].unkwn7[4])<<8)+(uint8(game.objects[self.num].unkwn7[5])<<16)+(uint8(game.objects[self.num].unkwn7[6])<<24);

When I get around to it I'll probably implement this into the DLL with the name heal (or something close to that at least), but for now the above code will work.
Age ratings for movies and games (and similar) have never been a good idea.
One can learn a lot from reinventing wheels.
An unsound argument is not the same as an invalid one.
volatile in C++ does not mean thread-safe.
Do not make APIs unnecessarily asynchronous.
Make C++ operator > again
Trump is an idiot.
Reply
Thanks given by: fr33xgames




Users browsing this thread: 1 Guest(s)