Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[New G2O][Shared] OOP Area Manager
#1
*Introduction:

NOTE! This script requires ONE TIMER to work

Info: You can support development of this code. Report me every bug below. I'll try to fix it.
NOTE! If you want to report a bug, make sure, that this isn't your fault!

I was thinking about merging my two scripts: area-manager with circle-manager, and i make some changes based on circle script.
From now on there is one script, and inside of it there are 3 classes, first is BaseArea, which is used to inherit some repeated things,
the other two are: Area which is working pretty similar to area-manager script (you can create area with any shape you want),
and the last one is Circle which is used to create and manage 2d circles or 3d cylinders.
Also, if you read some of my code, you can make your own class by extending the BaseArea class.
Older script topics will be removed from script section by the end of this year, so if you are using those two, make a copy!
I recommend you to use this version, because it's better and you can simply add something new.

*Video presentations:

presentation #1

presentation #2

Download

*Classes informations:



* class Area:


class constructor Area(table arguments)
{
// required constructor values

array pos = [{int or float x = value, int or float z = value}], // In this line is only showed one point, but area is made of more than one.

// optional constructor values

table y = {int or float min = value, int or float max = value}

string world = value, // if you don't give any value, area world will be equal to default server world from config.xml
}



*List of attributes:

NOTE! Informations about access to attributes are only recommendation to use them in specific way.
You always have full access to attributes.



readonly bool Area.isIn // property equal true, when player is in area
readonly array Area.polyX
readonly array Area.polyZ
fullaccess string Area.world

// Optional attributes for 3d areas (they will be null for 2d areas)

fullaccess null or table Area.polyY //{int or float min = value, int or float max = value}



*List of methods:


void Area.destroy() //Destroying object


*List of callbacks:


// Callback is null, when function isn't defined!

null or void Area.onEnter([[pid]])
null or void Area.onExit([[pid]])


*Examples:



*Object creation/deletion:

Squirrel Script
  1. // area (triangle) creation
  2. local area = Area({
  3. pos =
  4. [
  5. {x = -150, z = -200},
  6. {x = 425, z = 100},
  7. {x = -75, z = 600}
  8. ]
  9.  
  10. // min and max height example
  11. // y = {min = -500, max = 500}
  12.  
  13. world = "NEWWORLD\\NEWWORLD.ZEN" // slashes direction are very important!
  14. })
  15.  
  16. // removing object references (deletion)
  17. area = area.destroy()




*Reading object attribute:

Squirrel Script
  1. local area = Area({
  2. pos =
  3. [
  4. {x = -150, z = -200},
  5. {x = 425, z = 100},
  6. {x = -75, z = 600}
  7. ]
  8.  
  9. world = "NEWWORLD\\NEWWORLD.ZEN"
  10. })
  11.  
  12. print(area.world)




*Defining object callbacks:

Squirrel Script
  1. local area = Area({
  2. pos =
  3. [
  4. {x = -150, z = -200},
  5. {x = 425, z = 100},
  6. {x = -75, z = 600}
  7. ]
  8.  
  9. world = "NEWWORLD\\NEWWORLD.ZEN"
  10. })
  11.  
  12. // client callbacks
  13. area.onEnter = function()
  14. {
  15. print("You have entered into triangle area!")
  16. }
  17.  
  18. area.onExit = function()
  19. {
  20. print("You have exit from triangle area")
  21. }
  22.  
  23. // server callbacks
  24. area.onEnter = function(pid)
  25. {
  26. print(pid + " have entered into triangle area!")
  27. }
  28.  
  29. area.onExit = function(pid)
  30. {
  31. print(pid + " have exit from triangle area")
  32. }




* class Circle:


class constructor Circle(table arguments)
{
// required constructor values

int or float x = value,
int or float z = value,

// optional constructor values

table y = {int or float min = value, int or float max = value}

string world = value, // if you don't give any value, area world will be equal to default server world from config.xml

int radius = value,
int verticesCount = value,
}


*List of attributes:

NOTE! Informations about access to attributes are only recommendation to use them in specific way.
You always have full access to attributes.



readonly bool Circle.isIn // property equal true, when player is in area
readonly int or float Circle.x
readonly int or float Circle.z
readonly int Circle.radius // default value is equal to 500
readonly int Circle.verticesCount // default value is equal to 0 (this means, that you're working with the real circle, without points)
readonly array Circle.polyX
readonly array Circle.polyZ
fullaccess string Circle.world

// Optional attributes for 3d cylinders (they will be null for 2d circles)

fullaccess null or table Circle.polyY //{int or float min = value, int or float max = value}


*List of methods:


void Circle.setRadius(int radius) //Changing circle radius/size
void Circle.setPosition(int x, table or null y, int z) //Changing object position
void Circle.setVerticesCount(int vertex) //Changing circle amount of points, if you set 0, you will be working with the real circle (without points)
void Circle.destroy() //Destroying object


*List of callbacks:


// Callback is null, when function isn't defined!

null or void Circle.onEnter([[pid]])
null or void Circle.onExit([[pid]])


*Examples:



*Object creation/deletion:

Squirrel Script
  1. // 2d circle creation
  2. circle <- Circle({x = 0, z = 0, radius = 500})
  3.  
  4. // 3d cylinder creation
  5. circle <- Circle({x = 0, y = {min = -200, max = 600}, z = 0, radius = 500})
  6.  
  7. // removing object references (deletion)
  8. circle = circle.destroy()



*Reading object attribute:

Squirrel Script
  1. circle <- Circle({x = 0, z = 0, y = {min = -100, max = 250}})
  2.  
  3. print(circle.isIn)



*Defining object callbacks:

Squirrel Script
  1. circle <- Circle({x = 0, z = 0, y = {min = -100, max = 250}})
  2.  
  3. // client callbacks
  4. circle.onEnter = function()
  5. {
  6. print("You have entered into area!")
  7. }
  8.  
  9. circle.onExit = function()
  10. {
  11. print("You have exit from area")
  12. }
  13.  
  14. // server callbacks
  15. circle.onEnter = function(pid)
  16. {
  17. print(pid + " have entered into area!")
  18. }
  19.  
  20. circle.onExit = function(pid)
  21. {
  22. print(pid + " have exit from area")
  23. }


Reply
#2
Script and thread have been updated!

Changes:

Thread:
*Corrected examples in Area class (there was creation with Circle class, which was wrong)
*Changed Area (triangle) position(s) in example. Now triangle is bigger.

Script:
*Fixed critical bug (there was a problem with properly called events, in fact only one object events were working, now this problem has been resolved)
*Removed method baseArea.add. Code from this method has been moved into baseArea constructor.
Reply
#3
Script and thread have been updated!

Changes in script:
* Script from now on, isn't only client-side, but shared, that means, that you can load the script also on server-side.
* Removed debug mode, due to shared modification, if you like to have debug mode, you have to write it yourself.
* Removed config table, if you want to configure something in script, simply look, how it works for example, you can modify the delay of the timer, it's easy to find.
* changed name of class baseArea to BaseArea
* Small refactoring of the code (removed unnecessary type checking, corrected OOP code implementation, simplified classes which inherits from BaseClass
* Renamed Circle.vertex to Circle.verticesCount (also, renamed a method setVertex to setVerticesCount)
* Renamed method remove to destroy. Also, method is returning null, this can be used to put deletion in one line of code.
* Now, circle doesn't require to specify verticesCount, you can work with real circles, by not specifying any verticesCount, or set it to 0 (default is 0). This will cause to treat the circle area as REAL circle. You can even easily switch between vericesCount and real circle without vertexes by simply calling setVerticesCount.
* From now on, script doesn't work in render event, but in timer, and require ONE TIMER to work.

Changes in thread:
- Updated thread for new version of scripts (minor changes/corrections).
- Updated download link

Below, i give you a link to old topic and old script, if you still want to use the old version. I'm not going to support it, and it's uploaded on zippyshare hosting (that means, that file will expire after some time, so if you want an old code, download it quickly!).
download the old script and topic
Reply
#4
Script and thread have updated!

I've rushed this changes, and forgot to pass a pid to callbacks on server side. Thanks for Sendilkelm for noticing this oversight.
Also, i've update the thread slightly, by adding example usage on server side (only callbacks are used differently, because they have pid argument on server side, but on client side they don't).

Forgive me for this mistake, next i'll check everything before publishing it.
Reply
#5
Script has been updated!

Another oversight has been fixed.
I haven't tested this script with someone (server-side), and checking if players are in area was working good, but only for one player.
Now this works.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [New G2O][Client] Free Camera Patrix 2 2,215 06.05.2020, 18:53
Last Post: Patrix
  [New G2O][Client-Side] bindKey Patrix 6 5,343 14.11.2018, 02:32
Last Post: Patrix
  [New G2O][Client-Side] OOP Camera Movement Patrix 1 2,491 20.10.2018, 14:22
Last Post: Patrix
  [New G2O][Shared] Command Handler Patrix 3 3,775 05.09.2018, 15:42
Last Post: Patrix
  [New G2O][Shared] packetListener Patrix 3 4,052 20.06.2018, 18:43
Last Post: Tommy
  [G2O v.0.1.2][Server-Side] NPC Manager Quarchodron 16 10,496 21.01.2018, 19:59
Last Post: Quarchodron
  [New G2O][Client-Side] Key Combination Patrix 1 2,292 23.12.2017, 13:16
Last Post: Patrix
  [G2O v.0.1.0][Client-Side] Notice Board Quarchodron 0 1,891 27.06.2017, 14:28
Last Post: Quarchodron

Forum Jump:


Users browsing this thread: 1 Guest(s)