Jump to content

تعديل ع كود


Recommended Posts

السلام عليكم

ذا كود حفظ فلوس

م زبط معي بالرغم من م يطلع اخطاء بالدي بق

addEventHandler ("onResourceStart",root,
	function ()
		executeSQLQuery("CREATE TABLE IF NOT EXISTS datanamee (  money, account )")
	end
)
-------------
addEventHandler("onPlayerLogin", getRootElement(),
function ( source )
Pmoney = getPlayerMoney ( source )
Paccount = getAccountName( getPlayerAccount( source ) )
executeSQLQuery("INSERT INTO datanamee( money, account ) VALUES(?, ?)",Pmoney, Paccount )
end
)
-----------
addEventHandler("onPlayerQuit", getRootElement(),
function ( source )
Pmoney = getPlayerMoney ( source )
Paccount = getAccountName( getPlayerAccount( source ) )
 if Paccount and not isGuestAccount ( account ) then
executeSQLQuery("UPDATE datanamee SET money=? WHERE account=?", Pmoney, Paccount )
end
end
)
--------
addEventHandler("onPlayerLogin", getRootElement(),
function ( source )
Pmoney = getPlayerMoney ( source )
Paccount = getAccountName( getPlayerAccount( source ) )
executeSQLQuery("SELECT money FROM datanamee WHERE account = ?", Paccount )
setPlayerMoney(source,Pmoney)
end
)

 

Link to comment

onPlayerLogin ليش حاط حدثين ؟

اتوقع مشكلتك منه لآنه في اول حدث رح يضيف انه فلوس الاعب هي 0 بعدها الحدث الثاني رح يجيب الفلوس يلي هي 0 ويعطيك ياها , شيل الحدث الاول : هذا

addEventHandler("onPlayerLogin", getRootElement(),
function ( source )
Pmoney = getPlayerMoney ( source )
Paccount = getAccountName( getPlayerAccount( source ) )
executeSQLQuery("INSERT INTO datanamee( money, account ) VALUES(?, ?)",Pmoney, Paccount )
end
)

 

Link to comment
local save = dbConnect( "sqlite", "save.db" )
dbExec(save, "CREATE TABLE IF NOT EXISTS saveData ( AccountName, Money)")


function saveMoney (player)
	local Account = getPlayerAccount(player)
	if Account and  not isGuestAccount (Account) then
		local Money = getPlayerMoney(player)
		dbExec(save, "UPDATE saveData SET Money = ? WHERE AccountName = ?",Money, getAccountName(Account) )
	end
end

function loadMoney( player )
	local account = getPlayerAccount(player)
	if account and not isGuestAccount(account) then
		local result = dbPoll(dbQuery(save, "SELECT * FROM saveData WHERE AccountName = ? ", getAccountName(account)), -1)
			if #result > 0 then
				givePlayerMoney(player,result[1]["Money"])
		end
	end
end

addEventHandler("onPlayerQuit",root,
function()
	saveMoney(source)
end)

addEventHandler("onPlayerLogin",root,
function()
	loadMoney(source)
end)

addEventHandler("onResourceStop", root,
function(res)
	if res == getThisResource() then
		for i , v in pairs (getElementsByType("player") ) do
			saveMoney(v)
		end
	end
end)

غير مجرب

Edited by #BrosS
Link to comment
addEventHandler ( "onResourceStart", resourceRoot, 
	function ( )
		executeSQLQuery ( "CREATE TABLE IF NOT EXISTS datanamee ( money, account )" )
	end
)

addEventHandler("onPlayerLogin", root, 
	function ( _, playeraccount )
		local result = executeSQLQuery ( "SELECT money FROM datanamee WHERE account=?", getAccountName ( playeraccount ) )
		if ( #result ~= 0 ) then
			setPlayerMoney ( source, result[1].money )
		end
	end
)

addEventHandler ( "onPlayerQuit", root, 
	function ( )
		local playeraccount = getPlayerAccount ( source )
		if ( playeraccount ) and not isGuestAccount ( playeraccount ) then
			local playermoney = getPlayerMoney ( source )
			local result = executeSQLQuery ( "SELECT money FROM datanamee WHERE account=?", getAccountName ( playeraccount ) )
			if ( #result == 0 ) then
				executeSQLQuery ( "INSERT INTO datanamee ( account, money ) VALUES ( ?, ? )", getAccountName ( playeraccount ), playermoney )
			else
				executeSQLQuery ( "UPDATE datanamee SET money=? WHERE account=?", playermoney, getAccountName ( playeraccount ) )
			end
		end
	end
)

جرب ..

Edited by ` Allawi
Link to comment
function onPlayerQuit ( )
      -- when a player leaves, store his current money amount in his account data
      local playeraccount = getPlayerAccount ( source )
      if ( playeraccount ) and not isGuestAccount ( playeraccount ) then -- if the player is logged in
            local playermoney = getPlayerMoney ( source ) -- get the player money
            setAccountData ( playeraccount, "piraterpg.money", playermoney ) -- save it in his account
      end
end
 
function onPlayerLogin (_, playeraccount )
      -- when a player logins, retrieve his money amount from his account data and set it
      if ( playeraccount ) then
            local playermoney = getAccountData ( playeraccount, "piraterpg.money" )
            -- make sure there was actually a value saved under this key (check if playermoney is not false).
            -- this will for example not be the case when a player plays the gametype for the first time
            if ( playermoney ) then
                  setPlayerMoney ( source, playermoney )
            end
      end
end
 
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit )
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin )

مثال بسيط من الويكي

Link to comment
1 hour ago, #MR.NaiF said:

function onPlayerQuit ( )
      -- when a player leaves, store his current money amount in his account data
      local playeraccount = getPlayerAccount ( source )
      if ( playeraccount ) and not isGuestAccount ( playeraccount ) then -- if the player is logged in
            local playermoney = getPlayerMoney ( source ) -- get the player money
            setAccountData ( playeraccount, "piraterpg.money", playermoney ) -- save it in his account
      end
end
 
function onPlayerLogin (_, playeraccount )
      -- when a player logins, retrieve his money amount from his account data and set it
      if ( playeraccount ) then
            local playermoney = getAccountData ( playeraccount, "piraterpg.money" )
            -- make sure there was actually a value saved under this key (check if playermoney is not false).
            -- this will for example not be the case when a player plays the gametype for the first time
            if ( playermoney ) then
                  setPlayerMoney ( source, playermoney )
            end
      end
end
 
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit )
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin )

مثال بسيط من الويكي

هوي يبي ب 

SQL

وليس بالفنكشات لي عطيته

+

شبااب ساعدوه

 

 

Edited by Dr.Marco
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...