K4stic Posted May 5, 2013 Share Posted May 5, 2013 Error line 9: bad argument #1 to 'gsub' (string expected, got boolean) function showWinMessageF (player) PlayerName = addTeamColor(player) addEventHandler ( "onClientRender", getRootElement(), WinTextRendering ) setTimer(function() removeEventHandler("onClientRender",getRootElement(), WinTextRendering) end, 6000,1) end addEvent( "showWinMessage", true ) addEventHandler( "showWinMessage", getRootElement(), showWinMessageF ) dxDrawColorTextLine(''..string.gsub(PlayerName,"#%x%x%x%x%x%x",'').." is the final survivor!", 0, -148, sw, sh-148, tocolor(0,0,0,255), 1, "bankgothic", "center", "center") function dxDrawColorTextLine(str, ax, ay, bx, by, color, scale, font, alignX, alignY) Texts = {} Texts = string.explode(str,"/newline/") for i=1,#Texts do dxDrawText(Texts[i], ax, ay+(dxGetFontHeight ( scale, font ))*(i-1), bx, by, color, scale, font, alignX, alignY) end end function string.explode(self, separator) Check("string.explode", "string", self, "ensemble", "string", separator, "separator") if (#self == 0) then return {} end if (#separator == 0) then return { self } end return loadstring("return {\""..self:gsub(separator, "\",\"").."\"}")() end Link to comment
MTA Team 0xCiBeR Posted May 6, 2013 MTA Team Share Posted May 6, 2013 lol thats because in your gsub your first argument is PlayerName...And the global for that dosent represent a player... Link to comment
K4stic Posted May 6, 2013 Author Share Posted May 6, 2013 sorry how i can fix it i just first time using string.gsub bad know it and the addTeamColor(player) getting other function me prob only with string.gsub Link to comment
denny199 Posted May 6, 2013 Share Posted May 6, 2013 That's because you used here: PlayerName = addTeamColor(player) without LOCAL so it will NOT be for the function. after that you are not showing your full code at all. Please, post serverside and al the needed functions like addTeamColor, and explain a bit more what you are trying to accomplish. -You didn't showed the addTeamColor function -You didn't show the trigger -Your scripts have errors because nothing triggers the function with onClientRender (addEventHandler ( "onClientRender", getRootElement(), WinTextRendering )) Kindly regards, Danny Link to comment
K4stic Posted May 6, 2013 Author Share Posted May 6, 2013 And trigger working perfect i saying only at line 37 is the bug with gsub Full code local sw,sh = guiGetScreenSize() function addTeamColor(player) local playerTeam = getPlayerTeam ( player ) if ( playerTeam ) then local r,g,b = getTeamColor ( playerTeam ) local n1 = toHex(r) local n2 = toHex(g) local n3 = toHex(b) if r <= 16 then n1 = "0"..n1 end if g <= 16 then n2 = "0"..n2 end if b <= 16 then n3 = "0"..n3 end return "#"..n1..""..n2..""..n3..""..getPlayerNametagText(player) else return getPlayerNametagText(player) end end function toHex ( n ) local hexnums = {"0","1","2","3","4","5","6","7", "8","9","A","B","C","D","E","F"} local str,r = "",n%16 if n-r == 0 then str = hexnums[r+1] else str = toHex((n-r)/16)..hexnums[r+1] end return str end function showWinMessageF (player) PlayerName = addTeamColor(player) addEventHandler ( "onClientRender", getRootElement(), WinTextRendering ) setTimer(function() removeEventHandler("onClientRender",getRootElement(), WinTextRendering) end, 6000,1) end addEvent( "showWinMessage", true ) addEventHandler( "showWinMessage", getRootElement(), showWinMessageF ) function WinTextRendering() dxDrawColorTextLine(''..string.gsub( PlayerName, '#%x%x%x%x%x%x', '' ).." is the final survivor!", 0, -148, sw, sh-148, tocolor(0,0,0,255), 1, "bankgothic", "center", "center") dxDrawColorText(''..PlayerName..' #ffffffis the final #ffffffsurvivor!', 0, -150, sw, sh-150, tocolor(255,255,255,Alpha), 1, "bankgothic", "center", "center") end ------------------------------------------------------------------------------------------------------------ function getPointFromDistanceRotation(x, y, dist, angle) local a = math.rad(90 - angle); local dx = math.cos(a) * dist; local dy = math.sin(a) * dist; return x+dx, y+dy; end function dxDrawColorTextLine(str, ax, ay, bx, by, color, scale, font, alignX, alignY) Texts = {} Texts = string.explode(str,"/newline/") for i=1,#Texts do dxDrawText(Texts[i], ax, ay+(dxGetFontHeight ( scale, font ))*(i-1), bx, by, color, scale, font, alignX, alignY) end end function dxDrawColorText(str, ax, ay, bx, by, color, scale, font, alignX, alignY) Texts = {} Texts = string.explode(str,"/newline/") for i=1,#Texts do dxDrawColorTextNext(Texts[i], ax, ay+(dxGetFontHeight ( scale, font ))*(i-1), bx, by, color, scale, font, alignX, alignY) end end function dxDrawColorTextNext(str, ax, ay, bx, by, color, scale, font, alignX, alignY) if alignX then if alignX == "center" then local w = dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font) ax = ax + (bx-ax)/2 - w/2 elseif alignX == "right" then local w = dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font) ax = bx - w end end if alignY then if alignY == "center" then local h = dxGetFontHeight(scale, font) ay = ay + (by-ay)/2 - h/2 elseif alignY == "bottom" then local h = dxGetFontHeight(scale, font) ay = by - h end end local pat = "(.-)#(%x%x%x%x%x%x)" local s, e, cap, col = str:find(pat, 1) local last = 1 while s do if cap == "" and col then color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), Alpha) end if s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) ax = ax + w color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), Alpha) end last = e + 1 s, e, cap, col = str:find(pat, last) end if last <= #str then cap = str:sub(last) local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) end end function string.explode(self, separator) Check("string.explode", "string", self, "ensemble", "string", separator, "separator") if (#self == 0) then return {} end if (#separator == 0) then return { self } end return loadstring("return {\""..self:gsub(separator, "\",\"").."\"}")() end function Check(funcname, ...) local arg = {...} if (type(funcname) ~= "string") then error("Argument type mismatch at 'Check' ('funcname'). Expected 'string', got '"..type(funcname).."'.", 2) end if (#arg % 3 > 0) then error("Argument number mismatch at 'Check'. Expected #arg % 3 to be 0, but it is "..(#arg % 3)..".", 2) end for i=1, #arg-2, 3 do if (type(arg[i]) ~= "string" and type(arg[i]) ~= "table") then error("Argument type mismatch at 'Check' (arg #"..i.."). Expected 'string' or 'table', got '"..type(arg[i]).."'.", 2) elseif (type(arg[i+2]) ~= "string") then error("Argument type mismatch at 'Check' (arg #"..(i+2).."). Expected 'string', got '"..type(arg[i+2]).."'.", 2) end if (type(arg[i]) == "table") then local aType = type(arg[i+1]) for _, pType in next, arg[i] do if (aType == pType) then aType = nil break end end if (aType) then error("Argument type mismatch at '"..funcname.."' ('"..arg[i+2].."'). Expected '"..table.concat(arg[i], "' or '").."', got '"..aType.."'.", 3) end elseif (type(arg[i+1]) ~= arg[i]) then error("Argument type mismatch at '"..funcname.."' ('"..arg[i+2].."'). Expected '"..arg[i].."', got '"..type(arg[i+1]).."'.", 3) end end end fileDelete("winEffect.lua") 1 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