Jump to content

كود حفظ الداتا لما اللاعب يخرج


Recommended Posts

السلام عليكم شباب عاوز الكود اللي يحفظ الداتا لما اللاعب يسيب السيرفر و يرجعها ليه تاني لما يرجع السيرفر و شكرا 

 

Just now, mohamed hussein said:

السلام عليكم شباب عاوز الكود اللي يحفظ الداتا لما اللاعب يسيب السيرفر و يرجعها ليه تاني لما يرجع السيرفر و شكرا 

 

@#BrosS

Link to comment
Just now, mohamed hussein said:

السلام عليكم شباب عاوز الكود اللي يحفظ الداتا لما اللاعب يسيب السيرفر و يرجعها ليه تاني لما يرجع السيرفر و شكرا 

 

@#BrosS

setElementData
getElementData

-- or

getPlayerAccount
isGuestAccount
setAccountData
getAccountData

 

Link to comment

SQL , setAccountData , database

'onPlayerQuit'
'onPlayerLogin'
"onResourceStart"
"onResourceStop"
-- fist suggestion
dbConnect
dbExec
dbPoll
dbQuery
-- sdfkhsdfkl
executeSQLQuery
-- dkshfskdfhqklSFFKLMSDGF
setAccountData

 

@Killer Project الداتا تروح لما اللاعب يطلع او المود يتوقف

Link to comment
Just now, #_iMr.[E]coo said:

executeSQLQuery
getPlayerSerial
"onPlayerJoin"
"onPlayerQuit"
"onResourceStop"
"onResourceStart"

 

ممكن تعطيني مثال هو الكود في مود سيريال انزله لك و تسويلي حفظ؟

1 minute ago, Killer Project said:

setElementData
getElementData

-- or

getPlayerAccount
isGuestAccount
setAccountData
getAccountData

 

ممكن تعطيني مثال هو الكود في مود سيريال انزله لك و تسويلي حفظ؟

1 minute ago, #BrosS said:

SQL , setAccountData , database


'onPlayerQuit'
'onPlayerLogin'
"onResourceStart"
"onResourceStop"
-- fist suggestion
dbConnect
dbExec
dbPoll
dbQuery
-- sdfkhsdfkl
executeSQLQuery
-- dkshfskdfhqklSFFKLMSDGF
setAccountData

 

ممكن تعطيني مثال هو الكود في مود سيريال انزله لك و تسويلي حفظ؟

 

Link to comment
Just now, #BrosS said:

SQL , setAccountData , database


'onPlayerQuit'
'onPlayerLogin'
"onResourceStart"
"onResourceStop"
-- fist suggestion
dbConnect
dbExec
dbPoll
dbQuery
-- sdfkhsdfkl
executeSQLQuery
-- dkshfskdfhqklSFFKLMSDGF
setAccountData

 

@Killer Project الداتا تروح لما اللاعب يطلع او المود يتوقف


بالأكونت ما تروح الداتا ذذ

Link to comment
blipq = {}
function vehLocation(player,com)
if isPedInVehicle ( player ) then
daveh = getPedOccupiedVehicle(player)
blipq[getPlayerName(player)] = createBlipAttachedTo(daveh,46,1,0,0,0,255,0,99999.0,player)
setElementData(daveh,"parked",true)
end
end
addCommandHandler("سيارتي",vehLocation)

function mohamed(veh)
if getElementData(veh,"parked") == true then
setElementData(veh,"parked",false)
destroyElement(blipq[getPlayerName(source)])
end
end
addEventHandler("onPlayerVehicleEnter",getRootElement(),mohamed)
 

شباب الكود اهو عاوز احفظو بحيث الداتا ما تروح 

Link to comment
local Save = {};
function isAccountExists( Account )
	local DB = dbPoll(dbQuery(TestDB, "SELECT * FROM test WHERE PlayerAccount = ?", Account), -1);
	if type(DB) == "table" and #DB ~= 0 and tostring(DB[1]["PlayerAccount"]) == tostring(Account) then
		return true
	end
end

addEventHandler( "onResourceStart", resourceRoot,
function ()
	TestDB = dbConnect("sqlite","test.db");
	dbExec(TestDB, "CREATE TABLE IF NOT EXISTS test ( PlayerAccount, parked )" );
	for k,v in ipairs(getElementsByType("player")) do
		if not isGuestAccount(getPlayerAccount(v)) then
			local row = dbPoll(dbQuery(TestDB, "SELECT * FROM test WHERE PlayerAccount = ?", getAccountName(getPlayerAccount(v))), -1);
			if not isAccountExists(getAccountName(getPlayerAccount(v))) then
				dbExec(TestDB, "INSERT INTO test ( PlayerAccount, parked ) VALUES( ?, ? )", getAccountName(getPlayerAccount(v)), "0");
			else
				for index, value in ipairs(row) do
					if not (Save[v]) then 
						Save[v] = {["data"] = false};
					end
					Save[v]["data"] = value["parked"]
				end
			end
		end
	end	
end );


addEventHandler("onPlayerQuit", root,
function ()
	local playeraccount = getPlayerAccount(source);
	if playeraccount and not isGuestAccount(playeraccount) then
		local data = Save[source]["data"] or false
		local row = dbPoll (dbQuery(TestDB, "SELECT * FROM test WHERE PlayerAccount = ?",  getAccountName(playeraccount) ), -1)
		if isAccountExists(getAccountName(playeraccount)) then
			dbExec(TestDB, "UPDATE test SET parked = ? WHERE PlayerAccount = ?", tostring(Save[source]["data"]), getAccountName(playeraccount));
		end
	end
	Save[source] = nil
end );

addEventHandler("onPlayerLogin", root,
function ( _, playeraccount)
	if playeraccount then
		local time = dbPoll ( dbQuery(TestDB, "SELECT * FROM test WHERE PlayerAccount = ?",  getAccountName(playeraccount) ), -1);
		if isAccountExists(getAccountName(playeraccount)) then
			for index, value in ipairs(time) do
				setElementData (source,"parked", value["parked"] );
				Save[source]["data"] = value["parked"];
			end
		else
			setElementData (source, "parked",false )
			dbExec(TestDB, "INSERT INTO test ( PlayerAccount, parked ) VALUES( ?, ? )", getAccountName(playeraccount), "0");
			Save[source]["data"] = false
		end
	end
end );

addEventHandler("onResourceStop", resourceRoot, 
function ()
    for k,v in ipairs(getElementsByType("player")) do
	    if not isGuestAccount(getPlayerAccount(v)) then
			local data = Save[v]["data"] or false
			if isAccountExists(getAccountName(getPlayerAccount(v))) then
				dbExec(TestDB, "UPDATE test SET parked = ? WHERE PlayerAccount = ?", data, getAccountName(getPlayerAccount(v)) )
			end
		end
	end
end );

Author : MoDeR2014

#BrosS : تخريب  

Edited by #BrosS
fix something
Link to comment
3 minutes ago, mohamed hussein said:

blipq = {}
function vehLocation(player,com)
if isPedInVehicle ( player ) then
daveh = getPedOccupiedVehicle(player)
blipq[getPlayerName(player)] = createBlipAttachedTo(daveh,46,1,0,0,0,255,0,99999.0,player)
setElementData(daveh,"parked",true)
end
end
addCommandHandler("سيارتي",vehLocation)

function mohamed(veh)
if getElementData(veh,"parked") == true then
setElementData(veh,"parked",false)
destroyElement(blipq[getPlayerName(source)])
end
end
addEventHandler("onPlayerVehicleEnter",getRootElement(),mohamed)
 

شباب الكود اهو عاوز احفظو بحيث الداتا ما تروح 

@#_iMr.[E]coo   @Killer Project   @#BrosS

2 minutes ago, #BrosS said:

local Save = {};
function isAccountExists( Account )
	local DB = dbPoll(dbQuery(TestDB, "SELECT * FROM test WHERE PlayerAccount = ?", Account), -1);
	if type(DB) == "table" and #DB ~= 0 and tostring(DB[1]["PlayerAccount"]) == tostring(Account) then
		return true
	end
end

addEventHandler( "onResourceStart", resourceRoot,
function ()
	TestDB = dbConnect("sqlite","test.db");
	dbExec(TestDB, "CREATE TABLE IF NOT EXISTS test ( PlayerAccount, parked )" );
	for k,v in ipairs(getElementsByType("player")) do
		if not isGuestAccount(getPlayerAccount(v)) then
			local row = dbPoll(dbQuery(TestDB, "SELECT * FROM test WHERE PlayerAccount = ?", getAccountName(getPlayerAccount(v))), -1);
			if not isAccountExists(getAccountName(getPlayerAccount(v))) then
				dbExec(TestDB, "INSERT INTO test ( PlayerAccount, parked ) VALUES( ?, ? )", getAccountName(getPlayerAccount(v)), "0");
			else
				for index, value in ipairs(row) do
					if not (Save[v]) then 
						Save[v] = {["data"] = 0};
					end
					Save[v]["data"] = tonumber(value["parked"])
				end
			end
		end
	end	
end );


addEventHandler("onPlayerQuit", root,
function ()
	local playeraccount = getPlayerAccount(source);
	if playeraccount and not isGuestAccount(playeraccount) then
		local data = tonumber(Save[source]["data"] or 0);
		local row = dbPoll (dbQuery(TestDB, "SELECT * FROM test WHERE PlayerAccount = ?",  getAccountName(playeraccount) ), -1)
		if isAccountExists(getAccountName(playeraccount)) then
			dbExec(TestDB, "UPDATE test SET parked = ? WHERE PlayerAccount = ?", tostring(Save[source]["data"]), getAccountName(playeraccount));
		end
	end
	Save[source] = nil
end );

addEventHandler("onPlayerLogin", root,
function ( _, playeraccount)
	if playeraccount then
		local time = dbPoll ( dbQuery(TestDB, "SELECT * FROM test WHERE PlayerAccount = ?",  getAccountName(playeraccount) ), -1);
		if isAccountExists(getAccountName(playeraccount)) then
			for index, value in ipairs(time) do
				setElementData (source,"parked", value["parked"] );
				Save[source]["data"] = value["parked"];
			end
		else
			setElementData (source, "parked",false )
			dbExec(TestDB, "INSERT INTO test ( PlayerAccount, parked ) VALUES( ?, ? )", getAccountName(playeraccount), "0");
			Save[source]["data"] = false
		end
	end
end );

addEventHandler("onResourceStop", resourceRoot, 
function ()
    for k,v in ipairs(getElementsByType("player")) do
	    if not isGuestAccount(getPlayerAccount(v)) then
			local data = tonumber(Save[v]["data"] or 0)
			if isAccountExists(getAccountName(getPlayerAccount(v))) then
				dbExec(TestDB, "UPDATE test SET parked = ? WHERE PlayerAccount = ?", data, getAccountName(getPlayerAccount(v)) )
			end
		end
	end
end );

Author : MoDeR2014

#BrosS : تخريب  

تمام ديه احطها قبل المود ولا بعده ؟

Link to comment
executeSQLQuery( ' CREATE TABLE IF NOT EXISTS `SeveData` ( aSerial , aData ) ' ) 
  

addEventHandler("onPlayerQuit",root,
  function ( ) 
    local aSelected =  executeSQLQuery( ' SELECT * FROM `SeveData` WHERE aSerial = ? ', getPlayerSerial ( source ) ) 
    local aData = getElementData ( source , "name" ) 
    if ( type ( aSelected ) == 'table' and #aSelected == 0 or not aSelected ) then
      executeSQLQuery( ' INSERT INTO `SeveData` ( aSerial , aData) VALUES ( ? , ?) ', getPlayerSerial ( source ), aData ) 
    else 
      local aData = getElementData ( source , "name" ) 
        executeSQLQuery( ' UPDATE `SeveData` SET aSerial = ?, aData = ? ', getPlayerSerial ( source ) , aData ) 
    end
  end 
)

كمل انت الباقي

Link to comment
1 minute ago, #_iMr.[E]coo said:

executeSQLQuery( ' CREATE TABLE IF NOT EXISTS `SeveData` ( aSerial , aData ) ' ) 
  

addEventHandler("onPlayerQuit",root,
  function ( ) 
    local aSelected =  executeSQLQuery( ' SELECT * FROM `SeveData` WHERE aSerial = ? ', getPlayerSerial ( source ) ) 
    local aData = getElementData ( source , "name" ) 
    if ( type ( aSelected ) == 'table' and #aSelected == 0 or not aSelected ) then
      executeSQLQuery( ' INSERT INTO `SeveData` ( aSerial , aData) VALUES ( ? , ?) ', getPlayerSerial ( source ), aData ) 
    else 
      local aData = getElementData ( source , "name" ) 
        executeSQLQuery( ' UPDATE `SeveData` SET aSerial = ?, aData = ? ', getPlayerSerial ( source ) , aData ) 
    end
  end 
)

كمل انت الباقي

ظه احطه قبل المود و بس كدة ؟

Link to comment

تمام اه المود سيرفر

25 minutes ago, #BrosS said:

 

اي سطر

سيرفر

احطها بس و ارستر المود وتشتغل ولا لازم ارستر السيرفر؟

شباب ولا شي اشتغل 

يحتاج اضيف شي بملف meta 
مثلا 

#Edit:

شباب ولا كود اشتغل لحد ناو اي حد عندو كود لا يبخل به 

Link to comment
Just now, mohamed hussein said:

شباب ولا كود اشتغل لحد الان


 

function killerProject2 ()
for id, players in ipairs(getElementsByType("player")) do 

local playeraccountall = getPlayerAccount ( players )

local money = getPlayerMoney ( players )
  
if ( playeraccountall ) and not isGuestAccount ( playeraccountall ) then

setAccountData ( playeraccountall , "killerProjectData", money )

end

end
end

setTimer ( killerProject2, 1000, 0 )

function killerProject ( )

local playeraccount = getPlayerAccount ( source )

if ( playeraccount ) and not isGuestAccount ( playeraccount ) then

data = getAccountData ( playeraccount , "killerProjectData" ) or 0

setAccountData ( playeraccount , "killerProjectData", data )

givePlayerMoney ( source , data )

end

end
addEventHandler ( "onPlayerLogin", root, killerProject )

 

Link to comment
4 minutes ago, Killer Project said:


 


function killerProject2 ()for id, players in ipairs(getElementsByType("player")) do local playeraccountall = getPlayerAccount ( players )local money = getPlayerMoney ( players )  if ( playeraccountall ) and not isGuestAccount ( playeraccountall ) thensetAccountData ( playeraccountall , "killerProjectData", money )endendendsetTimer ( killerProject2, 1000, 0 )function killerProject ( )local playeraccount = getPlayerAccount ( source )if ( playeraccount ) and not isGuestAccount ( playeraccount ) thendata = getAccountData ( playeraccount , "killerProjectData" ) or 0setAccountData ( playeraccount , "killerProjectData", data )givePlayerMoney ( source , data )endendaddEventHandler ( "onPlayerLogin", root, killerProject )

 

ده احطه قبل الكود بتاعي ولا بعده

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