McFree Posted March 14, 2016 Share Posted March 14, 2016 В общем проблема такая, пишу возрождение после смерти через определенное время. При выходе из игры во время это времени ожидания то оно записывается в БД MySQL и собственно при заходе продолжается. В общем сам проблемный код заключается в получении информации с БД. Пишет что не воспринимает nil параметр, хотя в БД указано 50 в типе float. И вторая проблема в спавне игрока в определенной позиции. По истечению времени ожидания надпись пропадает и остается лишь экран ожидания: local respawnDelay = tonumber( get( 'respawn_delay' ) ) or 3 local wastedTimes = { } addEventHandler( "onResourceStart", resourceRoot, function( ) -- clients need this setting local CharacterDelay = exports.sql:query_assoc( "SELECT TimeToRespawn FROM characters WHERE characterID = " .. tonumber( getCharacterID( player ) ) ) if CharacterDelay then setElementData( source, "respawnDelay", respawnDelay ) end end ) addEventHandler( "onPlayerWasted", root, function( ) -- save when the player died to avoid anyone bypassing our delay wastedTimes[ source ] = getTickCount( ) end ) addEventHandler( "onPlayerQuit", root, function( ) wastedTimes[ source ] = nil if exports.sql:query_free( "UPDATE characters SET TimeToRespawn = " .. wastedTimes[ source ] .. " WHERE characterID = " .. tonumber( getCharacterID( player ) ) ) then return true end end ) addEvent( "onPlayerRespawn", true ) addEventHandler( "onPlayerRespawn", root, function( ) if source == client then -- we only want players who're actually dead and logged in if isLoggedIn( source ) and isPedDead( source ) then -- check if we can already respawn if wastedTimes[ source ] and getTickCount( ) - wastedTimes[ source ] >= respawnDelay * 1000 then -- hide the screen fadeCamera( source, false, 1 ) -- spawn him at the hospital setTimer( function( source ) if isElement( source ) and isLoggedIn( source ) and isPedDead( source ) then spawnPlayer( source, -2654, 634, 14.5, 180, getElementModel( source ), 0, 0 ) fadeCamera( source, true ) setCameraTarget( source, source ) setCameraInterior( source, 0 ) end end 1200, 1, source ) -- reset the wasted time counter wastedTimes[ source ] = nil end end end 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