Jump to content

NameColor


HeXo

Recommended Posts

i have downloaded this resource: https://community.multitheftauto.com/index.php?p=resources&s=details&id=192

but i can't get it working

-- ************* SPECIAL RELEASE *************** 
-- ************* MADE BY FATALITRY  ************** 
-- ************* SCRIPTNAME :     **************** 
-- ************* NAMECOLOR      ***************** 
-- ************* A MUST HAVE FOR CLANS!! *************** 
  
function tuPlayerHasPower(player) 
   -- Return true if the player belongs to any of the priveledged users  
  for i,groupName in pairs({"clan"}) do 
   if tuPlayerInACLGroup(player,groupName) then 
  
local clanAdmin = { [1]={start=1, finish=4, name="HeXo"} 
local clanVIP = { [1]={start=1, finish=4, name="TaTo"} } 
local g_Root = getRootElement() 
  
addEventHandler('onPlayerChat', g_Root, 
    function(msg, type) 
        if type == 0 then 
            cancelEvent() 
             
            local isAdmin = false 
            for i,j in ipairs(clanAdmin) do 
                if ( string.sub(getClientName(source), j.start, j.finish) == j.name ) then 
                    isAdmin = true 
                end 
            end 
             
            local isVIP = falset 
            for i,j in ipairs(clanVIP) do 
                if ( string.sub(getClientName(source), j.start, j.finish) == j.name ) then 
                    isVIP = true 
                end 
            end 
  
            local isMember = falset 
            for i,j in ipairs(clanMember) do 
                if ( string.sub(getClientName(source), j.start, j.finish) == j.name ) then 
                    isMember = true 
                end 
            end 
             
            if ( isAdmin ) then 
                outputChatBox("#3300FF[Admin] " .. getClientName(source) .. ': ' .. "#3300FF" .. msg:gsub('#%x%x%x%x%x%x', ''), g_Root, 0, 0, 0, true) 
            else( isVIP ) then 
                outputChatBox("#33FF66[Mod] " .. getClientName(source) .. ': ' .. "#FFFFFF" .. msg:gsub('#%x%x%x%x%x%x', ''), g_Root, 0, 0, 0, true) 
            end 
        end 
    end 
  
) 

Any ideas?

Or if u guys have a better way to let the admin nick and message in RED, tell me.

Sorry about my bad english.

Edited by Guest
Link to comment

I'm not sure why this was posted as it doesn't work. tuPlayerHasPower() and the four lines with it are from a function I posted here a while back - but the function is incomplete. The event handler isn't hooked in either.

Link to comment

I think someone else can better make this code from scratch. Would work better and might even take less time. I'll look what it was intended to do and if I know another way of doing it. You'll hear it if I made any big progress in it. ;)

EDIT: Stuck! I don't know how to convert a string to a variable... There exists like "tonumber", "tostring" etc. But something like "tovar"doesn't... I'll keep on looking. But I have to go in about 20 to 30 minutes... If I can't finish it, I'll post it. If I can, I'll post it. :P (I'll edit this post again)

EDIT2: I'm almost done, but g2g... Doesn't work yet, so someone else may finish it and improve it:

-- ************* IMPROVED RELEASE *************** 
-- ************* MADE BY GAMESNERT *************** 
-- ************* SCRIPTNAME : *************** 
-- ************* NAMECOLOR (working version) *************** 
-- ************* A MUST HAVE FOR CLANS!! *************** 
-- ************* ORIGINAL BY: FATALITRY *************** 
  
accountdat={} 
  
function init() 
    local xmlFile=xmlLoadFile("config.xml") 
    if xmlFile then 
        local configNode=true 
        i=0 
        while configNode~=false do 
            configNode=xmlFindSubNode(xmlFile,"user",i) 
            if configNode then 
                local xmlReadName=xmlNodeGetAttribute(configNode,"name") 
                local xmlReadClass=xmlNodeGetAttribute(configNode,"class") 
                accountdat[xmlReadName]={name=xmlReadName, class=xmlReadClass} 
                accountdat[i+1]=accountdat[xmlReadName] 
            else 
                if i<1 then 
                    outputDebugString(getResourceName(getThisResource()) .. ": No users were found in the config file! The script won't have any effect!") 
                end 
            end 
            i=i+1 
        end 
        configNode=false 
        configNode=xmlFindSubNode(xmlFile,"colors",0) 
        if configNode then 
            local readAdmin=xmlNodeGetAttribute(configNode,"admin") 
            local readModerator=xmlNodeGetAttribute(configNode,"moderator") 
            local readMember=xmlNodeGetAttribute(configNode,"member") 
            accountdat["colors"]={admin=readAdmin,moderator=readModerator,member=readMember} 
        else 
            outputDebugString(getResourceName(getThisResource()) .. ": No color setting could be found! The script won't have any effect!") 
        end 
    end 
end 
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),init) 
  
function onPlayerTalk(msg,msgType) 
    if msgType==0 then 
        local className=accountdat[getClientName(source)].class 
        if className=="admin" then class=admin end 
        if className=="moderator" then class=moderator end 
        if className=="member" then class=member end 
        local color=accountdat["colors"].class 
        if class~=nil or class~=false then 
            outputChatBox(color .. "[" .. className .. "] " .. getClientName(source) .. ": " .. "#FFFFFF" .. msg,getRootElement(),0,0,0,true) 
        else 
            outputChatBox("Booooooo!",getRootElement(),0,0,0) 
        end 
    end 
end 
addEventHandler("onPlayerChat",getRootElement(),onPlayerTalk) 
  
function stopNormalChat(msg,type) 
    if type==0 then 
        cancelEvent() 
    end 
end 
addEventHandler("onPlayerChat",getRootElement(),stopNormalChat) 

The problem is that color (in outputChatBox) seems to be nil for some reason, also the pointless "if class==..." was because I found no other solution... Let's hope this'll work soon!

EDIT3: Lol, forgot the rest of the files:

config.xml:

<config> 
    <user name="Gamesnert" class="admin"/> 
  
    <colors admin="#FF0000" moderator="#00FF00" member="#0000FF"/> 
</config> 

Aslong as you have a meta.xml leading to the script file, and you fix a few things... It SHOULD work... Atleast better than the other one, it was a shame to see someone making a big function which does not even have an "addEvent- or Command- Handler" ...

Link to comment

Yes I know, I didn't have time to fix that bug yet... :/ Getting on it in a few moments.

EDIT: Finally the forums work again... I got "500 - Internal Server Error" all the time...

Anyway, I fixed the script, and am even updating it FURTHER! So this is the script FOR NOW: (note that it could be the config might not be fully correct, I had to change it for the changes I'm making now...)

config.xml

<config> 
    <user name="Gamesnert" class="admin"/> 
    <user name="Anyone" class="moderator"/> 
  
    <colors admin="#FF0000" moderator="#0000FF" member="#FFFFFF"/> 
</config> 

Script:

-- ************* IMPROVED RELEASE V1.0 *************** 
-- ************* MADE BY GAMESNERT *************** 
-- ************* SCRIPTNAME : *************** 
-- ************* NAMECOLOR (working version) *************** 
-- ************* A MUST HAVE FOR CLANS!! *************** 
-- ************* ORIGINAL BY: FATALITRY *************** 
  
accountdat={} 
  
function init() 
    local xmlFile=xmlLoadFile("config.xml") 
    if xmlFile then 
        local configNode=true 
        i=0 
        while configNode~=false do 
            configNode=xmlFindSubNode(xmlFile,"user",i) 
            if configNode then 
                local xmlReadName=xmlNodeGetAttribute(configNode,"name") 
                local xmlReadClass=xmlNodeGetAttribute(configNode,"class") 
                accountdat[xmlReadName]={name=xmlReadName, class=xmlReadClass} 
                accountdat[i+1]=accountdat[xmlReadName] 
            else 
                if i<1 then 
                    outputDebugString(getResourceName(getThisResource()) .. ": No users were found in the config file! The script won't have any effect!") 
                end 
            end 
            i=i+1 
        end 
        configNode=false 
        configNode=xmlFindSubNode(xmlFile,"colors",0) 
        if configNode then 
            local readAdmin=xmlNodeGetAttribute(configNode,"admin") 
            local readModerator=xmlNodeGetAttribute(configNode,"moderator") 
            local readMember=xmlNodeGetAttribute(configNode,"member") 
            accountdat["colors"]={["admin"]=readAdmin,["moderator"]=readModerator,["member"]=readMember} 
        else 
            outputDebugString(getResourceName(getThisResource()) .. ": No color setting could be found! The script won't have any effect!") 
        end 
    end 
end 
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),init) 
  
function onPlayerTalk(msg,msgType) 
    if msgType==0 then 
        if accountdat[getClientName(source)] then 
            class=accountdat[getClientName(source)].class 
        else 
            class="member" 
        end 
        local color=accountdat["colors"][tostring(class)] 
        outputChatBox(color .. "[" .. class .. "] " .. getClientName(source) .. ": " .. "#FFFFFF" .. msg,getRootElement(),0,0,0,true) 
        cancelEvent() 
    end 
end 
addEventHandler("onPlayerChat",getRootElement(),onPlayerTalk) 

Extra feature in next version: Your own classes by editing config.xml! Will be done soon, only still have a few bugs :/

Link to comment

Wow! it's getting better.

First: I send 2 messages each time i write a text.

Second: I can't put the tag like [Admin] or [MoD], just [admin] and [mod]

Third: If a normal player enter on the server and put my name on, he will have the red name...

how can i change this things?

(You should put this version on MTABeta, its alot better!)

Link to comment

Send two messages? That's pretty weird... 1 with color and 1 without? If the case I just said, make sure cancelEvent() is present in the code like in my example.

The update was all about making your OWN classes, and it is coming along nicely, except for some bugs that'll suck up some of my time, and I love that. :D So moderator, admin and member are just classes. My script doesn't support tags... (yet) But when you can make your own classes, you can rename moderator to mod for example. The same way you edit colors of the classes right now!

I'll devellop this further, and yes... Security has ALWAYS been an issue of mine... Luckily, there are account-functions! Now let's hope I can finish it today or tomorrow, because from saterday till 2 weeks later... I'm outdoors... If I can't make it, please someone else fix it. But let's hope I can finish it myself intime!

And I'll post it on that site when it's done. Only when people can actually use it, you should give it. ;)

Also: Keep in mind that I'll make the script as editable as possible from the config! Make sure you make as little changes to the script as possible! Very sensitive code to errors... :/

EDIT: Alllrighty then! V1.01 is done except for the security fix! (which probably won't even take 20 minutes) Since it's pointless to release an update now and over 20 minutes, I only give this update now. (in the case anyone needs to know when it's done) But the next look at this post, it'll probably contain the totally changed piece of code.

Link to comment
Send two messages? That's pretty weird... 1 with color and 1 without? If the case I just said, make sure cancelEvent() is present in the code like in my example.

Yes, it's 1 with color and other without. i let my script this way:

-- ************* IMPROVED RELEASE V1.0 *************** 
-- ************* MADE BY GAMESNERT *************** 
-- ************* SCRIPTNAME : *************** 
-- ************* NAMECOLOR (working version) *************** 
-- ************* A MUST HAVE FOR CLANS!! *************** 
-- ************* ORIGINAL BY: FATALITRY *************** 
  
accountdat={} 
  
function init() 
    local xmlFile=xmlLoadFile("config.xml") 
    if xmlFile then 
        local configNode=true 
        i=0 
        while configNode~=false do 
            configNode=xmlFindSubNode(xmlFile,"user",i) 
            if configNode then 
                local xmlReadName=xmlNodeGetAttribute(configNode,"name") 
                local xmlReadClass=xmlNodeGetAttribute(configNode,"class") 
                accountdat[xmlReadName]={name=xmlReadName, class=xmlReadClass} 
                accountdat[i+1]=accountdat[xmlReadName] 
            else 
                if i<1 then 
                    outputDebugString(getResourceName(getThisResource()) .. ": No users were found in the config file! The script won't have any effect!") 
                end 
            end 
            i=i+1 
        end 
        configNode=false 
        configNode=xmlFindSubNode(xmlFile,"colors",0) 
        if configNode then 
            local readAdmin=xmlNodeGetAttribute(configNode,"admin") 
            local readModerator=xmlNodeGetAttribute(configNode,"moderator") 
            local readMember=xmlNodeGetAttribute(configNode,"member") 
            accountdat["colors"]={["admin"]=readAdmin,["moderator"]=readModerator,["member"]=readMember} 
        else 
            outputDebugString(getResourceName(getThisResource()) .. ": No color setting could be found! The script won't have any effect!") 
        end 
    end 
end 
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),init) 
  
function onPlayerTalk(msg,msgType) 
    if msgType==0 then 
        if accountdat[getClientName(source)] then 
            class=accountdat[getClientName(source)].class 
        else 
            class="member" 
        end 
        local color=accountdat["colors"][tostring(class)] 
        outputChatBox(color .. "[" .. class .. "] " .. getClientName(source) .. ": " .. "#FFFFFF" .. msg,getRootElement(),0,0,0,true) 
        cancelEvent() 
    end 
end 
addEventHandler("onPlayerChat",getRootElement(),onPlayerTalk) 
  
function stopNormalChat(msg,type) 
    if type==0 then 
        cancelEvent() 
    end 
end 
addEventHandler("onPlayerChat",getRootElement(),stopNormalChat) 

i have Added this on the end:

function stopNormalChat(msg,type) 
    if type==0 then 
        cancelEvent() 
    end 
end 
addEventHandler("onPlayerChat",getRootElement(),stopNormalChat) 

But i'm still sending 2 messages.

Link to comment

Hmmm... Ok, try the new script: (the security doesn't work yet, so the -- make it comments. Since they don't mean anything ATM anyway :/)

config.xml:

<config> 
    <!-- The configuration file, which holds all the info about players, classes and colors. --> 
    <!-- To add a class, add it in <class .. /> with the classname between the "".           --> 
    <!-- After that, you might want to add a color too. (or edit an existing one)            --> 
    <!-- For those tasks, you can just edit and add user etc. like in this example.          --> 
    <!-- If you have any problems with this code, contact Gamesnert on the forums.           --> 
    <!-- Note! Anyone not specified will become "member", and this class is auto generated.  --> 
  
    <classes class1="admin" class2="supermod" class3="mod"/> 
  
    <user name="Gamesnert" class="admin"/> 
    <user name="Anyone" class="supermod"/> 
    <user name="Someone" class="mod"/> 
  
    <colors admin="#FF0000" supermod="#00FF00" mod="#0000FF" member="#FFFFFF"/> 
</config> 

(Note: The names (except the first) were for debug reasons. I don't know anyone calling himself: "anyone" xD Also note that if you delete the member color, it will output the normal message! (not for the other ones though :/))

Script:

-- ************* IMPROVED RELEASE V1.01 *************** 
-- ************* MADE BY GAMESNERT *************** 
-- ************* SCRIPTNAME : *************** 
-- ************* NAMECOLOR (working version) *************** 
-- ************* A MUST HAVE FOR CLANS!! *************** 
-- ************* ORIGINAL BY: FATALITRY *************** 
  
accountdat={["classes"]={}, ["colors"]={}} 
  
function init() 
    local xmlFile=xmlLoadFile("config.xml") 
    if xmlFile then 
        local configNode=false 
        configNode=xmlFindSubNode(xmlFile,"classes",0) 
        if configNode then 
            class=true 
            i=1 
            while class~=false do 
                class=xmlNodeGetAttribute(configNode,"class"..i) 
                if class~=false and class~=nil then 
                    accountdat["classes"][i]=class 
                else 
                    class=false 
                    outputDebugString("No more classes found! " .. i .. " classes were created in total.") 
                end 
                i=i+1 
            end 
        end 
        local configNode=true 
        i=0 
        while configNode~=false do 
            configNode=xmlFindSubNode(xmlFile,"user",i) 
            if configNode then 
                local xmlReadName=xmlNodeGetAttribute(configNode,"name") 
                local xmlReadClass=xmlNodeGetAttribute(configNode,"class") 
                accountdat[xmlReadName]={name=xmlReadName, class=xmlReadClass} 
                accountdat[i+1]=accountdat[xmlReadName] 
            else 
                if i<1 then 
                    outputDebugString(getResourceName(getThisResource()) .. ": No users were found in the config file! The script won't have any effect!") 
                end 
                configNode=false 
            end 
            i=i+1 
        end 
        configNode=false 
        configNode=xmlFindSubNode(xmlFile,"colors",0) 
        if configNode then 
            class=true 
            i=1 
            while class~=false do 
                if accountdat["classes"][i] then 
                    class=accountdat["classes"][i] 
                    local color=xmlNodeGetAttribute(configNode,class) 
                    accountdat["colors"][class]=color 
                else 
                    if i<2 then 
                        outputDebugString(getResourceName(getThisResource()) .. ": Could not find any classes!") 
                    else 
                        if xmlNodeGetAttribute(configNode,"member") then 
                            accountdat["colors"]["member"]=xmlNodeGetAttribute(configNode,"member") 
                        end 
                    end 
                    class=false 
                end 
                i=i+1 
            end 
        else 
            outputDebugString(getResourceName(getThisResource()) .. ": No color setting could be found! The script won't have any effect!") 
        end 
        xmlUnloadFile(xmlFile) 
    else 
        outputDebugString(getResourceName(getThisResource()) .. ': No file named "config.xml" found!') 
    end 
end 
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),init) 
  
function onPlayerTalk(msg,msgType) 
--  if getClientAccount(source) and accountdat[getClientName(source)] then 
        if msgType==0 then 
            if accountdat[getClientName(source)] then 
                class=accountdat[getClientName(source)].class 
            else 
                class="member" 
            end 
            color=accountdat["colors"][class] 
            if color then 
                outputChatBox(color .. "[" .. class .. "] " .. getClientName(source) .. ": " .. "#FFFFFF" .. msg,getRootElement(),0,0,0,true) 
                cancelEvent() 
            else 
                if class~="member" then 
                    outputDebugString(getResourceName(getThisResource()) .. ": Could not output chat from .. " .. getClientName(source) .. "!") 
                end 
            end 
        end 
--  else 
--      outputChatBox("Your nick is equal to the name of a protected account. Please log in to chat.",source,255,0,0) 
--  end 
end 
addEventHandler("onPlayerChat",getRootElement(),onPlayerTalk) 
  
function nickChangeProtection(oldNick,newNick) 
    if accountdat[newNick]~=false and accountdat[newNick]~=nil then 
        kickPlayer(source,"Console","Changing nick to a protected nick.") 
    end 
end 
--addEventHandler("onClientChangeNick",getRootElement(),nickChangeProtection) 

If you want, remove the --. Has no effect at all... Lol. :P

Anyway, alot bigger isn't it? And it might be just what you lookin' for. If you need big extra's, (except for the security...) PM me. I'll post this on MTAbeta.com tomorrow. (when I (hopefully) finished the security)

And I wish I never said it only took 20 mins. xD

Link to comment

The Script grown alot :P

But i'm still sending 2 messages, don't know why...

i tryed to add the CancelEvent but it dont work either.

If u can help me with this i'll be glad.

Anyway Thanks for your help, u are helping me alot :D

Link to comment

hey guys,

YEA IT IS MY SCRIPT

and if im honest i stole it!! :oops:

and im not rlly good in lua i only put in some things.

and for the fix i only need one thing to know (do you use freeroam) So yes you need to open freeroam and delete the lines Wich output you message onto the chatbox then you will not double talk. :wink:

If no Srry idk how to fix that. :(

If you guys dont like the script Please say that so i can delete the script

FIX FOR YOUR SCRIPT IF YOU STILL WANT THE ORIGINAL

local clanAdmin = { [1]={start=1, finish=4, name="Hexo"}} -- DONT FORGET THIS!!!: If The Last Person Has "} AT THE END THE HOEL SCRIPT WONT WORK THE FIRST PERSON HAS TO HAVE "}} AT THE END!!!!!!!!!!!!!! 
local clanVIP = { [1]={start=1, finish=4, name="TaTo"} } 
local g_Root = getRootElement() 
  
addEventHandler('onPlayerChat', g_Root, 
    function(msg, type) 
        if type == 0 then 
            cancelEvent() 
             
            local isAdmin = false 
            for i,j in ipairs(clanAdmin) do 
                if ( string.sub(getClientName(source), j.start, j.finish) == j.name ) then 
                    isAdmin = true 
                end 
            end 
             
            local isVIP = falset 
            for i,j in ipairs(clanVIP) do 
                if ( string.sub(getClientName(source), j.start, j.finish) == j.name ) then 
                    isVIP = true 
                end 
            end 
             
            if ( isAdmin ) then 
                outputChatBox("#FF0000[Admin] " .. getClientName(source) .. ': ' .. "#FFFFFF" .. msg:gsub('#%x%x%x%x%x%x', ''), g_Root, 0, 0, 0, true) 
            elseif( isVIP ) then 
                outputChatBox("#00FF00[VIP] " .. getClientName(source) .. ': ' .. "#FFFFFF" .. msg:gsub('#%x%x%x%x%x%x', ''), g_Root, 0, 0, 0, true) 
            else 
    --If you disable the outputChatBox in the freeroam script you can choose a color for guests too by enabling this line. 
                outputChatBox("#FFFF00" .. getClientName(source) .. ': ' .. "#FFFFFF" .. msg:gsub('#%x%x%x%x%x%x', ''), g_Root, 0, 0, 0, true)   
            end 
        end 
    end 
) 

I Fixed It So i Hope it will work For you now

Regardings,

Fatalitry

Edited by Guest
Link to comment

I'm still looking to the security problems...

It might be that you have 2 events with "onPlayerChat" that output it to the chatbox. You might have to edit that. Because I don't have those problems with exactly the same script. :/

And Dylan, seriously stealing scripts is totally NOT a good idea... As you can see it didn't even work at first, you missed about 4 things to close some started things... And the rest still was buggy... Also, if you're not good in Lua, NEVER start difficult! The piece of code you "made" was quite sophisticated, and when you're a starter you must try the easy scripts first. Learn doing it without even using any of the tutorials. Then you know when you're ready to make it a bit more difficult.

And well, Dylan. If you want your own custom class, you'll have to edit the main lua file, which is not user-friendly and may be too difficult for starters. So to be honest, if I would have to choose, I would have gone with mine... You can edit it all in 1 file, detailed explanation, a few examples in it, and almost fully customizable without learning Lua. So I kind of doubt anyone will really need your script now... Idk, but this is what I expect and my opinion.

And does freeroam even do that? If so you only need to remove the ones in "onPlayerChat". Otherwise you won't get ANY system messages at all... (atleast, not the chatbox ones :/)

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