Jump to content

Forbidden nickname


acp___(PL)

Recommended Posts

I'm trying to write my first script from scratch

I want to that after 5 minutes when someone with nick "Player" or else forbiden nicks join server:

- appears on the screen (not in the chat window) information how and why the must change nickname

- message is set to grow more and more difficult game

But is the future of the script, yet I have a problem with the operating function and trigger ...

What do I wrong:

meta.xml

<meta>
<script src="player_server.lua" />
<script src="player_client.lua" type="client" />
</meta>

player_client.lua

g_Root = getRootElement()
 
addEvent( "onPlayer_instruktion", true )
addEventHandler( "onPlayer_instruktion", g_Root, instruktionToPlayer )
 
function instruktionToPlayer ( j_PlayerName )
outputChatBox( "TEST client side" .. j_PlayerName, sourcePlayer )
outputChatBox( "TEST client side" )
end

player_client.lua

g_Root = getRootElement()
 
function forbidenPlayer ()
local joinedPlayerName = getPlayerName ( source )
triggerClientEvent ( sourcePlayer, "onPlayer_instruktion", g_Root, joinedPlayerName )
outputChatBox( "TEST " .. joinedPlayerName .. " server side", sourcePlayer, 0, 255, 0)
end
addEventHandler ( "onPlayerJoin", g_Root, forbidenPlayer )

Link to comment

first:

g_Root = getRootElement()
 
addEvent( "onPlayer_instruktion", true )
 
function instruktionToPlayer ( j_PlayerName )
outputChatBox( "TEST client side" .. j_PlayerName )
outputChatBox( "TEST client side" )
end
addEventHandler( "onPlayer_instruktion", g_Root, instruktionToPlayer )

try to put addEventHandler after function you want to call.

second:

g_Root = getRootElement()
 
function forbidenPlayer ()
local joinedPlayerName = getPlayerName ( source )
triggerClientEvent ( source, "onPlayer_instruktion", g_Root, joinedPlayerName )
outputChatBox( "TEST " .. joinedPlayerName .. " server side", source, 0, 255, 0)
end
addEventHandler ( "onPlayerJoin", g_Root, forbidenPlayer )

You have put 'source' in the 'getPlayerName' function but in the next lines you used 'sourcePlayer'..idk why... so i changed 'sourcePlayer' on 'source', cse i think 'sourcePlayer' in this case is nil.

Link to comment

Now works :lol: but I do not know why it does not show me a text on the screen (shown only in the chat window) :roll:

client side (doesn't display text on the screen, shown only in the chat window):

g_Root = getRootElement()
local screenWidth, screenHeight = guiGetScreenSize()
 
function createText ()
   dxDrawText( "TEST", screenWidth/2, screenHeight/2, tocolor ( 0, 0, 0, 255 ), 10, "pricedown")
end
 
function instruktionToPlayer ( j_PlayerName )
outputChatBox( "TEST client side" .. j_PlayerName )
outputChatBox( "TEST client side" )
addEventHandler("onClientRender",g_Root, createText)
end
addEvent( "onPlayer_instruktion", true )
addEventHandler( "onPlayer_instruktion", g_Root, instruktionToPlayer )

server side (work, do what I wont):

g_Root = getRootElement()
 
function forbidenPlayer ()
local joinedPlayerName = getPlayerName ( source )
if joinedPlayerName == "Player" then
	triggerClientEvent ( source, "onPlayer_instruktion", g_Root, joinedPlayerName )
	outputChatBox( "TEST " .. joinedPlayerName .. " server side", source, 0, 255, 0)
end
end
addEventHandler ( "onPlayerJoin", g_Root, forbidenPlayer )

Perhaps there is another function to display text on screen?

Link to comment
function createText ()
dxDrawText( "TEST2", screenWidth/2, screenHeight/2, screenWidth, screenHeight,  tocolor ( 0, 0, 0, 255 ), 2, "pricedown")
end
addEventHandler( 'onClientRender', getRootElement(), createText )

dx functions must be attached to 'render' event, cse dx images, text etc. rendering in one frame.

Edited by Guest
Link to comment

I tried something like this and it does not work ...

I read the wiki and not only that, but I have something bad to understand ...

g_Root = getRootElement()
local screenWidth, screenHeight = guiGetScreenSize()
 
function createText ()
   dxDrawText( "TEST", screenWidth/2, screenHeight/2, tocolor ( 0, 0, 0, 255 ), 10, "pricedown")
end
 
function instruktionToPlayer ( j_PlayerName )
outputChatBox( "TEST client side" .. j_PlayerName )
outputChatBox( "TEST client side" )
addEventHandler("onClientRender",g_Root, createText)
end
addEvent( "onPlayer_instruktion", true )
addEventHandler( "onPlayer_instruktion", g_Root, instruktionToPlayer )
 
function createText2 ()
dxDrawText( "TEST2", screenWidth/2, screenHeight/2, tocolor ( 0, 0, 0, 255 ), 2, "pricedown")
end
addEventHandler( 'onClientRender', getRootElement(), createText2 )

lines 16-19

in the middle of the screen should be a string TEST2 ...

Link to comment

hehe, i thought that you will get this mistake, but you didnt..

well anyway, you must read wiki carefully. Look at the dxDrawText Syntax. You missed some arguments in your example, such as 'right' and 'bottom' arguments.

dxDrawText( "TEST2", screenWidth/2, screenHeight/2, screenWidth, screenHeight,  tocolor ( 0, 0, 0, 255 ), 2, "pricedown")

this should work.

Link to comment

With your help almost finished the script

>>> Client side finished <<<

everything works, until more then one player begin to change the nicknames on banned

How to assign a variable or a timer to player >>>Server side<<<?

Or maybe do it differently?

player_server.lua

g_Root = getRootElement()
forbidenListOfNicks = { 'fuck' , 'player' , 'huj' , 'kurwa' , 'dupa' , 'pizda' , 'cipa' , 'skurw' , 'kutas' , 'jebac' }
 
function signalFromTimer (the_source )
triggerClientEvent ( the_source, "onPlayer_instruktion", g_Root )
end
function signalFromTimer2 (the_source )
triggerClientEvent ( the_source, "onPlayer_instruktion2", g_Root )
end
function signalFromTimer3 (the_source )
triggerClientEvent ( the_source, "onPlayer_instruktion3", g_Root )
end
function signalInformationChat ( the_source )
outputChatBox ( "To remove the warning text from the screen and hide black strips change nickname!" , the_source, 0, 255, 0, 255 )
end
function signalInformationKick ( the_source )
outputChatBox ( "You have 60 seconds to change the nickname, or you will be kicked!" , the_source, 255, 255, 0, 255  )
end
function signalToKick ( the_source )
kickPlayer(the_source, "Despite warnings not changed nick!")
end
 
function forbidenPlayer ()
local joinedPlayerName = getPlayerName ( source )
for forbidenNickKeyFinder, forbidenNickFinded in ipairs(forbidenListOfNicks) do
	newNickFinder, newNickFinderEnd = string.find(string.lower(joinedPlayerName), forbidenNickFinded)
	outputChatBox ( "TESTjoin: key=" ..forbidenNickKeyFinder.. " forbiden=" ..forbidenNickFinded )
	if newNickFinder then break end
end
if newNickFinder then
	setTimer ( signalFromTimer, 30*1000, 1, source )
	setTimer ( signalFromTimer2, 45*1000, 1, source )
	setTimer ( signalFromTimer3, 60*1000, 1, source )
	setTimer ( signalInformationChat, 20*1000, 3, source)
	setTimer ( signalInformationKick, 80*1000, 1, source)
	setTimer ( signalToKick, 100*1000, 1, source)
	newNickFinderOCB = string.sub(joinedPlayerName, newNickFinder, newNickFinderEnd)
	outputChatBox ( "This part of nick is forbiden: " ..newNickFinderOCB )
end
end
addEventHandler ( "onPlayerJoin", g_Root, forbidenPlayer )
function forbidenChangePlayer (oldForNick, newForNick)
for forbidenNickKeyFinder, forbidenNickFinded in ipairs(forbidenListOfNicks) do
	newNickFinder, newNickFinderEnd = string.find(string.lower(newForNick), forbidenNickFinded)
	oldNickFinder = string.find(string.lower(oldForNick), forbidenNickFinded)
	outputChatBox ( "TESTchange: key=" ..forbidenNickKeyFinder.. " forbiden=" ..forbidenNickFinded )
	if newNickFinder or oldNickFinder then break end
end
if newNickFinder and oldNickFinder then
	newNickFinderOCB = string.sub(newForNick, newNickFinder, newNickFinderEnd)
	outputChatBox ( "This part of nick is forbiden NO: " ..newNickFinderOCB )
elseif newNickFinder then
	setTimer ( signalFromTimer, 30*1000, 1, source )
	setTimer ( signalFromTimer2, 45*1000, 1, source )
	setTimer ( signalFromTimer3, 60*1000, 1, source )
	setTimer ( signalInformationChat, 20*1000, 3, source)
	setTimer ( signalInformationKick, 80*1000, 1, source)
	setTimer ( signalToKick, 100*1000, 1, source)
	newNickFinderOCB = string.sub(newForNick, newNickFinder, newNickFinderEnd)
	outputChatBox ( "This part of nick is forbiden N: " ..newNickFinderOCB )
elseif oldNickFinder then
	outputChatBox ( "test O" )
	triggerClientEvent ( "onPlayer_hide_instruktion", g_Root )
	timersFN = getTimers ( )
	for timerKeyFN, timerValueFN in ipairs(timersFN) do
		killTimer ( timerValueFN )
	end
end
end
addEventHandler ( "onPlayerChangeNick", g_Root, forbidenChangePlayer )
function forbidenQuitPlayer()
timersFN = getTimers ( )
for timerKeyFN, timerValueFN in ipairs(timersFN) do
	killTimer ( timerValueFN )
end
end
addEventHandler ( "onPlayerQuit", g_Root, forbidenQuitPlayer )

player_client.lua

g_Root = getRootElement()
local screenWidth, screenHeight = guiGetScreenSize()
 
function createText ()
local forbiden_nick = getPlayerName(getLocalPlayer())
dxDrawText( forbiden_nick.. " change nick!", 10, 10, screenWidth-10, screenHeight-10, tocolor ( 255, 0, 0, 255 ), 1, "pricedown", "center", "center")
end
function createText2 ()
local forbiden_nick = getPlayerName(getLocalPlayer())
dxDrawText( "You are using a >>>" ..forbiden_nick.. "<<< nickname which is forbidden!", 10, 60, screenWidth-10, screenHeight-10, tocolor ( 0, 255, 0, 255 ), 2, "default", "center", "center")
dxDrawText( "Change the nickname! You can change your nick in settings! <Esc> --> <settings>", 10, 150, screenWidth-10, screenHeight-10, tocolor ( 0, 0, 255, 255 ), 2, "default", "center", "center")
end
function createText3 ()
if k_zam_playFN > 6 then
	zamazywacz_ekrFN = "|" ..zamazywacz_ekrFN
	zamazywacz_ekrFN2 = "||" ..zamazywacz_ekrFN2
	zamazywacz_ekrFN3 = "||||" ..zamazywacz_ekrFN3
	k_zam_playFN = 0
else
	k_zam_playFN = k_zam_playFN +1
end
dxDrawText( zamazywacz_ekrFN , 1, 1, screenWidth-1, screenHeight-1, tocolor ( 0, 0, 0, 255 ), 3, "pricedown", "center", "top", false, true)
dxDrawText( zamazywacz_ekrFN2 , 1, 1, screenWidth-1, screenHeight-1, tocolor ( 0, 0, 0, 255 ), 2, "pricedown", "center", "top", false, true)
dxDrawText( zamazywacz_ekrFN3 , 1, 1, screenWidth-1, screenHeight-1, tocolor ( 0, 0, 0, 255 ), 1, "pricedown", "center", "top", false, true)
end
 
function instruktionToPlayer ()
addEventHandler("onClientRender",g_Root, createText)
end
function instruktionToPlayer2 ()
addEventHandler("onClientRender",g_Root, createText2)
end
function instruktionToPlayer3 ()
k_zam_playFN = 0
zamazywacz_ekrFN = "|"
zamazywacz_ekrFN2 = "||"
zamazywacz_ekrFN3 = "||||"
addEventHandler("onClientRender",g_Root, createText3)
end
function hideInstruktionToPlayer ()
removeEventHandler("onClientRender",g_Root, createText)
removeEventHandler("onClientRender",g_Root, createText2)
removeEventHandler("onClientRender",g_Root, createText3)
end
addEvent( "onPlayer_instruktion", true )
addEventHandler( "onPlayer_instruktion", g_Root, instruktionToPlayer )
addEvent( "onPlayer_instruktion2", true )
addEventHandler( "onPlayer_instruktion2", g_Root, instruktionToPlayer2 )
addEvent( "onPlayer_instruktion3", true )
addEventHandler( "onPlayer_instruktion3", g_Root, instruktionToPlayer3 )
addEvent( "onPlayer_hide_instruktion", true )
addEventHandler( "onPlayer_hide_instruktion", g_Root, hideInstruktionToPlayer )

Link to comment
  • 3 weeks later...

I do not know why, when they are at least two persons from the prohibited and one change to the correct nickname, warning them both disappear ...

player_client.lua

g_Root = getRootElement()
local screenWidth, screenHeight = guiGetScreenSize()
 
function createText ()
local forbiden_nick = getPlayerName(getLocalPlayer())
dxDrawText( forbiden_nick.. " change nick!", 10, 10, screenWidth-10, screenHeight-10, tocolor ( 255, 0, 0, 255 ), 1, "pricedown", "center", "center")
end
function createText2 ()
local forbiden_nick = getPlayerName(getLocalPlayer())
dxDrawText( "You are using a >>>" ..forbiden_nick.. "<<< nickname which is forbidden!", 100, 40, screenWidth-10, screenHeight-100, tocolor ( 0, 255, 0, 255 ), 2, "default", "center", "center", false, true)
dxDrawText( "Change the nickname! You can change your nick in settings! <Esc> --> <settings>", 100, 160, screenWidth-10, screenHeight-100, tocolor ( 0, 0, 255, 255 ), 2, "default", "center", "center", false, true)
end
function createText3 ()
if k_zam_playFN > 6 then
	zamazywacz_ekrFN = "|" ..zamazywacz_ekrFN
	zamazywacz_ekrFN2 = "||" ..zamazywacz_ekrFN2
	zamazywacz_ekrFN3 = "||||" ..zamazywacz_ekrFN3
	k_zam_playFN = 0
else
	k_zam_playFN = k_zam_playFN +1
end
dxDrawText( zamazywacz_ekrFN , 1, 1, screenWidth-1, screenHeight-1, tocolor ( 0, 0, 0, 255 ), 3, "pricedown", "center", "top", false, true)
dxDrawText( zamazywacz_ekrFN2 , 1, 1, screenWidth-1, screenHeight-1, tocolor ( 0, 0, 0, 255 ), 2, "pricedown", "center", "top", false, true)
dxDrawText( zamazywacz_ekrFN3 , 1, 1, screenWidth-1, screenHeight-1, tocolor ( 0, 0, 0, 255 ), 1, "pricedown", "center", "top", false, true)
end
 
function instruktionToPlayer ()
addEventHandler("onClientRender",g_Root, createText)
end
function instruktionToPlayer2 ()
addEventHandler("onClientRender",g_Root, createText2)
end
function instruktionToPlayer3 ()
k_zam_playFN = 0
zamazywacz_ekrFN = "|"
zamazywacz_ekrFN2 = "||"
zamazywacz_ekrFN3 = "||||"
addEventHandler("onClientRender",g_Root, createText3)
end
function hideInstruktionToPlayer ()
removeEventHandler("onClientRender",g_Root, createText)
removeEventHandler("onClientRender",g_Root, createText2)
removeEventHandler("onClientRender",g_Root, createText3)
end
addEvent( "onPlayer_instruktion", true )
addEventHandler( "onPlayer_instruktion", g_Root, instruktionToPlayer )
addEvent( "onPlayer_instruktion2", true )
addEventHandler( "onPlayer_instruktion2", g_Root, instruktionToPlayer2 )
addEvent( "onPlayer_instruktion3", true )
addEventHandler( "onPlayer_instruktion3", g_Root, instruktionToPlayer3 )
addEvent( "onPlayer_hide_instruktion", true )
addEventHandler( "onPlayer_hide_instruktion", g_Root, hideInstruktionToPlayer )

player_server.lua

local g_Root = getRootElement()
local forbidenListOfNicks = { 'fuck' , 'player' , 'huj' , 'kurwa' , 'dupa' , 'pizda' , 'cipa' , 'skurw' , 'kutas' , 'jebac' }
local timersForbidenNick = {}
 
function signalFromTimer (the_source )
triggerClientEvent ( the_source, "onPlayer_instruktion", g_Root )
end
function signalFromTimer2 (the_source )
triggerClientEvent ( the_source, "onPlayer_instruktion2", g_Root )
end
function signalFromTimer3 (the_source )
triggerClientEvent ( the_source, "onPlayer_instruktion3", g_Root )
end
function signalInformationChat ( the_source )
outputChatBox ( "To remove the warning text from the screen and hide black strips change nickname!" , the_source, 0, 255, 0, 255 )
end
function signalInformationKick ( the_source )
outputChatBox ( "You have 60 seconds to change the nickname, or you will be kicked!" , the_source, 255, 255, 0, 255  )
end
function signalToKick ( the_source )
kickPlayer(the_source, "Despite warnings not changed nick!")
end
 
function forbidenPlayer ()
local joinedPlayerName = getPlayerName ( source )
for forbidenNickKeyFinder, forbidenNickFinded in ipairs(forbidenListOfNicks) do
	newNickFinder, newNickFinderEnd = string.find(string.lower(joinedPlayerName), forbidenNickFinded)
	outputConsole ( "TESTjoin: key=" ..forbidenNickKeyFinder.. " forbiden=" ..forbidenNickFinded )
	if newNickFinder then break end
end
if newNickFinder then
	timersForbidenNick[joinedPlayerName] = {}
	timersForbidenNick[joinedPlayerName][1] = setTimer ( signalFromTimer, 30*1000, 1, source )
	timersForbidenNick[joinedPlayerName][2] = setTimer ( signalFromTimer2, 45*1000, 1, source )
	timersForbidenNick[joinedPlayerName][3] = setTimer ( signalFromTimer3, 60*1000, 1, source )
	timersForbidenNick[joinedPlayerName][4] = setTimer ( signalInformationChat, 70*1000, 7, source)
	timersForbidenNick[joinedPlayerName][5] = setTimer ( signalInformationKick, 540*1000, 1, source)
	timersForbidenNick[joinedPlayerName][6] = setTimer ( signalToKick, 600*1000, 1, source)
	newNickFinderOCB = string.sub(joinedPlayerName, newNickFinder, newNickFinderEnd)
	outputChatBox ( "This part of nick is forbiden: " ..newNickFinderOCB )
end
end
addEventHandler ( "onPlayerJoin", g_Root, forbidenPlayer )
function forbidenChangePlayer (oldForNick, newForNick)
for forbidenNickKeyFinder, forbidenNickFinded in ipairs(forbidenListOfNicks) do
	newNickFinder, newNickFinderEnd = string.find(string.lower(newForNick), forbidenNickFinded)
	oldNickFinder = string.find(string.lower(oldForNick), forbidenNickFinded)
	outputConsole ( "TESTchange: key=" ..forbidenNickKeyFinder.. " forbiden=" ..forbidenNickFinded )
	if newNickFinder or oldNickFinder then break end
end
if newNickFinder and oldNickFinder then
	newNickFinderOCB = string.sub(newForNick, newNickFinder, newNickFinderEnd)
	outputChatBox ( "This part of nick is forbiden: " ..newNickFinderOCB )
elseif newNickFinder then
	timersForbidenNick[newForNick] = {}
	timersForbidenNick[newForNick][1] = setTimer ( signalFromTimer, 30*1000, 1, source )
	timersForbidenNick[newForNick][2] = setTimer ( signalFromTimer2, 45*1000, 1, source )
	timersForbidenNick[newForNick][3] = setTimer ( signalFromTimer3, 60*1000, 1, source )
	timersForbidenNick[newForNick][4] = setTimer ( signalInformationChat, 80*1000, 3, source)
	timersForbidenNick[newForNick][5] = setTimer ( signalInformationKick, 540*1000, 1, source)
	timersForbidenNick[newForNick][6] = setTimer ( signalToKick, 600*1000, 1, source)
	newNickFinderOCB = string.sub(newForNick, newNickFinder, newNickFinderEnd)
	outputChatBox ( "This part of new nick is forbiden: " ..newNickFinderOCB )
elseif oldNickFinder then
	outputConsole ( "test O" )
	triggerClientEvent ( "onPlayer_hide_instruktion", g_Root )
	timersFN = getTimers ( timersForbidenNick[oldForNick] )
	for timerKeyFN, timerValueFN in ipairs(timersFN) do
		killTimer ( timerValueFN )
	end
end
end
addEventHandler ( "onPlayerChangeNick", g_Root, forbidenChangePlayer )
function forbidenQuitPlayer()
local quitPlayerName = getPlayerName ( source )
timersFN = getTimers ( timersForbidenNick[quitPlayerName] )
for timerKeyFN, timerValueFN in ipairs(timersFN) do
	killTimer ( timerValueFN )
end
end
addEventHandler ( "onPlayerQuit", g_Root, forbidenQuitPlayer )

should also add a line in the ACL

And so the script appears on the screen:

http://img35.imageshack.us/img35/2357/m ... 175900.png

http://img444.imageshack.us/img444/7319 ... 181012.png

Link to comment
triggerClientEvent ( "onPlayer_hide_instruktion", g_Root )

This will be triggered for every player. This client-side event hides your text, so if you trigger this event for everyone you will hide the text for everyone.

What is this supposed to do:

timersFN = getTimers ( timersForbidenNick[oldForNick] )

timersForbidenNick[oldForNick] this is a table... getTimers doesn't expect you to pass table.

And why don't you do it all client-side and just tell server when to kick the player? There is onClientPlayerChangeNick event client side.

Also, why do you use this?:

string.find(string.lower(joinedPlayerName), forbidenNickFinded)

Why do you want to kick players that have nick like "ImGod:O"?

I haven't looked harder into this script but these 3 are just quickly found... I bet there are more things you should think about.

Link to comment

50p, very thanks for help

so many times I looked at it and did not pay attention

it should be of course:

triggerClientEvent ( source, "onPlayer_hide_instruktion", g_Root )

string.find(string.lower(joinedPlayerName), forbidenNickFinded)

string.lower :arrow: by that I have in the table less items

string.find :arrow: has two tasks captures: eg. "curseYouAll" and protects: eg. join Player, after worning change his nick to Player1

timersFN = getTimers ( timersForbidenNick[oldForNick] )

I want to disable all timers associated with the player

how to disable the timer:timersForbidenNick[oldForNick][1] :?:

killTimer (timersForbidenNick[oldForNick][1])

Now I think it should be so:

for timerKeyFN, timerValueFN in ipairs(timersForbidenNick[oldForNick]) do
		killTimer ( timersForbidenNick[oldForNick][timerKeyFN] )
end

or

for timerKeyFN, timerValueFN in ipairs(timersForbidenNick[oldForNick]) do
		killTimer ( timerValueFN )
end

but

ERROR: ...atch/resourcecache/2paq-player_f_n/player_server.lua:71: bad argument #1 to "ipairs' (table expected, got nil)

it is a table :!:

timersForbidenNick[newForNick] = {}
	timersForbidenNick[newForNick][1] = setTimer ( signalFromTimer, 30*1000, 1, source )
	timersForbidenNick[newForNick][2] = setTimer ( signalFromTimer2, 45*1000, 1, source )
	timersForbidenNick[newForNick][3] = setTimer ( signalFromTimer3, 60*1000, 1, source )
	timersForbidenNick[newForNick][4] = setTimer ( signalInformationChat, 80*1000, 3, source)
	timersForbidenNick[newForNick][5] = setTimer ( signalInformationKick, 540*1000, 1, source)
	timersForbidenNick[newForNick][6] = setTimer ( signalToKick, 600*1000, 1, source)

Link to comment

You just showed timersForbidenNick[ newForNick ] = {} but your code complains about timersForbidenNick[oldForNick].

Why don't you learn debugging? https://wiki.multitheftauto.com/wiki/Debugging

This will solve most of your problems if you know what the error message tells you.

Add this function to your code and call it whenever you want to kill player timers...

function killPlayerTimers( playerName )
for timerKeyFN, timerValueFN in ipairs( timersForbidenNick[ playerName ] ) do
killTimer ( timerValueFN )
end
   timersForbidenNick[ oldPlayerName ] = nil;
end

Let's kill some timers:

local playerName = getPlayerName( player )
killPlayerTimers( playerName )

Bare in mind that getPlayerName returns what is player's name NOW (at the time of calling) not the old name.

Link to comment

I'm trying to understand

player name changes

so if I will index from the new (or current) name is not the same as the old index :?:

acp___ change nick to Player

oldForNick=acp___, newForNick=Player

if newNickFinder then
	timersForbidenNick[Player] = {}
	timersForbidenNick[Player][1] = setTimer ( signalFromTimer, 30*1000, 1, source )
	timersForbidenNick[Player][2] = setTimer ( signalFromTimer2, 45*1000, 1, source )
	timersForbidenNick[Player][3] = setTimer ( signalFromTimer3, 60*1000, 1, source )
	timersForbidenNick[Player][4] = setTimer ( signalInformationChat, 70*1000, 7, source)
	timersForbidenNick[Player][5] = setTimer ( signalInformationKick, 540*1000, 1, source)
	timersForbidenNick[Player][6] = setTimer ( signalToKick, 600*1000, 1, source)
end

timersForbidenNick[newForNick] :arrow:Player change nick to 2paq (oldForNick=Player, newForNick=2paq) :arrow: timersForbidenNick[oldForNick] :?:

timersForbidenNick[newForNick]=timersForbidenNick[oldForNick] :?:

before change newForNick = Player, after change oldForNick = Player (getPlayerName( player ) = Player)

elseif oldNickFinder then
	for timerKeyFN, timerValueFN in ipairs(timersForbidenNick[Player]) do
		killTimer ( timerValueFN )
	end
	timersForbidenNick[ Player ] = nil
end

Link to comment

Why don't you make "player" element as the index in the table? Player element will stay the same for as long as player is connected (even when he/she changes his/her name).

addEventHandler( "onPlayerJoin", getRootElement(),
function( )
       timersForbidenNick[ source ] = { };
-- and rest of the code ...
end
)
 
function killPlayerTimers( player )
for timerKeyFN, timerValueFN in ipairs( timersForbidenNick[ player ] ) do
killTimer ( timerValueFN )
end
   timersForbidenNick[ player ] = nil;
end
 
--then for example:
addEventHandler( "onPlayerChangeNick", getRootElement(),
function ( )
       killPlayerTimers( source );
end
)

Link to comment

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.
×
×
  • Create New...