Jump to content

addEventHandeler Problem


TABoOoT

Recommended Posts

hi i am a new scripter and i ran into a problem, i made a script to replace strings with emojis.

my problem is the following on the client the script is

local root = getRootElement() 
local rroot = getResourceRootElement() 
local sx,sy = guiGetScreenSize() 
local chatbox = getChatboxLayout() 
local y = chatbox["chat_scale"][2] 
local lineas = chatbox["chat_lines"] 
local font = "default" 
  
if chatbox["chat_font"] == 1 then 
    font = "clear" 
elseif chatbox["chat_font"] == 2 then 
    font = "default-bold" 
elseif chatbox["chat_font"] == 3 then 
    font = "arial" 
end 
  
addEventHandler("SpecialEmojis", root,function(txt) 
for k,v in ipairs(getElementsByType("gui-staticimage",rroot)) do 
        local gx,gy = guiGetPosition(v,true) 
        if string.len(txt) > 100 then 
            guiSetPosition(v, gx,gy-0.025,true) 
        else 
            guiSetPosition(v, gx,gy-0.025,true) 
        end 
        if gy <= 0.01 then 
            destroyElement(v) 
        end 
    end 
    txt = string.gsub(txt,"#[%x][%x][%x][%x][%x][%x]","") 
    local len = 0 
    if string.len(txt) > 48 then 
        return 
    end 
    if string.find(txt,"ضض") then 
        local text = string.gsub(txt,"ضض","") 
        local len = dxGetTextWidth(text,chatbox["chat_scale"][1],font) 
        local lfin = convertirRelativo(len) 
        outputDebugString("LEN="..tostring(len).." LFIN="..tostring(lfin)) 
        local img = guiCreateStaticImage(0.01875+lfin,0.02+(0.025*(lineas-1)),0.02,0.025,"dai/3tb.png",true) 
    end 
end) 
  
function convertirRelativo(x) 
    local rx = x/sx 
     
    return rx 
end 

and on server side its

function dai ( ) 
    if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Admin")) then 
    triggerClientEvent ( "SpecialEmojis", source ) 
    end 
end 

the main thing i want my script to do is to check if the player is in admin group and then when he types "ضض" in chat it replaces with an emoji which is 3tb.png

thanks...

Link to comment

Client

local root = getRootElement() 
local rroot = getResourceRootElement() 
local sx,sy = guiGetScreenSize() 
local chatbox = getChatboxLayout() 
local y = chatbox["chat_scale"][2] 
local lineas = chatbox["chat_lines"] 
local font = "default" 
  
if chatbox["chat_font"] == 1 then 
    font = "clear" 
elseif chatbox["chat_font"] == 2 then 
    font = "default-bold" 
elseif chatbox["chat_font"] == 3 then 
    font = "arial" 
end 
  
addEvent("SpecialEmojis", true)  
addEventHandler("SpecialEmojis", root,function(txt) 
for k,v in ipairs(getElementsByType("gui-staticimage",rroot)) do 
        local gx,gy = guiGetPosition(v,true) 
        if string.len(txt) > 100 then 
            guiSetPosition(v, gx,gy-0.025,true) 
        else 
            guiSetPosition(v, gx,gy-0.025,true) 
        end 
        if gy <= 0.01 then 
            destroyElement(v) 
        end 
    end 
    txt = string.gsub(txt,"#[%x][%x][%x][%x][%x][%x]","") 
    local len = 0 
    if string.len(txt) > 48 then 
        return 
    end 
    if string.find(txt,"ضض") then 
        local text = string.gsub(txt,"ضض","") 
        local len = dxGetTextWidth(text,chatbox["chat_scale"][1],font) 
        local lfin = convertirRelativo(len) 
        outputDebugString("LEN="..tostring(len).." LFIN="..tostring(lfin)) 
        local img = guiCreateStaticImage(0.01875+lfin,0.02+(0.025*(lineas-1)),0.02,0.025,"dai/3tb.png",true) 
    end 
end) 
  
function convertirRelativo(x) 
    local rx = x/sx 
    
    return rx 
end 

Server

function dai (thePlayer ) 
    if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Admin")) then 
    triggerClientEvent ( thePlayer, "SpecialEmojis", root ) 
    end 
end 

Link to comment
Client
local root = getRootElement() 
local rroot = getResourceRootElement() 
local sx,sy = guiGetScreenSize() 
local chatbox = getChatboxLayout() 
local y = chatbox["chat_scale"][2] 
local lineas = chatbox["chat_lines"] 
local font = "default" 
  
if chatbox["chat_font"] == 1 then 
    font = "clear" 
elseif chatbox["chat_font"] == 2 then 
    font = "default-bold" 
elseif chatbox["chat_font"] == 3 then 
    font = "arial" 
end 
  
addEvent("SpecialEmojis", true)  
addEventHandler("SpecialEmojis", root,function(txt) 
for k,v in ipairs(getElementsByType("gui-staticimage",rroot)) do 
        local gx,gy = guiGetPosition(v,true) 
        if string.len(txt) > 100 then 
            guiSetPosition(v, gx,gy-0.025,true) 
        else 
            guiSetPosition(v, gx,gy-0.025,true) 
        end 
        if gy <= 0.01 then 
            destroyElement(v) 
        end 
    end 
    txt = string.gsub(txt,"#[%x][%x][%x][%x][%x][%x]","") 
    local len = 0 
    if string.len(txt) > 48 then 
        return 
    end 
    if string.find(txt,"ضض") then 
        local text = string.gsub(txt,"ضض","") 
        local len = dxGetTextWidth(text,chatbox["chat_scale"][1],font) 
        local lfin = convertirRelativo(len) 
        outputDebugString("LEN="..tostring(len).." LFIN="..tostring(lfin)) 
        local img = guiCreateStaticImage(0.01875+lfin,0.02+(0.025*(lineas-1)),0.02,0.025,"dai/3tb.png",true) 
    end 
end) 
  
function convertirRelativo(x) 
    local rx = x/sx 
    
    return rx 
end 

Server

function dai (thePlayer ) 
    if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Admin")) then 
    triggerClientEvent ( thePlayer, "SpecialEmojis", root ) 
    end 
end 

when i type in chat "ضض" it dosent replace it with the (png) any other ideas? :?:

Link to comment
local root = getRootElement() 
local rroot = getResourceRootElement() 
local sx,sy = guiGetScreenSize() 
local chatbox = getChatboxLayout() 
local y = chatbox["chat_scale"][2] 
local lineas = chatbox["chat_lines"] 
local font = "default" 
  
if chatbox["chat_font"] == 1 then 
    font = "clear" 
elseif chatbox["chat_font"] == 2 then 
    font = "default-bold" 
elseif chatbox["chat_font"] == 3 then 
    font = "arial" 
end 
  
addEvent("SpecialEmojis", true) 
addEventHandler("SpecialEmojis", root,function(txt) 
for k,v in ipairs(getElementsByType("gui-staticimage",rroot)) do 
        local gx,gy = guiGetPosition(v,true) 
        if string.len(txt) > 100 then 
            guiSetPosition(v, gx,gy-0.025,true) 
        else 
            guiSetPosition(v, gx,gy-0.025,true) 
        end 
        if gy <= 0.01 then 
            destroyElement(v) 
        end 
    end 
    txt = string.gsub(txt,"#%x%x%x%x%x%x","") 
    local len = 0 
    if string.len(txt) > 48 then 
        return 
    end 
    if string.find(txt,"ضض") then 
        local text = string.gsub(txt,"ضض","") 
        local len = dxGetTextWidth(text,chatbox["chat_scale"][1],font) 
        local lfin = convertirRelativo(len) 
        outputDebugString("LEN="..tostring(len).." LFIN="..tostring(lfin)) 
        local img = guiCreateStaticImage(0.01875+lfin,0.02+(0.025*(lineas-1)),0.02,0.025,"dai/3tb.png",true) 
    end 
end) 
  
function convertirRelativo(x) 
    local rx = x/sx 
    
    return rx 
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...