Hallo, ich habe das Reallife Reloaded AFK System in mein Extended eingefügt. Alles klappt, bis auf die Tabliste, dort wird kein [AFK] Präfix angezeigt, trotz Eintrag in die playerlist.lua!
Bitte um Hilfe!
Hier die Codes:
Spoiler anzeigen
Lua
Afk_Client.luca
--------------------
-- Copyright 2012 --
-- tiRed und RenX --
--------------------
--------------- AFK GEHEN ---------------
afkaction = false
oldAFKXPos = 0
oldAFKYPos = 0
addCommandHandler ( "afk",
function ( )
if getLocalPlayer() then
local playingtime = getElementData ( getLocalPlayer(), "playingtime" )
local pminute = playingtime - math.floor ( playingtime / 60 ) * 60
if tonumber ( pminute ) ~= 0 then
if tonumber ( getElementData ( getLocalPlayer(), "nodmzone" ) ) == 1 then
if not getPedOccupiedVehicle ( getLocalPlayer() ) then
if not afkaction then
if not getElementData ( getLocalPlayer(), "afk" ) and not isTimer ( afkTimer ) then
if not getElementData ( getLocalPlayer(), "tazered" ) or not getElementData ( getLocalPlayer(), "growing" ) then
outputChatBox ( "Bewege dich nicht, in 10 Sekunden bist du AFK", 0, 125, 0 )
afkaction = true
afkTimer = setTimer ( checkafk, 500, -1 )
afkRuns = 0
afkX, afkY, afkZ = getElementPosition ( getLocalPlayer() )
else
outputChatBox ( "Das ist im Moment nicht moeglich", 125, 0, 0 )
end
else
outputChatBox ( "Du bist bereits AFK", 125, 0, 0 )
end
elseif afkaction then
afkaction = false
triggerServerEvent ( "afk_freeze", getLocalPlayer(), getLocalPlayer() )
toggleAllControls ( true, true, true )
outputChatBox ( "Du bist nicht mehr AFK", 0, 125, 0 )
end
else
outputChatBox ( "In einem Fahrzeug kannst du dich nicht AFK gehen", 125, 0, 0 )
end
else
outputChatBox ( "Du kannst nur in einer DM-freien Zone AFK gehen", 125, 0, 0 )
end
else
outputChatBox ( "Zur vollen Spielstunde ist es nicht moeglich AFK zu gehen", 125, 0, 0 )
end
end
end
)
function checkafk ( )
if getLocalPlayer() then
local x, y, z = getElementPosition ( getLocalPlayer() )
afkRuns = afkRuns + 1
if x == afkX and y == afkY and z == afkZ and not isPedDead ( getLocalPlayer() ) then
if tonumber ( afkRuns ) == 20 then
outputChatBox ( "Du bist nun AFK", 0, 125, 0 )
killTimer ( afkTimer )
toggleAllControls ( false, true, false )
triggerServerEvent ( "afk_freeze", getLocalPlayer(), getLocalPlayer() )
-- afkendTimer = setTimer ( afkend, 500, -1 )
-- afkendX, afkendY, afkendZ = getElementPosition ( getLocalPlayer() )
end
else
outputChatBox ( "AFK-Vorgang abgebrochen!", 125, 0, 0 )
killTimer ( afkTimer )
end
end
end
--[[
function afkend ( )
if getLocalPlayer() then
if getElementData ( getLocalPlayer(), "afk" ) then
if not afkaction then
local x, y, z = getElementPosition ( getLocalPlayer() )
if x == afkendX and y == afkendY and z == afkendZ and not isPedDead ( getLocalPlayer() ) then
afkaction = false
else
afkaction = true
end
else
outputChatBox ( "AFK-Vorgang abgebrochen!", 125, 0, 0 )
setElementData ( getLocalPlayer(), "afk", false )
killTimer ( afkendTimer )
end
end
end
end
]]--
--------------- AFK CHECKING ---------------
action = false
oldAFKXPos = 0
oldAFKYPos = 0
function setInvulnerable ( bool )
invulnerable = bool
end
function isInvulnerable ()
return invulnerable
end
function godModeHandler ()
if invulnerable then
cancelEvent()
end
end
addEventHandler ( "onClientPedDamage", getLocalPlayer(), godModeHandler )
function afkCheck_func ()
if getElementData ( getLocalPlayer(), "loggedin" ) then
if not vioGetElementData ( getLocalPlayer(), "afk" ) then
if not action and getElementData ( getLocalPlayer(), "jailtime" ) <= 0 then
local x, y, z = getElementPosition ( getLocalPlayer() )
triggerServerEvent ( "logoutPlayer", getLocalPlayer(), x, y, z, getElementInterior ( getLocalPlayer() ), getElementDimension ( getLocalPlayer() ) )
else
action = false
end
end
end
end
setTimer ( afkCheck_func, 600000, -1 )
afkRun = 0
function positionAFKCheck ()
if not vioGetElementData ( getLocalPlayer(), "afk" ) then
local x, y, z = getElementPosition ( getLocalPlayer() )
local dist = getDistanceBetweenPoints2D ( oldAFKXPos, oldAFKYPos, x, y )
afkRun = afkRun + 1
if dist > 5 or getElementHealth ( getLocalPlayer() ) <= 1 or isElement ( gImage["Back"] ) or guiGetVisible ( gWindow["pokerOwnCards"] ) then
afkRun = 0
action = true
end
if afkRun == 26 then
outputChatBox ( "WARNUNG: Du wirst in einer Minute ausgeloggt.", 125, 0, 0 )
end
oldAFKXPos = x
oldAFKYPos = y
end
end
setTimer ( positionAFKCheck, 20000, -1 )
function AFKPlayerChat ( msg )
if not vioGetElementData ( getLocalPlayer(), "afk" ) then
local tok = gettok ( msg, 1, string.byte ( ':' ) )
if tok then
if string.find ( tok, getPlayerName ( getLocalPlayer() ) ) then
action = true
end
end
end
end
addEventHandler ( "onClientChatMessage", getRootElement(), AFKPlayerChat )
--------------- SAVE FUNKTION ---------------
function save_func ()
if not vioGetElementData ( getLocalPlayer(), "afk" ) then
if not getPedOccupiedVehicle ( getLocalPlayer() ) and not isTimer ( logoutTimer ) then
if getElementData ( getLocalPlayer(), "In_DMArena" ) == 1 then
outputChatBox ( "Du kannst dich hier nicht ausloggen!", 125, 0, 0 )
else
outputChatBox ( "Du wirst in 30 Sekunden ausgeloggt, bitte bleibe an deiner jetzigen Position!", 0, 125, 0 )
logoutTimer = setTimer ( checkLogout, 500, -1 )
logoutRuns = 0
logoutX, logoutY, logoutZ = getElementPosition ( getLocalPlayer() )
end
end
end
end
addCommandHandler ( "save", save_func )
function checkLogout ()
if not vioGetElementData ( getLocalPlayer(), "afk" ) then
local x, y, z = getElementPosition ( getLocalPlayer() )
logoutRuns = logoutRuns + 1
if x == logoutX and y == logoutY and z == logoutZ and not isPedDead ( getLocalPlayer() ) then
if logoutRuns == 60 then
triggerServerEvent ( "logoutPlayer", getLocalPlayer(), x, y, z, getElementInterior ( getLocalPlayer() ), getElementDimension ( getLocalPlayer() ) )
elseif logoutRuns/10 == math.floor ( logoutRuns/10+.01 ) then
outputChatBox ( "Du wirst in "..((60-logoutRuns)/2).." Sekunden ausgeloggt!", 150, 150, 0 )
end
else
outputChatBox ( "Logout abgebrochen!", 125, 0, 0 )
killTimer ( logoutTimer )
end
end
end
[/spoiler]
Alles anzeigen
Playerlist_client.lua:
Lua
[spoiler]local playerListLabels = {}
local playerListFactionMembersLabel = {}
local playersOnline = {}
local playersOnlineData = {}
local curPlayerListPosition = 1
local playerCount = 0
local playerListWidth = 484
local playerListHeight = 311
local maxPlayersInCurList = 17
local maxPlayers = 128
local playersToScrollPerButton = 10
function recieveServerSlotCount ( max )
maxPlayers = max
end
addEvent ( "recieveServerSlotCount", true )
addEventHandler ( "recieveServerSlotCount", getRootElement(), recieveServerSlotCount )
triggerServerEvent ( "getServerSlotCount", lp )
local radioUpState, radioDownState, weaponUpState, weaponDownState
function fillPlayerListOnStart ()
local players = getElementsByType ( "player" )
for key, index in pairs ( players ) do
playerCount = playerCount + 1
playersOnlineData[index] = playerCount
playersOnline[playerCount] = index
end
end
fillPlayerListOnStart ()
function clientPlayerListDisconnect ()
local i = playersOnlineData[source]
playersOnline[i] = nil
playerCount = playerCount - 1
end
addEventHandler ( "onClientPlayerQuit", getRootElement(), clientPlayerListDisconnect )
function clientPlayerListConnect ()
local i
for k = 1, maxPlayers do
if not playersOnline[k] then
i = k
break
end
end
playerCount = playerCount + 1
playersOnlineData[source] = i
playersOnline[i] = source
end
addEventHandler ( "onClientPlayerJoin", getRootElement(), clientPlayerListConnect )
function showPlayerList ()
if gImage["playerList"] then
guiSetVisible ( gImage["playerList"], true )
else
local label, img
gImage["playerList"] = guiCreateStaticImage(screenwidth/2-playerListWidth/2,screenheight/2-playerListHeight/2,playerListWidth,playerListHeight,"images/colors/c_black.jpg",false)
guiSetAlpha(gImage["playerList"],1)
label = guiCreateLabel(12,9,51,23,"Name",false,gImage["playerList"])
guiSetAlpha(label,1)
guiLabelSetColor(label,255,255,255)
guiLabelSetVerticalAlign(label,"top")
guiLabelSetHorizontalAlign(label,"left",false)
guiSetFont(label,"default-bold-small")
img = guiCreateStaticImage(8,23,453,5,"images/colors/c_red.jpg",false,gImage["playerList"])
guiSetAlpha(img,0.7)
label = guiCreateLabel(165,8,88,23,"Sozialer Status",false,gImage["playerList"])
guiSetAlpha(label,1)
guiLabelSetColor(label,255,255,255)
guiLabelSetVerticalAlign(label,"top")
guiLabelSetHorizontalAlign(label,"left",false)
guiSetFont(label,"default-bold-small")
label = guiCreateLabel(278,7,52,20,"Spielzeit",false,gImage["playerList"])
guiSetAlpha(label,1)
guiLabelSetColor(label,255,255,255)
guiLabelSetVerticalAlign(label,"top")
guiLabelSetHorizontalAlign(label,"left",false)
guiSetFont(label,"default-bold-small")
img = guiCreateStaticImage(151,28,3,268,"images/colors/c_red.jpg",false,gImage["playerList"])
guiSetAlpha(img,0.7)
img = guiCreateStaticImage(265,28,3,268,"images/colors/c_red.jpg",false,gImage["playerList"])
guiSetAlpha(img,0.7)
label = guiCreateLabel(346,8,62,16,"Telefonnr.",false,gImage["playerList"])
guiSetAlpha(label,1)
guiLabelSetColor(label,255,255,255)
guiLabelSetVerticalAlign(label,"top")
guiLabelSetHorizontalAlign(label,"left",false)
guiSetFont(label,"default-bold-small")
img = guiCreateStaticImage(333,28,3,268,"images/colors/c_red.jpg",false,gImage["playerList"])
guiSetAlpha(img,0.7)
img = guiCreateStaticImage(413,28,3,268,"images/colors/c_red.jpg",false,gImage["playerList"])
guiSetAlpha(img,0.7)
label = guiCreateLabel(421,8,57,15,"Ping",false,gImage["playerList"])
guiSetAlpha(label,1)
guiLabelSetColor(label,255,255,255)
guiLabelSetVerticalAlign(label,"top")
guiLabelSetHorizontalAlign(label,"left",false)
guiSetFont(label,"default-bold-small")
gImage["playerListBarBG"] = guiCreateStaticImage(472,0,12,playerListHeight,"images/colors/c_white.jpg",false,gImage["playerList"])
guiSetAlpha(gImage["playerListBarBG"],0.7)
gImage["playerListBarPull"] = guiCreateStaticImage(0,17,12,33,"images/colors/c_black.jpg",false,gImage["playerListBarBG"])
guiSetAlpha(gImage["playerListBarPull"],1)
gLabel["playerListPlayers"] = guiCreateLabel(8,296,100,18,"0/"..maxPlayers.." Spieler",false,gImage["playerList"])
guiSetAlpha(gLabel["playerListPlayers"],1)
guiLabelSetColor(gLabel["playerListPlayers"],255,255,255)
guiLabelSetVerticalAlign(gLabel["playerListPlayers"],"top")
guiLabelSetHorizontalAlign(gLabel["playerListPlayers"],"left",false)
guiSetFont(gLabel["playerListPlayers"],"default-bold-small")
for i, index in pairs ( factionColors ) do
if i > 0 then
local r, g, b = factionColors[i][1], factionColors[i][2], factionColors[i][3]
playerListFactionMembersLabel[i] = guiCreateLabel(8+75+(i)*20,296,20,18,"",false,gImage["playerList"])
guiSetAlpha(playerListFactionMembersLabel[i],1)
guiLabelSetColor(playerListFactionMembersLabel[i],r,g,b)
guiLabelSetVerticalAlign(playerListFactionMembersLabel[i],"top")
guiLabelSetHorizontalAlign(playerListFactionMembersLabel[i],"left",false)
guiSetFont(playerListFactionMembersLabel[i],"default-bold-small")
end
end
for i = 1, maxPlayersInCurList do
playerListLabels[i] = {}
playerListLabels[i][1] = guiCreateLabel(10,30 - 15 + 15 * i,141,16,"",false,gImage["playerList"])
playerListLabels[i][2] = guiCreateLabel(155,30 - 15 + 15 * i,141,16,"",false,gImage["playerList"])
playerListLabels[i][3] = guiCreateLabel(270,30 - 15 + 15 * i,141,16,"",false,gImage["playerList"])
playerListLabels[i][4] = guiCreateLabel(338,30 - 15 + 15 * i,141,16,"",false,gImage["playerList"])
playerListLabels[i][5] = guiCreateLabel(418,30 - 15 + 15 * i,141,16,"",false,gImage["playerList"])
for k = 1, 5 do
guiSetAlpha(playerListLabels[i][k],1)
guiLabelSetColor(playerListLabels[i][k],255,255,255)
guiLabelSetVerticalAlign(playerListLabels[i][k],"top")
guiLabelSetHorizontalAlign(playerListLabels[i][k],"left",false)
guiSetFont(playerListLabels[i][k],"default-bold-small")
end
guiLabelSetColor ( playerListLabels[i][2], 200, 200, 0 )
end
end
updatePlayerList ()
end
function updateFactionPlayerCount ()
factionCounter = {}
local players = getElementsByType ( "player" )
for key, index in pairs ( players ) do
local i = getElementData ( index, "fraktion" )
if i then
if not factionCounter[i] then
factionCounter[i] = {}
end
factionCounter[i][index] = true
end
end
for i, index in pairs ( factionColors ) do
if playerListFactionMembersLabel[i] then
local length = tableLength ( factionCounter[i] )
if length > 0 then
guiSetText ( playerListFactionMembersLabel[i], length )
else
guiSetText ( playerListFactionMembersLabel[i], "" )
end
end
end
end
function tableLength ( table )
local i = 0
if table then
for _, _ in pairs ( table ) do
i = i + 1
end
end
return i
end
function updatePlayerList ()
if guiGetVisible ( gImage["playerList"] ) then
updateFactionPlayerCount ()
guiSetText ( gLabel["playerListPlayers"], playerCount.."/"..maxPlayers.." Spieler" )
reFillPlayerList ()
playerListUpdateTimer = setTimer ( updatePlayerList, 1000, 1 )
end
end
function reAdjustPlayerListScollBar ()
pxPerPlayer = playerListHeight / ( playerCount )
barSize = maxPlayersInCurList / playerCount * playerListHeight
if barSize > playerListHeight then
barSize = 1
barYPos = 0
else
barYPos = ( curPlayerListPosition - 1 ) * ( pxPerPlayer )
end
guiSetSize ( gImage["playerListBarPull"], 17, barSize, false )
guiSetPosition ( gImage["playerListBarPull"], 0, barYPos, false )
end
function reFillPlayerList ()
for key, index in pairs ( playerListLabels ) do
for i = 1, 5 do
guiSetText ( playerListLabels[key][i], "" )
end
end
local i = 0
local k = 0
local name, rang, playingtime, ping, r, g, b
for z = -2, factioncount do
for key, index in pairs ( playersOnline ) do
if ( z == -2 and not getElementData ( index, "loggedin" ) ) or ( z == -1 and getElementData ( index, "loggedin" ) == 0 ) or getElementData ( index, "fraktion" ) == z then
i = i + 1
if k > maxPlayersInCurList then
break
end
if i >= curPlayerListPosition then
k = k + 1
name = getPlayerName ( index )
rang = getElementData ( index, "socialState" )
ping = tonumber ( getPlayerPing ( index ) )
if not rang then
rang = "Verbinden..."
nr = ""
playingtime = ""
r, g, b = 175, 175, 175
else
nr = getElementData ( index, "telenr" )
local faction = getElementData ( index, "fraktion" )
r, g, b = factionColors[faction][1], factionColors[faction][2], factionColors[faction][3]
playingtime = getElementData ( index, "playingtime" )
playingtime = math.floor ( playingtime / 60 )..":"..( playingtime - math.floor ( playingtime / 60 ) * 60 )
end
if getElementData ( index, "afk" ) then
guiSetText ( playerListLabels[k][1], name.."[AFK]" )
elseif not getElementData ( index, "afk" ) then
guiSetText ( playerListLabels[k][1], name )
end
guiSetText ( playerListLabels[k][1], name )
guiSetText ( playerListLabels[k][2], rang )
guiSetText ( playerListLabels[k][3], playingtime )
guiSetText ( playerListLabels[k][4], nr )
guiSetText ( playerListLabels[k][5], ping )
pr, pg, pb = getPingColor ( ping )
guiLabelSetColor ( playerListLabels[k][1], r, g, b )
guiLabelSetColor ( playerListLabels[k][5], pr, pg, pb )
end
end
end
end
end
function getPingColor ( ping )
if ping <= 50 then
return 0, 200, 0
elseif ping <= 150 then
return 200, 200, 0
else
return 200, 0, 0
end
end
function playerListScrollDown ()
if curPlayerListPosition < playerCount - maxPlayersInCurList + playersToScrollPerButton then
curPlayerListPosition = curPlayerListPosition + playersToScrollPerButton
else
curPlayerListPosition = playerCount
end
reFillPlayerList ()
end
function playerListScrollUp ()
if curPlayerListPosition > playersToScrollPerButton then
curPlayerListPosition = curPlayerListPosition - playersToScrollPerButton
else
curPlayerListPosition = 1
end
reFillPlayerList ()
end
function playerListKeyPressed ( key, state )
if state == "down" then
radioUpState = isControlEnabled ( "radio_next" )
radioDownState = isControlEnabled ( "radio_previous" )
weaponUpState = isControlEnabled ( "next_weapon" )
weaponDownState = isControlEnabled ( "previous_weapon" )
toggleControl ( "radio_next", false )
toggleControl ( "radio_previous", false )
toggleControl ( "next_weapon", false )
toggleControl ( "previous_weapon", false )
if isTimer ( playerListUpdateTimer ) then
killTimer ( playerListUpdateTimer )
end
scollBarAdjustTimer = setTimer ( reAdjustPlayerListScollBar, 50, -1 )
bindKey ( "mouse_wheel_up", "down", playerListScrollUp )
bindKey ( "mouse_wheel_down", "down", playerListScrollDown )
showPlayerList ()
else
toggleControl ( "radio_next", radioUpState )
toggleControl ( "radio_previous", radioDownState )
toggleControl ( "next_weapon", weaponUpState )
toggleControl ( "previous_weapon", weaponDownState )
killTimer ( scollBarAdjustTimer )
unbindKey ( "mouse_wheel_up", "down", playerListScrollUp )
unbindKey ( "mouse_wheel_down", "down", playerListScrollDown )
guiSetVisible ( gImage["playerList"], false )
end
end
bindKey ( "tab", "both", playerListKeyPressed )[/spoiler]
Alles anzeigen