![]() |
Better ATTR's
After finding out that there was a 223 character limit on attributes, and a limited amount of them available for use, I decided to write my own system for handling cross-client communications in the same way that attributes work.
This basically lets you set variables like "player.test = 10; player.shareVar("test");" on the client, then on any OTHER client, use findPlayer or whatever other method to get that player's object, and get the value of the same variable! "player.chat = findPlayer("Hezzy002").test;" will print 10, just as it was set! ;) The variables are stored permanently in an SQL database as well, and are reproduced on login. Installation: 1) Create a new SQL DB named crossplayer 2) Add the crap below to your server, make sure if you change the weapon or DBNPC names you change any references to that name. DBNPC Crossplayer-Control PHP Code:
-System/Client/Crossplayer PHP Code:
Crossplayer-Class PHP Code:
QUICK EXAMPLE: PHP Code:
Thanks! It's helped me alot in development on my server, and I hope it helps out you guys too :D *This is my first contribution, so please point out anything that I've done wrong. It's not a complicated script but I find it very useful. I'm not sure if there's more optimization that can be done or not, I did some optimization where I form it like a packet to handle multiple, instead of spamming the account name over the server and wasting bandwidth. Let me know if you're going to use this for something, it'd be nice to know that something I wrote is floating out there being useful to other people! |
Player attributes aren't limited to 223 characters, RC just cuts them off there. You could rewrite this system using player attributes with no issues as long as you made sure staff never edited a player's attributes with RC.
Something about creating a table for each account feels wrong. I wonder if there's really any benefit in doing that over having a well-indexed table with an "account" column in addition to the "name" and "value" columns. |
Quote:
Quote:
|
setting player.attr[3] to some massive string (10k) on the serverside and echoing the length clientside is always returning 223. I imagine there is a limit for it clientside since that data is being passed to all players in the same players level.
attributes array is also really inflexible, cannot store arrays, and apparently stumbles if you try to store something like 255_255_255, truncating it to just 255. |
Quote:
|
Quote:
|
Quote:
Example: PHP Code:
|
I guess I should have been more specific, if you store an array of integers it will truncate the rest.
PHP Code:
|
Quote:
PHP Code:
PHP Code:
|
There's probably something you can be doing different if you need more than 233 characters of data in an attr.
You're committing an SQL Atrocity (Search Google: "new table for each user") by creating a new table of data for each player, and aren't really gaining any kind of performance boost by doing that at all. SQL just seems really overkill for this. I.e: PHP Code:
|
Quote:
Quote:
Quote:
|
Quote:
|
Quote:
PHP Code:
|
Quote:
Your table should just be: account flag value add an index to account and you're good to go. Your attempt at making it more efficient by giving each account their own table is actually much more in-efficient. If you have 10 people online and you call shareVars on one person, you're calling around 12+ queries (and triggers too) in one call. If you made your table properly, you could use one query to get everyone's flag and variables. I.e: SELECT account, name, value FROM flags WHERE account IN ('account1', 'account2') Package the result up and send it to your client. |
Quote:
|
Quote:
Personally, I'm not a fan of making everyone's "better ATTRs" accessible to everyone all the time rather than when they're needed. Rather than using a hack to get around the limitations of an ATTR it's probably better to make your system work without having to sync a significant amount of data. Can you explain the situation where you need it to work like this? |
Quote:
|
I believe attrs are only sent to other players within the scope of players array unless otherwise defined in the server ops, dunno if anyone thinks/knows otherwise.
could limit it to that and allow for a global scope (added column to table?) if you really wanted and I think that would come closer to matching attr as they currently are. |
Quote:
You can easily hide the "ugly" code related to the player attr with a class, and write common accessors and mutator functions. pl.getNicknameColor() is just as self-documenting than pl.nicknameColor. |
Quote:
Other than that, the syntax is better than attr's, it requires less work to get it to be self-documenting, it's easier for the scripter, it doesn't require casting to a string to work correctly with things like arrays, there's no 223 character limit, and you can use more than 30 should you desire to. I don't see any of the consequences you're talking about, period. I mean, I could be wrong, what consequences are you talking about? |
Quote:
The limitations of using an ATTR can be avoided with a proper design, and writing functions to retrieve and parse the information from it. If the data is too large, it should be requested as needed not loaded ahead for convenience. Class: player_shared_data PHP Code:
PHP Code:
Code that's documented is much more valuable to other scripters than code that is just written a way that self-documents itself. If the server can do it on it's own, let the server do it for you instead of re-creating the wheel. |
Yeah mate, I know you can do that, but this is my way of doing it and you still haven't told me any consequences for using my system. I'm interested in those severe consequences that are bothering you so much, because if they bother someone with so much experience in GS2, then they should bother me too. Can you just state them and maybe I can rectify them? I like my system because I hate limits and I'm sure you do too.
|
Quote:
You have to handle the entire synchronization process with your own scripts, and the more players you have on the server the more unneeded strain is going to placed on the server, and the changes to the variables your synchronizing will only be as efficient as your system that syncs it. The limit is there to prevent people from doing terrible things, and if your system needs to break it there's probably a better way to do it. So a system that lets you break the limit is only going to allow those terrible things to happen. I.e: Syncing massive amounts of useless data. Your system needs the ability to only sync to clients that need it instead of just everyone regardless if they need it or not. |
Quote:
|
| All times are GMT +2. The time now is 11:05 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.