Jump to content

Making nick color gui


#Honda-R

Recommended Posts

  
GUIEditor = { 
    button = {}, 
    window = {}, 
    edit = {}, 
    label = {} 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        GUIEditor.window[1] = guiCreateWindow(421, 223, 195, 122, "Nick Color", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
  
        GUIEditor.label[1] = guiCreateLabel(23, 39, 183, 25, "Example: #000000 ", false, GUIEditor.window[1]) 
        guiSetFont(GUIEditor.label[1], "default-bold-small") 
        guiSetProperty(GUIEditor.label[1], "AlwaysOnTop", "True") 
        GUIEditor.edit[1] = guiCreateEdit(27, 83, 90, 24, "", false, GUIEditor.window[1]) 
        GUIEditor.button[1] = guiCreateButton(123, 84, 39, 23, "Set", false, GUIEditor.window[1]) 
        GUIEditor.label[2] = guiCreateLabel(23, 24, 183, 25, "Enter code of nick color", false, GUIEditor.window[1]) 
        guiSetFont(GUIEditor.label[2], "default-bold-small")     
    end 
) 
  

Help me to make it , i will share it to mta community :)

I will try to explain everything

lets start

        GUIEditor.edit[1] = guiCreateEdit(27, 83, 90, 24, "", false, GUIEditor.window[1]) 

a place where player should write HTML Color code like : #000000

Then on player click button set

        GUIEditor.button[1] = guiCreateButton(123, 84, 39, 23, "Set", false, GUIEditor.window[1]) 

somehow get code

  from GUIEditor.edit[1] .

And

get player nick

set player nick [html COLOR] And his name.

Example how it works

Player are named "Scripter" then he writes in to edit place #000000 and press set. Then his nicks changes to #000000Scripter

Link to comment

As Pain mentioned, you'll have to use guiGetText to fetch the text from the EditField, for example;

fetchHexColour = guiGetText(GUIEditor.edit[1]) 

Now the colour code has been fetched by guiGetText and stored in a variable, "fetchHexColour". Now you'd have to trigger a server-event and pass this variable along with it. First you'll have to create the actual event, and then have it triggered by a client. For example;

server.lua:

function onClientSetColour_Server_Handler(fetchHexColour) 
    if(fetchHexColour ~= nil) then 
        playerNameTag = getPlayerNametagText(source) --Source is the client that triggered the event. 
        hR, hG, hB = getColorFromString(fetchHexColour) -- Have to convert Hex to RGBA to set the colour. hexRed etc... 
        SetPlayerNametagColor(source, hR, hG, hB) 
    else 
        outputChatBox("Error: Nothing was entered!", client, 255, 0, 0) 
    end 
end 
addEvent("onClientSetColour", true) 
addEventHandler("onClientSetColour", getRootElement(), onClientSetColour_Server_Handler) 

Then have the above event triggered by the client;

client.lua:

triggerServerEvent("onClientSetColour", getLocalPlayer(), fetchHexColour) 

I'd also suggest you rename the GUI variables to make life easier. :)

The code above might not work, it was written out of memory of things I've used before... Hopefully it will ;P

Link to comment

I'l try to make :x

local editBOX = GUIEditor.edit[1] = guiCreateEdit(27, 83, 90, 24, "", false, GUIEditor.window[1])

setPlayerName ( sPlayerElement, taggedName )

local Name = getPlayerName(getLocalPlayer())

setPlayerName ( editBOX, taggedName )

Damn! i tottaly messed up!

Link to comment

setPlayerName is a server side only function, You can't use it with guiCreateEdit ( wihch is client side function ) .

I think you should read more about MTA scripting in the wiki first, Then continue working on your script / resource .

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