Jump to content

Mhhh textlib? :S


#Paper

Recommended Posts

i have this code:

function showKills(text, y, teamName) 
teamName = dxText:create( text, 15, y, false, 'bankgothic', 0.50, 'left') 
teamName:type('stroke', 1, 0, 0, 0, 255) 
end 
addEvent ( "showKillsForTeam", true ) 
addEventHandler ( "showKillsForTeam", getRootElement(), showKills ) 
  
function modifyKills(text, teamName) 
teamName:text( text ) 
end 
addEvent ( "modifyKillsForTeam", true ) 
addEventHandler ( "modifyKillsForTeam", getRootElement(), showKills ) 

but modifyKills function doesn't work: doesn't set the text, maybe he can't find the text element?

Link to comment

teamName shouldn't be a function paratemer for modifyKills or showKills ..

teamName should be a global variable in your client script.

and shouldn't this line: addEventHandler ( "modifyKillsForTeam", getRootElement(), showKills )

actually be

addEventHandler ( "modifyKillsForTeam", getRootElement(), modifyKills )

?

Link to comment
teamName should be a global variable in your client script.

i think that i need it, cuz when i create the text the event is triggere by a for cicle in SS, teamName in modifyKills in needed cuz i need to delete the text whit the team name, not as name teamName...

P.S: Attempt to call method "text" in modifyKills

Link to comment

I'm pretty sure that your SS isn't sending to CS a variable containing an object of textlib

'text' is obvious that is sent (from the FOR in SS)

but just make a table of teamName = {} and use teamName[text] = dxText:create( text, 15, y, false, 'bankgothic', 0.50, 'left')

this table will be global variable in CS (so remove it from function parameter)

and call the same teamName[text] in modifyKills function

Link to comment

so, i create teamName = {} in cs and then i make a for cicle in CS for make the text whit dxCreate and then for modify it same for?

------------------SS 
for k,v in ipairs(gameTeams) do 
     local teamName = v.name 
     triggerClientEvent("onAddTeam", getRootElement(), teamName)   
end 
triggerClientEvent("showKillsForTeam", getRootElement()) 
------------------CS 
local teamName = {} 
  
function addTeam(teamName) 
teamName = teamName[teamName] 
end 
addEvent ( "onAddTeam", true ) 
addEventHandler ( "onAddTeam", getRootElement(), addTeam ) 
  
function showKills() 
local textBoost = 240 
for k, team in ipairs(teamName) do 
    team[text] = dxText:create( text, 15, y, false, 'bankgothic', 0.50, 'left') 
    team[text]:type('stroke', 1, 0, 0, 0, 255) 
    textBoost = textBoost + 15 
end 
end 
addEvent ( "showKillsForTeam", true ) 
addEventHandler ( "showKillsForTeam", getRootElement(), showKills ) 

Link to comment
  
    ------------------SS 
    for k,v in ipairs(gameTeams) do 
         local teamName = v.name 
         triggerClientEvent("onAddTeam", getRootElement(), teamName)  
    end 
    triggerClientEvent("showKillsForTeam", getRootElement()) 
    ------------------CS 
    local teamName = {} 
      
    function addTeam(name) 
    teamName[name] = name 
    end 
    addEvent ( "onAddTeam", true ) 
    addEventHandler ( "onAddTeam", getRootElement(), addTeam ) 
      
     local teamDraw = {} 
    function showKills() 
    local textBoost = 240 
    for k, team in pairs(teamName) do 
        teamDraw[team] = dxText:create( team, 15, y, false, 'bankgothic', 0.50, 'left') 
        teamDraw[team]:type('stroke', 1, 0, 0, 0, 255) 
        textBoost = textBoost + 15 
    end 
    end 
    addEvent ( "showKillsForTeam", true ) 
    addEventHandler ( "showKillsForTeam", getRootElement(), showKills ) 

I'm not sure what exactly you're trying to do, I think the code can be simplified a lot but here's how I think you should do it (based on your code)

Link to comment
  
    ------------------SS 
    for k,v in ipairs(gameTeams) do 
         local teamName = v.name 
         triggerClientEvent("onAddTeam", getRootElement(), teamName)  
    end 
    triggerClientEvent("showKillsForTeam", getRootElement()) 
    ------------------CS 
    local teamName = {} 
      
    function addTeam(name) 
    teamName[name] = name 
    end 
    addEvent ( "onAddTeam", true ) 
    addEventHandler ( "onAddTeam", getRootElement(), addTeam ) 
      
     local teamDraw = {} 
    function showKills() 
    local textBoost = 240 
    for k, team in pairs(teamName) do 
        teamDraw[team] = dxText:create( team, 15, y, false, 'bankgothic', 0.50, 'left') 
        teamDraw[team]:type('stroke', 1, 0, 0, 0, 255) 
        textBoost = textBoost + 15 
    end 
    end 
    addEvent ( "showKillsForTeam", true ) 
    addEventHandler ( "showKillsForTeam", getRootElement(), showKills ) 

I'm not sure what exactly you're trying to do, I think the code can be simplified a lot but here's how I think you should do it (based on your code)

works just the draw, when i need to change it:

function modifyKills(text, teamName) 
teamDraw[teamName]:text( text ) 
end 
addEvent ( "modifyKillsForTeam", true ) 
addEventHandler ( "modifyKillsForTeam", getRootElement(), modifyKills ) 

attempt to index field ? (nil value)

@ line 2

P.S: How can i make that when a new map start the script destroy the old texts and makes new?

Link to comment
  
    function modifyKills(oldText, newText) 
    teamDraw[oldText]:text( newText ) 
    teamDraw[newText] = teamDraw[oldText] 
    end 
    addEvent ( "modifyKillsForTeam", true ) 
    addEventHandler ( "modifyKillsForTeam", getRootElement(), modifyKills ) 
  

try this but you'll need the old text and the new text as arguments for the triggerServerEvent

my experience with textlib is pretty limited maybe someone else can help more if this won't do it.

Link to comment
  
    function modifyKills(oldText, newText) 
    teamDraw[oldText]:text( newText ) 
    teamDraw[newText] = teamDraw[oldText] 
    end 
    addEvent ( "modifyKillsForTeam", true ) 
    addEventHandler ( "modifyKillsForTeam", getRootElement(), modifyKills ) 
  

try this but you'll need the old text and the new text as arguments for the triggerServerEvent

my experience with textlib is pretty limited maybe someone else can help more if this won't do it.

I'll try, and for delete and make again the text when a new map start?

Link to comment

So, i tryed whit this code:

function addTeam(name, text) 
teamName[name] = text 
end 
addEvent ( "onAddTeam", true ) 
addEventHandler ( "onAddTeam", getRootElement(), addTeam ) 
  
local teamDraw = {} 
function showKills() 
local textBoost = 240 
for k, team in pairs(teamName) do 
    teamDraw[team] = dxText:create( k, 15, textBoost, false, 'bankgothic', 0.50, 'left') 
    teamDraw[team]:type('stroke', 1, 0, 0, 0, 255) 
    textBoost = textBoost + 15 
end 
end 
addEvent ( "showKillsForTeam", true ) 
addEventHandler ( "showKillsForTeam", getRootElement(), showKills ) 
  
function modifyKills(newText, teamName) 
teamDraw[teamName] = newText 
teamDraw[teamName]:text( newText ) 
end 
addEvent ( "modifyKillsForTeam", true ) 
addEventHandler ( "modifyKillsForTeam", getRootElement(), modifyKills ) 

So, addTeam(name, text), name is the team name and text is the text to write, and i store the table whit the team name and whit text to write (teamName[name] = text)

for k, team in pairs(teamName) do 
    teamDraw[team] = dxText:create( k, 15, textBoost, false, 'bankgothic', 0.50, 'left') 
    teamDraw[team]:type('stroke', 1, 0, 0, 0, 255) 
    textBoost = textBoost + 15 
end 

whit this for i create the text whit the team name first called and the string is the text first called.

The text have been create but doesn't modify, i tryed whit this command:

function test (player) 
local teamID = getElementData( player, "tdma.teamid" ) 
gameTeams[teamID].kills = gameTeams[teamID].kills + 1 
triggerClientEvent("modifyKillsForTeam", getRootElement(), rgbToHex(getTeamColor(getTeamFromName(gameTeams[teamID].name)))..gameTeams[teamID].name .. ": " .. gameTeams[teamID].kills .. "/" .. gameMaxKills .. " Kills", gameTeams[teamID].name) 
end 
addCommandHandler("testmod", test) 

function modifyKills(newText, teamName) 
teamDraw[teamName] = newText 
teamDraw[teamName]:text( newText ) 
end 

and whit this func i modify the text team name and the text and i set the text whit new one :D

but bad argument on modify CS func: attempt to call method 'text' (a nil value)

any help?

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