Forum

> > CS2D > Scripts > MySQL SaveScript
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch MySQL SaveScript

6 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt MySQL SaveScript

Marcell
Super User Off Offline

Zitieren
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

alt Re: MySQL SaveScript

VADemon
User Off Offline

Zitieren
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.
1× editiert, zuletzt 22.12.14 19:31:37

alt Re: MySQL SaveScript

Ajmin
User Off Offline

Zitieren
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
2× editiert, zuletzt 26.12.14 08:31:42

alt Re: MySQL SaveScript

Zeik
User Off Offline

Zitieren
Is as simple as finding wherever you do the "level = level + 1" and writing the saving script in there.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht