Jump to content

bug help when player join


iiv03

Recommended Posts

hey everyone have bug here and i don't know how fix that

colour = {}
colour.r = 255
colour.g = 85
colour.b = 85

function rgbToHex ( nR, nG, nB )
    local sColor = "#"
    nR = string.format ( "%X", nR or 255 )
    sColor = sColor .. ( ( string.len ( nR ) == 1 ) and ( "0" .. nR ) or nR )
    nG = string.format ( "%X", nG or 255 )
    sColor = sColor .. ( ( string.len ( nG ) == 1 ) and ( "0" .. nG ) or nG )
    nB = string.format ( "%X", nB or 255 )
    sColor = sColor .. ( ( string.len ( nB ) == 1 ) and ( "0" .. nB ) or nB )
    return sColor
end

local tagColor = rgbToHex(colour.r,colour.g,colour.b) or "#FFFFFF"

function updateTeamSettings(cmd,R,G,B)
    if not tonumber(R) or not tonumber(G) or not tonumber(B) then return end
R,G,B = tonumber(R),tonumber(G),tonumber(B)
    if R <= 50 and G <= 50 and B <= 50 then
        colour.r = 255
        colour.g = 255
        colour.b = 255
    else
        colour.r = R
        colour.g = G
        colour.b = B
    end
        tagColor = rgbToHex(colour.r,colour.g,colour.b) or "#FFFFFF"
        if enemyTeam then
            team[2] = enemyTeam
            updateTeamColour()
        else
            --team[2] = createTeam ( enemyName, colour.r,colour.g,colour.b)
            if team[2] then
                updateTeamColour()
            end
        end
    end
addCommandHandler("color",updateTeamSettings)
addEventHandler("onClientPlayerJoin", getRootElement(), updateTeamSettings)

function updateTeamColour()
	setTeamColor ( team[2], colour.r, colour.g, colour.b )
end
addEventHandler("onClientPlayerJoin", getRootElement(), updateTeamColour)


function text()
  
				dxDrawText("Alive Players[#334455"..home_alive.."#ffffff/"..tagColor..enemy_team.."#ffffff]",sX,sY*0.03,sX*0.2,sY*0,tocolor(255,255,255,255),clanwar_data_fontSize*1.2,clanwar_data_font,"center","center",false,false,false,true)

end
addEventHandler("onClientRender", root, text)

after i change the colors team and i do reconnect
the color is due to the same thing and I want it to save the colors

in server work ..

but in didn't work client not work?

Edited by xFabel
Link to comment
setTeamColor
Server-only function
 
 

to fix it use

https://wiki.multitheftauto.com/wiki/TriggerServerEvent

server file

function changeclr ( tesm,r,g,b )
    setTeamColor ( team,r,g,b )end
addEvent( "changeclr", true )
addEventHandler( "changeclr", resourceRoot,changeclr )

 

 

client

your full code

+

function updateTeamColour()

 triggerServerEvent ( "changeclr", resourceRoot,team[2], colour.r, colour.g, colour.b )

end
addEventHandler("onClientPlayerJoin", getRootElement(), updateTeamColour)

 

 

 

Edited by komal
  • Like 1
Link to comment
  On 09/11/2019 at 19:52, komal said:

setTeamColor
Server-only function
 
 

to fix it use

https://wiki.multitheftauto.com/wiki/TriggerServerEvent

server file


function changeclr ( tesm,r,g,b )    setTeamColor ( team,r,g,b )endaddEvent( "changeclr", true )addEventHandler( "changeclr", resourceRoot,changeclr )

 

 

client

your full code

+

function updateTeamColour()


 triggerServerEvent ( "changeclr", resourceRoot,team[2], colour.r, colour.g, colour.b )

end
addEventHandler("onClientPlayerJoin", getRootElement(), updateTeamColour)

 

 

 

Expand  

Thanks a lot

Link to comment
  On 09/11/2019 at 19:52, komal said:
setTeamColor
Server-only function
 
 

to fix it use

https://wiki.multitheftauto.com/wiki/TriggerServerEvent

server file

 
  1.  
  1. function changeclr ( tesm,r,g,b )    setTeamColor ( team,r,g,b )endaddEvent( "changeclr", true )addEventHandler( "changeclr", resourceRoot,changeclr )

 

 

client

your full code

+

function updateTeamColour()

 
  1.  
  1. triggerServerEvent ( "changeclr", resourceRoot,team[2], colour.r, colour.g, colour.b )

end
addEventHandler("onClientPlayerJoin", getRootElement(), updateTeamColour)

 

 

 

Expand  

hey there is not fix yet can u help me it's still not updating color when i reconnect or join server

Client Side

colour = {}
colour.r = 255
colour.g = 85
colour.b = 85

function rgbToHex ( nR, nG, nB )
    local sColor = "#"
    nR = string.format ( "%X", nR or 255 )
    sColor = sColor .. ( ( string.len ( nR ) == 1 ) and ( "0" .. nR ) or nR )
    nG = string.format ( "%X", nG or 255 )
    sColor = sColor .. ( ( string.len ( nG ) == 1 ) and ( "0" .. nG ) or nG )
    nB = string.format ( "%X", nB or 255 )
    sColor = sColor .. ( ( string.len ( nB ) == 1 ) and ( "0" .. nB ) or nB )
    return sColor
end

local tagColor = rgbToHex(colour.r,colour.g,colour.b) or "#FFFFFF"

function updateTeamSettings(cmd,R,G,B)
    if not tonumber(R) or not tonumber(G) or not tonumber(B) then return end
R,G,B = tonumber(R),tonumber(G),tonumber(B)
    if R <= 50 and G <= 50 and B <= 50 then
        colour.r = 255
        colour.g = 255
        colour.b = 255
    else
        colour.r = R
        colour.g = G
        colour.b = B
    end
        tagColor = rgbToHex(colour.r,colour.g,colour.b) or "#FFFFFF"
        if enemyTeam then
            team[2] = enemyTeam
            TeamColor()
        else
            --team[2] = createTeam ( enemyName, colour.r,colour.g,colour.b)
            if team[2] then
                TeamColor()
            end
        end
    end
addCommandHandler("color",updateTeamSettings)
addEventHandler("onClientPlayerJoin", getRootElement(), updateTeamSettings)

function TeamColor()
     triggerServerEvent ( "updateTeamColour", resourceRoot,team[2], colour.r, colour.g, colour.b )
end
addEventHandler("onClientPlayerJoin", getRootElement(), TeamColor) 


function text()
  
dxDrawText("Alive Players[#334455"..home_alive.."#ffffff/"..tagColor..enemy_team.."#ffffff]",sX,sY*0.03,sX*0.2,sY*0,tocolor(255,255,255,generalAlpha),clanwar_data_fontSize*1.2,clanwar_data_font,"center","center",false,false,false,true)
end
addEventHandler("onClientRender", root, text)

Server Side

team = {}
colour = {}
colour.r = 255
colour.g = 85
colour.b = 85

function rgbToHex ( nR, nG, nB )
    local sColor = "#"
    nR = string.format ( "%X", nR or 255 )
    sColor = sColor .. ( ( string.len ( nR ) == 1 ) and ( "0" .. nR ) or nR )
    nG = string.format ( "%X", nG or 255 )
    sColor = sColor .. ( ( string.len ( nG ) == 1 ) and ( "0" .. nG ) or nG )
    nB = string.format ( "%X", nB or 255 )
    sColor = sColor .. ( ( string.len ( nB ) == 1 ) and ( "0" .. nB ) or nB )
    return sColor
end

local tagColor = rgbToHex(colour.r,colour.g,colour.b) or "#FFFFFF"

function updateTeamSettings(playerSource,cmd,R,G,B)
    local playerName = getPlayerName(playerSource)
    local account = getPlayerAccount (playerSource)
    local account_name = getAccountName(account)
    if isObjectInACLGroup ( "user." .. account_name, aclGetGroup ( "Admin" )) then
    if not tonumber(R) or not tonumber(G) or not tonumber(B) then outputChatBox("#313131こコBOT#ffffff| #ffffffWrong Syntax #abcdef/color R G B",playerSource,255,255,255,true) return end
R,G,B = tonumber(R),tonumber(G),tonumber(B)
    if R <= 50 and G <= 50 and B <= 50 then--R,G,B = ,tonumber(G),tonumber(B)
        colour.r = 255
        colour.g = 255
        colour.b = 255
    else
        colour.r = R
        colour.g = G
        colour.b = B
    end
        tagColor = rgbToHex(colour.r,colour.g,colour.b) or "#FFFFFF"
		triggerClientEvent(getRootElement(), "updateName", getRootElement(), homeName, homeTag, enemyName, enemyTag,colour.r,colour.g,colour.b)
		outputChatBox("#313131こコBOT#ffffff| #ffffffTeam Colour successfully changed",playerSource,255,255,255,true)
        local enemyTeam = getTeamFromName(enemyName)
        if enemyTeam then
            team[2] = enemyTeam
            updateTeamColour()
        else
            team[2] = createTeam ( enemyName, colour.r,colour.g,colour.b)
            if team[2] then
                updateTeamColour()
            end
        end
    end
end
addCommandHandler("color",updateTeamSettings)

function updateTeamColour()
	setTeamColor ( team[2], colour.r, colour.g, colour.b )
end
addEvent("updateTeamColour", true)
addEventHandler("updateTeamColour", resourceRoot, updateTeamColour)

btw in server side work updatecolor when i reconnect but in client not work please help i'm so confused :/

 

 

Edited by xFabel
Link to comment

your worng is in client side

here      

 

if enemyTeam then  <<<<<<<<<<<<<<<<<<  your should write your team name with   getTeamFromName("write your team here")
 

 

your full codes shoud be like that


Client side :

 

local colour = {}
local tagColor
local teams = {}
colour.r = 128    
colour.g = 128    
colour.b = 128    



function updateTeamSettings(cmd,R,G,B)
    if not tonumber(R) or not tonumber(G) or not tonumber(B) then return end
    R,G,B = tonumber(R),tonumber(G),tonumber(B)

        if getTeamFromName("enemyName") then
            teams[2] = getTeamFromName("enemyName")
     triggerServerEvent ( "updateTeamColour", resourceRoot,getTeamFromName("enemyName"),R,G,B)
        end
    end
addCommandHandler("color",updateTeamSettings)


function tryRandomClr()
     triggerServerEvent ( "updateTeamColour", resourceRoot,getTeamFromName("enemyName"), math.random(1,255),math.random(1,255),math.random(1,255))
end
addEventHandler("onClientPlayerJoin", getRootElement(),tryRandomClr)


function text()
dxDrawText("Alive Players[#334455"..home_alive.."#ffffff/"..tagColor..enemy_team.."#ffffff]",sX,sY*0.03,sX*0.2,sY*0,tocolor(255,255,255,generalAlpha),clanwar_data_fontSize*1.2,clanwar_data_font,"center","center",false,false,false,true)
end
addEventHandler("onClientRender", root, text)




 

 

 

server side :

 

 


teams = {}
colour = {}
colour.r = 255
colour.g = 85
colour.b = 85
enemyName = "enemyName"
local tagColor

function updateTeamSettings(playerSource,cmd,R,G,B)
    local playerName = getPlayerName(playerSource)
    local account = getPlayerAccount (playerSource)
    local account_name = getAccountName(account)
    if isObjectInACLGroup ( "user." .. account_name, aclGetGroup ( "Admin" )) then
    if not tonumber(R) or not tonumber(G) or not tonumber(B) then outputChatBox("#313131こコBOT#ffffff| #ffffffWrong Syntax #abcdef/color R G B",playerSource,255,255,255,true) return end
R,G,B = tonumber(R),tonumber(G),tonumber(B)

    outputChatBox("#313131こコBOT#ffffff| #ffffffTeam Colour successfully changed",playerSource,255,255,255,true)

        local enemyTeam = getTeamFromName(enemyName)

        if enemyTeam then
            teams[2] = enemyTeam
           setTeamColor (enemyTeam,R,G,B)
        else
            teams[2] = createTeam ( enemyName,R,G,B)
            if teams[2] then
           setTeamColor (teams[2],R,G,B)
            end
        end

    end
end
addCommandHandler("color",updateTeamSettings)

function updateTeamColour(team,r,g,b)
           setTeamColor (team,r,g,b)
end
addEvent("updateTeamColour", true)
addEventHandler("updateTeamColour", resourceRoot, updateTeamColour)

 

Edited by komal
Link to comment
  On 09/11/2019 at 22:15, komal said:

your worng is in client side

here      

 

if enemyTeam then  <<<<<<<<<<<<<<<<<<  your should write your team name with   getTeamFromName("write your team here")
 

 

Expand  

not work

local tagColor = rgbToHex(colour.r,colour.g,colour.b) or "#FFFFFF"
function updateTeamSettings(cmd,R,G,B)
    if not tonumber(R) or not tonumber(G) or not tonumber(B) then return end
R,G,B = tonumber(R),tonumber(G),tonumber(B)
    if R <= 50 and G <= 50 and B <= 50 then
        colour.r = 255
        colour.g = 255
        colour.b = 255
    else
        colour.r = R
        colour.g = G
        colour.b = B
    end
        tagColor = rgbToHex(colour.r,colour.g,colour.b) or "#FFFFFF"
		local enemyTeam = getTeamFromName(enemyName)
        if enemyTeam then
            team[2] = enemyTeam
            TeamColor()
        else
            if team[2] then
                TeamColor()
            end
        end
    end
addCommandHandler("color",updateTeamSettings)

function TeamColor()
     triggerServerEvent ( "updateTeamColour", resourceRoot,team[2], colour.r, colour.g, colour.b )
end

 

Edited by xFabel
Link to comment
  On 09/11/2019 at 22:25, xFabel said:

not work


local tagColor = rgbToHex(colour.r,colour.g,colour.b) or "#FFFFFF"function updateTeamSettings(cmd,R,G,B)    if not tonumber(R) or not tonumber(G) or not tonumber(B) then return endR,G,B = tonumber(R),tonumber(G),tonumber(B)    if R <= 50 and G <= 50 and B <= 50 then        colour.r = 255        colour.g = 255        colour.b = 255    else        colour.r = R        colour.g = G        colour.b = B    end        tagColor = rgbToHex(colour.r,colour.g,colour.b) or "#FFFFFF"		local enemyTeam = getTeamFromName(enemyName)        if enemyTeam then            team[2] = enemyTeam            TeamColor()        else            if team[2] then                TeamColor()            end        end    endaddCommandHandler("color",updateTeamSettings)function TeamColor()     triggerServerEvent ( "updateTeamColour", resourceRoot,team[2], colour.r, colour.g, colour.b )end

 

Expand  

why you dont use player join event in server side ?

function playerjoinToserver()

addEventHandler ( "onPlayerJoin", getRootElement(),playerjoinToserver)

https://wiki.multitheftauto.com/wiki/OnPlayerJoin

 

 

 

 

====

this is your full code

 

 

client

 


 

function text()
dxDrawText("Alive Players[#334455"..home_alive.."#ffffff/"..tagColor..enemy_team.."#ffffff]",sX,sY*0.03,sX*0.2,sY*0,tocolor(255,255,255,generalAlpha),clanwar_data_fontSize*1.2,clanwar_data_font,"center","center",false,false,false,true)
end
addEventHandler("onClientRender", root, text)

 

 

 

 

server


 

teams = {}
colour = {}
colour.r = 255
colour.g = 85
colour.b = 85
enemyName = "enemyName"
local tagColor

function updateTeamSettings(playerSource,cmd,R,G,B)
    local playerName = getPlayerName(playerSource)
    local account = getPlayerAccount (playerSource)
    local account_name = getAccountName(account)
    if isObjectInACLGroup ( "user." .. account_name, aclGetGroup ( "Admin" )) then
    if not tonumber(R) or not tonumber(G) or not tonumber(B) then outputChatBox("#313131こコBOT#ffffff| #ffffffWrong Syntax #abcdef/color R G B",playerSource,255,255,255,true) return end
R,G,B = tonumber(R),tonumber(G),tonumber(B)

    outputChatBox("#313131こコBOT#ffffff| #ffffffTeam Colour successfully changed",playerSource,255,255,255,true)

        local enemyTeam = getTeamFromName(enemyName)

        if enemyTeam then
            teams[2] = enemyTeam
           setTeamColor (enemyTeam,R,G,B)
        else
            teams[2] = createTeam ( enemyName,R,G,B)
            if teams[2] then
           setTeamColor (teams[2],R,G,B)
            end
        end

    end
end
addCommandHandler("color",updateTeamSettings)

function updateTeamColour(team,r,g,b)
           setTeamColor (team,r,g,b)
end




function joinplr()
setTeamColor (getTeamFromName(enemyName),math.random(1,255),math.random(1,255),math.random(1,255))
end
addEventHandler("onPlayerJoin", getRootElement(), joinplr)

 

Edited by komal
Link to comment
  On 09/11/2019 at 22:31, komal said:

why you dont use player join event in server side ?

 
  1.  
  1.  
  1. function playerjoinToserver()addEventHandler ( "onPlayerJoin", getRootElement(),playerjoinToserver)

https://wiki.multitheftauto.com/wiki/OnPlayerJoin

 

 

 

 

====

Expand  

like this not work ?

function updateTeamColour()
	setTeamColor ( team[2], colour.r, colour.g, colour.b )
end
addEvent("updateTeamColour", true)
addEventHandler("updateTeamColour", resourceRoot, updateTeamColour)
addEventHandler("onPlayerJoin", getRootElement(), updateTeamColour)

server side

Edited by xFabel
Link to comment
  On 09/11/2019 at 22:43, xFabel said:

like this not work ?


function updateTeamColour()
	setTeamColor ( team[2], colour.r, colour.g, colour.b )
end
addEvent("updateTeamColour", true)
addEventHandler("updateTeamColour", resourceRoot, updateTeamColour)
addEventHandler("onPlayerJoin", getRootElement(), updateTeamColour)

server side

Expand  

Where are team and colour defined?

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