Potato_Tomato420 Posted November 2, 2021 Share Posted November 2, 2021 I'm currently making a custom nametag script for my server but i have a problem with showing the players wanted level. It shows the wanted level.. how could i fix this? local GUI = {} local label = {} local image = {} function showCustomNametag (sResource) if sResource == getThisResource() then local players = getElementsByType ("player") for i, player in ipairs (players) do GUI.i = dgsCreate3DInterface (-2631.4, 609, 13.45, 1, 0.5, 200, 100, tocolor(255,255,255,255), 0, 1, 0) if localPlayer == player then dgsSetVisible (GUI.i, false) end dgsSetProperty (GUI.i, "maxDistance", 10) dgsSetProperty (GUI.i, "fadeDistance", 7) dgs3DInterfaceAttachToElement (GUI.i, player, 0, 0, 1) local bg = dgsCreateImage (0, 0, 1, 0.2, nil, true, GUI.i, tocolor(0,0,0,255)) label.i = dgsCreateLabel (0, 0, 200, 15, getPlayerName (player), false, GUI.i) table.insert (label, label.i) dgsSetProperty (label.i , "textColor", tocolor(255,255,255,255)) dgsSetProperty (label.i , "alignment", {"center", "top"}) dgsSetProperty (label.i , "font", textH1) if getPlayerWantedLevel (player) > 0 then image.i = dgsCreateImage (0, 20, 200, 20, "assets/images/wantedLevel/"..getPlayerWantedLevel (player)..".png", false, GUI.i) table.insert (image, image.i) end setElementData (player, "playerNametagID", i) end end end addEventHandler ("onClientResourceStart", root, showCustomNametag) function updateNick(name) local ID = getElementData (localPlayer, "playerNametagID") dgsSetText (label[ID], name) end addEvent ("SAnametag:updateNick", true) addEventHandler ("SAnametag:updateNick", localPlayer, updateNick) Link to comment
GoodNight Posted November 2, 2021 Share Posted November 2, 2021 Try change if getPlayerWantedLevel (player) > 0 then image.i = dgsCreateImage (0, 20, 200, 20, "assets/images/wantedLevel/"..getPlayerWantedLevel (player)..".png", false, GUI.i) table.insert (image, image.i) end into if (getPlayerWantedLevel (player) > 0) and (player ~= localPlayer) then image.i = dgsCreateImage (0, 20, 200, 20, "assets/images/wantedLevel/"..getPlayerWantedLevel (player)..".png", false, GUI.i) table.insert (image, image.i) end 1 Link to comment
The_GTA Posted November 2, 2021 Share Posted November 2, 2021 Hello Potato_Tomato42, 1) you seem to have trouble understanding the Lua syntax. Here are some (but not all) faulty lines I am referring to: GUI.i = dgsCreate3DInterface (-2631.4, 609, 13.45, 1, 0.5, 200, 100, tocolor(255,255,255,255), 0, 1, 0) ... label.i = dgsCreateLabel (0, 0, 200, 15, getPlayerName (player), false, GUI.i) ... image.i = dgsCreateImage (0, 20, 200, 20, "assets/images/wantedLevel/"..getPlayerWantedLevel (player)..".png", false, GUI.i) I think you want to save UI element handles for each player on your server and store them inside the table. But did you know that the expression "obj.key" is looking-up into "obj" by specifier constant string "i" and not the value of the i variable? I think you want to change the code to... GUI[i] = dgsCreate3DInterface (-2631.4, 609, 13.45, 1, 0.5, 200, 100, tocolor(255,255,255,255), 0, 1, 0) ... and all faulty lines based on the same syntax adjustment. The expression obj[key] does lookup into obj by key variable key. 2) also you are not handling the case when somebody new is joining into your server. This person does also require a nametag but you are just assigning nametags to the players that are joined at the point of resource start, ignoring the case when new players arrive. Please use the onClientPlayerJoin event to assign a new nametag. Hope this helps! 1 Link to comment
Potato_Tomato420 Posted November 2, 2021 Author Share Posted November 2, 2021 Thx all, i'm not that good at tables at the moment, still learning Also i'm aware that the resource wouldn't assign a nametag to new players, i'm still working on it. Thx for the help! 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