buba123 Posted July 26, 2012 Share Posted July 26, 2012 Hi i have code what show in scoreboard how many zombies you have killed and save it to account file but in scoreboard zombie kills is only update when you relogin it doesnt in game when you kill, i add timer but it still doesnt work what is wrong here? exports.scoreboard:addScoreboardColumn('Zabite Zombie') addEvent("onZombieWasted",true) addEventHandler("onZombieWasted",root, function (killer) givePlayerMoney(killer, 2) addPlayerZombieKills(killer) end) function addPlayerZombieKills(killer) local account = getPlayerAccount(killer) if isGuestAccount(account) then return end local zombieKills = getAccountData(account,"Zabite Zombie") if not zombieKills then setAccountData(account,"Zabite Zombie",0) end setAccountData(account,"Zabite Zombie",tonumber(zombieKills)+1) end addEventHandler("onPlayerLogin",root, function () local account = getPlayerAccount(source) if isGuestAccount(account) then return end local zombieKills = getAccountData(account,"Zabite Zombie") if zombieKills then setElementData(source,"Zabite Zombie",tostring(zombieKills)) else setElementData(source,"Zabite Zombie",0) end end) function timer() setTimer( addPlayerZombieKills, 1000, 1, source ) end Link to comment
robhol Posted July 26, 2012 Share Posted July 26, 2012 Don't double post, you already have a topic. Set element data when you update the kills, the scoreboard pays attention to element data for players, not account data. Link to comment
buba123 Posted July 26, 2012 Author Share Posted July 26, 2012 Ok sorry for that ; P and thank i try this Link to comment
buba123 Posted July 26, 2012 Author Share Posted July 26, 2012 and dont work i try with loops and still doesnt work i dont know how to do if someone kill zombie it add to scoreboard not only to account data -.- Link to comment
AMARANT Posted July 26, 2012 Share Posted July 26, 2012 First thing you need to have dxscoreboard resource. Then you have to add somewhere in your script a function named "scoreboardAddColumn". Having passed required arguments through that function you can display your kills in scoreboard. But keep in mind that you have to set element data in order it to work. Link to comment
buba123 Posted July 26, 2012 Author Share Posted July 26, 2012 i have colum in scoreboard what show how many zombie you kill but if you join server first time you have 0 zombie kill then you kill some zombies but in scoreboard it show 0. you are doing relogin and now it show how many zombie you kill to that time when you relogin. i want to update that zombie kills ingame without player must relogin to see it Link to comment
AMARANT Posted July 26, 2012 Share Posted July 26, 2012 When you kill a zombie add to player's element data 1 kill. Just set it via "setElementData" function because scoreboard works only with element data. It's very easy. Link to comment
buba123 Posted July 26, 2012 Author Share Posted July 26, 2012 i make somethnk like this function updatePlayersZKILLS ( ) for index, player in ipairs ( getElementsByType "player" ) do setElementData ( player, "Zabite Zombie", tonumber(zombieKills)+1 ) end end setTimer ( updatePlayersZKILLS, 1000, 0 ) but in console it write i cant arthmetic to nill... what is wrong? Link to comment
AMARANT Posted July 26, 2012 Share Posted July 26, 2012 You chose a bad way to update the scoreboard. Instead of checking every player on the server every second you should make it like this: function ZombieDies(ammo,killer) local zombieKills = getElementData(killer,"Zabite Zombie") setElementData(killer,"Zabite Zombie",zombieKills+1) end addEventHandler("onPedWasted", getRootElement(), ZombieDies) -- I'm not sure how you made your zombies but I guess they're peds anyway... Link to comment
buba123 Posted July 26, 2012 Author Share Posted July 26, 2012 it work thank ; ) but for one kill zombie i get warrning and error warning:bad argument @ 'getelementdata' [expected element at argument 1, got boolean] this line local zombieKills = getElementData(killer,"Zabite Zombie") and error:attempt to perform arithmetic on local 'zombieKills' this line setElementData(killer,"Zabite Zombie",(zombieKills)+1) Link to comment
AMARANT Posted July 26, 2012 Share Posted July 26, 2012 It should help: function ZombieDies(ammo,killer) if (killer) then local zombieKills = getElementData(killer,"Zabite Zombie") setElementData(killer,"Zabite Zombie",zombieKills+1) end end addEventHandler("onPedWasted", getRootElement(), ZombieDies) Link to comment
buba123 Posted July 26, 2012 Author Share Posted July 26, 2012 Thank you it works and have one question do you have resource what save pos, money ,wpns and ammo like my save zombie kills? couse i cant find any ;c Link to comment
Anderl Posted July 26, 2012 Share Posted July 26, 2012 You can find them on community, but you will have to edit it to work with your zombie kills or you can make your own. Link to comment
buba123 Posted July 26, 2012 Author Share Posted July 26, 2012 i find now weapons but it dont save couse have erros. function table.empty( t ) if type( t ) ~= "table" then return false end return not next( t ) end addEventHandler( "onPlayerLogin",root, function( ) local acc = getPlayerAccount( source ) if acc then local weap = getAccountData( acc,'weapons' ) if weap then loadstring( "t = { "..weap.." } ".. "for _,v in pairs( t ) do ".. "giveWeapon( "..source..",v[1],v[2],false ) ".. "end" )( ) end end end ) addEventHandler( "onPlayerQuit",root, function( ) local acc = getPlayerAccount( source ) if acc and not isGuestAccount( acc ) then if not table.empty( tWeap[ source ] ) then local eStr = "" for _,v in pairs( tWeap[ source ] ) do eStr = eStr.."{"..v[1]..","..v[2].."}," end setAccountData( acc,"weapons",eStr:sub( 0,#eStr-1 ) ) end end end ) ? Link to comment
Anderl Posted July 26, 2012 Share Posted July 26, 2012 Telling us what and where is the error would be easier. Link to comment
buba123 Posted July 26, 2012 Author Share Posted July 26, 2012 attemp to index global 'tWep' <a nil value> Link to comment
Anderl Posted July 26, 2012 Share Posted July 26, 2012 There is no such table called 'tWeap'. Link to comment
AMARANT Posted July 26, 2012 Share Posted July 26, 2012 And please use lua-tag. It makes your code easer to understand. Link to comment
buba123 Posted July 26, 2012 Author Share Posted July 26, 2012 ok i found other script with save money pos wep and skin ; P now i just trying add to it money update like zombie kills ; D 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