isa_Khamdan Posted August 20, 2013 Share Posted August 20, 2013 Hello , I want to load the PlayTime from AccountData to another script and check if the play time is 30 hours or more to be able to do a function so can anyone tell me to do that? This will load the PlayTime from the AccountData local time = getAccountData ( playeraccount, "PlayTime" ) local hou = getAccountData ( playeraccount, "PlayTime-hour") local min = getAccountData ( playeraccount, "PlayTime-min") local sec = getAccountData ( playeraccount, "PlayTime-sec") I want help in the rest Link to comment
Castillo Posted August 20, 2013 Share Posted August 20, 2013 Just do: if ( hou >= 30 ) then -- Do your thing here. end Link to comment
isa_Khamdan Posted August 20, 2013 Author Share Posted August 20, 2013 Just do: if ( hou >= 30 ) then -- Do your thing here. end It say error " compare number with Boolean" ? Link to comment
isa_Khamdan Posted August 20, 2013 Author Share Posted August 20, 2013 This is the code ( Not the full code only the part I edited ) addEvent( 'HOUSE_Buy', true ); addEventHandler( 'HOUSE_Buy', root, function( cost, key ) local accName = getAccountName( getPlayerAccount( client ) ); local houseCounter = 0; local time = getAccountData ( playeraccount, "PlayTime" ) local hou = getAccountData ( playeraccount, "PlayTime-hour") local min = getAccountData ( playeraccount, "PlayTime-min") local sec = getAccountData ( playeraccount, "PlayTime-sec") for i, v in ipairs( getElementsByType( 'marker', getResourceRootElement() ) ) do if getElementData( v, 'HS_INFO' )then local owner = getElementData( v, 'HS_INFO' )[7]; if owner == accName and ( hou >= 30 ) then houseCounter = houseCounter + 1; end; end; end; Link to comment
Castillo Posted August 20, 2013 Share Posted August 20, 2013 Means that "hou" is returning false or nil. Link to comment
isa_Khamdan Posted August 20, 2013 Author Share Posted August 20, 2013 Means that "hou" is returning false or nil. That's the PlayTime Script I think there is a mistake in getting playtime in the code I edited --[[ ------------------------------------------------- original script credits to Yakuza.Real and solidsnake and kenix viewtopic.php?f=91&t=40132 ------------------------------------------------- booo just fix it ]] exports.scoreboard:addScoreboardColumn('PlayTime') local t = { } function checkValues( source,arg1,arg2) if (arg2 >= 60) then t[ source ][ 'min' ] = tonumber( t[ source ][ 'min' ] or 0 ) + 1 t[ source ][ 'sec' ] = 0 end if (arg1 >= 60) then t[ source ][ 'min' ] = 0 t[ source ][ 'hour' ] = tonumber( t[ source ][ 'hour' ] or 0 ) + 1 end return arg1, arg2 end setTimer( function( ) for _, v in pairs( getElementsByType( "player" ) ) do if (not t[ v ]) then t[ v ] = { ["hour"] = 0, ["min"] = 0, ["sec"] = 0 } end t[ v ][ 'sec' ] = tonumber( t[ v ][ 'sec' ] or 0 ) + 1 local min,sec = checkValues ( v, t[ v ][ 'min' ] or 0, t[ v ][ 'sec' ] or 0 ) local hour = tonumber( t[ v ][ 'hour' ] or 0 ) setElementData( v, "PlayTime", tostring( hour )..':'..tostring( min )..':'..tostring( sec ) ) end end, 1000, 0 ) function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local sValue = getElementData( source,'PlayTime' ) local hour = tonumber( t[ source ][ 'hour' ] or 0 ) local min = tonumber( t[ source ][ 'min' ] or 0 ) local sec = tonumber( t[ source ][ 'sec' ] or 0 ) setAccountData ( playeraccount, "PlayTime-hour", tostring(hour) ) setAccountData ( playeraccount, "PlayTime-min", tostring(min) ) setAccountData ( playeraccount, "PlayTime-sec", tostring(sec) ) setAccountData ( playeraccount, "PlayTime", tostring(sValue) ) end t[ source ] = nil end function onPlayerLogin (_, playeraccount ) if ( playeraccount ) then local time = getAccountData ( playeraccount, "PlayTime" ) local hou = getAccountData ( playeraccount, "PlayTime-hour") local min = getAccountData ( playeraccount, "PlayTime-min") local sec = getAccountData ( playeraccount, "PlayTime-sec") if ( time ) then setElementData ( source, "PlayTime", time ) t[ source ]["hour"] = tonumber(hou) t[ source ]["min"] = tonumber(min) t[ source ]["sec"] = tonumber(sec) else setElementData ( source, "PlayTime",0 ) setAccountData ( playeraccount, "PlayTime",0 ) end end end addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) addEventHandler ( "onPlayerLogin", root, onPlayerLogin ) Link to comment
Castillo Posted August 20, 2013 Share Posted August 20, 2013 Found your mistake, you didn't define "playeraccount" on the "HOUSE_Buy" event. addEvent( 'HOUSE_Buy', true ); addEventHandler( 'HOUSE_Buy', root, function( cost, key ) local playeraccount = getPlayerAccount( client ) local accName = getAccountName( playeraccount ); local houseCounter = 0; local time = getAccountData ( playeraccount, "PlayTime" ) local hou = getAccountData ( playeraccount, "PlayTime-hour") local min = getAccountData ( playeraccount, "PlayTime-min") local sec = getAccountData ( playeraccount, "PlayTime-sec") for i, v in ipairs( getElementsByType( 'marker', getResourceRootElement() ) ) do if getElementData( v, 'HS_INFO' )then local owner = getElementData( v, 'HS_INFO' )[7]; if owner == accName and ( hou >= 30 ) then houseCounter = houseCounter + 1; end; end; end; Link to comment
isa_Khamdan Posted August 20, 2013 Author Share Posted August 20, 2013 Found your mistake, you didn't define "playeraccount" on the "HOUSE_Buy" event. addEvent( 'HOUSE_Buy', true ); addEventHandler( 'HOUSE_Buy', root, function( cost, key ) local playeraccount = getPlayerAccount( client ) local accName = getAccountName( playeraccount ); local houseCounter = 0; local time = getAccountData ( playeraccount, "PlayTime" ) local hou = getAccountData ( playeraccount, "PlayTime-hour") local min = getAccountData ( playeraccount, "PlayTime-min") local sec = getAccountData ( playeraccount, "PlayTime-sec") for i, v in ipairs( getElementsByType( 'marker', getResourceRootElement() ) ) do if getElementData( v, 'HS_INFO' )then local owner = getElementData( v, 'HS_INFO' )[7]; if owner == accName and ( hou >= 30 ) then houseCounter = houseCounter + 1; end; end; end; People with less than 30 hours PlayTime still can buy houses? is there anythings wrong with the code? Link to comment
Castillo Posted August 21, 2013 Share Posted August 21, 2013 Well, that's not the whole function. Link to comment
isa_Khamdan Posted August 21, 2013 Author Share Posted August 21, 2013 (edited) Deleted Edited August 21, 2013 by Guest Link to comment
Castillo Posted August 21, 2013 Share Posted August 21, 2013 addEvent( 'HOUSE_Buy', true ); addEventHandler( 'HOUSE_Buy', root, function( cost, key ) local playeraccount = getPlayerAccount( client ) local accName = getAccountName( playeraccount ); local houseCounter = 0; for i, v in ipairs( getElementsByType( 'marker', getResourceRootElement() ) ) do if getElementData( v, 'HS_INFO' ) then local owner = getElementData( v, 'HS_INFO' )[7]; if owner == accName then houseCounter = houseCounter + 1; end; end; end; local time = getAccountData ( playeraccount, "PlayTime" ) local hou = getAccountData ( playeraccount, "PlayTime-hour") local min = getAccountData ( playeraccount, "PlayTime-min") local sec = getAccountData ( playeraccount, "PlayTime-sec") if houseCounter >= tonumber( get( 'playerHouseCounter' ) ) or ( hou < 30 ) then outputChatBox( '* You can not buy this house because you already have one or you have not reached 30 hours Play Time!', client, 255, 51, 36, true ); setPedFrozen( client, false ); return false; end; if getPlayerMoney( client ) >= tonumber( cost ) then outputChatBox( '* Key has been set to #00FF00'..key, client, 255, 51, 36, true ); outputChatBox( '* Congratulations! You have bought a house!', client, 255, 255, 0 ); sql.Query( "UPDATE house_data SET owner = '"..accName.."', key = '"..key.."' WHERE ID = ?", getElementData( client, 'mrk_in' ) ); takePlayerMoney( client, cost ); local mrk = getHouseByID( getElementData( client, 'mrk_in' ) ); local t = {}; for i = 1, 6 do t[i] = getElementData( mrk, 'HS_INFO' )[i]; end; t[7] = accName; t[8] = key; t[9] = getElementData( client, 'mrk_in' ); setElementData( mrk, 'HS_INFO', { t[1], t[2], t[3], t[4], t[5], t[6], t[7], t[8], t[9] } ); setMarkerColor( mrk, 255, 51, 36, 150 ); setTimer( onPlayerHouseMarkerHit, 50, 1, client, mrk, true ); else outputChatBox( '* You do not have enough money to buy this house!', client, 255, 51, 36 ); onPlayerHouseMarkerHit( client, getHouseByID( getElementData( client, 'mrk_in' ) ), true ); end; end ); Link to comment
isa_Khamdan Posted August 21, 2013 Author Share Posted August 21, 2013 addEvent( 'HOUSE_Buy', true ); addEventHandler( 'HOUSE_Buy', root, function( cost, key ) local playeraccount = getPlayerAccount( client ) local accName = getAccountName( playeraccount ); local houseCounter = 0; for i, v in ipairs( getElementsByType( 'marker', getResourceRootElement() ) ) do if getElementData( v, 'HS_INFO' ) then local owner = getElementData( v, 'HS_INFO' )[7]; if owner == accName then houseCounter = houseCounter + 1; end; end; end; local time = getAccountData ( playeraccount, "PlayTime" ) local hou = getAccountData ( playeraccount, "PlayTime-hour") local min = getAccountData ( playeraccount, "PlayTime-min") local sec = getAccountData ( playeraccount, "PlayTime-sec") if houseCounter >= tonumber( get( 'playerHouseCounter' ) ) or ( hou < 30 ) then outputChatBox( '* You can not buy this house because you already have one or you have not reached 30 hours Play Time!', client, 255, 51, 36, true ); setPedFrozen( client, false ); return false; end; if getPlayerMoney( client ) >= tonumber( cost ) then outputChatBox( '* Key has been set to #00FF00'..key, client, 255, 51, 36, true ); outputChatBox( '* Congratulations! You have bought a house!', client, 255, 255, 0 ); sql.Query( "UPDATE house_data SET owner = '"..accName.."', key = '"..key.."' WHERE ID = ?", getElementData( client, 'mrk_in' ) ); takePlayerMoney( client, cost ); local mrk = getHouseByID( getElementData( client, 'mrk_in' ) ); local t = {}; for i = 1, 6 do t[i] = getElementData( mrk, 'HS_INFO' )[i]; end; t[7] = accName; t[8] = key; t[9] = getElementData( client, 'mrk_in' ); setElementData( mrk, 'HS_INFO', { t[1], t[2], t[3], t[4], t[5], t[6], t[7], t[8], t[9] } ); setMarkerColor( mrk, 255, 51, 36, 150 ); setTimer( onPlayerHouseMarkerHit, 50, 1, client, mrk, true ); else outputChatBox( '* You do not have enough money to buy this house!', client, 255, 51, 36 ); onPlayerHouseMarkerHit( client, getHouseByID( getElementData( client, 'mrk_in' ) ), true ); end; end ); It doesn't work you get frozen in your place even if you have enough money and 30 hours Play Time. Error : attempt to compare string with number. Link to comment
Castillo Posted August 21, 2013 Share Posted August 21, 2013 Thing is, the script that saves time saves it only on quit, so it won't be updated when you try to buy the house. Link to comment
isa_Khamdan Posted August 21, 2013 Author Share Posted August 21, 2013 Thing is, the script that saves time saves it only on quit, so it won't be updated when you try to buy the house. Can I edit it so it will update the time on marker hit? function onPlayerHouseMarkerHit( player, mrk, cursor ) local acc = getPlayerAccount( player ); if isGuestAccount( acc ) then outputChatBox( '* You must be logged in to get in this house!', player, 255, 51, 36 ); setElementData( player, 'mrk_in', nil ); setPedFrozen( player, false ); return false; end; local tts = { [1] = true, [2] = false, [3] = false, [4] = true, [5] = false, [6] = false }; if isObjectInACLGroup( 'user.'..getAccountName( acc ), aclGetGroup( 'Admin' ) ) then tts[6] = true; tts[2] = true; tts[3] = true; tts[5] = true; end; local owner = getElementData( mrk, 'HS_INFO' )[7]; local accName = getAccountName( acc ); if owner == accName then tts[1] = false; tts[2] = true; tts[3] = true; tts[4] = true; tts[5] = true; end; if owner ~= accName and owner ~= '' then tts[1] = false; end; if owner == '' then if isObjectInACLGroup( 'user.'..getAccountName( acc ), aclGetGroup( 'Admin' ) ) then tts[4] = true; else tts[4] = false; end; end; tts[7] = getElementData( mrk, 'HS_INFO' )[9]; tts[8] = getElementData( mrk, 'HS_INFO' )[7]; tts[9] = getElementData( mrk, 'HS_INFO' )[6]; triggerClientEvent( player, 'openHouseManagementWnd', root, tts, cursor ); end; Link to comment
Castillo Posted August 21, 2013 Share Posted August 21, 2013 No need for that, you can get the element data. addEvent( 'HOUSE_Buy', true ); addEventHandler( 'HOUSE_Buy', root, function( cost, key ) local playeraccount = getPlayerAccount( client ) local accName = getAccountName( playeraccount ); local houseCounter = 0; for i, v in ipairs( getElementsByType( 'marker', getResourceRootElement() ) ) do if getElementData( v, 'HS_INFO' ) then local owner = getElementData( v, 'HS_INFO' )[7]; if owner == accName then houseCounter = houseCounter + 1; end; end; end; local playTime = getElementData ( client, "PlayTime" ) or "0:0:0" local playTimeSplitted = split ( playTime, ":" ) local hours = 0 if ( playTimeSplitted ) then hours = tonumber ( playTimeSplitted [ 1 ] ) end if houseCounter >= tonumber( get( 'playerHouseCounter' ) ) or ( hours < 30 ) then outputChatBox( '* You can not buy this house because you already have one or you have not reached 30 hours Play Time!', client, 255, 51, 36, true ); setPedFrozen( client, false ); return false; end; if getPlayerMoney( client ) >= tonumber( cost ) then outputChatBox( '* Key has been set to #00FF00'..key, client, 255, 51, 36, true ); outputChatBox( '* Congratulations! You have bought a house!', client, 255, 255, 0 ); sql.Query( "UPDATE house_data SET owner = '"..accName.."', key = '"..key.."' WHERE ID = ?", getElementData( client, 'mrk_in' ) ); takePlayerMoney( client, cost ); local mrk = getHouseByID( getElementData( client, 'mrk_in' ) ); local t = {}; for i = 1, 6 do t[i] = getElementData( mrk, 'HS_INFO' )[i]; end; t[7] = accName; t[8] = key; t[9] = getElementData( client, 'mrk_in' ); setElementData( mrk, 'HS_INFO', { t[1], t[2], t[3], t[4], t[5], t[6], t[7], t[8], t[9] } ); setMarkerColor( mrk, 255, 51, 36, 150 ); setTimer( onPlayerHouseMarkerHit, 50, 1, client, mrk, true ); else outputChatBox( '* You do not have enough money to buy this house!', client, 255, 51, 36 ); onPlayerHouseMarkerHit( client, getHouseByID( getElementData( client, 'mrk_in' ) ), true ); end; end ); Link to comment
isa_Khamdan Posted August 21, 2013 Author Share Posted August 21, 2013 No need for that, you can get the element data. addEvent( 'HOUSE_Buy', true ); addEventHandler( 'HOUSE_Buy', root, function( cost, key ) local playeraccount = getPlayerAccount( client ) local accName = getAccountName( playeraccount ); local houseCounter = 0; for i, v in ipairs( getElementsByType( 'marker', getResourceRootElement() ) ) do if getElementData( v, 'HS_INFO' ) then local owner = getElementData( v, 'HS_INFO' )[7]; if owner == accName then houseCounter = houseCounter + 1; end; end; end; local playTime = getElementData ( client, "PlayTime" ) or "0:0:0" local playTimeSplitted = split ( playTime, ":" ) local hours = 0 if ( playTimeSplitted ) then hours = tonumber ( playTimeSplitted [ 1 ] ) end if houseCounter >= tonumber( get( 'playerHouseCounter' ) ) or ( hours < 30 ) then outputChatBox( '* You can not buy this house because you already have one or you have not reached 30 hours Play Time!', client, 255, 51, 36, true ); setPedFrozen( client, false ); return false; end; if getPlayerMoney( client ) >= tonumber( cost ) then outputChatBox( '* Key has been set to #00FF00'..key, client, 255, 51, 36, true ); outputChatBox( '* Congratulations! You have bought a house!', client, 255, 255, 0 ); sql.Query( "UPDATE house_data SET owner = '"..accName.."', key = '"..key.."' WHERE ID = ?", getElementData( client, 'mrk_in' ) ); takePlayerMoney( client, cost ); local mrk = getHouseByID( getElementData( client, 'mrk_in' ) ); local t = {}; for i = 1, 6 do t[i] = getElementData( mrk, 'HS_INFO' )[i]; end; t[7] = accName; t[8] = key; t[9] = getElementData( client, 'mrk_in' ); setElementData( mrk, 'HS_INFO', { t[1], t[2], t[3], t[4], t[5], t[6], t[7], t[8], t[9] } ); setMarkerColor( mrk, 255, 51, 36, 150 ); setTimer( onPlayerHouseMarkerHit, 50, 1, client, mrk, true ); else outputChatBox( '* You do not have enough money to buy this house!', client, 255, 51, 36 ); onPlayerHouseMarkerHit( client, getHouseByID( getElementData( client, 'mrk_in' ) ), true ); end; end ); Thanks A lot it works great now 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