Forum

> > CS2D > Scripts > MySQL SaveScript
Forums overviewCS2D overview Scripts overviewLog in to reply

English MySQL SaveScript

6 replies
To the start Previous 1 Next To the start

old MySQL SaveScript

Marcell
Super User Off Offline

Quote
Hey,

I making currently a Save System to MySQL which works a bit, but i need a bit help..

Well the question is the next: its saves USGN ID and your score"level", but i only want to save if level changes. so whenever you do level up its should save, but whenever no, its shouldn't.. any idea how to do it?

(I dont know userstats how should be readed, but maybe thats the solution).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
dofile("sys/lua/configs/main_config.lua")
     
function GetUsgn(id)
	if player(id, "bot") then
		return 0
    end
	return player(id, "usgn")
end

function GetScore(id)
	if GetUsgn(id) then
		return player(id, "score")
	end
end
     
addhook("minute","saveStats")
function saveStats(id)
		for _, id in pairs(player(0,"table")) do
		local usgn = GetUsgn(id)
		local level = GetScore(id)
		if usgn > 0 then
		if level > 0 then
			  res = assert (con:execute(string.format([[
			  INSERT INTO stats
			  VALUES ('%s', '%s')]], usgn, level)
			  ))
		print("©000255000Adatok mentve")
		else
			return 0;
		end
	end
end
end

old Re: MySQL SaveScript

VADemon
User Off Offline

Quote
You need to hook into the level system script, it's the only place that knows when a player gets a level up
UPD: Ofc you can use user Ajmin approach, but I would consider it being a dirty hack.
edited 1×, last 22.12.14 07:31:37 pm

old Re: MySQL SaveScript

Ajmin
User Off Offline

Quote
Make a variable :
1
oldlvl = {}
This variable's default value should be different from level's value!
I think level will be set to 1 as default so make :
1
oldlvl[id]=0

Note: Level should be never set to 0 in any manner!

Save this variable (oldlvl) which should be loaded too.
Then add this to save func:
1
2
3
if oldlvl[id]~=level[id] then
oldlvl[id]=level[id]
-----other save stuffs

Hope i helped!
Regards,
Ajmin
edited 2×, last 26.12.14 08:31:42 am

old Re: MySQL SaveScript

Zeik
User Off Offline

Quote
Is as simple as finding wherever you do the "level = level + 1" and writing the saving script in there.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview