Author Topic: How to use the DB to store variables  (Read 3856 times)

Glider⠠⠵

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 472
  • ⠠⠵
    • View Profile
How to use the DB to store variables
« on: July 04, 2011, 11:35:17 AM »
I taught myself how to use the existing War3Source DB handle to store your own stuff and I thought I'd write this into a little snippet to share with everyone else.

This plugin will create a simple table and add a killcounter for each unique player on the server (bots are ignored). Everytime they score a kill, the counter is increased by one.

I tried commenting the code to give a rough understanding of what is happening and why certain things are there. Just ask if you have any question 8)
« Last Edit: July 04, 2011, 11:46:47 AM by Glider »

Revan

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: How to use the DB to store variables
« Reply #1 on: August 10, 2011, 01:27:54 PM »
Cool, thats realy nice! - great material for learning thanks  ;D
#war3source on gamesurge

Glider⠠⠵

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 472
  • ⠠⠵
    • View Profile
Re: How to use the DB to store variables
« Reply #2 on: October 04, 2011, 09:02:39 AM »
Here's a real world example of a custom addon that uses the DB. This has been running on my server stable for months but I'm about to replace it with a new version so I have no real use for this old code, but I'm sure somebody else can get some learning material from this.

Short overview: The addon is GunGrind and it was written for L4D2. It sorts weapons into different categorys (SMG, SHOTGUN, SNIPER etc) and whenever you deal damage, reload or hit an enemy with them the plugin saves the data to the database. When you deal damage your previous dealt damage / 10000000 is added on top of your damage (Meaning if you did 1 million damage you get a damage increase of 1%). I wanted to hook the amount of reloads to a reload speed buff and the amount of hits to a ASPD buff but in the end I left it at a damage buff.

Warning: The code is unpolished and quite rough. Also I wanted to implement a few features but then later decided against them - regardless there's some stub comments/code for them.

If anybody wants to pick this up and use it for another engine or something (I think it might make a great CSS addition) feel free to do so. I think a really cool thing would be if the table would grow dynamically. When somebody deals damage -> get their weapon and check if its in the table. If it isn't, add the column. Then you wouldn't have to define anything and could get everything dynamically.
« Last Edit: October 05, 2011, 10:23:05 AM by Glider⠠⠵ »