Einheit-101 Posted June 24, 2011 Share Posted June 24, 2011 Hello Community, I created this script some months ago. It is a rank system and there is a little problem: Ive tested it ALONE in the map editor and it worked PERFECTLY. It counted Kills, updates the rank, plays the sound and draws the image. BUT Then i tested the script with more people and it was CRAZY! I dont Know what exactly it did but i had very strange kill numbers and ranks. I think the server-side script counts 1 kill of any player for ALL Players but i dont know how to make it correct working. If you want the whole script for testing yourself ask me, here is a cut version because there is a lot of unnessecary stuff (i marked it) I really hope anyone can help me out here and this script will work later because my players ask me everytime WHEN THIS GOD DAMN RANK SYSTEM IS FINISHED. Clinet stuff -- This creates an image on the right side of the screen, it works and is not important addEvent("image", true) image1 = nil function imager() local xp,yp = guiGetScreenSize() x = xp/2 - 150/2+500 y = yp/2 - 250 image1 = guiCreateStaticImage( x,y, 150, 150, "rang/r1.png", false ) end addEventHandler("image", getRootElement(), imager) -- this changes the image according to a new rank and plays a sound. it Works too. for i = 1, 23 do addEvent ( "r"..tostring ( i ), true ) addEventHandler ( "r"..tostring ( i ), getResourceRootElement ( ), function ( ) guiStaticImageLoadImage( image1, "rang/r"..tostring( i )..".png" ) lvlup = playSound("lvlup.mp3",false) setSoundVolume(lvlup,1) end ) end Server Stuff -- this adds the scoreboard columns, it works. function scorebrett() exports.scoreboard:addScoreboardColumn("Kills") exports.scoreboard:addScoreboardColumn("Rank") end addEventHandler( "onResourceStart", getResourceRootElement(getThisResource()), scorebrett ) -- this gets the rank/kill data onPlayerLogin. function onLogin() local player = getPlayerAccount ( source ) local myRank = getAccountData(player,"rank") local zombieKills = getAccountData(player, "zombieKills") triggerClientEvent("image", getRootElement()) if (myRank == "" or myRank == nil or myRank == false) then -- if rank doesnt exist or there is an error myRank = "[1]PVT" else setElementData (source, "Rank", myRank) setElementData (source, "Kills", tostring ( zombieKills )) zombieKills = tonumber(zombieKills) if myRank == "[1]PVT" then triggerClientEvent("image", getRootElement()) else if myRank == "[2]PFC" then triggerClientEvent("r2", getRootElement()) else if myRank == "[3]SPC" then triggerClientEvent("r3", getRootElement()) else if myRank == "[4]CPL" then triggerClientEvent("r4", getRootElement()) else if myRank == "[5]SGT" then triggerClientEvent("r5", getRootElement()) else if myRank == "[6]SSG" then triggerClientEvent("r6", getRootElement()) -- ...there are 23 ranks... end end end end end end if (zombieKills == "" or zombieKills == nil or zombieKills == false) then zombieKills = 0 end end addEventHandler("onPlayerLogin", getRootElement(), onLogin) -- this gives money and counts the kills and sets the ElementData. function reward(ammo, killer) if ( killer ) and ( killer ~= source ) then local player = getPlayerAccount ( killer ) local myRank = getAccountData(player,"rank") local zombieKills = getAccountData(player, "zombieKills") if (getElementData (source, "zombie") == true) then if zombieKills == nil then zombieKills = 0 end if myRank == nil then myRank = "[1]PVT" end givePlayerMoney(killer, 30 ) zombieKills = zombieKills+1 setAccountData (player,"zombieKills", tostring ( zombieKills )) setElementData ( killer, "Kills", tostring ( zombieKills )) if (getAccountData (player,"zombieKills") == "20") then myRank = "[2]PFC" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Private First Class.", getRootElement()) triggerClientEvent("r2", getRootElement()) else if (getAccountData (player,"zombieKills") == "40") then myRank = "[3]SPC" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Specialist.", getRootElement()) triggerClientEvent("r3", getRootElement()) else if (getAccountData (player,"zombieKills") == "100") then myRank = "[4]CPL" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Corporal.", getRootElement()) triggerClientEvent("r4", getRootElement()) else if (getAccountData (player,"zombieKills") == "200") then myRank="[5]SGT" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Sergeant.", getRootElement()) triggerClientEvent("r5", getRootElement()) else if (getAccountData (player,"zombieKills") == "350") then myRank="[6]SSG" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Staff Sergeant.", getRootElement()) triggerClientEvent("r6", getRootElement()) else if (getAccountData (player,"zombieKills") == "600") then myRank="[7]SFC" setAccountData (player,"rank", myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Sergeant First Class.", getRootElement()) triggerClientEvent("r7", getRootElement()) --....and so on..... end end end end end end end end end addEventHandler("onPedWasted", getRootElement(), reward) -- this is used to reset all data to 0 function nullAccount(playersource) local acc = getPlayerAccount ( playersource ) setAccountData (acc,"zombieKills", "0") setAccountData (acc,"rank", "[1]PVT") triggerClientEvent("image", getRootElement()) outputChatBox("Account reset succesfully.", source) end addCommandHandler("zero", nullAccount) And, oh, excuse my english. Link to comment
will briggs Posted June 24, 2011 Share Posted June 24, 2011 Hiw did it go crazy? Were there any errors in /debugscript 3 Link to comment
Einheit-101 Posted June 25, 2011 Author Share Posted June 25, 2011 The errors are the following: If a player gets promoted, the sound (clientscript) can hear everyone and the picture gets changed for all players. We worked on the script for some hours today and fixed most other errors. But the picture bug is still a problem. EDIT::: This is the updated, full version of the server-side script. function scorebrett() exports.scoreboard:addScoreboardColumn("Kills") exports.scoreboard:addScoreboardColumn("Rank") end addEventHandler( "onResourceStart", getResourceRootElement(getThisResource()), scorebrett ) function onLogin() local player = getPlayerAccount ( source ) local myRank = getAccountData(player,"rank") local zombieKills = getAccountData(player, "zombieKills") triggerClientEvent("image", getRootElement()) if (myRank == "" or myRank == nil or myRank == false) then myRank = "[1]PVT" else setElementData (source, "Rank", myRank) setElementData (source, "Kills", tostring ( zombieKills )) zombieKills = tonumber(zombieKills) if myRank == "[1]PVT" then triggerClientEvent("image", getRootElement()) else if myRank == "[2]PFC" then triggerClientEvent("r2", getRootElement()) else if myRank == "[3]SPC" then triggerClientEvent("r3", getRootElement()) else if myRank == "[4]CPL" then triggerClientEvent("r4", getRootElement()) else if myRank == "[5]SGT" then triggerClientEvent("r5", getRootElement()) else if myRank == "[6]SSG" then triggerClientEvent("r6", getRootElement()) else if myRank == "[7]SFC" then triggerClientEvent("r7", getRootElement()) else if myRank == "[8]MSG" then triggerClientEvent("r8", getRootElement()) else if myRank == "[9]1SG" then triggerClientEvent("r9", getRootElement()) else if myRank == "[10]SGM" then triggerClientEvent("r10", getRootElement()) else if myRank == "[11]CSM" then triggerClientEvent("r11", getRootElement()) else if myRank == "[12]SMA" then triggerClientEvent("r12", getRootElement()) else if myRank == "[13]2LT" then triggerClientEvent("r13", getRootElement()) else if myRank == "[14]1LT" then triggerClientEvent("r14", getRootElement()) else if myRank == "[15]CPT" then triggerClientEvent("r15", getRootElement()) else if myRank == "[16]MAJ" then triggerClientEvent("r16", getRootElement()) else if myRank == "[17]LTC" then triggerClientEvent("r17", getRootElement()) else if myRank == "[18]COL" then triggerClientEvent("r18", getRootElement()) else if myRank == "[19]BG" then triggerClientEvent("r19", getRootElement()) else if myRank == "[20]MG" then triggerClientEvent("r20", getRootElement()) else if myRank == "[21]LTG" then triggerClientEvent("r21", getRootElement()) else if myRank == "[22]GEN" then triggerClientEvent("r22", getRootElement()) else if myRank == "[23]GA" then triggerClientEvent("r23", getRootElement()) end end end end end end end end end end end end end end end end end end end end end end end end if (zombieKills == "" or zombieKills == nil or zombieKills == false or zombieKills == true) then zombieKills = 0 end end addEventHandler("onPlayerLogin", getRootElement(), onLogin) function reward(ammo, killer) if ( killer ) and ( killer ~= source ) then local player = getPlayerAccount ( killer ) local myRank = getAccountData(player,"rank") local zombieKills = getAccountData(player, "zombieKills") if (zombieKills == "" or zombieKills == nil or zombieKills == false or zombieKills == true) then zombieKills = 0 end if (getElementData (source, "zombie") == true) then if myRank == nil then myRank = "[1]PVT" end givePlayerMoney(killer, 30 ) zombieKills = zombieKills+1 setAccountData (player,"zombieKills", tostring ( zombieKills )) setElementData ( killer, "Kills", tostring ( zombieKills )) if (getAccountData (player,"zombieKills") == "100") then myRank = "[2]PFC" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Private First Class.", getRootElement()) triggerClientEvent("r2", getRootElement()) else if (getAccountData (player,"zombieKills") == "150") then myRank = "[3]SPC" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Specialist.", getRootElement()) triggerClientEvent("r3", getRootElement()) else if (getAccountData (player,"zombieKills") == "225") then myRank = "[4]CPL" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Corporal.", getRootElement()) triggerClientEvent("r4", getRootElement()) else if (getAccountData (player,"zombieKills") == "350") then myRank="[5]SGT" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Sergeant.", getRootElement()) triggerClientEvent("r5", getRootElement()) else if (getAccountData (player,"zombieKills") == "500") then myRank="[6]SSG" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Staff Sergeant.", getRootElement()) triggerClientEvent("r6", getRootElement()) else if (getAccountData (player,"zombieKills") == "750") then myRank="[7]SFC" setAccountData (player,"rank", myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Sergeant First Class.", getRootElement()) triggerClientEvent("r7", getRootElement()) else if (getAccountData (player,"zombieKills") == "1150") then myRank="[8]MSG" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Master Sergeant.", getRootElement()) triggerClientEvent("r8", getRootElement()) else if (getAccountData (player,"zombieKills") == "1700") then myRank="[9]1SG" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a First Sergeant.", getRootElement()) triggerClientEvent("r9", getRootElement()) else if (getAccountData (player,"zombieKills") == "2550") then myRank="[10]SGM" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Sergeant Major.", getRootElement()) triggerClientEvent("r10", getRootElement()) else if (getAccountData (player,"zombieKills") == "3800") then myRank = "[11]CSM" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Command Sergeant Major.", getRootElement()) triggerClientEvent("r11", getRootElement()) else if (getAccountData (player,"zombieKills") == "5750") then myRank="[12]SMA" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Sergeant Major of the Army.", getRootElement()) triggerClientEvent("r12", getRootElement()) elseif (getAccountData (player,"zombieKills") == "8650") then myRank="[13]2LT" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Second Lieutenant.", getRootElement()) triggerClientEvent("r13", getRootElement()) else if (getAccountData (player,"zombieKills") == "12500") then myRank="[14]1LT" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a First Lieutenant.", getRootElement()) triggerClientEvent("r14", getRootElement()) else if (getAccountData (player,"zombieKills") == "19500") then myRank="[15]CPT" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Captain.", getRootElement()) triggerClientEvent("r15", getRootElement()) else if (getAccountData (player,"zombieKills") == "29000") then myRank="[16]MAJ" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Major.", getRootElement()) triggerClientEvent("r16", getRootElement()) else if (getAccountData (player,"zombieKills") == "43500") then myRank="[17]LTC" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Lieutenant Colonel.", getRootElement()) triggerClientEvent("r17", getRootElement()) else if (getAccountData (player,"zombieKills") == "65500") then myRank="[18]COL" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Colonel.", getRootElement()) triggerClientEvent("r18", getRootElement()) else if (getAccountData (player,"zombieKills") == "98500") then myRank="[19]BG" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Brigadier General.", getRootElement()) triggerClientEvent("r19", getRootElement()) else if (getAccountData (player,"zombieKills") == "150000") then myRank="[20]MG" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Major General.", getRootElement()) triggerClientEvent("r20", getRootElement()) else if (getAccountData (player,"zombieKills") == "221000") then myRank="[21]LTG" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a Lieutenant General.", getRootElement()) triggerClientEvent("r21", getRootElement()) else if (getAccountData (player,"zombieKills") == "350000") then myRank="[22]GEN" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has been promoted. He is now a General.", getRootElement()) triggerClientEvent("r22", getRootElement()) else if (getAccountData (player,"zombieKills") == "500000") then myRank="[23]GA" setAccountData (player,"rank",myRank) setElementData ( killer, "Rank", myRank ) outputChatBox (getPlayerName(killer).." has reached the highest rank! He is General of the Army!", getRootElement()) triggerClientEvent("r23", getRootElement()) end end end end end end end end end end 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