Feature #234

XP save

Added by Harlekin over 5 years ago. Updated almost 3 years ago.

Status:Fixed% Done:

100%

Priority:Normal
Assignee:Radegast
Category:Lua scripts
Target version:ET: Legacy Development - ALL

Description

XP save system would be nice.

Save XP while reconnect (eg. 1 map), or reset XP after X maps after connecting.

ETPub like XP save would be also nice


Related issues

Related to Lua scripts for the Legacy mod - Feature #181: Add some kind of user management to the mod for online se... In Progress 29.01.2013

Associated revisions

Revision f184d0d2
Added by IR4T4 over 5 years ago

game: set/reset XP Lua functions activated refs #234

Revision 5862386c
Added by Radegast almost 5 years ago

lua: added XP Save script

Revision ea55f531
Added by Radegast almost 5 years ago

lua: (xpsave) clean up

Revision de568515
Added by Radegast almost 5 years ago

lua: (xp save) prevent sql injections with modified cl_guid, refs #234

History

#1 Updated by IR4T4 over 5 years ago

  • Target version set to 2.71rc2

#2 Updated by IR4T4 over 5 years ago

  • Assignee set to RaFaL
  • % Done changed from 0 to 20

G_XP_Set(clientNum , xp, skill, add) and G_ResetXP(clientNum) Lua functions are available.

#3 Updated by Dragonji over 5 years ago

  • Subject changed from xpsave to XP save
  • Description updated (diff)

#4 Updated by IR4T4 over 5 years ago

  • Priority changed from Low to Normal

#5 Updated by IR4T4 about 5 years ago

  • Target version changed from 2.71rc2 to 2.77

#6 Updated by IR4T4 about 5 years ago

  • Assignee deleted (RaFaL)

#7 Updated by IR4T4 about 5 years ago

  • Target version changed from 2.77 to 2.71rc3

#8 Updated by IR4T4 almost 5 years ago

  • Target version changed from 2.71rc3 to 2.71rc4

#9 Updated by Radegast almost 5 years ago

  • Assignee set to Radegast
  • Target version changed from 2.71rc4 to 2.77
  • % Done changed from 20 to 30

I started working on a Lua module which will provide XP save functionality using a database. It’s the first Lua module that I’ve written and I have only tested it between two maps, so it is not ready yet and needs some clean up and improvement.

It should be useful to server admins until we add engine-side database support.

luasql module with sqlite3 driver is required, but other database drivers may be used instead with a small change. It could also be tweaked to use file backend instead of a database.

EDIT: here is the script: https://github.com/etlegacy/lua_scripts/blob/master/xpsave/xpsave.lua

#10 Updated by Radegast almost 5 years ago

One more thing, when engine-side database support is ready, it will be easy to migrate and import XP data from this script.

#11 Updated by Radegast almost 5 years ago

  • % Done changed from 30 to 60

I added a check in the script for valid guid which prevents sql injections, so people can now start testing this on their servers.

The right way to prevent sql injections would be using con:prepare with bind_names, but this should be sufficient.

#12 Updated by Radegast almost 5 years ago

  • Project changed from ET: Legacy Development to Lua scripts for the Legacy mod
  • Category changed from Mod QAGAME to Lua scripts
  • Status changed from New to Fixed
  • Target version changed from 2.77 to ALL
  • % Done changed from 60 to 100

#13 Updated by eLBati almost 3 years ago

Radegast wrote:

EDIT: here is the script: https://github.com/etlegacy/lua_scripts/blob/master/xpsave/xpsave.lua

Hi,

I tried saving this script to legacy dir. I tried several versions of LuaSQLite3, saving sqlite3.so to legacy/lualibs/luasql/sqlite3.so, but it seems the sqlite3.so library is not able to run standard LUA functions, like lua_settop and lua_checkstack. See http://dev.etlegacy.com/boards/2/topics/431?r=2253#message-2253

How should this script be used?

Thanks

#14 Updated by Spyhawk almost 3 years ago

Again, pretty much sure LuaSQL should be compiled with symbols so the Lua API can communicate with the database.
The files provided by the package managers seem not to provide them. I’m not a compiler expert but I’ll try to have a look into this in the following days.

#16 Updated by eLBati almost 3 years ago

Hi,
I’m using xpsave.lua script and I get into the following problem: after having collected some XP, when I disconnect and reconnect, server log says

Lua API: et_ClientBegin error running lua script: [string "xpsave.lua"]:186: bad argument #2 to 'G_XP_Set' (number has no integer representation)

and XP is partially or totally not restored.

Do you know why this happens?
Thanks

#17 Updated by Spyhawk almost 3 years ago

XP is actually a float, not an integer. In previous Lua, all numbers were float. You might want to force initialization by using "0.0" instead of "0" only.

note: XP are float because of XP sharing between engineers, which divides points earned when constructing between them instead of only giving the whole set of points to the last engineer. If your issue happens only with engineers... then that’s the issue.

#18 Updated by eLBati almost 3 years ago

Spyhawk wrote:

XP is actually a float, not an integer. In previous Lua, all numbers were float. You might want to force initialization by using "0.0" instead of "0" only.

Do you mean like this
https://github.com/eLBati/etlegacy-lua_scripts/commit/b71a57dc1caf8a147da72139ce4203f62da39461
?

note: XP are float because of XP sharing between engineers, which divides points earned when constructing between them instead of only giving the whole set of points to the last engineer. If your issue happens only with engineers... then that’s the issue.

Actually it surely happened when I was medic: I lost all 'light weapons’ XP

#19 Updated by eLBati almost 3 years ago

I am now testing
https://github.com/Zelly/ZellyLuas/blob/master/ZXpSave.lua
on my server.
It seems to work so far

Also available in: Atom PDF