GRoot = getRootElement()
GRRoot = getResourceRootElement()
UserFolderName = "UserFolder"
function OnModeStart(startedmode)
SecondTimerAddress = setTimer(SecondTimer, 1000, false)
end
function OnPlayerJoin()
ResetPlayerValue(source)
fadeCamera(source, true)
SpawnPlayer(source)
setCameraTarget(source, source)
ClearChatBox(source)
end
function OnPlayerTarget(targetelement)
end
function OnPlayerSpawn()
setElementPosition ( source, 100, 100, 20)
end
function OnPlayerWasted(ammo, killerelement, weapon, bodypart)
setTimer(SpawnPlayer, 5000, 1, source)
end
function OnPlayerDamage(attackerelement, weapon, bodypart, damage)
end
function OnPlayerChat(message, messageType)
cancelEvent()
outputChatBox("[Player] ".. getPlayerName(source) .. " : " .. message)
end
addEventHandler("onResourceStart", GRRoot, OnModeStart)
addEventHandler("onPlayerTarget", GRoot, OnPlayerTarget)
addEventHandler("onPlayerJoin", GRoot, OnPlayerJoin)
addEventHandler("onPlayerSpawn", GRoot, OnPlayerSpawn)
addEventHandler("onPlayerWasted", GRoot, OnPlayerWasted)
addEventHandler("onPlayerDamage", GRoot, OnPlayerDamage)
addEventHandler("onPlayerChat", GRoot, OnPlayerChat)
function consoleCheckParameters ( playerSource, commandName, ... )
local parametersTable = {...}
local parameterCount = #parametersTable
outputChatBox ( "Number of parameters: " .. parameterCount, playerSource )
local stringWithAllParameters = table.concat( parametersTable, ", " )
outputChatBox ( "Parameters passed: " .. stringWithAllParameters, playerSource )
end
function RegisterPlayer(playerSource, commandName, id, password)
if GetPlayerValue(playerSource, "Registered") then
outputChatBox ("이미 가입 하셨습니다. 로그인 해주세요.", playerSource )
return
end
local UFN = GetUserFileName(id)
if IsXmlCreated(UFN) then
outputChatBox ("이미 이 아이디는 생성 되있습니다.", playerSource )
else
local thenode = xmlCreateFile (UFN, "UserData")
if thenode then
xmlNodeSetValue (thenode, password)
xmlCreateChild (thenode, "Info")
xmlSaveFile(thenode)
xmlUnloadFile(thenode)
outputChatBox ("성공적으로 아이디가 생성되었습니다.", playerSource )
SetPlayerValue(playerSource, "Registered", true)
setTimer(SavePlayer, 3000, 1, playerSource, id)
else
outputChatBox ("계정생성중 오류가 발생하였습니다.", playerSource )
outputChatBox ("[아이디는 영어로 해주세요]", playerSource )
end
end
end
function LoginPlayer(playerSource, commandName, id, password)
local UFN = GetUserFileName(id)
local thenode = xmlLoadFile(UFN)
if thenode then
if xmlNodeGetValue(thenode) == password then
local thenode_info = xmlFindChild (thenode, "Info", 0)
SetPlayerValue(playerSource, "Password", xmlNodeGetValue(thenode))
SetPlayerValue(playerSource, "Age", xmlNodeGetAttribute (thenode_info, "Age"))
outputChatBox ("성공적으로 로그인 되었습니다.", playerSource)
else
outputChatBox ("비밀번호가 틀립니다.", playerSource)
print(xmlNodeGetValue(thenode)..password)
end
xmlUnloadFile(thenode)
else
outputChatBox ("존재하지 않는 아이디입니다.", playerSource)
end
end
addCommandHandler ( "Check", consoleCheckParameters)
addCommandHandler ( "register", RegisterPlayer)
addCommandHandler ( "login", LoginPlayer)
function SpawnPlayer(playerelement)
spawnPlayer(playerelement, 0.0, 0.0, 0.0, 0.0, 0)
end
function GiveElementHealth(theelement, health)
setElementHealth(theelement, getElementHealth(theelement) + health)
end
function GetConnectedPlayers()
local playerstable = getElementsByType("player")
return table.getn(playerstable)
end
function SecondTimer()
local playerstable = getElementsByType("player")
for tablepos, tableelement in ipairs(playerstable) do
local x, y, z = getElementPosition(tableelement)
--triggerClientEvent (tableelement, "onExplosionBlood", tableelement, x, y, z)
end
end
function ClearChatBox(playerelement)
for i = 0, 15 do
outputChatBox(" ", playerelement)
end
end
function GetUserFileName(id)
return string.format("%s/%s.xml", UserFolderName, id)
end
function IsXmlCreated(xmlname)
if not xmlLoadFile(xmlname) then
return false
end
xmlUnloadFile(xmlname)
return true
end
function MakeXmlFile(xmlname, subject)
local thenode = xmlCreateFile (xmlname, subject)
if thenode then
xmlSaveFile(thenode)
end
end
function GetPlayerValue(playerelement, valuename)
return getElementData (playerelement, valuename)
end
function SetPlayerValue(playerelement, valuename, value)
return setElementData (playerelement, valuename, value)
end
function ResetPlayerValue(playerelement)
SetPlayerValue(playerelement, "Registered", false)
SetPlayerValue(playerelement, "Age", 0)
end
function SavePlayer(playerelement, id)
local pnode = xmlLoadFile(GetUserFileName(id))
local thenode_info = xmlFindChild (pnode, "Info", 0)
xmlNodeSetAttribute (thenode_info, "Age", GetPlayerValue(playerelement, "Age"))
xmlSaveFile(pnode)
xmlUnloadFile(pnode)
end
This is my serverside.
help me.