Page 1 of 1

Convert GG4 wins to GG5

PostPosted: Thu Nov 20, 2008 8:08 pm
by PitBull
Someone of you maybe already read it in some other posts that I am writing on a wins-converter for GG4 to GG5.

Currently I'm stuck! My Problem is the following:
I open the old database with:
es.sql('open', 'gg_database', '|gungame4/db')

So far, so good. Now I'm getting all the data of the gg_players table:

es.sql('query', 'gg_database', 'gg4c_db', 'SELECT * FROM gg_players')

Also no error, still looks good for me. Now I close the database:

es.sql('close', 'gg_database')

First part is done. Now I want to get each player of the database-data and import it in the GG5 dict_winners-array.
I tried it like the following:

for steamid in gg4c_db[steamid]:
    dict_winners[steamid]['name'] = gg4c_db[name]
    dict_winners[steamid]['wins'] = gg4c_db[wins]

Here the errors start.

File "/home/css/jb/cstrike/addons/eventscripts/gungame/custom_addons/gg_gg4_convert/gg_gg4_convert.py", line 61, in convert
             for steamid in gg4c_db[steamid]:
UnboundLocalError: local variable 'steamid' referenced before assignment

There is a error with gg4c_db[steamid].
In this moment I asked myself an important question: If I get the complete data out of the database, how is it safed in the keygroup?
After this question, I asked me another: I said Keygroup... do I work the same way with a keygroup like with an array? Hmm, lets ask the ESP-Wiki.
So I searched for keygroup, but all I got was a reference to the ESS-Wiki which didn't helped me.

Maybe you can help me?
Best Regards, PitBull

PostPosted: Thu Nov 20, 2008 8:13 pm
by RideGuy
Change it to:
for steamid in gg4c_db:
    dict_winners[steamid]['name'] = gg4c_db[name]
    dict_winners[steamid]['wins'] = gg4c_db[wins]

I have never worked with sql but it looks like you are on the right track. If you get this to work we would love to add it to gg_convert.


Thanks,
RideGuy

PostPosted: Thu Nov 20, 2008 8:22 pm
by PitBull
I'll give it a try. Thanks

~PitBull

PostPosted: Fri Nov 21, 2008 1:43 pm
by PitBull
I tried it, but it doesn't work at all. I think the problem is that the result of the SQL-query is saved in a keygroup, not in an array. I edited the code the following:
    es.sql('open', 'gg_database', '|gungame4/db')
    es.sql('query', 'gg_database', 'gg4c_db', 'SELECT * FROM gg_players')
    es.sql('close', 'gg_database')
    for steamid in gg4c_db:
        dict_winners[steamid]['name'] = gg4c_db['name']
        dict_winners[steamid]['wins'] = gg4c_db['wins']
        gungamelib.saveWinnerDatabase()
    else:
        es.log('Error: Can not run the for-loop!')

And the error came. So ES/Python isn't running the loop at all. Maybe this helps you...

Best Regards, PitBull

PostPosted: Fri Nov 21, 2008 2:36 pm
by RideGuy
If you post a GG4 database I'll give it a shot.

Thanks,
RideGuy

Re: Convert GG4 wins to GG5

PostPosted: Fri Nov 21, 2008 3:09 pm
by PitBull
Here you go ;)

Best Regards, PitBull

PostPosted: Fri Nov 21, 2008 6:21 pm
by Warren
We have added a GunGame4 converter based off of that code you started PitBull. Thanks for the help!

http://code.google.com/p/gungame-python ... tail?r=553

PostPosted: Fri Nov 21, 2008 6:30 pm
by PitBull
I'm glad you did it! I'm also very impressed how you realised it ;)
Maybe you should check if the database exists. The ESP-Wiki says that the server may crash if the keygroup is deleted before running this command. And not existing equals to removed in my eyes ;).
ESP-Wiki wrote:May crash the server if the KeyValues instance is referenced after the keygroup is removed.


~PitBull

Re:

PostPosted: Sat Nov 22, 2008 11:32 am
by Saul
PitBull wrote:And not existing equals to removed in my eyes ;).


Nah. KeyValues doesn't work like that. It uses pointers to KeyValues. If the KeyValues is removed, you now have a NULL pointer -- that will cause a crash.

PostPosted: Sat Nov 22, 2008 12:23 pm
by PitBull
Again I learned something ;)

Thank you,
~PitBull

Re:

PostPosted: Sun Nov 30, 2008 12:42 am
by Saul
PitBull wrote:Again I learned something ;)

Thank you,
~PitBull


The more you know...