Jump to content

Again a Rank system....


Einheit-101

Recommended Posts

Posted (edited)

***EDITET CODE***

Hey Guys,

I made a final version of my rank script but it still doesnt work. The console/server does not output anything.

INFOS:

This script should promote you to a new rank if you have killed a amount of zombies, a gui element should show your rank.

this "guiCreateStaticImage" should create a image and every rank has a different one.

I use setAccountData because i want to save the rank.

I also want a dxscoreboard tab showing the rank; it shows the tab rank, but nothing else.

SERVER:

  
function onResourceStart(startedResource) 
if startedResource == getThisResource() then 
        call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Rank") 
end 
end 
addEventHandler("onResourceStart", getRootElement(), onResourceStart) 
  
pic = false 
  
addEvent( "onZombieWasted" ); 
addEventHandler( "onZombieWasted", getRootElement(), 
function( killer ) 
local player = getPlayerAccount ( killer ) 
local myRank = getAccountData(player,"rank") 
local zombieKills = getAccountData(player, "zombieKills") 
    if (myRank == "" or myRank == nil or myRank == false) then 
        if pic == false then 
            myRank = "[1]PVT" 
            triggerClientEvent("imagecall", getRootElement()) 
            pic = true 
        end 
    end 
        if (zombieKills == "" or zombieKills == nil or zombieKills == false) then 
        zombieKills = 0 
    setAccountData (killer,"zombieKills",zombieKills+1); 
    givePlayerMoney( killer, 25 ) --give money for killed Zombies 
  
if (getAccountData (player,"zombieKills") == 20) then 
                  setAccountData (player,"rank","[2]PFC") 
                  outputChatBox (getPlayerName(killer)" has been promoted. He is now a Private First Class.") 
            triggerClientEvent("r1", getRootElement()) 
        elseif (getAccountData (player,"zombieKills") == 40) then 
                  setAccountData (player,"rank","[3]SPC") 
                  outputChatBox (getPlayerName(killer)" has been promoted. He is now a Specialist.") 
            triggerClientEvent("r2", getRootElement()) 
        elseif (getAccountData (player,"zombieKills") == 100) then 
                  setAccountData (player,"rank","[4]CPL") 
                  outputChatBox (getPlayerName(killer)" has been promoted. He is now a Corporal.") 
            triggerClientEvent("r3", getRootElement()) 
        elseif (getAccountData (player,"zombieKills") == 200) then 
                  setAccountData (player,"rank","[5]SGT") 
                  outputChatBox (getPlayerName(killer)" has been promoted. He is now a Sergeant.") 
            triggerClientEvent("r4", getRootElement()) 
        elseif (getAccountData (player,"zombieKills") == 350) then 
                  setAccountData (player,"rank","[6]SSG") 
                  outputChatBox (getPlayerName(killer)" has been promoted. He is now a Staff Sergeant.") 
            triggerClientEvent("r5", getRootElement()) 
        elseif (getAccountData (player,"zombieKills") == 600) then 
          setAccountData (player,"rank","[7]SFC") 
                  outputChatBox (getPlayerName(killer)" has been promoted. He is now a Sergeant First Class.") 
            triggerClientEvent("r6", getRootElement()) 
        elseif (getAccountData (player,"zombieKills") == 900) then 
          setAccountData (player,"rank","[8]MSG") 
                  outputChatBox (getPlayerName(killer)" has been promoted. He is now a Master Sergeant.") 
            triggerClientEvent("r7", getRootElement()) 
        elseif (getAccountData (player,"zombieKills") == 1500) then 
          setAccountData (player,"rank","[9]1SG") 
                  outputChatBox (getPlayerName(killer)" has been promoted. He is now a First Sergeant.") 
            triggerClientEvent("r8", getRootElement()) 
        elseif (getAccountData (player,"zombieKills") == 1800) then 
          setAccountData (player,"rank","[10]SGM") 
                  outputChatBox (getPlayerName(killer)" has been promoted. He is now a Sergeant Major.") 
            triggerClientEvent("r9", getRootElement()) 
        elseif (getAccountData (player,"zombieKills") == 2300) then 
          setAccountData (player,"rank","[11]CSM") 
                  outputChatBox (getPlayerName(killer)" has been promoted. He is now a Command Sergeant Major.") 
            triggerClientEvent("r10", getRootElement()) 
        elseif (getAccountData (player,"zombieKills") == 3000) then 
          setAccountData (player,"rank","[12]SMA") 
                  outputChatBox (getPlayerName(killer)" has been promoted. He is now a Sergeant Major of the Army.") 
            triggerClientEvent("r11", getRootElement()) 
        elseif (getAccountData (player,"zombieKills") == 4000) then 
          setAccountData (player,"rank","[13]2LT") 
                  outputChatBox (getPlayerName(killer)" has been promoted. He is now a Second Lieutenant.") 
            triggerClientEvent("r12", getRootElement()) 
        elseif (getAccountData (player,"zombieKills") == 5500) then 
          setAccountData (player,"rank","[14]1LT") 
                  outputChatBox (getPlayerName(killer)" has been promoted. He is now a First Lieutenant.") 
            triggerClientEvent("r13", getRootElement()) 
        elseif (getAccountData (player,"zombieKills") == 7000) then 
          setAccountData (player,"rank","[15]CPT") 
                  outputChatBox (getPlayerName(killer)" has been promoted. He is now a Captain.") 
            triggerClientEvent("r14", getRootElement()) 
        elseif (getAccountData (player,"zombieKills") == 9000) then 
          setAccountData (player,"rank","[16]MAJ") 
                  outputChatBox (getPlayerName(killer)" has been promoted. He is now a Major.") 
            triggerClientEvent("r15", getRootElement()) 
        elseif (getAccountData (player,"zombieKills") == 11500) then 
          setAccountData (player,"rank","[17]LTC") 
                  outputChatBox (getPlayerName(killer)" has been promoted. He is now a Lieutenant Colonel.") 
            triggerClientEvent("r16", getRootElement()) 
        elseif (getAccountData (player,"zombieKills") == 14000) then 
          setAccountData (player,"rank","[18]COL") 
                  outputChatBox (getPlayerName(killer)" has been promoted. He is now a Colonel.") 
            triggerClientEvent("r17", getRootElement()) 
        elseif (getAccountData (player,"zombieKills") == 17000) then 
          setAccountData (player,"rank","[19]BG") 
                  outputChatBox (getPlayerName(killer)" has been promoted. He is now a Brigadier General.") 
            triggerClientEvent("r18", getRootElement()) 
        elseif (getAccountData (player,"zombieKills") == 21000) then 
          setAccountData (player,"rank","[20]MG") 
                  outputChatBox (getPlayerName(killer)" has been promoted. He is now a Major General.") 
            triggerClientEvent("r19", getRootElement()) 
        elseif (getAccountData (player,"zombieKills") == 26000) then 
          setAccountData (player,"rank","[21]LTG") 
                  outputChatBox (getPlayerName(killer)" has been promoted. He is now a Lieutenant General.") 
            triggerClientEvent("r20", getRootElement()) 
        elseif (getAccountData (player,"zombieKills") == 35000) then 
          setAccountData (player,"rank","[22]GEN") 
                  outputChatBox (getPlayerName(killer)" has been promoted. He is now a General.") 
            triggerClientEvent("r21", getRootElement()) 
        elseif (getAccountData (player,"zombieKills") == 50000) then 
          setAccountData (player,"rank","[23]GA") 
                  outputChatBox (getPlayerName(killer)" has reached the highest rank! He is General of the Army!") 
            triggerClientEvent("r22", getRootElement()) 
        end 
    end 
end 
) 
  

CLIENT:

  
local xp,yp = guiGetScreenSize() 
x = xp/2 - 60/2+ 500 
y = yp/2 - 60/2 + yp/4.5 
  
function image() 
        image1 = guiCreateStaticImage( x, y, 50, 48, "rang/r1.png", false ) 
end 
addEvent("imagecall", true) 
addEventHandler("imagecall", getRootElement(), image) 
  
function guiElement() 
    if look == nil then 
               look = 0 
               display = textCreateDisplay() 
               textDisplayAddObserver (display,killer) 
               rank = textCreateTextItem ("Rank: "..myRank,0.8,0.53,"medium",255,50,0,150,1.5) 
               textDisplayAddText (display,rank) 
        elseif look == 0 then 
               textItemSetText (rank,"Rank: "..myRank) 
               textItemSetText (rank,"Rank: "..myRank) 
    end 
addEventHandler("onClientResourceStart", getRootElement(), guiElement) 
  
addEvent("r1", true) 
function image2() 
destroyElement(image1) 
image2 = guiCreateStaticImage( x,y,50,60, "rang/r2.png", false ) 
end 
addEvent("r2", true) 
function image3() 
destroyElement(image3) 
image3 = guiCreateStaticImage( x,y,50,55, "rang/r3.png", false ) 
end 
addEvent("r3", true) 
function image4() 
destroyElement(image4) 
image4 = guiCreateStaticImage( x,y,50,55, "rang/r4.png", false ) 
end 
addEvent("r4", true) 
function image5() 
destroyElement(image5) 
image5 = guiCreateStaticImage( x,y,50,63, "rang/r5.png", false ) 
end 
addEvent("r5", true) 
function image6() 
destroyElement(image6) 
image6 = guiCreateStaticImage( x,y,50,75, "rang/r6.png", false ) 
end 
addEvent("r6", true) 
function image7() 
destroyElement(image7) 
image7 = guiCreateStaticImage( x,y,50,83, "rang/r7.png", false ) 
end 
addEvent("r7", true) 
function image8() 
destroyElement(image8) 
image8 =guiCreateStaticImage( x,y,50,90, "rang/r8.png", false ) 
end 
addEvent("r8", true) 
function image9() 
destroyElement(image9) 
image9 = guiCreateStaticImage( x,y,50,90, "rang/r9.png", false ) 
end 
addEvent("r9", true) 
function image10() 
destroyElement(image10) 
image10 = guiCreateStaticImage( x,y,50,90, "rang/r10.png", false ) 
end 
addEvent("r10", true) 
function image11() 
destroyElement(image11) 
image12 = guiCreateStaticImage( x,y,50,90, "rang/r11.png", false ) 
end 
addEvent("r11", true) 
function image12() 
destroyElement(image12) 
image13 = guiCreateStaticImage( x,y,50,90, "rang/r12.png", false ) 
end 
addEvent("r12", true) 
function image13() 
destroyElement(image13) 
image14 = guiCreateStaticImage( x,y,24,60, "rang/r13.png", false ) 
end 
addEvent("r13", true) 
function image14() 
destroyElement(image14) 
image15 = guiCreateStaticImage( x,y,24,60, "rang/r14.png", false ) 
end 
addEvent("r14", true) 
function image15() 
destroyElement(image15) 
image16 = guiCreateStaticImage( x,y,60,58, "rang/r15.png", false ) 
end 
addEvent("r15", true) 
function image16() 
destroyElement(image16) 
image17 = guiCreateStaticImage( x,y,60,60, "rang/r16.png", false ) 
end 
addEvent("r16", true) 
function image17() 
destroyElement(image17) 
image18 = guiCreateStaticImage( x,y,60,60, "rang/r17.png", false ) 
end 
addEvent("r17", true) 
function image18() 
destroyElement(image18) 
image19 = guiCreateStaticImage( x,y,108,61, "rang/r18.png", false ) 
end 
addEvent("r18", true) 
function image19() 
destroyElement(image19) 
image20 = guiCreateStaticImage( x,y,67,64, "rang/r19.png", false ) 
end 
addEvent("r19", true) 
function image20() 
destroyElement(image20) 
image21 = guiCreateStaticImage( x,y,112,57, "rang/r20.png", false ) 
end 
addEvent("r20", true) 
function image21() 
destroyElement(image21) 
image22 = guiCreateStaticImage( x,y,112,41, "rang/r21.png", false ) 
end 
addEvent("r21", true) 
function image22() 
destroyElement(image22) 
image23 = guiCreateStaticImage( x,y,143,39, "rang/r22.png", false ) 
end 
addEvent("r22", true) 
function image23() 
destroyElement(image23) 
image24 = guiCreateStaticImage( x,y,112,104, "rang/r23.png", false ) 
end 
addEventHandler( "r1", getRootElement(), image2 ) 
addEventHandler( "r2", getRootElement(), image3 ) 
addEventHandler( "r3", getRootElement(), image4 ) 
addEventHandler( "r4", getRootElement(), image5 ) 
addEventHandler( "r5", getRootElement(), image6 ) 
addEventHandler( "r6", getRootElement(), image7 ) 
addEventHandler( "r7", getRootElement(), image8 ) 
addEventHandler( "r8", getRootElement(), image9 ) 
addEventHandler( "r9", getRootElement(), image10 ) 
addEventHandler( "r10", getRootElement(), image11 ) 
addEventHandler( "r11", getRootElement(), image12 ) 
addEventHandler( "r12", getRootElement(), image13 ) 
addEventHandler( "r13", getRootElement(), image14 ) 
addEventHandler( "r14", getRootElement(), image15 ) 
addEventHandler( "r15", getRootElement(), image16 ) 
addEventHandler( "r16", getRootElement(), image17 ) 
addEventHandler( "r17", getRootElement(), image18 ) 
addEventHandler( "r18", getRootElement(), image19 ) 
addEventHandler( "r19", getRootElement(), image20 ) 
addEventHandler( "r20", getRootElement(), image21 ) 
addEventHandler( "r21", getRootElement(), image22 ) 
addEventHandler( "r22", getRootElement(), image23 ) 
  

I HAVE ADDED ALL THE CODE.

Edited by Guest

n-560x95_FFFFFF_FFFFFF_000000_000000.png

Posted
  
function image3 
destroyElement(image3) 
image3 = guiCreateStaticImage( x,y,50,55, "rang/r3.png", false ) 
end 
  

this if wrong. function HAVE TO be defined with brackets ( )

also you CAN'T name variable same as function!

you have function image3, and you are creating variable called image3.

and instead of making thousand of events - make one, and pass some arguments to it. like:

  
triggerClientEvent(player, "event", player, my_argument, my_next_argument) 
--and on client 
function handler(my_argument, my_next_argument) 
  --create image here, based on argument 
end 
addEventHandler("event", getRootElement(), handler) 
  

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

WHAT?!? I forgot the brackets? A n00b mistake³!

And i dent know how to make it like you said with the arguments^^ I already said that its enough for me when it just works anyway; a small/efficient script is not sooo important.

n-560x95_FFFFFF_FFFFFF_000000_000000.png

Posted

if you are learning something - make it good :)

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

your functions are still called same as variables (image2, image3, image4)..

also: you have variable pic in server side - it will cause only one player to see the image (if i actually understood what it shoud do)!!

make a table:

local pic = { }

and read/write values as:

pic[playerElement] = false

etc

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

only one player should see the picture. its a rank logo. I understand that like "i have to rename the functions because they have the same name as the images". I work on it...

n-560x95_FFFFFF_FFFFFF_000000_000000.png

Posted

so only ONE player of all should see the picture at all? i dont think so.

every player should see image - his OWN rank.

right?

or maybe i dont understand how it should work?

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

Hmmm.... Under the bar showing your money should be a picture showing your rank. other players cant see this picture. its like a HUD element.

n-560x95_FFFFFF_FFFFFF_000000_000000.png

Posted

yea, so am i right.

there is global server variable.

then server sends a picture trigger to one client, and send variable to true, preventing other clients to see their image (no trigger).

solution is few posts above :)

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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