Jump to content

Custom Elements


CallumD

Recommended Posts

My spawn menu is coded pretty badly so the client-side is about 1,000 lines big. So I've decided to shrink it down. I thought of making custom elements server-side and using them for the menu's contents. I don't get why the code below dosn't work (only snippets of the whole code of course).

Server-side:

city1 = createElement ( "city", "Los Santos" )
city2 = createElement ( "city", "Flint County" ) -- etc, etc

Client-side:

local cities = getElementsByType ( "city" )
for city, cityName in ipairs ( cities ) do
local row = guiGridListAddRow ( cityGridList )
guiGridListSetItemText ( cityGridList, row, cityColumn, cityName, false, false )
end

On the other hand, could anybody suggest a better way of storing the grid lists items? Preferably a way that clients don't download it.

Link to comment

It's a simple solution, and you'll kick yourself for this. :P

local cities = getElementsByType ( "city" )

This is going to return an element table as you expect, but the values will not be the element ID's but the element objects:

cities = {
   1 = element:"memory pointer"
   2 = element:"another memory pointer"
   ...
}
--the actual pointer memory address doesn't matter - you're getting element objects is all you need to concern yourself with

All you need to do is fetch the "id" Element Data from that element object:

for city, cityElem in ipairs ( cities ) do
local row = guiGridListAddRow ( cityGridList )
local cityName = getElementData ( cityElem, "id" )
guiGridListSetItemText ( cityGridList, row, cityColumn, cityName, false, false )
end

Have fun. :D

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