Newbie Posted February 10, 2014 Share Posted February 10, 2014 (edited) exports.scoreboard:addScoreboardColumn('Rank') addEventHandler("onPlayerLogin", root, function(_, account) local rankss = getAccountData(account, "Race Loses") if rankss then if (rankss >= 0) and (rankss <= 4) then setElementData(source,"Rank","R1") elseif (rankss >= 5) and (rankss <= 10) then setElementData(source,"Rank","R2") elseif (rankss >= 11) and (rankss <= 249) then setElementData(source,"Rank","R3") elseif (rankss >= 250) and (rankss <= 499) then setElementData(source,"Rank","R4") end end end) function checkRank ( player ) local rankss = getElementData(source, "Rank") outputChatBox( "Your rank:" ..rankss,player) end addCommandHandler ( "rank", checkRank ) I tryed to put a command in my rank script. But it doest work. In the scoreboard, it works and showing my rank. Edited February 10, 2014 by Guest Link to comment
Bonsai Posted February 10, 2014 Share Posted February 10, 2014 AddCommandHandler doesn't have a source. You gotta use the player parameter. function checkRank ( player ) local rankss = getElementData(player, "Rank") Link to comment
Newbie Posted February 10, 2014 Author Share Posted February 10, 2014 AddCommandHandler doesn't have a source.You gotta use the player parameter. function checkRank ( player ) local rankss = getElementData(player, "Rank") Works thanks. addEventHandler ("onPlayerChat",getRootElement(), function(message,type) local nick = getPlayerName(source) local ranks1 = getElementData(player, "Rank") if (string.find(message,"!rank")) and not (string.find(message," !rank")) then outputChatBox("#FFA824*" .. nick .."#FFA824 rank is #FFA824" ..ranks1, getRootElement(), 255, 255, 255, true) end end) When i do in this way. It does not. Where did i failed ? Link to comment
myonlake Posted February 10, 2014 Share Posted February 10, 2014 Because there is no element "player". local ranks1 = getElementData(player, "Rank") Link to comment
Newbie Posted February 10, 2014 Author Share Posted February 10, 2014 Because there is no element "player". local ranks1 = getElementData(player, "Rank") There is. Look at the 4 line. Link to comment
myonlake Posted February 10, 2014 Share Posted February 10, 2014 No, there isn't, you misunderstood me. You have to switch it to 'source' in order for it to work. There is no player parameter anywhere, so you can't return the player element by that name neither. Link to comment
Newbie Posted February 10, 2014 Author Share Posted February 10, 2014 No, there isn't, you misunderstood me. You have to switch it to 'source' in order for it to work. There is no player parameter anywhere, so you can't return the player element by that name neither. Aaaah. Thanks . Link to comment
Saml1er Posted February 10, 2014 Share Posted February 10, 2014 (edited) He meant. local ranks1 = getElementData(source, "Rank") But in case of getAccountData addEventHandler("onPlayerLogin", root, function ( _, acc ) local ranks1 = getAccountData ( getPlayerAccount ( acc ), "Rank") -- your code end ) You can also replace acc with source for getPlayerAccount. EDIT: Oh seems that's not the problem. ;p Edited February 11, 2014 by Guest Link to comment
Newbie Posted February 10, 2014 Author Share Posted February 10, 2014 He meant. local ranks1 = getElementData(source, "Rank") But in case of getAccountData addEventHandler("onPlayerLogin", root, function ( _, acc ) local ranks1 = getAccountData ( getPlayerAccount ( acc ), "Rank") -- your code You can also replace acc with source for getPlayerAccount. EDIT: Oh seems that's not the problem. ;p I already did it. But thanks. Link to comment
Newbie Posted February 10, 2014 Author Share Posted February 10, 2014 I have another Q. There's problem. I need to update(refresh) the rank stat every 5 secods. What should i update ? "Race Loses" or "Rank" And what should i use ? Link to comment
Karuzo Posted February 10, 2014 Share Posted February 10, 2014 I think you could to that with onClientRender if im right. Link to comment
myonlake Posted February 10, 2014 Share Posted February 10, 2014 Why do you have to refresh it constantly? Link to comment
Newbie Posted February 10, 2014 Author Share Posted February 10, 2014 I think you could to that with onClientRender if im right. I will try it Why do you have to refresh it constantly? It updates only after relogin Link to comment
.:HyPeX:. Posted February 10, 2014 Share Posted February 10, 2014 OnClientRender would be a waste if you want to make it every 5 sec, and cant be used server-side. I suggest you using a timer with infinite loop, like this: LoopTimer = setTimer(function() --Do Stuff end, 5000, 0) Link to comment
myonlake Posted February 10, 2014 Share Posted February 10, 2014 What's the point in refreshing it if you don't have to refresh it in the first place? You can refresh it as you use it, instead. Link to comment
Newbie Posted February 10, 2014 Author Share Posted February 10, 2014 function update() local rankss = getAccountData(account, "Race Loses") end addEventHandler("onPlayerWasted", getRootElement(), update) I decided to make it refresh onPlayerWasted but still.. Refresh's only when Login. Link to comment
myonlake Posted February 10, 2014 Share Posted February 10, 2014 Because you're not saving nor getting anything except the current data, which you want to update... What do you want to update it to? Why do you want it to update constantly? Link to comment
Newbie Posted February 10, 2014 Author Share Posted February 10, 2014 Because you're not saving nor getting anything except the current data, which you want to update...What do you want to update it to? Why do you want it to update constantly? I just want to update result when i get when type !rank Lets say i have 1 Lose. And my rank should be R1 I have 6 loses and my rank should be R2. It working, but the rank updating only when player relogins. I need to update because players could see rank everytime it has changed. And dont need to relog Link to comment
Newbie Posted February 10, 2014 Author Share Posted February 10, 2014 Any suggestions ? Link to comment
Moderators IIYAMA Posted February 10, 2014 Moderators Share Posted February 10, 2014 Any suggestions ? Why not up date the rank at the moment you are losing/winning? Link to comment
Newbie Posted February 10, 2014 Author Share Posted February 10, 2014 Any suggestions ? Why not up date the rank at the moment you are losing/winning? Okay! Can you show an example ? Link to comment
Moderators IIYAMA Posted February 10, 2014 Moderators Share Posted February 10, 2014 Any suggestions ? Why not up date the rank at the moment you are losing/winning? Okay! Can you show an example ? Write the same code as at your first post, only at the place were the score get set. No example needed... Link to comment
Newbie Posted February 10, 2014 Author Share Posted February 10, 2014 Totally messed up.. function update() local rankss = getAccountData(account, "Race Loses") end addEventHandler("onPlayerWasted", getRootElement(), update) onPlayerWasted - Same like lose. Because player died. And Race Loses comes +1 What should i add or delete to make it working ? Link to comment
Moderators IIYAMA Posted February 10, 2014 Moderators Share Posted February 10, 2014 A LOT, addEventHandler("onPlayerWasted", root, function () local player = source local account = getPlayerAccount (player) if not isGuestAccount ( account) then local rankss = (getAccountData(account, "Race Loses") or 0)+1 if rankss >= 0 then if (rankss <= 4) then if getElementData(player,"Rank") ~= "R1" then setElementData(player,"Rank","R1") end elseif (rankss <= 10) then if getElementData(player,"Rank") ~= "R2" then setElementData(player,"Rank","R2") end elseif (rankss <= 249) then if getElementData(player,"Rank") ~= "R3" then setElementData(player,"Rank","R3") end elseif (rankss <= 499) then if getElementData(player,"Rank") ~= "R4" then setElementData(player,"Rank","R4") end end end setAccountData(account,"Race Loses",rankss) 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