Jump to content

Mr.Twerky Needs A Little help :c


justn

Recommended Posts

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 by Guest
Link to comment
 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
 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

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

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

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 :P !

Link to comment

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

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

_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

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