Bassam*Syria Posted June 22, 2014 Share Posted June 22, 2014 السلام عليكم و قسم اعرف اني كترت عليكون و كتيير بس اليوم جيت و طالبكون تعدلولي على مود المود هو عبارة عن لفل كل ما تقتل زومبي يزيد بس انا ابي اخليه لما يتقل لاعب مب زومبي لو تقدر تساعدوني لاااااااااااااااااهنت لا تقصرو الاكواد سيرفر local ExpRewardForKill = {1, 8} local levels = {} addEventHandler ( "onResourceStart", resourceRoot, function ( ) connection = dbConnect( "sqlite", "levels.db" ) --exports["scoreboard"]:scoreboardAddColumn ( "level", root, 90, "Player's Level") if ( connection )then dbExec ( connection, "CREATE TABLE IF NOT EXISTS levels (levelID INTEGER PRIMARY KEY NOT NULL, accountName TEXT, level INT, experience INT)" ) outputDebugString ( "Successfully connected to levels.db" ) else outputDebugString ( "Failed to connect to levels.db", 3 ) end local LivelsFile = xmlLoadFile ( "levels.xml" ) if ( LivelsFile ) then outputDebugString ( "levels.xml successfully open") for index, levelData in ipairs ( xmlNodeGetChildren ( LivelsFile ) ) do local levelAttributes = xmlNodeGetAttributes ( levelData ) table.insert(levels, { ["levelName"] = levelAttributes.levelName, ["experienceRequired"] = tonumber(levelAttributes.experienceRequired), ["moneyReward"] = tonumber(levelAttributes.moneyReward)}) end else outputDebugString ( "Failed to open to levels.xml", 1 ) end end ) --[[ addCommandHandler ( "level", function ( thePlayer ) removeElementData(thePlayer,"experience") removeElementData(thePlayer,"level") end ) ]] addEventHandler("onResourceStop",resourceRoot, function ( ) if isElement ( connection ) then setTimer(destroyElement, 1000, 1, connection ) end end ) addEventHandler("onResourceStop",resourceRoot, function () for index, player in ipairs(getElementsByType("player")) do local experience = tonumber(getElementData(player,"experience")) or 0 setPlayerExperience(player, experience) local PlayerLevel = tonumber(getElementData(player,"level")) or 1 setPlayerLevel(player, PlayerLevel) end end) function saveExpOnQuitOrLogout(account) local experience = tonumber(getElementData(source,"experience")) or 0 local PlayerLevel = tonumber(getElementData(source,"level")) or 1 if (experience) then if (account and account == "userdata") then setPlayerExperience(account, experience) setPlayerLevel(account, PlayerLevel) else setPlayerExperience(source, experience) setPlayerLevel(source, PlayerLevel) end end setElementData(source,"experience",0) end addEventHandler("onPlayerLogout",root,saveExpOnQuitOrLogout) addEventHandler("onPlayerQuit",root,saveExpOnQuitOrLogout) function CheckLevelFromExp(dataName) if (source and getElementType(source) == "player" and dataName == "experience") then local SourceLevel = tonumber( getElementData(source,"level") ) local SourceExp = tonumber( getElementData(source,"experience") ) local NewLvl = SourceLevel+1 if ( levels[SourceLevel] ) then if ( levels[NewLvl]) then local RequiredExp = tonumber( levels[SourceLevel]["experienceRequired"] ) if ( SourceExp >= RequiredExp ) then setElementData(source,"experience_n", tonumber(levels[NewLvl]["experienceRequired"])) setElementData(source,"level",NewLvl) setTimer(setElementData, 50, 1, source,"experience",0) givePlayerMoney(source,tonumber(levels[NewLvl].moneyReward)) triggerClientEvent ( source, "LevelUpEffect", source ) outputChatBox("*LEVEL UP* You're now level ".. tostring(NewLvl) .."! Congratulations.",source,0,255,0) end end end end end addEventHandler("onElementDataChange",root,CheckLevelFromExp) function OnZombieKill (killer) if (killer and killer ~= source) then if getPlayerAccount(killer) then local experience = tonumber(getElementData(killer,"experience")) local SourceLevel = getElementData(killer,"level") if ( not SourceLevel ) then SourceLevel = 1 setElementData(killer,"level",1) end if ( levels[SourceLevel+1] ) then local randomExperience = math.random(unpack(ExpRewardForKill)) if (experience) then setElementData(killer,"experience",experience+tonumber(randomExperience)) else setElementData(killer,"experience",randomExperience) end else setElementData(killer,"experience",tonumber(levels[SourceLevel]["experienceRequired"])) end end end end addEvent("onZombieWasted",true) addEventHandler ("onZombieWasted", root, OnZombieKill) addEventHandler("onPlayerLogin",root, function (_,account) local accountName = getAccountName(account) local handler = connection local query = dbQuery( handler, "SELECT accountName FROM levels WHERE accountName=?", tostring(accountName) ) local result, numrows, errmsg = dbPoll ( query, -1 ) if ( type( result ) == "table" and #result == 0 or not result ) then if dbExec( handler, "INSERT INTO `levels` (`levelID`, `accountName`, `level`, `experience`) VALUES (NULL, '".. accountName .."', '1', '0');") then setElementData(source, "experience", 0) setElementData(source, "experience_n", tonumber(levels[1].experienceRequired)) setElementData(source, "level", 1) end else local level = getPlayerLevel(source) setElementData(source, "experience", getPlayerExperience(source)) if (levels[level]) then setElementData(source, "experience_n", tonumber(levels[level].experienceRequired)) else setElementData(source, "experience_n", tonumber(levels[level -1].experienceRequired)) end setElementData(source, "level", level) end end) function getPlayerLevel(thePlayer) local handler = connection if (isElement(thePlayer) and getElementType(thePlayer) == "player") then account = getPlayerAccount(thePlayer) else account = thePlayer end if (not account or isGuestAccount(account)) then return false end local accountName = getAccountName(account) local query = dbQuery( handler, "SELECT level FROM `levels` WHERE accountName='".. tostring(accountName) .."'") local result, numrows, errmsg = dbPoll( query, -1 ) if (result) then return tonumber(result[1]["level"]) end end function setPlayerLevel(thePlayer, theLevel) local handler = connection if (isElement(thePlayer) and getElementType(thePlayer) == "player") then account = getPlayerAccount(thePlayer) else account = thePlayer end if (not account or isGuestAccount(account)) then return false end local accountName = getAccountName(account) if dbExec( handler, "UPDATE `levels` SET `level` = '" .. tonumber(theLevel) .. "' WHERE `accountName` = '" .. tostring(accountName) .."'" ) then return true else return false end end function getPlayerExperience(thePlayer) local handler = connection if (isElement(thePlayer) and getElementType(thePlayer) == "player") then account = getPlayerAccount(thePlayer) else account = thePlayer end if (not account or isGuestAccount(account)) then return false end local accountName = getAccountName(account) local query = dbQuery( handler, "SELECT experience FROM `levels` WHERE accountName='".. tostring(accountName) .."'") local result, numrows, errmsg = dbPoll( query, -1 ) if (result) then return tonumber(result[1]["experience"]) end end function setPlayerExperience(thePlayer, theExperience) local handler = connection if (isElement(thePlayer) and getElementType(thePlayer) == "player") then account = getPlayerAccount(thePlayer) else account = thePlayer end if (not account or isGuestAccount(account)) then return false end local accountName = getAccountName(account) if dbExec( handler, "UPDATE `levels` SET `experience` = '" .. tonumber(theExperience) .. "' WHERE `accountName` = '" .. tostring(accountName) .."'" ) then return true else return false end end 2 كلنت local sx, sy = guiGetScreenSize() function drawExperience() dxDrawRectangle((310/1024)*sx,(698/768)*sy,(481/1024)*sx,(36/768)*sy,tocolor(255,255,255,35),false) dxDrawRectangle((315/1024)*sx,(703/768)*sy,(472/1024)*sx,(26/768)*sy,tocolor(0,0,0,255),false) local experience = getElementData(localPlayer,"experience") or 0 local experience_n = getElementData(localPlayer,"experience_n") or 0 local level = getElementData(localPlayer,"level") or 1 local percent = (experience / experience_n * 100) if (percent >= 100) then percent = 100 elseif (experience_n < 1) then percent = 0 end dxDrawRectangle((320/1024)*sx,(706/768)*sy,(tonumber(percent)*4.64/1024)*sx,(20/768)*sy,tocolor(255,255,255,75),false) dxDrawBorderedText("Level: ".. tostring(level) .." | Experience Points: ".. tostring(experience) .." > ".. tostring(experience_n),(430/1024)*sx,(707/768)*sy,(667/1024)*sx,(724/768)*sy,tocolor(0,0,0,255),(sx/1024)*0.6,"bankgothic","center","center",false,false,false) end addEventHandler("onClientRender",root,drawExperience) function dxDrawBorderedText( text, x, y, w, h, color, scale, font, alignX, alignY, clip, wordBreak, postGUI ) dxDrawText ( text, x - 1, y - 1, w - 1, h - 1, tocolor ( 255, 255, 255, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) -- black dxDrawText ( text, x + 1, y - 1, w + 1, h - 1, tocolor ( 255, 255, 255, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) dxDrawText ( text, x - 1, y + 1, w - 1, h + 1, tocolor ( 255, 255, 255, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) dxDrawText ( text, x + 1, y + 1, w + 1, h + 1, tocolor ( 255, 255, 255, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) dxDrawText ( text, x - 1, y, w - 1, h, tocolor ( 255, 255, 255, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) dxDrawText ( text, x + 1, y, w + 1, h, tocolor ( 255, 255, 255, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) dxDrawText ( text, x, y - 1, w, h - 1, tocolor ( 255, 255, 255, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) dxDrawText ( text, x, y + 1, w, h + 1, tocolor ( 255, 255, 255, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) dxDrawText ( text, x, y, w, h, color, scale, font, alignX, alignY, clip, wordBreak, postGUI ) end addEvent ( "LevelUpEffect", true ) addEventHandler ( "LevelUpEffect", root, function ( ) PlayerLevelUpSound() addEventHandler("onClientRender",root,DrawLevelUp) setTimer(function() removeEventHandler("onClientRender",root,DrawLevelUp) end, 4000, 1) end ) function PlayerLevelUpSound() local sound = playSound("levelup.mp3") setSoundVolume(sound, 1) end function DrawLevelUp() dxDrawBorderedText( "LEVEL UP!!!", sx/2, sy/15, sx/2, sx/2, tocolor(255,144,0,255),(sx/1024)*2.5,"bankgothic","center","center",false,false,false ) end Link to comment
3NAD Posted June 22, 2014 Share Posted June 22, 2014 OnZombieKill سيرفر بدل وظيفة function OnPlayerKill (_, killer) if killer then if getElementType ( killer ) == "player" then if killer ~= source then if not isGuestAccount(getPlayerAccount(killer)) then local experience = tonumber(getElementData(killer,"experience")) local SourceLevel = getElementData(killer,"level") if ( not SourceLevel ) then SourceLevel = 1 setElementData(killer,"level",1) end if ( levels[SourceLevel+1] ) then local randomExperience = math.random(unpack(ExpRewardForKill)) if (experience) then setElementData(killer,"experience",experience+tonumber(randomExperience)) else setElementData(killer,"experience",randomExperience) end else setElementData(killer,"experience",tonumber(levels[SourceLevel]["experienceRequired"])) end end end end end end addEventHandler ("onPlayerWasted", root, OnPlayerKill) Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now