How to loop through Roblox studio to find all the humanoid and choose which is the closest one to chase? (For an Npc) - loops

I want to make a Npc that chases the nearest humanoids (Npc or Player) and I'm not sure how to loop through workspace to do that.
I tried experimenting with for loops but I'm a noob and I need help.
Ok i figured it out but One problem though, I use this script to check whether the npc is close and if its less than 3 to damage the other fighter... (fighter.HumanoidRootPart.Position.X. - closestEnemy.HumanoidRootPart.Position.X).Magnitude < 3...but when it runs and the npcs chase each other and they Touch each other it prints 55 or 30 even though they are legit touching each other.

Get the distance between you and the entity and check if its smaller. Its very simple math

Related

How to find a pointer in a game?

I am trying to find the offset/pointer for FIFA 22 timed finishing.
For example, if you double press "D" it will activate the timed finishing mechanic.
If you press them too quickly, too late or in the right time it will show like this "TOO EARLY" "TOO LATE" "EARLY" "GREAT TIMING"
I am trying to find this offset to modify, so everytime you shoot with timed finishing, so it will appear" GREAT TIMING" even if you don't do it right.
In FIFA 20, the offset is right here, in the attached photo.
Memory adress : 142BEC9A and you need to modify the C5 into C7, and all shots will be with green saying great timing.
But in FIFA 22, I cant' find it.
Can someone help me please, how do I know where to look? I mention I didn't found fifa 20 memory adress alone, I just got it from someone's cheat engine table.
How do I know where to find that memory adress for fifa 22 ?
https://www.youtube.com/watch?v=tk_F...channel=247CTF
Here it's a video so you can know how this game mechanic works, here in fifa 21, I had timed finishing hack activated, and as you can see, all shots were perfect.
How do I find that offset/pointer? Because it's not like searching for HP or Ammo in a shooter, to search 100, get some damage, and then do some rescan.
In the photo I posted, the adres 142BECD9A it's responsible 4for timed finishing.
The only thing I should do in that dump, is to modify the C5 into C7, and voila, all shots will be perfect.
My question is, how do you find this to modify in FIFA 22??
Ok, I don't personally own or play FIFA, but i've looked at the mechanic and can give you a few tips as to how to find it. But before that keep in mind that finding a code and knowing how to modify it is not a trivial task, like finding a value and changing it and may require you to have way more experience with cheat engine, game logic and assembly.
What you are trying to find is an instruction or instructions somewhere in the code which are responsible for figuring out how well you did the timing shot. There are many ways to get there, but my usual method is to start by finding a value very closely related to the instruction.
For example: If you are looking for an instruction that executes when the player gets damaged, you should probably find the player health, since it will likely be modified by that instruction.
With FIFA i noticed there is a bar that appears over the player's head when he does the timing shot in which bar there are lines moving towards the center. There is likely a value associated with the current value/position of that bar. Maybe when it's in the red zone the value is:10, and when it's in the green zone it might be 95-100.
To find it you can use the speedhack to slowdown your game and then search for unknown float/4 byte value and search for incremented.
Once you find the value play around with it and see if you can force it to be such that it always gives you the 'Great shot'
For changing the code:
With the value in hand you can use a 'find out what writes to that address' to find the code that modifies that value. If you can understand it and the instructions around it, you may be able to write a script that always sets it to a value that would cause it to give you 'Great timing'

How to do a parameterization in C?

I'm trying to find an algorithm for the game master mind with 4 numbers, where each number can be between 0 to 5, giving 1296 possibilities. With the first guess being 1,1,0,0
there are less options left.
I would like to know how to remove the options which are not suitable according to the first guess.
How to use an array(solutions) and array(current solutions)? Should I use parameterization for that?
Is there an algorithm in C to do that?
Thanks a lot for the help!
The simplest to implement is to simply loop trough all your elements and make the once that no longer work false. This might be the best idea here as looping trough 1300 elements is still quite fast however be aware that there is a faster solution in just finding which type of solutions are no longer available.
For mastermind there are multiple algorithms, see wikipedia, however for your first implementation I think they are too difficult.
You could start by using either
Thijser's idea (slightly better than brute-forcing all possibilities),
or try to emulate a human player: using that a white key-peg means correct color in wrong position and a black key-peg meaning correct color in correct position. You can write an easy recursion to take that info into account:
white-peg -> move the colors around ;
black-peg remove colors to find out which of the colors was the one that was correct-in-correct-pos.

Unity 2D/3D - Making a computer opponent (AI) for a match-3 game

I'm looking for guidance/advice on where to start to create a computer AI opponent for a match-3 game. This issue has been stumping me for years (literally), as I've not been able to figure it out. I've exhausted Google in finding this answer.
Sample match-3 games that have a computer opponent include: Puzzle Quest and Crystal Battle.
What programming methodologies are used in creating an AI opponent like this, and how can I apply it to Unity 2D scripting? Where/how can I start? I am mainly looking for a tutorial or something to get me started in the right direction. I realize this is not a quick an easy thing to do, but I would like to attempt it step by step so I can better understand things.
Thanks in advance!
There are two problems here:
Generating possible moves
Choosing the best move
If your board is reasonably small, you can simply brute-force both of them. For all positions in your grid check if you can move it up, down, left or right, and you have your move generator. (You should have checking for valid moves already implemented for a single-player version of the game).
Choosing the best move will be a bit more tricky, because you have to evaluate each move. Common way to do this is MiniMax method. General idea is that you build a tree of all possible moves in the next couple of turns and assign a score to each leaf. Then you reduce the tree so that parent node becomes max(leaves) if it is AIs turn to move, and min(leaves) if player moves. You end up with the score for your move at root.
Great resource for basic AI programming like this is Chess Programming Wiki (you won't need 90% of what is described there. Start with MiniMax and AlphaBeta algorithms).
On the other hand, for the simplest possible AI you can just pick a move at random, match-3 games are not the most demanding when it comes to planning your moves.
EDIT: As an afterthought, the following seems like a reasonable AI strategy for a match-3 game:
Assuming all the random gems added after each move cannot be matched in any way:
Pick a move that makes my opponent unable to move (has no child nodes).
If 1. is not possible, pick any move that guarantees me another move no matter which move my opponent picks (no child node is a leaf).
If 2. is not possible, pick random move.

How to use Random Walk to generate a dungeon map?

Ok so, I'm making a 2d dungeon crawler and I want to randomize a map for it. Right now it's look like I'm going to use a Random Walk algoritm for the path, combined with a Perlin Noise for different the underworld enviroments (currently only 1, as I'm using my own shitty looking tile set consisting of only 1 rook image and 1 grass image, but whatever :D)
So in figuring out how random walks work, it looks like I'm supposed to do something along the lines of this:
*create two-dimensional array sized after the map.
*pick random start postion and end postiont (I chose to put these on opposite sides of the map, randomly distributed across its side.
*follow these steps until you hit your finish point:
*pick a direction to 'walk' at random (only up, down, left, right because you otherwise I'm left with diagonal passes which the player can't walk through)
*'walk' that direction for a random amount of steps (I randomize amount of steps first then walk one by one for bound checking later, rather than just drawing a line).
*Everytime you 'walk' on a tile, turn that tile to 1 from originally 0.
*repeat above steps until you hit your finish point.
This leaves me with too much open ground, and too much closed ground. What I'm looking for is a path covered with rooms, sort of, but I want to control how big the 'rooms' become. I don't want 'rooms' to get too big, which some become. So I want the feeling of being in an enclosed space, but also I want to use as much of the map grid as possible.
Is a random walk not suited for this? I was thinking about making every step have a certain width to it, maybe that could work.
Or maybe I'm just implementing it wrong! I'm not a math genious sadly ;P

Pacman: how do the eyes find their way back to the monster hole?

I found a lot of references to the AI of the ghosts in Pacman, but none of them mentioned how the eyes find their way back to the central ghost hole after a ghost is eaten by Pacman.
In my implementation I implemented a simple but awful solution. I just hard coded on every corner which direction should be taken.
Are there any better/or the best solution? Maybe a generic one that works with different level designs?
Actually, I'd say your approach is a pretty awesome solution, with almost zero-run time cost compared to any sort of pathfinding.
If you need it to generalise to arbitrary maps, you could use any pathfinding algorithm - breadth-first search is simple to implement, for example - and use that to calculate which directions to encode at each of the corners, before the game is run.
EDIT (11th August 2010): I was just referred to a very detailed page on the Pacman system: The Pac-Man Dossier, and since I have the accepted answer here, I felt I should update it. The article doesn't seem to cover the act of returning to the monster house explicitly but it states that the direct pathfinding in Pac-Man is a case of the following:
continue moving towards the next intersection (although this is essentially a special case of 'when given a choice, choose the direction that doesn't involve reversing your direction, as seen in the next step);
at the intersection, look at the adjacent exit squares, except the one you just came from;
picking one which is nearest the goal. If more than one is equally near the goal, pick the first valid direction in this order: up, left, down, right.
I've solved this problem for generic levels that way: Before the level starts, I do some kind of "flood fill" from the monster hole; every tile of the maze that isn't a wall gets a number that says how far it is away from the hole. So when the eyes are on a tile with a distance of 68, they look which of the neighbouring tiles has a distance of 67; that's the way to go then.
For an alternative to more traditional pathfinding algorithms, you could take a look at the (appropriately-named!) Pac-Man Scent Antiobject pattern.
You could diffuse monster-hole-scent around the maze at startup and have the eyes follow it home.
Once the smell is set up, runtime cost is very low.
Edit: sadly the wikipedia article has been deleted, so WayBack Machine to the rescue...
You should take a look a pathfindings algorithm, like Dijsktra's Algorithm or A* algorithm. This is what your problem is : a graph/path problem.
Any simple solution that works is maintainable, reliable and performs well enough is a good solution. It sounds to me like you have already found a good solution ...
An path-finding solution is likely to be more complicated than your current solution, and hence more likely to require debugging. It will probably also be slower.
IMO, if it ain't broken, don't fix it.
EDIT
IMO, if the maze is fixed then your current solution is good / elegant code. Don't make the mistake of equating "good" or "elegant" with "clever". Simple code can also be "good" and "elegant".
If you have configurable maze levels, then maybe you should just do the pathfinding when you initially configure the mazes. Simplest would be to get the maze designer to do it by hand. I'd only bother automating this if you have a bazillion mazes ... or users can design them.
(Aside: if the routes are configured by hand, the maze designer could make a level more interesting by using suboptimal routes ... )
In the original Pacman the Ghost found the yellow pill eater by his "smell" he would leave a trace on the map, the ghost would wander around randomly until they found the smell, then they would simply follow the smell path which lead them directly to the player. Each time Pacman moved, the "smell values" would get decreased by 1.
Now, a simple way to reverse the whole process would be to have a "pyramid of ghost smell", which has its highest point at the center of the map, then the ghost just move in the direction of this smell.
Assuming you already have the logic required for chasing pacman why not reuse that? Just change the target. Seems like it would be a lot less work than trying to create a whole new routine using the exact same logic.
It's a pathfinding problem. For a popular algorithm, see http://wiki.gamedev.net/index.php/A*.
How about each square having a value of distance to the center? This way for each given square you can get values of immediate neighbor squares in all possible directions. You pick the square with the lowest value and move to that square.
Values would be pre-calculated using any available algorithm.
This was the best source that I could find on how it actually worked.
http://gameai.com/wiki/index.php?title=Pac-Man#Respawn
When the ghosts are killed, their disembodied eyes return to their starting location. This is simply accomplished by setting the ghost's target tile to that location. The navigation uses the same rules.
It actually makes sense. Maybe not the most efficient in the world but a pretty nice way to not have to worry about another state or anything along those lines you are just changing the target.
Side note: I did not realize how awesome those pac-man programmers were they basically made an entire message system in a very small space with very limited memory ... that is amazing.
I think your solution is right for the problem, simpler than that, is to make a new version more "realistic" where ghost eyes can go through walls =)
Here's an analog and pseudocode to ammoQ's flood fill idea.
queue q
enqueue q, ghost_origin
set visited
while q has squares
p <= dequeue q
for each square s adjacent to p
if ( s not in visited ) then
add s to visited
s.returndirection <= direction from s to p
enqueue q, s
end if
next
next
The idea is that it's a breadth-first search, so each time you encounter a new adjacent square s, the best path is through p. It's O(N) I do believe.
I don't know much on how you implemented your game but, you could do the following:
Determine the eyes location relative position to the gate. i.e. Is it left above? Right below?
Then move the eyes opposite one of the two directions (such as make it move left if it is right of the gate, and below the gate) and check if there are and walls preventing you from doing so.
If there are walls preventing you from doing so then make it move opposite the other direction (for example, if the coordinates of the eyes relative to the pin is right north and it was currently moving left but there is a wall in the way make it move south.
Remember to keep checking each time to move to keep checking where the eyes are in relative to the gate and check to see when there is no latitudinal coordinate. i.e. it is only above the gate.
In the case it is only above the gate move down if there is a wall, move either left or right and keep doing this number 1 - 4 until the eyes are in the den.
I've never seen a dead end in Pacman this code will not account for dead ends.
Also, I have included a solution to when the eyes would "wobble" between a wall that spans across the origin in my pseudocode.
Some pseudocode:
x = getRelativeOppositeLatitudinalCoord()
y
origX = x
while(eyesNotInPen())
x = getRelativeOppositeLatitudinalCoordofGate()
y = getRelativeOppositeLongitudinalCoordofGate()
if (getRelativeOppositeLatitudinalCoordofGate() == 0 && move(y) == false/*assume zero is neither left or right of the the gate and false means wall is in the way */)
while (move(y) == false)
move(origX)
x = getRelativeOppositeLatitudinalCoordofGate()
else if (move(x) == false) {
move(y)
endWhile
dtb23's suggestion of just picking a random direction at each corner, and eventually you'll find the monster-hole sounds horribly ineficient.
However you could make use of its inefficient return-to-home algorithm to make the game more fun by introducing more variation in the game difficulty. You'd do this by applying one of the above approaches such as your waypoints or the flood fill, but doing so non-deterministically. So at every corner, you could generate a random number to decide whether to take the optimal way, or a random direction.
As the player progresses levels, you reduce the likelihood that a random direction is taken. This would add another lever on the overall difficulty level in addition to the level speed, ghost speed, pill-eating pause (etc). You've got more time to relax while the ghosts are just harmless eyes, but that time becomes shorter and shorter as you progress.
Short answer, not very well. :) If you alter the Pac-man maze the eyes won't necessarily come back. Some of the hacks floating around have that problem. So it's dependent on having a cooperative maze.
I would propose that the ghost stores the path he has taken from the hole to the Pacman. So as soon as the ghost dies, he can follow this stored path in the reverse direction.
Knowing that pacman paths are non-random (ie, each specific level 0-255, inky, blinky, pinky, and clyde will work the exact same path for that level).
I would take this and then guess there are a few master paths that wraps around the entire
maze as a "return path" that an eyeball object takes pending where it is when pac man ate the ghost.
The ghosts in pacman follow more or less predictable patterns in terms of trying to match on X or Y first until the goal was met. I always assumed that this was exactly the same for eyes finding their way back.
Before the game begins save the nodes (intersections) in the map
When the monster dies take the point (coordinates) and find the
nearest node in your node list
Calculate all the paths beginning from that node to the hole
Take the shortest path by length
Add the length of the space between the point and the nearest node
Draw and move on the path
Enjoy!
My approach is a little memory intensive (from the perspective of Pacman era), but you only need to compute once and it works for any level design (including jumps).
Label Nodes Once
When you first load a level, label all the monster lair nodes 0 (representing the distance from the lair). Proceed outward labelling connected nodes 1, nodes connected to them 2, and so on, until all nodes are labelled. (note: this even works if the lair has multiple entrances)
I'm assuming you already have objects representing each node and connections to their neighbours. Pseudo code might look something like this:
public void fillMap(List<Node> nodes) { // call passing lairNodes
int i = 0;
while(nodes.count > 0) {
// Label with distance from lair
nodes.labelAll(i++);
// Find connected unlabelled nodes
nodes = nodes
.flatMap(n -> n.neighbours)
.filter(!n.isDistanceAssigned());
}
}
Eyes Move to Neighbour with Lowest Distance Label
Once all the nodes are labelled, routing the eyes is trivial... just pick the neighbouring node with the lowest distance label (note: if multiple nodes have equal distance, it doesn't matter which is picked). Pseudo code:
public Node moveEyes(final Node current) {
return current.neighbours.min((n1, n2) -> n1.distance - n2.distance);
}
Fully Labelled Example
For my PacMan game I made a somewhat "shortest multiple path home" algorithm which works for what ever labyrinth I provide it with (within my set of rules). It also works across them tunnels.
When the level is loaded, all the path home data in every crossroad is empty (default) and once the ghosts start to explore the labyrinth, them crossroad path home information keeps getting updated every time they run into a "new" crossroad or from a different path stumble again upon their known crossroad.
The original pac-man didn't use path-finding or fancy AI. It just made gamers believe there is more depth to it than it actually was, but in fact it was random. As stated in Artificial Intelligence for Games/Ian Millington, John Funge.
Not sure if it's true or not, but it makes a lot of sense to me. Honestly, I don't see these behaviors that people are talking about. Red/Blinky for ex is not following the player at all times, as they say. Nobody seems to be consistently following the player, on purpose. The chance that they will follow you looks random to me. And it's just very tempting to see behavior in randomness, especially when the chances of getting chased are very high, with 4 enemies and very limited turning options, in a small space. At least in its initial implementation, the game was extremely simple. Check out the book, it's in one of the first chapters.

Resources