koragg

[HELP] Update toptimes window on nickname change

Recommended Posts

Hey guys,

Is it possible to update the toptimes window forcefully for all players whenever a player changes their nickname? I tried using some of the functions in the resource but since it's all in OOP - Idk nothing.

Basically I've made the toptimes script to record account names into the database and to show account data as top name for all players in the F5 window. Every time a player changes their nickname that account data also changes so I want to forcefully update the F5 toptimes window for all playes online in order for it to be exactly up to date with the top names.

Share this post


Link to post
42 minutes ago, koragg said:

Is it possible to update the toptimes window forcefully for all players whenever a player changes their nickname?

It is possible, but what is the real problem?

- The synchronisation concept for the data?

Or

- How to use OOP?

 

 

Share this post


Link to post
Posted (edited)
1 hour ago, IIYAMA said:

It is possible, but what is the real problem?

- The synchronisation concept for the data?

Or

- How to use OOP?

 

 

How to use it I guess. I tried the below and nothing happened.

function onNickChange()
	self:updateTopText()
end
addEventHandler("onPlayerChangeNick", root, onNickChange)

also tried this:

function onNickChange()
	if g_SToptimesManager and g_SToptimesManager.mapTimes then
		g_SToptimesManager:updateTopText()
	end
end
addEventHandler("onPlayerChangeNick", root, onNickChange)

as well as this:
 

function onNickChange()
	if g_SToptimesManager then
		local map = exports.cr_mapmanager:getRunningGamemodeMap()
		local mapName = getResourceInfo(map, "name") or getResourceName(map)
		g_SToptimesManager:setModeAndMap("Sprint", mapName)
	end
end
addEventHandler("onPlayerChangeNick", root, onNickChange)

Problem is I don't know how to work with OOP in Lua at all! Imo those things or at least one should've worked, but none do and I get no errors in /debugscript 3.

Tried the above in the toptimes_server.Lua file^

Edited by koragg

Share this post


Link to post
addEventHandler('onPlayerChangeNick', g_Root,
	function(oldNick, newNick)
		if g_SToptimesManager and g_SToptimesManager.mapTimes then
			local index = g_SToptimesManager.mapTimes:getIndexForPlayer(source)
			if index then
				local row = g_SToptimesManager.mapTimes.dbTable.rows[index]
				row.playerName = newNick
				g_SToptimesManager:updateTopText()
			end
		end
	end
)

(toptimes_server.Lua)

Should do the job.

Share this post


Link to post
Posted (edited)
2 hours ago, koragg said:

Tried the above in the toptimes_server.Lua file^

I do not know that script, but I can explain Lua OOP a little bit.

 

At the very basic OOP is about creating objects and consider them as things and not just a data type, in Lua that is in this case a table. And as you know, you can add a lot of things in tables. It is a container used to keep things together. In the concept OOP, functions are part of this container as well. To keep things together, all functions that are saved inside can be used as being part of the table(container) it SELF. Which is where the keyword self comes from.

 

Some people refere to `functions` that are inside of tables/objects as `methods`. Because those functions are used to modify or use data from the table, it becomes an action that the table can do.

 

self is a key word, that reference to the table, where a method/function is saved in. If the function is not called from the table(container), self will become unavailable. The concept here is to keep the self/table as close as possible to the action the function must perform.

t = {}

function t:printSelf()
  print(self)
end

t:printSelf()
-----
t = {123} 
function t:getValue ()   
  print(self[1])
end 
t:getValue()

 

 

 

 

 

 

Edited by IIYAMA
  • Thanks 1

Share this post


Link to post

Thanks for clearing some things up @IIYAMA, I know how to use OOP in Java/C#/C++/etc but it's a bit weird in Lua for some reason :D

Fixed my problem with the below code put inside toptimes_server.Lua thanks to @Mihoje :)

function onNickChange()
	setTimer(function()
		for id, player in ipairs(getElementsByType("player")) do
			g_SToptimesManager:queueUpdate(player)
			g_SToptimesManager:updateTopText()
			local playerPosition = g_SToptimesManager.mapTimes:getIndexForPlayer(player)
			clientCall(player, 'onServerSentToptimes', g_SToptimesManager.toptimesDataForMap, g_SToptimesManager.serverRevision, playerPosition)
		end
	end, 1500, 1) -- This delay has to be bigger than the one which sets the current player name in the maptimes_server.Lua file!
end
addEventHandler("onPlayerChangeNick", root, onNickChange)

 

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.