Jump to content

is player connected


LagParty

Recommended Posts

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

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

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