Jump to content

Help in EXP/Level System


^Dev-PoinT^

Recommended Posts

Hi all see this i take it From Zombie Gamemode i want if Player kill a player get 1 EXp every kill = +1 EXP

Server Side

function a () 
local account = getPlayerAccount(p) 
setAccountData(account,"Kills",true) 
local old = getAccountData(account,"EXP") or 0 
setAccountData(account,"EXP",old+5) 
triggerClientEvent(p,"expOnChange",getRootElement(),old+5,5) 
end 
addEventHandler ( "onPlayerWasted", getRootElement(), a ) 
  
function deanimated( ammo, attacker, weapon, bodypart ) 
    if (attacker) then 
        if (getElementType ( attacker ) == "player") and (getElementType ( source ) == "ped") then 
            if (getElementData (source, "Kills") == true) then 
                local isExp = getAccountData(getPlayerAccount(attacker),"EXP") 
                local expr = false 
                if isExp then 
                   expr = tonumber(isExp) + 1 
                else 
                    expr = 1 
                end 
                triggerClientEvent ( attacker, "expOnChange", getRootElement(), expr, 1) 
                givePlayerMoney(attacker,tonumber(get("zombiegamemode.Reward"))+math.random(-100,100)) 
                setPedOnFire(source,false) 
                setPedHeadless(source,false) 
                local attacker2 = getPlayerAccount(attacker) 
                local oldZcount = getAccountData(attacker2,"EXP") 
                if oldZcount ~= false then 
                    setAccountData ( attacker2, "EXP", oldZcount+1  ) 
                    setElementData( attacker, "EXP", oldZcount+1 ) 
                    setPlayerAnnounceValue(attacker,"EXP",tostring(oldZcount+1)) 
                    triggerEvent ( "onPlayerWasted", source, attacker, weapon, bodypart ) 
                else 
                    setAccountData ( attacker2, "EXP", 1  ) 
                    setPlayerAnnounceValue(attacker,"score","1") 
                    setElementData( attacker, "EXP", 1 ) 
                    triggerEvent ( "onPlayerWasted", source, attacker, weapon, bodypart )                
                end 
            end 
        end 
    end 
end 
addEventHandler("onPlayerWasted", resourceRoot, deanimated) 

Client Side

unction clientsetupstarter(startedresource) 
    if startedresource == getThisResource() then 
        setTimer ( clientsetup, 1234, 1) 
        MainClientTimer1 = setTimer ( zombie_check, 1000, 0) 
        expLabel = guiCreateLabel(0.777,0.22,0.1708,0.0963,"EXP gained: ??\nTotal EXP: ??\nLevel: Unknown",true) 
        guiLabelSetColor(expLabel,0,255,0) 
        guiLabelSetVerticalAlign(expLabel,"top") 
        guiLabelSetHorizontalAlign(expLabel,"left",false) 
        guiSetFont(expLabel,"clear-normal") 
    end 
end 
  
local ttlgnd = 0 
function expChange(expr,gained) 
    ttlgnd = ttlgnd+gained 
    guiSetText(expLabel,"") 
    local level,levelnum = "#0 - Newbie",0 
    if expr >= 10 then level = "#1 - Novice" levelnum = 1 end 
    if expr >= 20 then level = "#2 - Average" levelnum = 2 end 
    if expr >= 100 then level = "#3 - Good" levelnum = 3 end 
    if expr >= 200 then level = "#4 - Killer" levelnum = 4 end 
    if expr >= 500 then level = "#5 - Skilled" levelnum = 5 end 
    if expr >= 1000 then level = "#6 - Elite" levelnum = 6 end 
    if expr >= 2000 then level = "#7 - Senior" levelnum = 7 end 
    if expr >= 3000 then level = "#8 - Amazing" levelnum = 8 end 
    if expr >= 5000 then level = "#9 - Pro" levelnum = 9 end 
    if expr >= 10000 then level = "#10 - Godlike" levelnum = 10 end 
    if expr >= 20000 then level = "#11 - God" levelnum = 11 end 
    guiSetText(expLabel,"EXP gained: "..ttlgnd.." (+"..gained..")\nTotal EXP: "..expr.."\nLevel: "..level) 
    setElementData(getLocalPlayer(),"Level",level) 
    setElementData(getLocalPlayer(),"levelnum",levelnum) 
end 
addEvent( "expOnChange", true ) 
addEventHandler( "expOnChange", getRootElement(), expChange ) 
addEventHandler("onClientResourceStart", getRootElement(), clientsetupstarter) 

Link to comment

Seems you are in way over your head Dev_Point :P

Another thing.. Are you even sure that your script has access to ' "zombiegamemode.Reward" ' ?

If I was you, I would shut down and delete this resource right away.

If you want an experience/level system for your gamemode, I would recommend that you read how other people have done it in the past. Not just MTA players, but for all games that have those elements included.

Could be games like World of Warcraft. There is TONS of info about the setup on the web.

Link to comment
You are right but iam not good as you are i have a Gamemode but its Need EXP/Level System :(

I know bud. I just wanted to remind you that you have to be realistic sometimes. I know that you really want your gamemode finished, but if some of the elements are too hard for you to do on your own, then you have to wait or get someone to help you finish it.

I know that you are putting a lot of work into your project, which is just fine.

But in the end, wouldnt it be a better feeling to have something you have created on your own, rather than to have 90% resources created by others?

Link to comment

Hi all i have Made This Server side if killer kill a player get +1 EXP every time he kill

P.S with Tabel for the EXP

exports.scoreboard:scoreboardAddColumn("EXP") 
  
give = {{[1] = "1"}, {{[2] = "2"}}, {{[3] = "3"}}} 
  
function win(ammo, killer, weapon, bodypart) 
    local H = getElementData(killer, "EXP") 
    local killer1 = getPlayerName(killer) 
    local noob = getPlayerName(source) 
    if killer and killer ~=source then 
    setElementData(killer, "EXP", tonumber(give) + 1) 
    outputChatBox(killer1 .. "Killed " .. noob .. " and gained +1 EXP", getRootElement(), 255, 255, 0, false) 
    end 
end 
addEventHandler("onPlayerWasted", getRootElement(), Win) 

Link to comment

Why do you need a table to just add +1 to a element data?

exports.scoreboard:scoreboardAddColumn("EXP") 
  
function win(ammo, killer, weapon, bodypart) 
    local H = getElementData(killer, "EXP") 
    local killer1 = getPlayerName(killer) 
    local noob = getPlayerName(source) 
    if killer and killer ~=source then 
    setElementData(killer, "EXP", tonumber(H)+1) 
    outputChatBox(killer1 .. "Killed " .. noob .. " and gained +1 EXP", getRootElement(), 255, 255, 0, false) 
    end 
end 
addEventHandler("onPlayerWasted", getRootElement(), Win) 

Link to comment

not just +1

i made the table for

1 = +1

2 = +1

3= +1

.... 10/EXP

you get it?

exports.scoreboard:scoreboardAddColumn("EXP") 
  
give = {{[1] = "1"}, {{[2] = "2"}}, {{[3] = "3"}}} 
  
function win(ammo, killer, weapon, bodypart) 
    local H = getElementData(killer, "EXP") 
    local killer1 = getPlayerName(killer) 
    local noob = getPlayerName(source) 
    if killer and killer ~=source then 
    setElementData(killer, "EXP", tonumber(give) + 1) 
    outputChatBox(killer1 .. "Killed " .. noob .. " and gained +1 EXP", getRootElement(), 255, 255, 0, false) 
    end 
end 
addEventHandler("onPlayerWasted", getRootElement(), Win) 

Link to comment
exports.scoreboard:scoreboardAddColumn("EXP") 
  
function win(ammo, killer, weapon, bodypart) 
    local H = getElementData(killer, "EXP") 
    local killer1 = getPlayerName(killer) 
    local noob = getPlayerName(source) 
    if killer and killer ~=source then 
    if tonumber(H) < 10 then 
         setElementData(killer, "EXP", tonumber(H)+1) 
    end 
    outputChatBox(killer1 .. "Killed " .. noob .. " and gained +1 EXP", getRootElement(), 255, 255, 0, false) 
    end 
end 
addEventHandler("onPlayerWasted", getRootElement(), Win) 

Should work.

Link to comment

i last thing

if EXP = 10 then

setPlayerLevel "lvl1"

....

exports.scoreboard:scoreboardAddColumn("EXP") 
exports.scoreboard:scoreboardAddColumn("Level") 
  
function win(ammo, killer, weapon, bodypart) 
    local H = getElementData(killer, "EXP") 
    local S = getElementData(killer, "Level") 
    local killer1 = getPlayerName(killer) 
    local noob = getPlayerName(source) 
    if killer and killer ~=source then 
    if tonumber(H) < 10 then 
    setElementData(killer, "Level", "Lvl 1") 
    if tonumber(S) < 20 then 
    setElementData(killer, "Level", "Lvl 2") 
    if tonumber(S) < 30 then 
    setElementData(killer, "Level", "Lvl 3") 
    if tonumber(S) < 40 then 
    setElementData(killer, "Level", "Lvl 4") 
    if tonumber(S) < 50 then 
    setElementData(killer, "Level", "Lvl 5") 
    if tonumber(S) < 60 then 
    setElementData(killer, "Level", "Lvl 6") 
         setElementData(killer, "EXP", tonumber(H)+1) 
    end 
    outputChatBox(killer1 .. "Killed " .. noob .. " and gained +1 EXP", getRootElement(), 255, 255, 0, false) 
    end 
end 
addEventHandler("onPlayerWasted", getRootElement(), Win) 

Link to comment
exports.scoreboard:scoreboardAddColumn("EXP") 
exports.scoreboard:scoreboardAddColumn("Level") 
  
function win(ammo, killer, weapon, bodypart) 
    local H = getElementData(killer, "EXP") 
    local S = getElementData(killer, "Level") 
    local killer1 = getPlayerName(killer) 
    local noob = getPlayerName(source) 
    if killer and killer ~=source then 
    setElementData(killer, "EXP", tonumber(H)+1) 
    if tonumber(H) == 10 then 
    setElementData(killer, "Level", "Lvl 1") 
    elseif tonumber(H) == 20 then 
    setElementData(killer, "Level", "Lvl 2") 
    elseif tonumber(H) == 30 then 
    setElementData(killer, "Level", "Lvl 3") 
    elseif tonumber(H) == 40 then 
    setElementData(killer, "Level", "Lvl 4") 
    elseif tonumber(H) == 50 then 
    setElementData(killer, "Level", "Lvl 5") 
    elseif tonumber(H) == 60 then 
    setElementData(killer, "Level", "Lvl 6") 
    end 
    outputChatBox(killer1 .. "Killed " .. noob .. " and gained +1 EXP", getRootElement(), 255, 255, 0, false) 
    end 
end 
addEventHandler("onPlayerWasted", getRootElement(), Win) 

Edited by Guest
Link to comment

server.lua:27: 'end' expected (to close 'if' at line 15) near ''

exports.scoreboard:scoreboardAddColumn("EXP") 
exports.scoreboard:scoreboardAddColumn("Level") 
  
function win(ammo, killer, weapon, bodypart) 
    local H = getElementData(killer, "EXP") 
    local S = getElementData(killer, "Level") 
    local killer1 = getPlayerName(killer) 
    local noob = getPlayerName(source) 
    if killer and killer ~=source then 
    setElementData(killer, "EXP", tonumber(H)+1) 
    if tonumber(H) == 10 then 
    setElementData(killer, "Level", "Lvl 1") 
    if tonumber(H) == 20 then 
    setElementData(killer, "Level", "Lvl 2") 
    if tonumber(H) == 30 then 
    setElementData(killer, "Level", "Lvl 3") 
    if tonumber(H) == 40 then 
    setElementData(killer, "Level", "Lvl 4") 
    if tonumber(H) == 50 then 
    setElementData(killer, "Level", "Lvl 5") 
    if tonumber(H) == 60 then 
    setElementData(killer, "Level", "Lvl 6") 
    end 
    outputChatBox(killer1 .. "Killed " .. noob .. " and gained +1 EXP", getRootElement(), 255, 255, 0, false) 
end 
addEventHandler( "onPlayerWasted", getRootElement(), Win) 

Edited by Guest
Link to comment

You removed one 'end'.

exports.scoreboard:scoreboardAddColumn("EXP") 
exports.scoreboard:scoreboardAddColumn("Level") 
  
function win(ammo, killer, weapon, bodypart) 
    local H = getElementData(killer, "EXP") 
    local S = getElementData(killer, "Level") 
    local killer1 = getPlayerName(killer) 
    local noob = getPlayerName(source) 
    if killer and killer ~=source then 
    setElementData(killer, "EXP", tonumber(H)+1) 
    if tonumber(H) == 10 then 
    setElementData(killer, "Level", "Lvl 1") 
    elseif tonumber(H) == 20 then 
    setElementData(killer, "Level", "Lvl 2") 
    elseif tonumber(H) == 30 then 
    setElementData(killer, "Level", "Lvl 3") 
    elseif tonumber(H) == 40 then 
    setElementData(killer, "Level", "Lvl 4") 
    elseif tonumber(H) == 50 then 
    setElementData(killer, "Level", "Lvl 5") 
    elseif tonumber(H) == 60 then 
    setElementData(killer, "Level", "Lvl 6") 
    end 
    outputChatBox(killer1 .. "Killed " .. noob .. " and gained +1 EXP", getRootElement(), 255, 255, 0, false) 
    end 
end 
addEventHandler( "onPlayerWasted", getRootElement(), win) 

Edited by Guest
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...