AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   SQLx help again :P (https://forums.alliedmods.net/showthread.php?t=82826)

Spunky 12-30-2008 15:37

SQLx help again :P
 
So basically, what I'm looking for is a way to store multiple values in a single field, and a way to read only the values I need from that field. An example field:

Code:

1337|57|96|48|32
Something like that. But I need a way to update it so that I can add new flags without disturbing previous flags, and also a way to cleanly read those values. I've seen this done, I just don't know how to do it.

YamiKaitou 12-30-2008 16:04

Re: SQLx help again :P
 
Why can't you use multiple fields?

Spunky 12-30-2008 17:37

Re: SQLx help again :P
 
Because it would look like shit. You think I haven't thought of that?

YamiKaitou 12-30-2008 18:01

Re: SQLx help again :P
 
Not sure what you mean but I wouldn't do that. If I am going to be managing each value separately, I would save them to a field by itself. The only reason why I would save it all to one field is if I using it for history purposes only. Personally, I would find that it looks much nicer if it was in separate fields, but it is your plugin after all.


If you really want to do this, you can use strtok

Hawk552 12-30-2008 18:42

Re: SQLx help again :P
 
What I do whenever I need that functionality is just build the table as a keytable. Then I have two fields:

Code:

key | value
-----------
    |
    |
    |

The key contains whatever I'm looking for on the user along with whatever key component of them I'm looking for:

Code:

key                  | value
--------------------------------------
STEAM_0:0:1|name    | Hawk
STEAM_0:0:1|kills    | 7
STEAM_0:0:1|deaths  | 0
etc...

Of course, you have many more rows, but it's the only way to make it truly dynamic. You can also separate them into different tables, but I think that's more cumbersome and harder to maintain. Another advantage of this method is that you can also make each key unique.

Spunky 12-30-2008 20:01

Re: SQLx help again :P
 
Hawk, you're familiar with Harbu's plugins, right? You've seen the items table and such right? I'm trying to do something like that, but I really don't want to dig through Harbu's horrible code.

Hawk552 12-30-2008 21:17

Re: SQLx help again :P
 
Quote:

Originally Posted by Spunky (Post 735813)
Hawk, you're familiar with Harbu's plugins, right? You've seen the items table and such right? I'm trying to do something like that, but I really don't want to dig through Harbu's horrible code.

Yes, I'm familiar with HWRP and I've written a few plugins for it. I also wrote a total rewrite of it called Apollo RP. I'm kinda surprised you've never heard of it. It uses the exact structure I was talking about and has an API in it which allows other plugins to use that structure for other applications.

Check it out; it's in my sig.

Spunky 12-31-2008 00:37

Re: SQLx help again :P
 
I know about ARP, I've just never run a server with it. Never cared to. I guess I'll check it out, but I hate combing through other people's code just for something simple...

Edit: I'm not gonna look through all of that...

Hawk552 12-31-2008 00:44

Re: SQLx help again :P
 
If you're trying to write something for a TSRP server, ARP is probably the better way to go because it has a complete API making it easier to develop stuff. The thing you're trying to do can probably be automated by the natives supplied in the data layer, so you'll never need to access the SQL database. The data layer is an API which allows you to manipulate and save a keytable into SQL automatically. My description may be simplifying it because it does much more than that, but that's all you really need to know for now. If you're interested or want to know more about it, feel free to post on the ARP board.

EDIT: Your loss. I tried to help. It's the best solution, but if you want to make more crap code like Harbu then be my guest.


All times are GMT -4. The time now is 09:06.

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