Raised This Month: $51 Target: $400
 12% 

Solved Operation cycles to find enities


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TheVaskov
Member
Join Date: Sep 2021
Location: Russia
Old 04-23-2022 , 12:06   Operation cycles to find enities
Reply With Quote #1

I have an entity object that follows another object. By default, it chooses its owner
I want to run an entity search cycle in a radius by class. find_sphere_class()
it seems to me that I should use do / while-cycles or for-cycles
But I can find the correct syntax for using them. Send me some tutorial or help.

The task is as follows:
I create an NPC dog that runs after me.
If it finds another player from the enemy team in the radius, then dog should run to him and bite him to death.
Dead player will drop weaponbox, a dog takes it in her teeth and carries it to me.
but if a player is found again along the way, then dog drops the weaponbox and runs to attack.
______- update after message by Crazy


https://youtu.be/ERR6T7d_4Q0

thanks a lot !
Attached Files
File Type: sma Get Plugin or Get Source (dod_jagendog.sma - 47 views - 17.6 KB)

Last edited by TheVaskov; 04-26-2022 at 06:53.
TheVaskov is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 04-23-2022 , 19:47   Re: Operation cycles to find enities (for, do, while)
Reply With Quote #2

find_sphere_class will store the entities, if any, in the entlist array you pass in, similar to get_players.

Code:
CoolFunction(dog) {     new entityList[20]     const Float:radius = 300.0     new numberOfEntities = find_sphere_class(dog, "weaponbox", radius, entityList, sizeof entityList)     if (numberOfEntities > 0)     {         // Found that many weaponboxes near the dog         // If you need to get the closest one, sort the array         new data[1]         data[0] = dog         SortCustom1D(entityList, numberOfEntities, "SortByShortestDistance")         // Finally, get a single weaponbox to work with         new weaponbox = entityList[0]         // Do something here         DogMoveToTarget(dog, weaponbox)     } } public SortByShortestDistance(elem1, elem2, const array[], const data[], data_size) {     new dog = data[0]     new Float:distanceToFirstOne = entity_range(dog, elem1)     new Float:distanceToSecondOne = entity_range(dog, elem2)     if (distanceToFirstOne < distanceToSecondOne)     {         return -1     }     if (distanceToFirstOne > distanceToSecondOne)     {         return 1     }     return 0 }
__________________









Last edited by CrazY.; 04-23-2022 at 19:48.
CrazY. is offline
Reply



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 -4. The time now is 10:32.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode