Jump to content

[HELP] Connect the players in the database


Recommended Posts

Hi, I'm having some problems and I'm having a hard time resolving them.

This is the .log

==================================================================
= Multi Theft Auto: San Andreas v1.5.6 [64 bit]
==================================================================
= Server name      : Default MTA Server
= Server IP address: auto
= Server port      : 22003
= 
= Log file         : ..o_linux_x64/mods/deathmatch/logs/server.log
= Maximum players  : 32
= HTTP port        : 22005
= Voice Chat       : Disabled
= Bandwidth saving : Medium
==================================================================
[19-05-03 19:18:26] Resources: 200 loaded, 0 failed
[19-05-03 19:18:27] MODULE: Loaded "MySQL 5.0 database module" (0.50) by "Alberto Alonso <[email protected]>"
[19-05-03 19:18:27] Starting resources...
[19-05-03 19:18:27] Server minclientversion is now 1.5.6-9.16588.0
[19-05-03 19:18:27] INFO: MAPMANAGER: Some important ACL permissions are missing. To ensure the correct functioning of Mapmanager, please write: aclrequest allow mapmanager all
[19-05-03 19:18:28] Successfully connect to MySQL server!
[19-05-03 19:18:28] ERROR: dayzmode/lib/team/s_team.lua:1: call: failed to call 'dayzconnect:MySQL' [string "?"]
[19-05-03 19:18:28] ERROR: dayzmode/lib/system/player.lua:1: call: failed to call 'dayzconnect:MySQL' [string "?"]
[19-05-03 19:18:28] ERROR: dayzmode/lib/system/player.lua:221: attempt to index local 'mysql' (a boolean value)
[19-05-03 19:18:36] Gamemode 'dayzconnect' started.
[19-05-03 19:18:36] Querying MTA master server... success! (Auto detected IP:149.56.252.100)
[19-05-03 19:18:36] Authorized serial account protection is enabled for the ACL group(s): `Admin`  See https://mtasa.com/authserial
[19-05-03 19:18:36] WARNING: <owner_email_address> not set
[19-05-03 19:18:36] Server started and is ready to accept connections!
[19-05-03 19:18:36] To stop the server, type 'shutdown' or press Ctrl-C
[19-05-03 19:18:36] Type 'help' for a list of commands.
[19-05-03 19:18:55] Server stopped!
[19-05-03 19:18:55] Stopping resources............................
[19-05-03 19:18:55] MODULE: Unloaded "MySQL 5.0 database module" (0.50) by "Alberto Alonso <[email protected]>"
[19-05-03 19:18:55] Closing SQLite3 database

This is the s_team.lua

local mysql = exports.dayzconnect:MySQL()

local function getDBTeam(name,host)
	local query = mysql.query('SELECT * FROM `teams` WHERE `name` = ?',name)
	if query then
		if query[1] then
			if host then
			outputDebugString(123)
				return false
			end
			return query[1]
		else
			mysql.exec('INSERT INTO `teams` (`name`,`host`) VALUES (?,?)',name,host)
			return getDBTeam(name)
		end
	end
end


local language = {
	['createteam'] = {'Created team: ','Создан клан: '},
	['moreinfo'] = {'More info: ','Больше информации: '},
	['doesnotnewteam'] = {'The team with the same name is already registered!','Команда с таким именем уже зарегистрирована!'},
	['ansinviteteam'] = {'Write the chat /yes or /no to accept or refuse an invitation','Напишите в чат /yes или /no чтобы принять или отклонить приглашение'},
	['sendinviteonlyhost'] = {'Send an invitation can only be a team leader!','Отправлять приглашения может только лидер команды!'},
	['playeralreadyteam'] = {'The player is already a member of another team! He must leave her to get an invitation.','Игрок уже состоит в другой команде! Ему необходимо покинуть её, чтобы получить приглашение.'},
	['writebadname'] = {'The name is entered incorrectly!','Имя введено неверно!'},
	['nocreateteambecauseonteam'] = {'You are already a member of a team!','Вы уже состоите в команде!'},
	['leaveteam'] = {'You left the team: ','Вы покинули команду: '},
	['addmode'] = {'Added a new chat mode: team','Добавлен новый режим чата: team'},
	['usemode'] = {'Use Ctrl, to switch the chat mode','Используйте Ctrl, чтобы переключать режимы чата'},
	['usecmd'] = {'Use commands:','Используйте команды:'},
	['info1'] = {'/addplayer PLAYER_NAME [add a player to the team]','/addplayer ИМЯ_ИГРОКА [добавить игрока в команду]'},
	['info2'] = {'/leaveteam [leave team]','/leaveteam [покинуть команду]'},
}

local function LANGUAGE(player,name)
	local lan = language[name]
	if lan then
		return lan[player:getData('options',false).language] or lan[1]
	end
	return name
end

local function isPlayerHostOfTeam(player,team)
	local team = getRegTeam(name)
	return player:getSerial() == team.host
end

local function setTeam(player,set)
	local oldTeam = player:getData('team')
	player:setData('team',set)
	player:setData('inviteteam',nil)
	if set then
		outputChat(player,LANGUAGE(player,'addmode'),'orange')
		outputChat(player,LANGUAGE(player,'usemode'),'orange')
		outputChat(player,LANGUAGE(player,'moreinfo')..'/infoteam','orange')
	elseif oldTeam then
		outputChat(player,LANGUAGE(player,'leaveteam')..oldTeam,'orange')
	end
end

local function newTeam(host,name)
	if host:getData('team') then
		outputChat(host,LANGUAGE(host,'nocreateteambecauseonteam'),'red')
	else
		local team = getDBTeam(name,host:getSerial())
		if not team then
			outputChat(host,LANGUAGE(host,'doesnotnewteam'),'red')
		else
			outputChat(host,LANGUAGE(host,'createteam')..name,'orange')
			setTeam(host,name)
		end
	end
end

local function invitePlayerTeam(host,inviteName)
	local team = host:getData('team')
	local player = getPlayerFromName(inviteName)
	if player then
		if player:getData('team') then
			outputChat(host,LANGUAGE(host,'playeralreadyteam'),'red')
		else
			player:setData('inviteteam',team)
			outputChat(player,LANGUAGE(player,'ansinviteteam'),'orange')
		end
	else
		outputChat(host,LANGUAGE(host,'writebadname'),'red')
	end
end

local function infoTeam(player)
	outputChat(player,LANGUAGE(player,'usecmd'),'orange')
	outputChat(player,LANGUAGE(player,'info1'),'orange')
	outputChat(player,LANGUAGE(player,'info2'),'orange')
end

function teamCommand(player,cmd,comment)
	if cmd == 'createteam' then
		if #comment > 2 and #comment < 32 then
			return newTeam(player,comment)
		end
	elseif (cmd == 'yes' or cmd == 'no') and player:getData('inviteteam') then
		return setTeam(player,(cmd == 'yes' and player:getData('inviteteam')))
	elseif cmd == 'addplayer' then
		return invitePlayerTeam(player,comment)
	elseif cmd == 'leaveteam' then
		return setTeam(player)
	elseif cmd == 'infoteam' then
		return infoTeam(player)
	end
end

This is the player.lua

local mysql = exports.dayzconnect:MySQL()

local function dbAccount(player,a)
	local a = a or {}
	local dbtype = mysql.server.type
	local serial = player:getSerial()
	local query,result = mysql.query('SELECT `serial` FROM '..dbtype..' WHERE `serial` = ?',serial)
	if query then
		if result > 0 then
			return (a.check and mysql.query('SELECT `serial` FROM '..dbtype..' WHERE `serial` = ?',serial)[1]) or true
		elseif a.create and mysql.exec('INSERT INTO '..dbtype..' (`name`,`serial`,`ip`) VALUES (?,?,?)',player:getName(),serial,player:getIP()) then
			return false
		end
	end
end

local defaultData = {
	['blood'] = 5000,
	['thirst'] = 80,
	['hunger'] = 75,
	['hands'] = false,
	['pain'] = false,
	['fracture'] = false,
	['temperature'] = 36.6,
	['damp'] = 0,
	['bleeding'] = {0},
}
local dataSave = {
	['options']=true,
	['face']=true,
	['team']=true,
	['coins']=true,
	['spawnclothes']=true,
}
for name,_ in pairs(defaultData) do
	dataSave[name] = true
end

local function dbBackup()
	local backupPass = '%DayZ+iPanda=Love%'
	return Account('backup',backupPass) or addAccount('backup',backupPass)
end

local function setItem(item,source)
	if item then
		item.id = nil
		if source then
			item.id = tostring(source)..tostring(item)
		end
		if type(item.o) == 'table' then
			local sx,sy = itemSize(item)
			for n=1,sx*sy do
				if item.o[n] then
					item.o[n].id = nil
					if source then
						item.o[n].id = tostring(source)..tostring(item.o[n])
					end
					if itemType(item.o[n].n) == 'cont' and type(item.o) == 'table' then
						local sx,sy = itemSize(item.o[n])
						for n2=1,sx*sy do
							if item.o[n].o[n2] then
								item.o[n].o[n2].id = nil
								if source then
									item.o[n].o[n2].id = tostring(source)..tostring(item.o[n].o[n2])
								end
							else
								if source then
									item.o[n].o[n2] = nil
								else
									item.o[n].o[n2] = false
								end
							end
						end
					end
				else
					if source then
						item.o[n] = nil
					else
						item.o[n] = false
					end
				end
			end
		end
	else
		item = false
	end
	return item
end

local function playerDefault(player)
	local playerpoints = getElementsByType('playerpoints')
	local x,y,z = getElementPosition(playerpoints[math.random(#playerpoints)])
	player:spawn(x,y,z+0.1,math.random(360),0,0)
	for data,value in pairs(defaultData) do
		player:setData(data,value)
	end
	local inventory = resetClothes(player,player:getData('spawnclothes'))
	for i,item in ipairs(inventory) do
		player:setData(itemType(item.n),item)
		if type(item.o) == 'table' then
			table.insert(inventory[i].o,{n='battery',c=1,id=tostring(player)..'battery'})
			table.insert(inventory[i].o,{n='wpn422flash',c=1,id=tostring(player)..'wpn422flash'})
		end
	end
	player:setData('inventory',inventory)
	player:setData('pockets',{})
	player:fadeCamera(true,4)
	local avatar = player:getData('avatar')
	if avatar and isElement(avatar) then
		avatar:setData('face',player:getData('face'))
	end
end

local function saveAccount(player)
	if player:getData('logedin') then
		player:setAnimation()
		player:setData('giveplayer',false)
		if player:isDead() then
			playerDefault(player)
		end
		local x,y,z = getElementPosition(player)
		if player:isInWater() then
			z = math.max(z,0)+10
		end
		local pos = toJSON({math.round(100,x,y,z,getPedRotation(player))})
		local data = {}
		for name,value in pairs(player:getAllData()) do
			if dataSave[name] then
				if name == 'hands' and value then
					value = setItem(value)
				end
				data[name] = value
			end
		end
		local data = toJSON(data)
		local inventory = {}
		for i,item in ipairs(player:getData('inventory')) do
			inventory[i] = setItem(item)
		end
		local inventory = toJSON(inventory)
		dbAccount(player,{create=true})
		mysql.exec(
			'UPDATE '..mysql.server.type..' SET `name` = ?, `ip` = ?, `pos` = ?, `data` = ?, `inventory` = ? WHERE `serial` = ?',
			player:getName(),player:getIP(),pos,data,inventory,player:getSerial()
		)
	end
end

local function playerLogin(player,accData)
	local x,y,z,rot = unpack(fromJSON(accData.pos))
	setElementPosition(player,x,y,z+0.1)
	setPedRotation(player,rot)
	player:setCameraTarget(player)
	player:fadeCamera(true,4)
end

local function playerSpawn(player)
	playerDefault(player)
	player:setCameraTarget(player)
	saveAccount(player)
end
addEvent('Spawn',true)
addEventHandler('Spawn',root,playerSpawn)

local function playerWasted(ammo,attacker,weapon,bodypart)
	source:fadeCamera(false,0)
	triggerClientEvent(source,'setBlackScreen',source,'You are dead')
	local x,y,z = getElementPosition(source)
	source:removeFromVehicle()
	if not source:isInWater() then
		local ped = Ped(source:getModel(),x,y,z,getPedRotation(source))
		ped:removeClothes(0)
		ped:removeClothes(2)
		ped:removeClothes(3)
		ped:setData('face',source:getData('face'))
		local hands = source:getData('hands')
		if hands then
			triggerEvent('createItem',ped,hands)
		end
		local loot = {}
		for i,item in ipairs(source:getData('inventory')) do
			loot[i] = setItem(item,ped)
			source:setData(itemType(item.n),false)
			ped:setData(itemType(item.n),item)
		end
		local data = {
			loot = loot,
		}
		ped:setData('data',data)
		ped:kill()
	end
	source:setPosition(6000,6000,0)
	--playerSpawn(source)
end
addEventHandler('onPlayerWasted',root,playerWasted)

local function destroyAvatar(player)
	local avatar = player:getData('avatar')
	if avatar and isElement(avatar) then
		avatar:destroy()
	end
end

local function createAvatar(player)
	destroyAvatar(player)
	local ped = Ped(0,6000,6000,10)
	ped:setFrozen(true)
	ped:removeClothes(0)
	ped:removeClothes(2)
	ped:removeClothes(3)
	ped:setData('face',player:getData('face'))
	ped:setData('noattach',true)
	player:setData('avatar',ped)
end

addEventHandler('onPlayerQuit',root,function()
	saveAccount(source)
	destroyAvatar(source)
end)

function mysql.destroy()
	mysql.connect:destroy()
	mysql.connect = nil
	outputServerLog('Destroy connect to MySQL server!')
end

addEventHandler('onResourceStop',resourceRoot,function()
	setGameSpeed(0.1)
	for _,player in ipairs(getElementsByType('player')) do
		if player:getData('logedin') then
			saveAccount(player)
			player:setFrozen(true)
		end
	end
	mysql.destroy()
	local backup = dbBackup()
	saveVehicles(backup)
	saveTents(backup)
end)

addEventHandler('onResourceStart',resourceRoot,function()
	for _,player in ipairs(getElementsByType('player')) do
		if player:getData('logedin') then
			createAvatar(player)
		end
		player:setFrozen(false)
	end
	local backup = dbBackup()
	if backup then
		if backup:getData('vehicles') then
			for _,data in ipairs(fromJSON(backup:getData('vehicles'))) do
				local vehpart = {}
				local vehdoor = {}
				for i=0,5 do
					vehpart[i] = data.vehpart[i+1]
					vehdoor[i] = data.vehdoor[i+1]
				end
				data.vehpart = vehpart
				data.vehdoor = vehdoor
				createVeh(data)
			end
		end
		if backup:getData('tents') then
			for _,data in ipairs(fromJSON(backup:getData('tents'))) do
				createTent(data)
			end
		end
	end
end)
--[[
addEventHandler('onPlayerLogin',root,function()
--	if not AdminSerial[source:getSerial()] then
--		return cancelEvent(true)
--	end
end)
--]]
addEventHandler('onPlayerStealthKill',root,function()cancelEvent()end)
addEventHandler('onPlayerChangeNick',root,function()cancelEvent()end)
addEventHandler('onPlayerJoin',root,function()
	for _,stat in ipairs({24,69,70,71,72,73,74,75,76,77,78,79,160,229,230}) do
		if stat == 69 or stat == 73 or stat == 75 then
			setPedStat(source,stat,500)
		else
			setPedStat(source,stat,999)
		end
	end
	setPedStat(source,23,300)
	setPedFightingStyle(source,5)
	for _,control in ipairs({'look_behind','next_weapon','previous_weapon','vehicle_look_behind','vehicle_look_right','vehicle_look_left','radar','action','change_camera'}) do
		toggleControl(source,control,false)
	end
	source:showHudComponent('all',false)
	source:showHudComponent('crosshair',true)
	source:setNametagShowing(false)
	showChat(source,false)
	source:removeClothes(0)
	source:removeClothes(2)
	source:removeClothes(3)
	local options = {
		language = 1,
		vperson = 3,
	}
	source:setData('options',options)
	local inventory,spawnclothes = resetClothes(source)
	source:setData('spawnclothes',spawnclothes)
	source:setData('inventory',inventory)
	source:setData('pockets',{})
	source:setData('chatbox',{})
	source:setData('coins',0)
	local db = dbAccount(source,{check=true})
	if db then
		source:setDimension(db.id)
		for name,value in pairs(fromJSON(db.data)) do
			if name == 'hands' and value then
				value = setItem(value,source)
			end
			source:setData(name,value)
		end
		local inventory = {}
		for i,item in ipairs(fromJSON(db.inventory)) do
			inventory[i] = setItem(item,source)
		end
		source:setData('inventory',inventory)
	else
		for i,player in ipairs(getElementsByType('player')) do
			if player == source then
				source:setDimension(i)
				break
			end
		end
	end

	for i,admin in ipairs(fromJSON(mysql.server.admin)) do
		if admin == source:getSerial() then
			source:setData('admin','admin'..i)
		end
	end
end)

function spawnOrLogin(player)
	local accData = dbAccount(player,{check=true})
	if accData and accData.pos then
		playerLogin(player,accData)
	else
		playerSpawn(player)
	end
	createAvatar(player)
	player:setDimension(0)
end

That's it, I do not know what else to do.

Link to comment

this function dayzconnect:MySQL not exported well.

Try to start dayzconnect game mode first then start dayzmode resource after.

if that not worked , check if the function (dayzconnect:MySQL) exported well in dayzconnect meta.xml.

Link to comment
<meta><download_priority_group>1</download_priority_group><oop>true</oop>
	<info author='iPanda' type='gamemode'/>
	<file src='connect.xml'/>
	<script src='class.lua'/>
	<script src='whitelist.lua'/>

	<export function='MySQL'/>

	<include resource='dayzbase'/>
	<include resource='dayzcache'/>
	<include resource='dayzconnect'/>
	<include resource='dayzedf'/>
    <include resource='dayzmap'/>
	<include resource='dayzmode'/>
	<include resource='dayzshop'/>
	<include resource='object_preview'/>
</meta>

This is my meta.xml, seems to be all right

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