Archived copy of warcraft-source.com, the Warcraft: Source (WCS) forum (2007–2011), rebuilt from the Internet Archive by wc3mods.net. This page was captured on 2009-09-25 (original capture). Home · Forum · All archived topics · Downloads
Warcraft-Source.com - WCS mod for CSS
September 25, 2009, 11:56:00 PM *
Welcome, Guest. Please login or register.
Login with username, password and session length
News: Races and Items added into Download section from our great Race Coders!
Such as... HOLLIDAY|NovaKiller|Stinkyfax|Frodo|TeacherCreature|Phat_Wizard
Google  
  Home   Forum   Help Search Login Register   *
Pages: [1]   Go Down
  Print  
This topic has not yet been rated! You have not rated this topic. Select a rating:
Author Topic: Key groups  (Read 312 times)
Rotgutts
Level 7 Expert
*****
Offline Offline

United States United States

Posts: 303


Krechure Feature



Merzlin
Merzlin
« on: August 03, 2008, 05:14:30 AM »

I'm getting ittensly into keygroups, does anyone have CRUCIAL info on Key Groups? How to make them, how to get them, how to check for them, any matti links, anything!
Logged

freddukes
Level 7 Expert
*****
Offline Offline

United Kingdom

Posts: 292



« Reply #1 on: August 03, 2008, 10:43:35 AM »

http://www.eventscripts.com/pages/Category:Key_Commands


The basic thing to remember is a "keygroup" is like a dictionary... the "keys" are like a page in a dictionary, and the "Keyvalue" is the definition on a page... e.g. Imagine you had a dictionary called "Collins dictionary 2006" and the definition "abacus" was on "page 1".... Then the "keygroup" in this case is "Collins dictionary 2006", the "key" is "page 1", and the "keyvalue" is "abacus" which will hold the definition of the term....

Similar.... If we had a "keygroup" called "Players", and inside that "keygroup" we had "keys" of all the players within our servers, and within each "key" there is 1 "key value" called "name", we could access it like this....

Code
GeSHi (eventscripts):
block load
{
 es_keygroupload Players
 // Open up a new keygroup within the server memory called "Players"... Now the keygroup is loaded we can use it to
 // define all our keys and keyvalues
 es_xset check 0
 // Assign a 'check' value to 0
 es_xset get_value 0
 // Assign a 'get_value' variable to hold a value of 0. We will use this to retrieve the value from the keyvalue
}
 
block unload
{
 // Okay upon unload, delete the keygroup from memory as we do not need the keygroup anymore
 es_keygroupdelete Players
}
 
event player_activate
{
 es_exists check key Players event_var(userid)
 // Okay... We are checking to see if the event_var(userid) key already exists in the keygroup Players... If it does, it will assign the variable check to hold 1, otherwise, that variable will hold 0.
 ifx true(check) do
 {
   // If the key exists, we're going to delete it so we can create the 'real' userid... In theory this should NEVER happen... But it's good practise to ensure you always check...
   es_keydelete Players event_var(userid)
   // Delete the key from the keygroup Players
 }
 // Okay... Now we're sure there is definitely NO key with the same value as the players userid, so create it...
 es_keycreate Players event_var(userid)
 // Create the value event_var(userid) inside the keygroup Players
 es_keysetvalue Players event_var(userid) "Name" event_var(es_username)
 // Okay... So here we are assigning a keyvalue to the players key..
 // Read it from right to left we get... We are assigning the value event_var(es_username) to be the keyvalue of "name" which is inside the key event_var(userid) which is a key of the keygroup Players
 // If you don't get that... Then re-read everything I've typed ;)
}
 
event player_say
{
 if (event_var(text) == "What is my name?") do
 {
   // Okay when a player types "What is my name?" we'll get the value of their username from the keygroup, then tell them it
   es_keygetvalue get_value Players event_var(userid) "Name"
   // Reading it from right to left we get we are getting the value which is held by the keyvlue "Name" within the key event_var(userid) which is held inside the keygroup Players and we are storing the value in get_value
   // get_value now contains the name of the player
   es_tell event_var(userid) Your name is server_var(get_value)
   // Just tell them their name
 }
}
 
event player_disconnect
{
 // Okay, the player has disconnected, so we need to free up some memory by deleting their key in the Keygroup. Again this is not necessary, but it's got practise.
 es_exists check key Players event_var(userid)
 // Check if the key exists, see player_activate
 ifx true(check) do
 {
   es_keydelete Players event_var(userid)
   // If the key exists then delete the player... Very similar to event player_activate only we don't need to re-create the key after.
 }
}
 

A note to remember:

Keygroups are slow, very slow.... If you only want to store 1 or 2 values on a temporary basis, you may want to look at playervar instead.

Keygroups can hold as many keys and keyvalues as you want, but once it's starts getting big, I'd suggest learning SQLite as it deals 'on access memory' which means only the column needed is loaded into memory rather than the whole database so it saves on A LOT of memory, and generally has massive speed increments over keygroups.

Hope you like this tutorial Wink

-freddukes
Logged

Rotgutts
Level 7 Expert
*****
Offline Offline

United States United States

Posts: 303


Krechure Feature



Merzlin
Merzlin
« Reply #2 on: August 03, 2008, 09:52:13 PM »

Loved it, thanks a ton! Smiley
Logged

CA AvasT
Level 7 Expert
*****
Offline Offline

Brazil Brazil

Posts: 375




doug_tiozao
« Reply #3 on: March 01, 2009, 08:50:56 PM »

Nice work brother
but i cant understand for what it serves?
for what it works?
races?
Scripts?
Logged

iLLuSion
Level 2 Apprentice
**
Offline Offline

Australia Australia

Posts: 48



« Reply #4 on: March 02, 2009, 08:51:21 AM »

Nice work brother
but i cant understand for what it serves?
for what it works?
races?
Scripts?

A lot of scripts with exp and levels use keygroups to store them in a db.
Logged
Maxxi
Level 7 Expert
*****
Offline Offline

Netherlands Netherlands

Posts: 1452



WWW
16maxpayne16

myServer 84.243.214.217:27015
(Warning: click connects through Steam)
« Reply #5 on: March 02, 2009, 09:47:00 AM »

Nice work brother
but i cant understand for what it serves?
for what it works?
races?
Scripts?
see like that players from above
"players"
{
         "steamid here"
         {
                  "name"
         }
}

if you save this you can save every steam id with a name attached to it in a db
you can do this with alot oh things
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Last 7 Shouts:
Today at 06:14:32 PM
I got Pink name and spammer rank on another forum Tongue
Today at 07:06:44 AM
is gameservers.com good place to host for server..i need to find one after i done with dedicated server
Today at 05:34:52 AM
yay just got desktop from mail....finaly get to be online in steam after week offf
September 24, 2009, 09:43:13 PM
haha, pink name = spammer Cheesy
September 24, 2009, 09:30:55 PM
can i have a pink name then? Cheesy
Recent
[Today at 11:14:25 PM]

[Today at 11:11:00 PM]

[Today at 11:00:25 PM]

[Today at 10:46:06 PM]

[Today at 10:44:35 PM]

[Today at 10:43:40 PM]

[Today at 10:39:31 PM]

[Today at 10:37:53 PM]

[Today at 10:25:31 PM]

[Today at 10:24:25 PM]
Theme switch

Powered by MySQL Powered by PHP Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC
TinyPortal v0.9.8 © Bloc
Valid XHTML 1.0! Valid CSS!
Page created in 0.214 seconds with 24 queries.