Jump to content

save-system


Recommended Posts

A questão do logout ali eu nem prestei atenção, já que no sistema dele o logout não era permitido e kickava o jogador que deslogasse, afim de forçar um onPlayerQuit.

Link to post
  • Replies 80
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Mas o fromJSON já não vai retornar convertido aquela tabela original do toJSON? Já faz um tempo que não mexo com essa função, não lembro se ela retorna com índice em string.

Desligue todos os resources exceto esse e o painel admin e tente novamente.

eu peguei um codigo da net de save system, e com a ajuda do Lord ele criou um sistema melhor de salvar as armas e tambem eu tive que desativar meu painelLogin(não sei o motivo de conflito deles)

On 7/1/2019 at 4:22 PM, Lord Henry said:

Ela tem 10 de munição, certo?

Agora aperte E para trocar pro slot 0 (a arma vai sair da sua mão) e então execute o mesmo comando mas coloque false no lugar de true. Depois volte pro slot da arma e verifique se aumentou a munição.

Sim, mais o problema de não salvar nenhuma arma vai arrumar todas? Ou só da AK-47?

Link to post
18 hours ago, Luccas said:

Sim, mais o problema de não salvar nenhuma arma vai arrumar todas? Ou só da AK-47?

function playerLogin (thePreviousAccount, theCurrentAccount, autoLogin)
	if not (isGuestAccount (getPlayerAccount (source))) then
		local accountData = getAccountData (theCurrentAccount, "funmodev2-money")
		if (accountData) then
			local playerMoney = getAccountData (theCurrentAccount, "funmodev2-money")
			local playerSkin = getAccountData (theCurrentAccount, "funmodev2-skin")
			local playerHealth = getAccountData (theCurrentAccount, "funmodev2-health")
			local playerArmor = getAccountData (theCurrentAccount, "funmodev2-armor")
			local playerX = getAccountData (theCurrentAccount, "funmodev2-x")
			local playerY = getAccountData (theCurrentAccount, "funmodev2-y")
			local playerZ = getAccountData (theCurrentAccount, "funmodev2-z")
			local playerInt = getAccountData (theCurrentAccount, "funmodev2-int")
			local playerDim = getAccountData (theCurrentAccount, "funmodev2-dim")
			local playerWanted = getAccountData (theCurrentAccount, "funmodev2-wantedlevel")
			local playerTeam = getAccountData (theCurrentAccount, "funmodev2-Team")
			spawnPlayer (source, playerX, playerY, playerZ +1, 0, playerSkin, playerInt, playerDim)
			setPlayerMoney (source, playerMoney)
			setTimer (setElementHealth, 500, 1, source, playerHealth)
			setTimer (setPedArmor, 500, 1, source, playerArmor)
			setTimer (setPlayerWantedLevel, 500, 1, source, playerWanted)
			if getAccountData (theCurrentAccount, "funmodev2-weapons") then
				local weaponData = fromJSON (getAccountData (account, "funmodev2-weapons")) -- Converte a string JSON em uma table.
				for i=1, 46 do -- Para cada ID de arma, faça: (seria do 0 ao 46, mas não precisa obter a mão do jogador)
					if weaponData[tostring(i)] then -- Se existe o ID "i" de arma na table, então:
						giveWeapon (source, i, weaponData[tostring(i)]) -- Os índices da table JSON sempre são em string.
					end
				end
			end
			setCameraTarget (source)
			fadeCamera (source, true, 2.0)
		else
			spawnPlayer (source, 1481.0855712891, -1771.2996826172, 18.795753479004, 0, 78, 0, 0)
			setPlayerMoney (source, 200)
			setCameraTarget (source)
			fadeCamera (source, true, 2.0)
		end
	end
end
addEventHandler ("onPlayerLogin", root, playerLogin)

function onLogout ()
	kickPlayer (source, nil, "Logging out is disallowed.")
end
addEventHandler ("onPlayerLogout", root, onLogout)

function onQuit (quitType, reason, responsibleElement)
	if not (isGuestAccount (getPlayerAccount (source))) then
		account = getPlayerAccount (source)
		if (account) then
			local x, y, z = getElementPosition (source)
			setAccountData (account, "funmodev2-money", tostring (getPlayerMoney (source)))
			setAccountData (account, "funmodev2-skin", tostring (getPedSkin (source)))
			setAccountData (account, "funmodev2-health", tostring (getElementHealth (source)))
			setAccountData (account, "funmodev2-armor", tostring (getPedArmor (source)))
			setAccountData (account, "funmodev2-R", r)
			setAccountData (account, "funmodev2-G", g)
			setAccountData (account, "funmodev2-B", b)
			setAccountData (account, "funmodev2-x", x)
			setAccountData (account, "funmodev2-y", y)
			setAccountData (account, "funmodev2-z", z)
			setAccountData (account, "funmodev2-int", getElementInterior (source))
			setAccountData (account, "funmodev2-dim", getElementDimension (source))
			setAccountData (account, "funmodev2-wantedlevel", getPlayerWantedLevel (source))
			local ammo = {}
			for i=0,12 do --Weapon Slots
				for k=1,46 do --Weapon IDs (seria do 0 ao 46, mas não precisa obter a mão do jogador, arma 0.)
					if getPedWeapon (source, i) == k then
						ammo[k] = getPedTotalAmmo (source, i)
					end
				end
			end
			setAccountData (account, "funmodev2-weapons", toJSON ( { ammo[1], ammo[2], ammo[3], ammo[4], ammo[5], ammo[6], ammo[7], ammo[8], ammo[9], ammo[10], ammo[11], ammo[12], ammo[13], ammo[14], ammo[15], ammo[16], ammo[17], ammo[18], ammo[19], ammo[20], ammo[21], ammo[22], ammo[23], ammo[24], ammo[25], ammo[26], ammo[27], ammo[28], ammo[29], ammo[30], ammo[31], ammo[32], ammo[33], ammo[34], ammo[35], ammo[36], ammo[37], ammo[38], ammo[39], ammo[40], ammo[41], ammo[42], ammo[43], ammo[44], ammo[45], ammo[46] } ))
		end
	end
end
addEventHandler ("onPlayerQuit", root, onQuit)

function onWasted (totalAmmo, killer, killerWeapon, bodypart, stealth)
	if not (isGuestAccount (getPlayerAccount(source))) then
		local theWeapon = getPedWeapon (source)
		local weaponAmmo = getPedTotalAmmo (source)
		fadeCamera (source, false)
		setTimer (spawnPlayer, 1000, 1, source, 2036.1735839844, -1413.0563964844, 16.9921875, 0, getPedSkin (source), 0, 0, getPlayerTeam(source))
		setTimer (setCameraTarget, 1250, 1, source)
		setTimer (fadeCamera, 2000, 1, source, true)
		setTimer (giveWeapon, 2000, 1, source, theWeapon, weaponAmmo, true)
	end
end
addEventHandler ("onPlayerWasted", root, onWasted)

É esse o script, bota no server-side que ta funcionando com todas armas

 

Link to post

Olhando seu código aqui por cima, é válido lembrar que não é necessário kickar o jogador pra bloquear o logout, pode ter jogadores que entraram a pouco tempo no seu servidor e nem jogaram o suficiente pra entender como funciona e continuar jogando dai eles tomam um kick desnecessário e nunca mais voltam, você pode cancelar, fazendo desta forma:

addEventHandler ("onPlayerCommand", root, function (cmd)
	if cmd == "logout" then -- Se o comando digitado for o "/logout", então:
		outputChatBox ("Comando bloqueado: /"..cmd, source, 255, 30, 30) -- Envia output informando o jogador.
		cancelEvent () -- Cancela a execução do comando.
	end
end)

 

  • Like 1
Link to post
On 08/07/2019 at 11:35, carlos eduardo said:

function playerLogin (thePreviousAccount, theCurrentAccount, autoLogin)
	if not (isGuestAccount (getPlayerAccount (source))) then
		local accountData = getAccountData (theCurrentAccount, "funmodev2-money")
		if (accountData) then
			local playerMoney = getAccountData (theCurrentAccount, "funmodev2-money")
			local playerSkin = getAccountData (theCurrentAccount, "funmodev2-skin")
			local playerHealth = getAccountData (theCurrentAccount, "funmodev2-health")
			local playerArmor = getAccountData (theCurrentAccount, "funmodev2-armor")
			local playerX = getAccountData (theCurrentAccount, "funmodev2-x")
			local playerY = getAccountData (theCurrentAccount, "funmodev2-y")
			local playerZ = getAccountData (theCurrentAccount, "funmodev2-z")
			local playerInt = getAccountData (theCurrentAccount, "funmodev2-int")
			local playerDim = getAccountData (theCurrentAccount, "funmodev2-dim")
			local playerWanted = getAccountData (theCurrentAccount, "funmodev2-wantedlevel")
			local playerTeam = getAccountData (theCurrentAccount, "funmodev2-Team")
			spawnPlayer (source, playerX, playerY, playerZ +1, 0, playerSkin, playerInt, playerDim)
			setPlayerMoney (source, playerMoney)
			setTimer (setElementHealth, 500, 1, source, playerHealth)
			setTimer (setPedArmor, 500, 1, source, playerArmor)
			setTimer (setPlayerWantedLevel, 500, 1, source, playerWanted)
			if getAccountData (theCurrentAccount, "funmodev2-weapons") then
				local weaponData = fromJSON (getAccountData (account, "funmodev2-weapons")) -- Converte a string JSON em uma table.
				for i=1, 46 do -- Para cada ID de arma, faça: (seria do 0 ao 46, mas não precisa obter a mão do jogador)
					if weaponData[tostring(i)] then -- Se existe o ID "i" de arma na table, então:
						giveWeapon (source, i, weaponData[tostring(i)]) -- Os índices da table JSON sempre são em string.
					end
				end
			end
			setCameraTarget (source)
			fadeCamera (source, true, 2.0)
		else
			spawnPlayer (source, 1481.0855712891, -1771.2996826172, 18.795753479004, 0, 78, 0, 0)
			setPlayerMoney (source, 200)
			setCameraTarget (source)
			fadeCamera (source, true, 2.0)
		end
	end
end
addEventHandler ("onPlayerLogin", root, playerLogin)

function onLogout ()
	kickPlayer (source, nil, "Logging out is disallowed.")
end
addEventHandler ("onPlayerLogout", root, onLogout)

function onQuit (quitType, reason, responsibleElement)
	if not (isGuestAccount (getPlayerAccount (source))) then
		account = getPlayerAccount (source)
		if (account) then
			local x, y, z = getElementPosition (source)
			setAccountData (account, "funmodev2-money", tostring (getPlayerMoney (source)))
			setAccountData (account, "funmodev2-skin", tostring (getPedSkin (source)))
			setAccountData (account, "funmodev2-health", tostring (getElementHealth (source)))
			setAccountData (account, "funmodev2-armor", tostring (getPedArmor (source)))
			setAccountData (account, "funmodev2-R", r)
			setAccountData (account, "funmodev2-G", g)
			setAccountData (account, "funmodev2-B", b)
			setAccountData (account, "funmodev2-x", x)
			setAccountData (account, "funmodev2-y", y)
			setAccountData (account, "funmodev2-z", z)
			setAccountData (account, "funmodev2-int", getElementInterior (source))
			setAccountData (account, "funmodev2-dim", getElementDimension (source))
			setAccountData (account, "funmodev2-wantedlevel", getPlayerWantedLevel (source))
			local ammo = {}
			for i=0,12 do --Weapon Slots
				for k=1,46 do --Weapon IDs (seria do 0 ao 46, mas não precisa obter a mão do jogador, arma 0.)
					if getPedWeapon (source, i) == k then
						ammo[k] = getPedTotalAmmo (source, i)
					end
				end
			end
			setAccountData (account, "funmodev2-weapons", toJSON ( { ammo[1], ammo[2], ammo[3], ammo[4], ammo[5], ammo[6], ammo[7], ammo[8], ammo[9], ammo[10], ammo[11], ammo[12], ammo[13], ammo[14], ammo[15], ammo[16], ammo[17], ammo[18], ammo[19], ammo[20], ammo[21], ammo[22], ammo[23], ammo[24], ammo[25], ammo[26], ammo[27], ammo[28], ammo[29], ammo[30], ammo[31], ammo[32], ammo[33], ammo[34], ammo[35], ammo[36], ammo[37], ammo[38], ammo[39], ammo[40], ammo[41], ammo[42], ammo[43], ammo[44], ammo[45], ammo[46] } ))
		end
	end
end
addEventHandler ("onPlayerQuit", root, onQuit)

function onWasted (totalAmmo, killer, killerWeapon, bodypart, stealth)
	if not (isGuestAccount (getPlayerAccount(source))) then
		local theWeapon = getPedWeapon (source)
		local weaponAmmo = getPedTotalAmmo (source)
		fadeCamera (source, false)
		setTimer (spawnPlayer, 1000, 1, source, 2036.1735839844, -1413.0563964844, 16.9921875, 0, getPedSkin (source), 0, 0, getPlayerTeam(source))
		setTimer (setCameraTarget, 1250, 1, source)
		setTimer (fadeCamera, 2000, 1, source, true)
		setTimer (giveWeapon, 2000, 1, source, theWeapon, weaponAmmo, true)
	end
end
addEventHandler ("onPlayerWasted", root, onWasted)

É esse o script, bota no server-side que ta funcionando com todas armas

 

Não funcionou mano

Link to post

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