.:HyPeX:. Posted September 27, 2013 Share Posted September 27, 2013 Just came out with the idea, we got a 32 Slot server on our clan, is there a function to get player count? (i know i could count them with like a joinquit and a table or local) but i'm asking if there is a function to get current player count in the server. This is to let only 31 players join and reserve a slot for the members (via getPlayerName on join). Thanks HyPeX Link to comment
glowdemon1 Posted September 27, 2013 Share Posted September 27, 2013 https://wiki.multitheftauto.com/wiki/GetPlayerCount - or you could use getElementsByType, but getPlayerCount would be easiler to use. Link to comment
.:HyPeX:. Posted September 28, 2013 Author Share Posted September 28, 2013 Found this problem.. i want to find the lastest player who joined who hasnt got the LxG in its name(to avoid kicking LxG players) How could i do the opposite into a table? like this? local LastLogued = table.gmatch(Players, ~LxG) Link to comment
.:HyPeX:. Posted September 28, 2013 Author Share Posted September 28, 2013 I've been working alot since this.. this is my end script.. (not sure if it will work the actual search of the name i asked on the previous post.. but if it does) ----Reservation-Script-by-HyPeX-- ----Locals---- local Players = {} local g_PlayerCount = getPlayerCount() local LastLogued = table.gmatch(Players, ~LxG) local TablePos = getElementData( source, TablePosition ) local accPlayer = getPlayerAccount( source ) ------------------------------- ----Messages of Startup---- outputChatBox ("#00aaff[Reservation]: 32nd Slot is Now reserved for LxG Members!",root, 255, 255, 255, true) ------------------------------- ----Functions--- antiFake = {} function credits(onPlayerJoin) local Name = getPlayerName(source) setElementData( accPlayer, TablePosition, math.random( 99999 )) table.insert(Players, TablePos, Name) if g_PlayerCount == 31 then if string.match(Name, LxG) = LxG then outputChatBox( "Welcome LxG Player, You are joining in a reserved Slot", source, 55, 125, 255 ) antiFake[source] = setTimer(function(source) antiFake[source] = nil end, 1000*60*2, 1, source) if string.match(LastLogued, LxG) then kickPlayer (LastLogued, Reservation, you were kicked becouse you were the lastest player who joined, sorry ) else kickPlayer(source, Reservation, This slot is reserved for a LxG Member, we're sorry) end else outputChatBox ( "Reserved Slot for LxG Members Script Online", source, 55, 125, 255 ) end end addEventHandler("onPlayerJoin", root, credits) function antiFakeLogin() Player = getPlayerFromName( source ) if isTimer(antiFake[source]) then outputchatbox ( "[Reservation]:"..Player.."was kicked for trying to fake the reserved slot!", 0, 175 ,255 ) kickPlayer( source, Reservation, Dont fake the reservation slot! ) end end addEventHandler("onPlayerChangeNick", getRootElement(), antiFakeLogin) addEventHandler ( "onResourceStop", resourceRoot, table.remove( Players, TablePos ) removeElementData( source, TablePosition ) addEventHandler ( "onPlayerQuit", root, onDeleteTables ) Link to comment
xXMADEXx Posted September 28, 2013 Share Posted September 28, 2013 you need to put messages in a string. Otherwise, the server will be looking for an invalid variable. Link to comment
.:HyPeX:. Posted September 28, 2013 Author Share Posted September 28, 2013 you need to put messages in a string. Otherwise, the server will be looking for an invalid variable. how? this should be the totally fixed end (without saying that) ----Reservation-Script-by-HyPeX-- ----Locals---- local Players = {} local g_PlayerCount = getPlayerCount() local LastLogued = table.match(Players, ~=LxG, 99999) local TablePos = getElementData( source, TablePosition ) local accPlayer = getPlayerAccount( source ) local Name = getPlayerName(source) ------------------------------- ----Messages of Startup---- outputChatBox ("#00aaff[Reservation]: 32nd Slot is Now reserved for LxG Members!",root, 255, 255, 255, true) ------------------------------- ----Functions--- antiFake = {} function credits(onPlayerJoin) setElementData( accPlayer, TablePosition, math.random( 99999 )) table.insert(Players, TablePos, Name) if g_PlayerCount == 2 then if string.match(Name, LxG) = LxG then outputChatBox( "Welcome LxG Player, You are joining in a reserved Slot", source, 55, 125, 255 ) antiFake[source] = setTimer(function(source) antiFake[source] = nil end, 1000*60*2, 1, source) kickPlayer(LastLogued, Reservation, you were kicked becouse you were the lastest player who joined. sorry ) else kickPlayer(source, Reservation, this slot is reserved for LxG Members. sorry ) end else outputChatBox ( "Reserved Slot for LxG Members Script Online", source, 55, 125, 255 ) end end addEventHandler("onPlayerJoin", root, credits) function antiFakeLogin() Player = getPlayerFromName( source ) if isTimer(antiFake[source]) then outputchatbox ( "[Reservation]:"..Player.."was kicked for trying to fake the reserved slot!", 0, 175 ,255 ) kickPlayer( source, Reservation, Dont fake the reservation slot! ) end end addEventHandler("onPlayerChangeNick", getRootElement(), antiFakeLogin) function ClearPlayerLeaving table.remove( Players, TablePos ) removeElementData( accPlayer, TablePosition ) end addEventHandler ( "onPlayerQuit", resourceRoot, ClearPlayerLeaving ) Link to comment
.:HyPeX:. Posted September 28, 2013 Author Share Posted September 28, 2013 Okay just totally missed the points, turn out i cant use the string to read a table, how can i use the same function string.match does on a table? Thanks HyPeX Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now