Jump to content

[REQ]Ranks system


Recommended Posts

Hello!

mujha ek chotta sa code cahiya mana ek criminal job bnayi hai lakin mujha ranks system bhi chaiya, like jab player car hijack karra ga or doursra player ko kill karra ga, etc............... so usaa ek point milla ga. ranks also must be show in scoreboard. pls pls

local ranks = { 
    {"Criminal", "Street Rat", 0}, 
    {"Criminal", "Mugger", 100}, 

Link to comment

:phew: finally maine bana li, though 30 minutes lagay lekin maine dynamic system banya hai, tum table main unlimited job names daal do aur unlimited ranks daal do, ye phir bhi un ko read/write karega.

-- Local tables cache, gets reset once script is stopped: 
jobRanks = { 
  
["Criminals"] = { 
    {"Street Rat", 0}, 
    {"Mugger", 100}, 
}, 
  
["Law-Enforcements"] = { 
    {"Street Cop", 0}, 
    {"Street Detective", 100}, 
} 
  
} 
  
jobPoints = { 
["Criminals"] = {}, 
["Law-Enforcements"] = {} 
} 
  
function updateJobProgress(acc, job, pts) 
    if (not acc) or (not job) then return end 
    local pts = tonumber(pts) or 1 
    jobPoints[job][acc] = getJobProgress(acc, job) + pts 
    updateJobRank(acc, job) 
    return true 
end 
  
function updateJobRank(acc, job) 
    if (not acc) or (not job) then return end 
    local prog = getJobProgress(acc, job) 
    local rank = 0 
    for k, v in pairs(jobRanks[job]) do 
        if prog > v[2] then 
            rank = rank + 1 
        end 
    end 
    if #jobRanks[job] < rank then rank = #jobRanks[job] end 
    if rank < 1 then rank = 1 end 
    return jobRanks[job][rank][1] 
end 
  
function getJobProgress(acc, job) 
    if (not acc) or (not job) then return end 
    return tonumber(jobPoints[job][acc]) or 0 
end 
  
function updateOnStop(res) 
    if res ~= getThisResource() then return end 
    for k, v in pairs(jobPoints) do 
        for i, d in pairs(v) do 
            local acc = getAccount(i) or nil 
            setAccountData(acc, "jobsProgress."..k, d or 0) 
            outputDebugString("UJP for: "..getAccountName(acc).." - Job: "..k.." - Progress: "..d) 
        end 
    end 
end 
addEventHandler("onResourceStop", root, updateOnStop) 
  
createTeam("Criminals") 
createTeam("Law-Enforcements") 
  
function updateOnStart(res) 
    if res ~= getThisResource() then return end 
    local accounts = getAccounts() 
    local teams = getElementsByType("team") 
    for k, v in pairs(accounts) do 
        for i, d in pairs(teams) do 
            local acc = getAccountName(v) 
            local job = getTeamName(d) 
            local progress = tonumber(getAccountData(v, "jobsProgress."..job)) or 0 
            if jobPoints[job] then 
                jobPoints[job][acc] = progress 
                outputDebugString("GJP for: "..acc.." - Job: "..job.." - Progress: "..progress) 
            end 
        end 
    end 
end 
addEventHandler("onResourceStart", root, updateOnStart) 
  
function ranks(plr, cmd, state, job, pts) 
    local acc = getAccountName(getPlayerAccount(plr)) 
    if state == "ujp" then 
        updateJobProgress(acc, job, pts) 
        outputChatBox("Job progress updated for "..job, plr) 
    elseif state == "ujr" then 
        outputChatBox("Your job rank is: "..updateJobRank(acc, job), plr) 
    else 
        outputChatBox("Your job progress is: "..getJobProgress(acc, job), plr) 
    end 
end 
addCommandHandler("jp", ranks) 

End main maine aik test code dala hai, go ig, type /jp [ujp or ujr or gjp] JobName points iss command ka ye matla hai:

/jobprogres [updatejobprogress or updatejobrank or getjobprogress] jobName points (Sab short forms hain) Aur jobName MUST be a job, warna masla ho ga.

Ye script job progress ko local tables main save karegi aur resource stop honay par isay account data main daal de gi, phir resource start honay par wapis table main daal de gi. Aur tests + debugging ke liye maine outputDebugString use kiya hai, uss ka output aisa ho ga:

UJP for: AccountName - Job: jobName - Progress: progress -- Updated job progress for...

GJP for: AccountName - Job: jobName - Progress: progress -- Gotjob progress for...

Koi edit main help chahiye ho to poocho.

Link to comment

wohi tou manie banaya hai, tum onPlayerHijack wali event parfunction daalo updateJobProgress(accountName, "Criminals", 1) 1 at end is optional, aap chahein tou ye number daaleing ya phir rehnay dein, ye 1 point de ga.

Ye lo ye code aakhir main daalo aur check karo:

--> Below are events which will update job progresses. 
function hijackPoints(plr, seat, jack) 
    local plrAcc = getAccountName(getPlayerAccount(plr)) -- Get account name of player who entered vehicle. 
    local plrTeam = getTeamName(getPlayerTeam(plr)) -- Get his team name. 
    if seat ~= 0 or not jacked or plrTeam ~= "Criminals" then return end -- If he is not at driver's seat OR he is not hijacking a player OR he is not a Criminal then don't proceed any further. 
    local jackTeam = getTeamName(getPlayerTeam(plr)) -- Get team name of player who got hijacked. 
    local points = 1 -- Default points the criminal would get by ordinary hijack. 
    if jackTeam == "Law-Enforcements" then points = 3 end -- If the player who is jacked, is Cop, then the criminal would get 3 points for his bravery. 
    updateJobProgress(plrAcc, "Criminals", points) -- Update points. 
    outputChatBox("Job Progress: Earned +"..points.." job progress by hijacking this player!", plr, 100, 100, 0) -- Tell the criminal that he succeeded. 
end 
addEventHandler("onVehicleEnter", root, hijackPoints) 
  
function arrestPoints(ammo, plr) 
    if (not plr) or (getElementType(plr) ~= "player") or (getTeamName(getPlayerTeam(source)) ~= "Law-Enforcements") then return end 
    local wanted = tonumber(getPlayerWantedLevel(plr)) or 0 
    if wanted < 1 then return end 
    local plrAcc = getAccountName(getPlayerAccount(plr)) 
    updateJobProgress(plrAcc, "Law-Enforcements", wanted) 
    outputChatBox("Job Progress: Earned +"..wanted.." job progress by killing a wanted criminal!", source, 100, 100, 0) 
end 
addEventHandler("onPlayerWasted", root, arrestPoints) 
  
function myRank(plr, cmd, arg) -- /myrank  
    local acc = getAccountName(getPlayerAccount(plr)) -- Get account name of player who typed cmd. 
    if not jobPoints[arg] then return end -- Did he entered the right job name followed by myrank cmd? 
    outputChatBox("Job Progress: Your job progress for "..arg.." is "..getJobProgress(acc, arg).."(Points) with rank "..updateJobRank(acc, arg), plr, 100, 100, 0) -- Output his job stats. 
end 
addCommandHandler("myrank", myRank) 

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