Jump to content

Points: wins, end race, time, cp


acp___(PL)

Recommended Posts

I start work on a script that allows players to collect points.

I started from help :lol: but this is because to have some sort of algorithm of :roll:

but will also describe what I wants to achieve an effect :fadein:

SCORING AND RANK SYSTEM
To be able to score points and have own rank you must had completed 5 races on the server.
All 5 races must be completed without disconnecting from the server!
 
######################################################################################################################
 
COMMANDS:
/showpoints - show how many you should collect points to the next title
/showrank - show grafic bar how much you should collect points to the next title
/bonus - show how many race / wins to benefit from the bonus scoring
 
######################################################################################################################
 
POINTS
Points gained in the race depends on the position at which you finish the race and the number of players on the server
For more then eight players:
1. first place - 25
2. second place - 20
3. third place - 15
4. fourth place - 12
5. fifth place - 10
6. sixth place - 8
7. seventh place - 7
8. eighth place - 6
9. ninth place - 5
10. tenth place - 4
11. eleventh place - 3
12. twelfth place - 2
other places - 1
For more then three players and less then eight:
1. first place - 20
2. second place - 15
3. Third place - 10
4. fourth place - 8
5. fifth place - 6
6. sixth place - 4
7. seventh place - 2
For one to three players:
1. first place - 15
2. second place - 10
3. Third place - 5
If you play alone you earn for finish race - 5 points
 
######################################################################################################################
 
BONUS POINTS
After you end 40 race (5 race to by rank not included):
- for every 10 checkpoints points you earn 1 points in one race
- for every 20 checkpoints points you earn 2 points in one race
- for every 50 checkpoints points you earn 5 points in one race
- for every 100 checkpoints points you earn 15 points in one race
- for every 200 checkpoints points you earn 30 points in one race
- for every 240 checkpoints points you earn 40 points in one race
 
For example, in the map of the 255 cp earn additional collected points:
255/10 = 25points
255/20 = 12*2 = 24points
255/50 = 5*5 = 25points
255/100 = 2*15 = 30points
255/200 = 1*30 = 30points
255/240 = 1*40 = 40points
25 + 24 + 25 + 30 + 30 + 40 = 120 points!!!
 
After you end 30 win (5 race to by rank not included):
- for each 10 minutes of play you earn 2 points
- for each 20 minutes of play you earn 5 points
- for each 30 minutes of play you earn 15 points
- for each 45 minutes of play you earn 25 points
 
For example, if you play 51 minutes, earn additional collected points:
51/10 = 5*2 = 10 points
51/20 = 2*5 = 10 points
51/30 = 1*15 = 15 points
51/45 = 1*20 = 25 points
10 + 10 + 15 + 25 = 60 points!!!

From the start, I am aware that I have somewhere to save the points allocated to players, best to use the database ... and the first problem :cry:

I'm not sure whether I good understand about creating a table, in the case of the existing reading:

tabelav.jpg

function createSQLStatsPoints ()
executeSQLCreateTable ( "stats_points", "player_nick TEXT, player_race INTEGER,  player_wins INTEGER, player_points INTEGER," )
end
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), createSQLStatsPoints )

And did I understand that the tables I could save up to registry.db using: executeSQLDropTable :?:

Link to comment
  • 2 weeks later...

I want to write to DB (line 18):

tabelavg.png

function stats_endRace (stats_rank)
local namePlayerSR = getPlayerName ( source )
local playerRaceSR = executeSQLSelect( "stats_points", "player_race", "player_nick='"..namePlayerSR.."'" )
if not playerRaceSR then
elseif ( type( playerRaceSR ) == "table" and #playerRaceSR == 0 ) then
	if not players_count_5races[namePlayerSR] then
		players_count_5races[namePlayerSR] = 0
		setElementData (source, 'numberRaceToBeRanktext', players_count_5races[namePlayerSR])
		triggerClientEvent ( source, "onPlayerShowTextInfoTobeRank", g_Root )
		triggerClientEvent ( source, "onPlayerShowCountRaceNo", g_Root )
	elseif players_count_5races[namePlayerSR] < 5 then
		players_count_5races[namePlayerSR] = players_count_5races[namePlayerSR] + 1
		setElementData (source, 'numberRaceToBeRanktext', players_count_5races[namePlayerSR])
	elseif players_count_5races[namePlayerSR] == 5 then
		players_count_5races[namePlayerSR] = nil
		triggerClientEvent ( source, "onPlayerHideCountRaceNo", g_Root )
		if stats_rank == 1 then local winsSRtoDB = 1 else local winsSRtoDB = 0 end
		executeSQLInsert ("stats_points", "'"..namePlayerSR.."','1','"..winsSRtoDB.."','0'")
	end
else
end
end

in this part of the script corresponds to the line 18

attempttoconcatenateglop.png

EDIT:

local winsSRtoDB = 0
		if stats_rank == 1 then winsSRtoDB = 1 end
		executeSQLInsert ("stats_points", "'"..namePlayerSR.."','1','"..winsSRtoDB.."','0'")

Link to comment

attention to the previous problem

I used a local variable in the wrong place, suggested to me that a friend from the server, edited the previous post and added this information

a new problem

arithmeticonfield.png

error in line 16

local g_Root = getRootElement()
local pointsCPzliczacz = {}
 
function remeberNumberPlayersInStartTimer()
local namePlayerpointsCPzliczacz = getPlayerName ( source )
pointsCPzliczacz[namePlayerpointsCPzliczacz] = 0
end
 
addEvent('onMapStarting')
addEventHandler('onMapStarting', g_Root , remeberNumberPlayersInStartTimer)
 
addEvent('onPlayerReachCheckpoint')
addEventHandler('onPlayerReachCheckpoint', g_Root,
function ()
	local namePlayerpointsCPzliczacz = getPlayerName ( source )
	pointsCPzliczacz[namePlayerpointsCPzliczacz] = pointsCPzliczacz[namePlayerpointsCPzliczacz] + 1
	outputConsole("Function: onPlayerReachCheckpoint - zliczacz=" ..pointsCPzliczacz[namePlayerpointsCPzliczacz])
end
)

Edit:

timererrors.png

on print screen line 92 = 6 on code

on print screen line 113 = 27 on code

on print screen line 114 = 28 on code

local timerBonus = {}
function playerQuitResetRace ()
local namePlayerQRR = getPlayerName ( source )
if players_count_5races[namePlayerQRR] then players_count_5races[namePlayerQRR] = nil end
if pointsCPzliczacz[namePlayerQRR] then pointsCPzliczacz[namePlayerQRR] = nil end
if timerBonus[1][namePlayerQRR] then killTimer(timerBonus[1][namePlayerQRR]) end
if timerBonus[2][namePlayerQRR] then killTimer(timerBonus[2][namePlayerQRR]) end
if timerBonus[3][namePlayerQRR] then killTimer(timerBonus[3][namePlayerQRR]) end
if timerBonus[4][namePlayerQRR] then killTimer(timerBonus[4][namePlayerQRR]) end
end
addEventHandler('onPlayerQuit', g_Root , playerQuitResetRace)
 
function playerJoinSetTimerBonus()
local namePlayerJSTB = getPlayerName ( source )
local giveBonusForTime10points = 2
local giveBonusForTime20points = 5
local giveBonusForTime30points = 15
local giveBonusForTime45points = 25
timerBonus[1][namePlayerJSTB] = setTimer (giveBonusForTime, 10000, 0, source, giveBonusForTime10points)
timerBonus[2][namePlayerJSTB] = setTimer (giveBonusForTime, 20050, 0, source, giveBonusForTime20points)
timerBonus[3][namePlayerJSTB] = setTimer (giveBonusForTime, 30100, 0, source, giveBonusForTime30points)
timerBonus[4][namePlayerJSTB] = setTimer (giveBonusForTime, 45000, 0, source, giveBonusForTime45points)
end
addEventHandler('onPlayerJoin', g_Root , playerJoinSetTimerBonus)
 
function giveBonusForTime(the_source, bonusPointsForTime)
local namePlayergiveBonusForTime = getPlayerName ( the_source )
outputConsole("Function: giveBonusForTime10; nick: " ..namePlayergiveBonusForTime.. "; points: " ..bonusPointsForTime)
end

Link to comment

I use outputchatbox and the more I do not understand why there is only one timer

consola.png

setTimer (giveBonusForTime, 10000, 0, source, giveBonusForTime10points) :arrow: 5-6 times (2 points)

setTimer (giveBonusForTime, 20050, 0, source, giveBonusForTime20points) :arrow: 2-3 times (5 points)

setTimer (giveBonusForTime, 30100, 0, source, giveBonusForTime30points) :arrow: 1 times (15 points)

setTimer (giveBonusForTime, 45000, 0, source, giveBonusForTime45points) :arrow: 1 times (25 points)

:x:x:x sum 9-11 times (on print screen only 8 times and all with 2 points ...) :arrowup:

when it comes to about 'onPlayerReachCheckpoint'

to be funnily I don't delate my line of thinking as I ran into the problem :lol:

I use this function in another script, and I know that the source is ok because there does

At the beginning of the script defines a table: local pointsCPzliczacz = {}

In line 6: pointsCPzliczacz[namePlayerpointsCPzliczacz] = 0 :arrow: set int

:idea::idea::idea::idea::idea::idea::idea::idea::idea::idea::idea::idea: :idea: :idea::idea::idea::idea::idea::idea::idea::idea::idea::idea::idea:

working solution

function remeberNumberPlayersInStartTimer()
local playersListpointsCPzliczacz = getElementsByType('player')
for kPlayerLpCPzl,playerpointsCPzliczacz in ipairs(playersListpointsCPzliczacz) do
	local namePlayerpointsCPzliczacz = getPlayerName ( playerpointsCPzliczacz )
	pointsCPzliczacz[namePlayerpointsCPzliczacz] = 0
	outputConsole("ipairs(playersListpointsCPzliczacz)" ..namePlayerpointsCPzliczacz.. "-->" ..pointsCPzliczacz[namePlayerpointsCPzliczacz])
end
end

function playerJoinSetTimerBonus()
local namePlayerJSTB = getPlayerName ( source )
pointsCPzliczacz[namePlayerJSTB] = 0
end
addEventHandler('onPlayerJoin', g_Root , playerJoinSetTimerBonus)

EDIT:

I know that the problem with the indexing table, but I do not know how to do it properly

in the wiki about it is not as well developed

consola.png

Error in line: 9

function remeberNumberPlayersInStartTimer()
local playersListpointsCPzliczacz = getElementsByType('player')
for kPlayerLpCPzl,playerpointsCPzliczacz in ipairs(playersListpointsCPzliczacz) do
	local namePlayerpointsCPzliczacz = getPlayerName ( playerpointsCPzliczacz )
	local playerRaceCPzliczacz = executeSQLSelect( "stats_points", "player_race", "player_nick='"..namePlayerpointsCPzliczacz.."'" )
	if ( type( playerRaceCPzliczacz ) == "table" and #playerRaceCPzliczacz == 0 ) or not playerRaceCPzliczacz then
		outputConsole("remeberNumberPlayersInStartTimer() - if ( type( playerRaceCPzliczacz ) == table and #playerRaceCPzliczacz == 0 ) or not playerRaceCPzliczacz")
	elseif ( type( playerRaceCPzliczacz ) == "table" and playerRaceCPzliczacz[1]['player_race'] > 0 ) then
		pointsCPzliczacz[1][namePlayerpointsCPzliczacz] = 0
		pointsCPzliczacz[2][namePlayerpointsCPzliczacz] = 0
		pointsCPzliczacz[3][namePlayerpointsCPzliczacz] = 0
		pointsCPzliczacz[4][namePlayerpointsCPzliczacz] = 0
		pointsCPzliczacz[5][namePlayerpointsCPzliczacz] = 0
		pointsCPzliczacz[6][namePlayerpointsCPzliczacz] = 0
		outputConsole("ipairs(playersListpointsCPzliczacz)" ..namePlayerpointsCPzliczacz.. "-->" ..pointsCPzliczacz[namePlayerpointsCPzliczacz])
	end
end
setTimer(remeberNumberPlayersInStart, 3000, 15)
end

Error in line: 11

function playerJoinSetTimerBonus()
local namePlayerJSTB = getPlayerName ( source )
local playerRaceJSTB = executeSQLSelect( "stats_points", "player_race", "player_nick='"..namePlayerJSTB.."'" )
if ( type( playerRaceJSTB ) == "table" and #playerRaceJSTB == 0 ) or not playerRaceJSTB then
	outputConsole("playerJoinSetTimerBonus() - if ( type( playerRaceJSTB ) == table and #playerRaceJSTB == 0 ) or not playerRaceJSTB")
elseif ( type( playerRaceJSTB ) == "table" and playerRaceJSTB[1]['player_race'] > 0 ) then
	local giveBonusForTime10points = 2
	local giveBonusForTime20points = 5
	local giveBonusForTime30points = 15
	local giveBonusForTime45points = 25
	timerBonus[1][namePlayerJSTB] = setTimer (giveBonusForTime, 10000, 0, source, giveBonusForTime10points)
	timerBonus[2][namePlayerJSTB] = setTimer (giveBonusForTime, 20050, 0, source, giveBonusForTime20points)
	timerBonus[3][namePlayerJSTB] = setTimer (giveBonusForTime, 30100, 0, source, giveBonusForTime30points)
	timerBonus[4][namePlayerJSTB] = setTimer (giveBonusForTime, 45000, 0, source, giveBonusForTime45points)
	outputConsole("playerJoinSetTimerBonus()" ..namePlayerJSTB.. "-->" ..pointsCPzliczacz[namePlayerJSTB])
end
end
addEventHandler('onPlayerJoin', g_Root , playerJoinSetTimerBonus)

EDIT2:

I found the solution:

http://www.lua.org/pil/11.2.html

Link to comment

does not work if - line: 17-23

local g_Root = getRootElement()
local screenWidth, screenHeight = guiGetScreenSize()
local g_Me = getLocalPlayer()
local barLevelTable = { "80000", "50000", "38000", "31000", "25000", "20000", "16000", "13000", "11000", "9200", "7500", "6000", "4700", "3500", "2500", "1600", "800", "400", "200", "100", "50", "10" }
 
--Level bar
function createBarLevelNext ()
dxDrawImage( 10, 200, 20, 360, "border.png" )
dxDrawRectangle( 12, 202, 18, 356, tocolor ( 0, 0, 0, 150 ) )
end
function hideBarLevelNext ()
removeEventHandler("onClientRender",g_Root, createBarLevelNext)
end
function playerShowBarLevelNext (timeAfterDelay)
local pointsInScriptStats = getElementData (g_Me, 'points.scriptStats')
for iShowBarLN, theNextLevelIs in ipairs(barLevelTable) do
	if pointsInScriptStats > theNextLevelIs then
		calkowitaWysokoscNextLevelBar = barLevelTable[iShowBarLN]
		liczbaJuzPosiadanychPunktow = pointsInScriptStats
		break
		outputConsole( "playerShowBarLevelNext () ipairs / for - theNextLevelIs: " ..theNextLevelIs)
		outputConsole( "playerShowBarLevelNext () ipairs / for - pointsInScriptStats: " ..pointsInScriptStats)
	end
outputConsole( "playerShowBarLevelNext () ipairs - theNextLevelIs: " ..theNextLevelIs)
outputConsole( "playerShowBarLevelNext () ipairs - barLevelTable[iShowBarLN]" ..barLevelTable[iShowBarLN])
outputConsole( "playerShowBarLevelNext () ipairs - iShowBarLN" ..iShowBarLN)
end
addEventHandler("onClientRender", g_Root, createBarLevelNext)
timerSBLN = setTimer (hideBarLevelNext, timeAfterDelay, 1)
end
addEvent( "onPlayerShowBarLevelNext", true )
addEventHandler( "onPlayerShowBarLevelNext", g_Root, playerShowBarLevelNext )
--Koniec

Link to comment

how to remove timers??

following function it looks like does not work

local g_Root = getRootElement()
local g_ResRoot = getResourceRootElement(getThisResource())
local pointsCPzliczacz = {}
local pointsCPzliczaczMarker = {}
local markerBonusTime = {}
local timerBonus = {}
local timerBonusCP = {}

function playerQuitResetRace (zmiennaDlaZmianyNicku)
local namePlayerQRR = getPlayerName ( source )
if zmiennaDlaZmianyNicku then namePlayerQRR = zmiennaDlaZmianyNicku end
if players_count_5races[namePlayerQRR] then players_count_5races[namePlayerQRR] = nil end
if pointsCPzliczaczMarker[namePlayerQRR] == 1 then
	if pointsCPzliczacz[namePlayerQRR][1] then pointsCPzliczacz[namePlayerQRR][1] = nil end
	if pointsCPzliczacz[namePlayerQRR][2] then pointsCPzliczacz[namePlayerQRR][2] = nil end
	if pointsCPzliczacz[namePlayerQRR][3] then pointsCPzliczacz[namePlayerQRR][3] = nil end
	if pointsCPzliczacz[namePlayerQRR][4] then pointsCPzliczacz[namePlayerQRR][4] = nil end
	if pointsCPzliczacz[namePlayerQRR][5] then pointsCPzliczacz[namePlayerQRR][5] = nil end
	if pointsCPzliczacz[namePlayerQRR][6] then pointsCPzliczacz[namePlayerQRR][6] = nil end
	if pointsCPzliczaczMarker[namePlayerQRR] then pointsCPzliczaczMarker[namePlayerQRR] = nil end
	outputConsole("if pointsCPzliczaczMarker[namePlayerQRR] == 1 then - nick: " ..namePlayerQRR)
end
if markerBonusTime[namePlayerQRR] == 1 then
	if timerBonus[namePlayerQRR][1] then killTimer(timerBonus[namePlayerQRR][1]) end
	if timerBonus[namePlayerQRR][2] then killTimer(timerBonus[namePlayerQRR][2]) end
	if timerBonus[namePlayerQRR][3] then killTimer(timerBonus[namePlayerQRR][3]) end
	if timerBonus[namePlayerQRR][4] then killTimer(timerBonus[namePlayerQRR][4]) end
	if markerBonusTime[namePlayerQRR] then markerBonusTime[namePlayerQRR] = nil end
	outputConsole("if markerBonusTime[namePlayerQRR] == 1 then - nick: " ..namePlayerQRR)
end
outputConsole("function playerQuitResetRace (zmiennaDlaZmianyNicku) - nick:" ..namePlayerQRR)
end
addEventHandler('onPlayerQuit', g_Root , playerQuitResetRace)

function ustawNaNowoDlaNowegoNicku (oldPointsNick, newPointsNick)
playerQuitResetRace(oldPointsNick)
setTimer (playerJoinSetTimerBonus, 50, 1, newPointsNick)
end
addEventHandler ( "onPlayerChangeNick", g_Root, ustawNaNowoDlaNowegoNicku )

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...