justn Posted March 21, 2014 Share Posted March 21, 2014 (edited) Hey guys, so the problem is, it doesn't set the occupation as 'Officer' or 'Staff' or 'Civillian' exports [ "scoreboard" ]:addScoreboardColumn ( "Occupation", 2 ) function thatit() if ( source ~= false) then local sourceTeam = getTeamName ( getPlayerTeam(source) ) if ( sourceTeam == "Police" ) then setElementData ( source, "Occupation", "Officer" ) elseif ( sourceTeam == "Staff" ) then setElementData ( source, "Occupation", "Staff" ) else setElementData ( source, "Occupation", "Civillian" ) end end end setTimer ( thatit, 2500, 0 ) Edited March 21, 2014 by Guest Link to comment
iPrestege Posted March 21, 2014 Share Posted March 21, 2014 Source + Player defined as ??? Link to comment
justn Posted March 21, 2014 Author Share Posted March 21, 2014 Source + Player defined as ??? Oops, I had player for some jobs i made and just copied it in to this script and forgot to changed it, but anyways, its still not working. Link to comment
Saml1er Posted March 21, 2014 Share Posted March 21, 2014 exports [ "scoreboard" ]:addScoreboardColumn ( "Occupation", 2 ) function thatit() local sourceTeam = getTeamName ( getPlayerTeam(localPlayer) ) if sourceTeam then if ( sourceTeam == "Police" ) then setElementData ( localPlayer, "Occupation", "Officer" ) elseif ( sourceTeam == "Staff" ) then setElementData ( localPlayer, "Occupation", "Staff" ) else setElementData ( localPlayer, "Occupation", "Civillian" ) end end end setTimer ( thatit, 2500, 0 ) This is a client side script now. Link to comment
justn Posted March 21, 2014 Author Share Posted March 21, 2014 exports [ "scoreboard" ]:addScoreboardColumn ( "Occupation", 2 ) function thatit() local sourceTeam = getTeamName ( getPlayerTeam(localPlayer) ) if sourceTeam then if ( sourceTeam == "Police" ) then setElementData ( localPlayer, "Occupation", "Officer" ) elseif ( sourceTeam == "Staff" ) then setElementData ( localPlayer, "Occupation", "Staff" ) else setElementData ( localPlayer, "Occupation", "Civillian" ) end end end setTimer ( thatit, 2500, 0 ) This is a client side script now. ..Now the occupation column doesn't show. Link to comment
Saml1er Posted March 21, 2014 Share Posted March 21, 2014 Are you sure that you modified your meta.xml ? anyways try this: exports [ "scoreboard" ]:addScoreboardColumn ( "Occupation", 2 ) function thatit() -- just removed and "if" statement local sourceTeam = getTeamName ( getPlayerTeam(localPlayer) ) if ( sourceTeam == "Police" ) then setElementData ( localPlayer, "Occupation", "Officer" ) elseif ( sourceTeam == "Staff" ) then setElementData ( localPlayer, "Occupation", "Staff" ) else setElementData ( localPlayer, "Occupation", "Civillian" ) end end setTimer ( thatit, 2500, 0 ) Link to comment
justn Posted March 21, 2014 Author Share Posted March 21, 2014 I don't need to modify the meta.mxl, because im using this script in a gamemode, i just copied your version of it and put it in the client side.. and the column still doesn't show up, wouldn't it be best to make this a server-sided script.. ? Link to comment
Saml1er Posted March 21, 2014 Share Posted March 21, 2014 I don't need to modify the meta.mxl, because im using this script in a gamemode, i just copied your version of it and put it in the client side.. and the column still doesn't show up, wouldn't it be best to make this a server-sided script.. ? The reason, I choose client side is because if you loop through all players every 2.5 seconds then you're server might lagg like hell but for client side I think it should be okay. Not sure but I think you need to replace this line with this: exports [ "scoreboard" ]:addScoreboardColumn ( "Occupation" ) Link to comment
justn Posted March 21, 2014 Author Share Posted March 21, 2014 I don't need to modify the meta.mxl, because im using this script in a gamemode, i just copied your version of it and put it in the client side.. and the column still doesn't show up, wouldn't it be best to make this a server-sided script.. ? The reason, I choose client side is because if you loop through all players every 2.5 seconds then you're server might lagg like hell but for client side I think it should be okay. Not sure but I think you need to replace this line with this: exports [ "scoreboard" ]:addScoreboardColumn ( "Occupation" ) Everytime i put your version (client-side) , the column doesnt show up, then when i put my version (server-side) and restart the scripts, it works, then when i reconnect , it doesn't work anymore Link to comment
iPrestege Posted March 21, 2014 Share Posted March 21, 2014 Client Side : CurrectDataValues = { -- { Team Name,What you want to show in the scoreboard! } { 'Police','Officer' }, { 'Staff','Staff' }, { 'Civillian','Civillian' }, } addEventHandler ( 'onClientRender',root, function ( ) local CurrectPlayerTeam = getPlayerTeam ( localPlayer ) local CurrectTeamName = getTeamName ( CurrectPlayerTeam ) for _,CurrectValue in ipairs ( CurrectDataValues ) do if CurrectPlayerTeam and CurrectTeamName == CurrectValue [ 1 ] then setElementData ( localPlayer,'Occupation',CurrectValue [ 2 ] ) end end end ) Server Side : exports [ "scoreboard" ]:addScoreboardColumn ( 'Occupation' ) addEventHandler ( 'onElementDataChange',root, function ( theName,theOldValue ) if getElementType ( source ) == 'player' then if theName == 'Occupation' then setElementData ( source,'Occupation',getElementData ( source,'Occupation' ) ) end end end ) Try that ! Link to comment
Saml1er Posted March 21, 2014 Share Posted March 21, 2014 AddScoreBoardColumn is a server side function. I really forgot that. Link to comment
WhoAmI Posted March 21, 2014 Share Posted March 21, 2014 Are you crazy? You are looping table 30-60 times per second. Isn't it better to create 'onPlayerTeamChange' event, and then setting data. Event will looks like _setPlayerTeam = setPlayerTeam addEvent ( "onPlayerTeamChange", true ) function setPlayerTeam ( player, team ) if not team or not player then return false end local oldTeam = getPlayerTeam ( player ) triggerEvent ( "onPlayerTeamChange", player, oldTeam, team ) return _setPlayerTeam ( player, team ) end and the usage addEventHandler ( "onPlayerTeamChange", root, function ( oldTeam, currentTeam ) --todo, Source is the Player who changed team end ) Link to comment
iPrestege Posted March 21, 2014 Share Posted March 21, 2014 Are you crazy? You are looping table 30-60 times per second. Isn't it better to create 'onPlayerTeamChange' event, and then setting data. Event will looks like _setPlayerTeam = setPlayerTeam addEvent ( "onPlayerTeamChange", true ) function setPlayerTeam ( player, team ) if not team or not player then return false end local oldTeam = getPlayerTeam ( player ) triggerEvent ( "onPlayerTeamChange", player, oldTeam, team ) return _setPlayerTeam ( player, team ) end and the usage addEventHandler ( "onPlayerTeamChange", root, function ( oldTeam, currentTeam ) --todo, Source is the Player who changed team end ) Please be a respected person / = .. using a render with a loop in the client side won't make a problem or any lag . Link to comment
Moderators Citizen Posted March 21, 2014 Moderators Share Posted March 21, 2014 Please be a respected person / = .. using a render with a loop in the client side won't make a problem or any lag First, he didn't insult you or wasn't a disrespectful person. He was just totally shocked someone wrote this awful script and pretend it's a good solution. I was also shocked when I saw your script and thought the same ("this guy is crazy"). And I'm even more shocked when you said it won't lag. It won't lag on the client side if the player has a pretty good computer and won't lag on the server side if there is not a lot of players on the server. But let's take an example okay ? So imagine you can manage to get 50 players on your server and all have 30 fps. Then the server part will take 1 500 executions per second right in the face (3 000 if they all have 60fps). And for what purpose ? Just to update an element data to set the current player team name. Do you still think it won't lag and still a good solution ? (I hope not anymore) And don't forget that there is the rest of the gamemode to run and others resources as well. Link to comment
justn Posted March 21, 2014 Author Share Posted March 21, 2014 .. So, can someone tell me, which is the best solution to this? Link to comment
Moderators Citizen Posted March 21, 2014 Moderators Share Posted March 21, 2014 .. So, can someone tell me, which is the best solution to this? If you had read what WhoAmI and I said, it's obviously the WhoAmI's code. Link to comment
justn Posted March 22, 2014 Author Share Posted March 22, 2014 Okay so i have tried this code, it works, but the problem is, when i set my team to another, the occupation doesn't change. _setPlayerTeam = setPlayerTeam addEvent ( "onPlayerTeamChange", true ) function setPlayerTeam ( player, team ) if not team or not player then return false end local oldTeam = getPlayerTeam ( player ) triggerEvent ( "onPlayerTeamChange", player, oldTeam, team ) return _setPlayerTeam ( player, team ) end addEventHandler ( "onPlayerTeamChange", root, function ( oldTeam, currentTeam ) if ( currentTeam == "Police" ) then setElementData ( source, "Occupation", "Officer" ) elseif ( currentTeam == "Staff" ) then setElementData ( source, "Occupation", "Staff" ) else setElementData ( source, "Occupation", "Civillian" ) end end ) Link to comment
WhoAmI Posted March 22, 2014 Share Posted March 22, 2014 You have to set team by using setPlayerTeam function inside this resource. 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