LagParty Posted December 13, 2009 Share Posted December 13, 2009 where is this function? i cant seem to find it Link to comment
JohnDoe91286 Posted December 14, 2009 Share Posted December 14, 2009 There is no such function. What exactly are you trying to do? Link to comment
LagParty Posted December 14, 2009 Author Share Posted December 14, 2009 simple: function isPlayerConnected(theplayer) <- returns true if the player is connected, false if its not. theplayer is a player element. Any substitute will do. Link to comment
50p Posted December 14, 2009 Share Posted December 14, 2009 If a player is not connected you will not get player element from nowhere. Link to comment
subenji99 Posted December 14, 2009 Share Posted December 14, 2009 If for some silly reason you are storing player elements in a variable and not cleaning that up when they quit then the variable will assert a "bad element pointer" error. But if you are really desperate for such a function then isElement(theVariable) will accomplish this. Link to comment
robhol Posted December 14, 2009 Share Posted December 14, 2009 function isPlayerOnline(NAME) return getPlayerFromName(NAME) ~= false; end --usage if isPlayerOnline("robhol") then -- ... end That's another way to do it. But you really should make an onPlayerQuit event handler, and destroy all script references to the player and their element, when they quit the game. Otherwise you get memory leaks, etc., and we don't want that, do we? And what were you supposed to use this for? Usually when a request this strange pops up, there's something in a script that can be improved. Link to comment
LagParty Posted December 14, 2009 Author Share Posted December 14, 2009 Thanks for your help. I'm converting an old sa-mp business-script to mta (and adding all the bonuses of the new system). The problem comes when a player leaves the server, because after that you have 5 minutes to come back or else your business will be sold. Also, the other players can't buy that player's business if he's not connected. This system helps players that are dropped from the server for any reason (time-out, crash, etc). Anyways, here's the code: addEventHandler("onPlayerQuit", rootElem, function() playerMarker[source] = nil setTimer(sellAllProperties, 300000, 1, source, getPlayerName(source), getPlayerMoney(source)) -- 5 minutes to come back end ) function sellAllProperties(playerID, pname, pmoney) local player = getPlayerFromName(pname) if player ~= false then return end -- if he's still connected then stop for mark,prop in pairs(properties) do if prop["owner"] == playerID then pmoney = pmoney + prop["price"]*0.5 prop["owner"] = nil setBlipColor(prop["blip"],0,255,0,180) setMarkerColor(mark,0,255,0,150) end end executeSQLUpdate("playerinfo", string.format("money = %d", pmoney), string.format("name = '%s'", pname) ) end 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