slotman Posted August 5, 2012 Posted August 5, 2012 (edited) Exp up but Level no up. Zombie sever Client function levelup () local Exp = getElementData(localPlayer,"ExP") local Level = getElementData(localPlayer,"Level") if isElement(expLabel) then destroyElement(expLabel) end expLabel = guiCreateLabel(0.777,0.22,0.1708,0.0963,"ExP gained: ??\nTotal ExP: ".. tostring(Exp) .."\nLevel: ".. tostring(Level),true) guiLabelSetColor(expLabel,0,255,0) guiLabelSetVerticalAlign(expLabel,"top") guiLabelSetHorizontalAlign(expLabel,"left",false) guiSetFont(expLabel,"clear-normal") setTimer ( levelup, 2000, 1) end setTimer ( levelup, 2000, 1) Server exports.scoreboard:scoreboardAddColumn("ExP") exports.scoreboard:scoreboardAddColumn("Level") local levels = {[30] = 1, [55] = 2, [75] = 3, [85] = 4, [95] = 5, [120] = 6, [150] = 7, [230] = 8, [350] = 9, [500] = 10} addEvent("onZombieWasted",true) addEventHandler("onZombieWasted",root, function (killer) addPlayerZombieKills(killer) end) function addPlayerZombieKills(killer) local account = getPlayerAccount(killer) if isGuestAccount(account) then return end local H = getElementData(killer, "ExP") local S = getElementData(killer, "Level") setElementData(killer, "ExP", tonumber(H)+5) if levels[tonumber(H)] then setElementData(killer, "Level", "lvl ".. tostring(levels[tonumber(H)]) .." !") triggerClientEvent ( killer, "playSound", killer ) end end function onLogin (_,account) setElementData(source, "Level", getAccountData(account, "lvl") or "Level 0 !") setElementData(source, "ExP", getAccountData(account, "exp") or "0") end addEventHandler ("onPlayerLogin", root, onLogin) function saveData(thePlayer, theAccount) if (theAccount and not isGuestAccount(theAccount)) then setAccountData (theAccount, "lvl", getElementData(thePlayer, "Level")) setAccountData (theAccount, "exp", getElementData(thePlayer, "ExP")) end end addEventHandler ("onPlayerQuit", root, function () saveData(source, getPlayerAccount(source)) end) addEventHandler ("onPlayerLogout", root, function (prev) saveData(source, prev) end) Edited August 5, 2012 by Guest
Castillo Posted August 5, 2012 Posted August 5, 2012 Well, it should work if your experience is on the table.
slotman Posted August 5, 2012 Author Posted August 5, 2012 well .Solidsnake14 help me .Level No up but exp up Edit: i come from THAILAND .I'm not good at English.
Castillo Posted August 5, 2012 Posted August 5, 2012 I've tested your script first, it seemed to work, although, I made some changes. -- client side: function levelup ( ) if isElement ( expLabel ) then destroyElement ( expLabel ) end local Exp = getElementData ( localPlayer, "ExP" ) local Level = getElementData ( localPlayer, "Level" ) expLabel = guiCreateLabel ( 0.777, 0.22, 0.1708, 0.0963, "ExP gained: ??\nTotal ExP: ".. tostring ( Exp ) .."\nLevel: ".. tostring ( Level ), true ) guiLabelSetColor ( expLabel, 0, 255, 0 ) guiLabelSetVerticalAlign ( expLabel, "top" ) guiLabelSetHorizontalAlign ( expLabel, "left", false ) guiSetFont ( expLabel, "clear-normal" ) setTimer ( levelup, 2000, 1 ) end setTimer ( levelup, 2000, 1 ) -- server side: exports.scoreboard:scoreboardAddColumn ( "ExP" ) exports.scoreboard:scoreboardAddColumn ( "Level" ) local levels = { [ 30 ] = 1, [ 55 ] = 2, [ 75 ] = 3, [ 85 ] = 4, [ 95 ] = 5, [ 120 ] = 6, [ 150 ] = 7, [ 230 ] = 8, [ 350 ] = 9, [ 500 ] = 10 } addEvent ( "onZombieWasted", true ) addEventHandler ( "onZombieWasted", root, function ( killer ) addPlayerZombieKills ( killer ) end ) function addPlayerZombieKills ( killer ) local account = getPlayerAccount ( killer ) if isGuestAccount ( account ) then return end local H = tonumber ( getElementData ( killer, "ExP" ) ) or 0 setElementData ( killer, "ExP", tonumber ( H ) + 5 ) local H = ( H + 5 ) if ( levels [ H ] ) then setElementData ( killer, "Level", "lvl ".. tostring ( levels [ H ] ) .." !" ) triggerClientEvent ( killer, "playSound", killer ) end end function onLogin ( _, account ) setElementData ( source, "Level", getAccountData ( account, "lvl" ) or "Level 0 !" ) setElementData ( source, "ExP", getAccountData ( account, "exp" ) or "0" ) end addEventHandler ( "onPlayerLogin", root, onLogin ) function saveData ( thePlayer, theAccount ) if ( theAccount and not isGuestAccount ( theAccount ) ) then setAccountData ( theAccount, "lvl", getElementData ( thePlayer, "Level" ) ) setAccountData ( theAccount, "exp", getElementData ( thePlayer, "ExP" ) ) end end addEventHandler ( "onPlayerQuit", root, function ( ) saveData ( source, getPlayerAccount ( source ) ) end ) addEventHandler ( "onPlayerLogout", root, function ( prev ) saveData ( source, prev ) end )
slotman Posted August 5, 2012 Author Posted August 5, 2012 meta "Castillo" type="script" name="exp/level system" description="exp/level system" version="3.1"/>
Castillo Posted August 5, 2012 Posted August 5, 2012 exports.scoreboard:scoreboardAddColumn ( "ExP" ) exports.scoreboard:scoreboardAddColumn ( "Level" ) local levels = { [ 30 ] = 1, [ 55 ] = 2, [ 75 ] = 3, [ 85 ] = 4, [ 95 ] = 5, [ 120 ] = 6, [ 150 ] = 7, [ 230 ] = 8, [ 350 ] = 9, [ 500 ] = 10 } addEvent ( "onZombieWasted", true ) addEventHandler ( "onZombieWasted", root, function ( killer ) addPlayerZombieKills ( killer ) end ) function addPlayerZombieKills ( killer ) local account = getPlayerAccount ( killer ) if isGuestAccount ( account ) then return end local H = tonumber ( getElementData ( killer, "ExP" ) ) or 0 outputChatBox ( "Cur experience: ".. tostring ( H ) ) setElementData ( killer, "ExP", tonumber ( H ) + 5 ) local H = ( H + 5 ) outputChatBox ( "New experience: ".. tostring ( H ) ) if ( levels [ H ] ) then setElementData ( killer, "Level", "lvl ".. tostring ( levels [ H ] ) .." !" ) triggerClientEvent ( killer, "playSound", killer ) else outputChatBox ( "No level for experience: ".. tostring ( H ) ) end end function onLogin ( _, account ) setElementData ( source, "Level", getAccountData ( account, "lvl" ) or "Level 0 !" ) setElementData ( source, "ExP", getAccountData ( account, "exp" ) or "0" ) end addEventHandler ( "onPlayerLogin", root, onLogin ) function saveData ( thePlayer, theAccount ) if ( theAccount and not isGuestAccount ( theAccount ) ) then setAccountData ( theAccount, "lvl", getElementData ( thePlayer, "Level" ) ) setAccountData ( theAccount, "exp", getElementData ( thePlayer, "ExP" ) ) end end addEventHandler ( "onPlayerQuit", root, function ( ) saveData ( source, getPlayerAccount ( source ) ) end ) addEventHandler ( "onPlayerLogout", root, function ( prev ) saveData ( source, prev ) end ) Try that and tell me what does it output to chat box.
slotman Posted August 5, 2012 Author Posted August 5, 2012 yes .show output chat box. but level no up.
Castillo Posted August 5, 2012 Posted August 5, 2012 That's obviously, you don't have the value 2486 on your levels table: local levels = { [ 30 ] = 1, [ 55 ] = 2, [ 75 ] = 3, [ 85 ] = 4, [ 95 ] = 5, [ 120 ] = 6, [ 150 ] = 7, [ 230 ] = 8, [ 350 ] = 9, [ 500 ] = 10 } See? your script searches for the experience on that table, if there is, you level up.
slotman Posted August 5, 2012 Author Posted August 5, 2012 No up. i setting [ 2700 ] = 1, I do not understand.
Castillo Posted August 5, 2012 Posted August 5, 2012 The way your script works is not good, because if the exact experience is not on the levels table, it won't level up.
Castillo Posted August 5, 2012 Posted August 5, 2012 I made your script to work different, this way it'll work. -- client side: function levelup ( ) if isElement ( expLabel ) then destroyElement ( expLabel ) end local Exp = getElementData ( localPlayer, "ExP" ) or 0 local Level = getElementData ( localPlayer, "Level" ) or 0 expLabel = guiCreateLabel ( 0.777, 0.22, 0.1708, 0.0963, "ExP gained: ??\nTotal ExP: ".. tostring ( Exp ) .."\nLevel: ".. tostring ( Level ), true ) guiLabelSetColor ( expLabel, 0, 255, 0 ) guiLabelSetVerticalAlign ( expLabel, "top" ) guiLabelSetHorizontalAlign ( expLabel, "left", false ) guiSetFont ( expLabel, "clear-normal" ) setTimer ( levelup, 2000, 1 ) end setTimer ( levelup, 2000, 1 ) -- server side: exports.scoreboard:scoreboardAddColumn ( "ExP" ) exports.scoreboard:scoreboardAddColumn ( "Level" ) local levels = { 30, 55, 75, 85, 95, 120, 150, 230, 350, 500 } addEvent ( "onZombieWasted", true ) addEventHandler ( "onZombieWasted", root, function ( killer ) addPlayerZombieKills ( killer ) end ) function addPlayerZombieKills ( killer ) local account = getPlayerAccount ( killer ) if isGuestAccount ( account ) then return end local H = tonumber ( getElementData ( killer, "ExP" ) ) or 0 local L = tonumber ( getElementData ( killer, "Level" ) ) or 0 setElementData ( killer, "ExP", tonumber ( H ) + 5 ) local H = ( H + 5 ) local L = ( L + 1 ) if ( L <= #levels ) and ( levels [ L ] ) and ( tonumber ( H ) >= tonumber ( levels [ L ] ) ) then setElementData ( killer, "Level", L ) triggerClientEvent ( killer, "playSound", killer ) end end function onLogin ( _, account ) setElementData ( source, "Level", getAccountData ( account, "lvl" ) or "Level 0 !" ) setElementData ( source, "ExP", getAccountData ( account, "exp" ) or "0" ) end addEventHandler ( "onPlayerLogin", root, onLogin ) function saveData ( thePlayer, theAccount ) if ( theAccount and not isGuestAccount ( theAccount ) ) then setAccountData ( theAccount, "lvl", getElementData ( thePlayer, "Level" ) ) setAccountData ( theAccount, "exp", getElementData ( thePlayer, "ExP" ) ) end end addEventHandler ( "onPlayerQuit", root, function ( ) saveData ( source, getPlayerAccount ( source ) ) end ) addEventHandler ( "onPlayerLogout", root, function ( prev ) saveData ( source, prev ) end )
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