Jump to content

getElementData issue


Lukkaz

Recommended Posts

  
function createPeds(client) 
local i = 1; -- character limit 
local accountID = getElementData(client, "gameaccountid") 
resultz = mysql:query("SELECT id, charactername, cked, lastarea, age, gender, faction_id, faction_rank, skin, DATEDIFF(NOW(), lastlogin) as llastlogin FROM characters WHERE account='" .. accountID .. "'") 
if resultz then 
addEventHandler("onPlayerClick",getRootElement(),pedSelInfo)     
playerid = getElementData(client, "playerid") 
    if ( mysql:num_rows(resultz) >= 1 ) then 
    local x = 2350 
        repeat 
            i=i+1 -- this is for counting. 
            x = x+3 
            dbSel = mysql:fetch_assoc(resultz) 
            peds = createPed(dbSel['skin'], x, 532.7783203125, 1.796875) 
            setElementDimension(peds, 65000+playerid) 
            setElementRotation(peds, 0,0,180) 
             
            setElementData(peds, "skin",dbSel['skin'], true) 
            setElementData(peds, "charactername", dbSel['charactername'], true) 
            setElementData(peds, "cked", dbSel['cked'], true) 
            setElementData(peds, "lastarea", dbSel['lastarea'], true) 
            setElementData(peds, "age", dbSel['age'], true) 
            setElementData(peds, "faction_id", dbSel['faction_id'], true) 
            setElementData(peds, "faction_rank", dbSel['faction_rank'], true) 
            setElementData(peds, "lastlogin", dbSel['lastlogin'], true) 
  
  
            outputDebugString(dbSel['skin']) 
            outputDebugString("Looper2 called!") 
         
        until i == 5 
    else  
         
         
    end 
  
end 
end 
  
  

I think the issue is when it loops it overwrites the previous loops data input. How can I set a unique key for each with every loop the function makes?

example; first look it saves setElementData(peds, "skin",dbSel['skin'], true)

the next loop would save under setElementData(peds, "skin2",dbSel['skin'], true)

or something along those lines. If anyone oculd help me I would deeply appreciate it!

Link to comment

Is this is what you want?

function createPeds(client) 
local accountID = getElementData(client, "gameaccountid") 
resultz = mysql:query("SELECT id, charactername, cked, lastarea, age, gender, faction_id, faction_rank, skin, DATEDIFF(NOW(), lastlogin) as llastlogin FROM characters WHERE account='" .. accountID .. "'") 
if resultz then 
addEventHandler("onPlayerClick",getRootElement(),pedSelInfo)    
playerid = getElementData(client, "playerid") 
    if ( mysql:num_rows(resultz) >= 1 ) then 
    local x = 2350 
        for i=0, 5 do 
            x = x+3 
            dbSel = mysql:fetch_assoc(resultz) 
            peds = createPed(dbSel['skin'], x, 532.7783203125, 1.796875) 
            setElementDimension(peds, 65000+playerid) 
            setElementRotation(peds, 0,0,180) 
            
            setElementData(peds, "skin"..i,dbSel['skin'], true) 
            setElementData(peds, "charactername", dbSel['charactername'], true) 
            setElementData(peds, "cked", dbSel['cked'], true) 
            setElementData(peds, "lastarea", dbSel['lastarea'], true) 
            setElementData(peds, "age", dbSel['age'], true) 
            setElementData(peds, "faction_id", dbSel['faction_id'], true) 
            setElementData(peds, "faction_rank", dbSel['faction_rank'], true) 
            setElementData(peds, "lastlogin", dbSel['lastlogin'], true) 
  
  
            outputDebugString(dbSel['skin']) 
            outputDebugString("Looper2 called!") 
       end     
    end 
  
  end 
end 

Link to comment

Okay sorry I will try to explain it more clearly,

So I am creating a character selection system where you click on the ped that represents the pedestrian you want to play as. (Sort of like valhalla's idea basically). Now when I use the script I created I get this....

331kigl.png

See they all share the same name. That is a problem. In the mySQL database they have all different names and ages. However their skin ID's are correct. The name and age are only correct for the female on the right.

Then what I was saying in later posts is if I only have the function loop once it gives the police officer with the correct name and age.

I hope this helps your understanding of my dilemma.

Link to comment

Sure,

  
  
function selectPedWindow(element, abX, abY, charName, charSkin, charCKed, charArea, charAge, charFaction, charRank, charLogin) 
  
            local x = abX - 75 
            local y = abY/4.5 
            local pedWin = guiCreateWindow(x, y,159,228,"",false) 
            guiSetAlpha(pedWin,.70) 
            guiWindowSetMovable(pedWin,false) 
            guiWindowSetSizable(pedWin,false) 
            guiSetVisible (pedWin, false) 
            --skinPicture = guiCreateStaticImage(0.2956,0.114,0.4025,0.1711,"",true,pedWin) 
            pedName = guiCreateLabel(0.1258,0.3158,0.6792,0.0614,"Name: "..tostring(charName).."",true,pedWin) 
            pedAge = guiCreateLabel(0.1258,0.3904,0.6792,0.0702,"Age: "..tostring(charAge).."",true,pedWin) 
            pedFaction = guiCreateLabel(0.1258,0.4561,0.6792,0.0614,"Faction:",true,pedWin) 
            pedFactionRank = guiCreateLabel(0.1258,0.5219,0.6792,0.0614,"Faction Rank:",true,pedWin) 
            pedLastLogin = guiCreateLabel(0.1258,0.6623,0.6792,0.0658,"Last Login:",true,pedWin) 
            pedArea = guiCreateLabel(0.1258,0.5921,0.6792,0.0614,"Last Area:",true,pedWin) 
            pedPlayB = guiCreateButton(0.2075,0.8158,0.5975,0.1404,"Play!",true,pedWin) 
  
            if guiGetVisible ( pedWin ) then 
            destroyElement(pedWin) 
            outputDebugString("window destroyed") 
            else 
            guiSetVisible(pedWin, true) 
            outputDebugString("window creating") 
            end 
end 
addEvent("selectPedWin", true) 
addEventHandler("selectPedWin", getRootElement(), selectPedWindow) 
  
  

Link to comment
local windowsData = {} 
windowsData["pedName"] = {} 
windowsData["pedAge"] = {} 
windowsData["pedFaction"] = {} 
windowsData["pedFactionRank"] = {} 
windowsData["pedLastLogin"] = {} 
windowsData["pedArea"] = {} 
windowsData["pedPlayB"] = {} 
  
function selectPedWindow(element, abX, abY, charName, charSkin, charCKed, charArea, charAge, charFaction, charRank, charLogin) 
            local x = abX - 75 
            local y = abY/4.5 
            local pedWin = guiCreateWindow(x, y,159,228,"",false) 
            guiSetAlpha(pedWin,.70) 
            guiWindowSetMovable(pedWin,false) 
            guiWindowSetSizable(pedWin,false) 
            guiSetVisible (pedWin, false) 
            --skinPicture = guiCreateStaticImage(0.2956,0.114,0.4025,0.1711,"",true,pedWin) 
            windowsData["pedName"][charName] = guiCreateLabel(0.1258,0.3158,0.6792,0.0614,"Name: "..tostring(charName).."",true,pedWin) 
            windowsData["pedAge"][charName] = guiCreateLabel(0.1258,0.3904,0.6792,0.0702,"Age: "..tostring(charAge).."",true,pedWin) 
            windowsData["pedFaction"][charName] = guiCreateLabel(0.1258,0.4561,0.6792,0.0614,"Faction:",true,pedWin) 
            windowsData["pedFactionRank"][charName] = guiCreateLabel(0.1258,0.5219,0.6792,0.0614,"Faction Rank:",true,pedWin) 
            windowsData["pedLastLogin"][charName] = guiCreateLabel(0.1258,0.6623,0.6792,0.0658,"Last Login:",true,pedWin) 
            windowsData["pedArea"][charName] = guiCreateLabel(0.1258,0.5921,0.6792,0.0614,"Last Area:",true,pedWin) 
            windowsData["pedPlayB"][charName] = guiCreateButton(0.2075,0.8158,0.5975,0.1404,"Play!",true,pedWin) 
  
            if guiGetVisible ( pedWin ) then 
            destroyElement(pedWin) 
            outputDebugString("window destroyed") 
            else 
            guiSetVisible(pedWin, true) 
            outputDebugString("window creating") 
            end 
end 
addEvent("selectPedWin", true) 
addEventHandler("selectPedWin", getRootElement(), selectPedWindow) 

Try that (not tested).

Link to comment

This is from the wiki:

mysqlQuery ( db, "onMySQLResult", "SELECT * FROM test" ) 
  
function onMySQLResult ( table ) 
    outputServerLog ( "Printing some test results" ) 
    outputServerLog ( table[1][1] ) 
    outputServerLog ( table[1][2] ) 
end 

Your dbSel['skin'] is wrong it should be dbSel[1][9] or but not sure about this one dbSel[1]['skin']

Link to comment

Solid, didn't work. JR it is not a mysql issue or else the peds wouldn't be set to the correct skin IDs. Here is my current code.

  
pedTable = {} 
  
  
  
function createPeds(client) 
local i = 1; -- character limit 
local accountID = getElementData(client, "gameaccountid") 
local playerid = getElementData(client, "playerid") 
results = mysql:query("SELECT id, charactername, cked, lastarea, age, gender, faction_id, faction_rank, skin, DATEDIFF(NOW(), lastlogin) as llastlogin FROM characters WHERE account='" .. accountID .. "'") 
if results then 
    if ( mysql:num_rows(results) >= 1 ) then 
       local x = 2350 
       local w = 0 
       for i=0, 4 do 
            x = x+3 
            w = w+1 
             
             dbSel = mysql:fetch_assoc(results) 
            table.insert(pedTable, w, createPed(dbSel['skin'], x, 532.7783203125, 1.796875)) 
             peds = pedTable[w] 
              
             setElementDimension(peds, 65000+playerid) 
             setElementRotation(peds, 0,0,180) 
             setElementData(peds, "skin"..i,dbSel['skin'], true) 
             setElementData(peds, "charactername", dbSel['charactername'], true) 
             setElementData(peds, "cked", dbSel['cked'], true) 
             setElementData(peds, "lastarea", dbSel['lastarea'], true) 
             setElementData(peds, "age", dbSel['age'], true) 
             setElementData(peds, "faction_id", dbSel['faction_id'], true) 
             setElementData(peds, "faction_rank", dbSel['faction_rank'], true) 
             setElementData(peds, "lastlogin", dbSel['lastlogin'], true) 
             
            addEventHandler("onPlayerClick",getRootElement(), 
            function (button,state, element, posX, posY, posZ, abX, abY) 
                if( state ~= "down" ) then 
                    if (getElementType(element) == "ped") then 
                    charName = getElementData(peds, "charactername", true) 
                    charSkin = getElementData(peds, "skin", true) 
                    charCKed = getElementData(peds, "cked", true) 
                    charArea = getElementData(peds, "lastarea", true) 
                    charAge = getElementData(peds, "age", true) 
                    charFaction = getElementData(peds, "faction_id", true) 
                    charRank = getElementData(peds, "faction_rank", true) 
                    charLogin = getElementData(peds, "lastlogin", true) 
                    outputDebugString("its a ped") 
                    triggerClientEvent("selectPedWin", getRootElement(), element, abX, abY, charName, charSkin, charCKed, charArea, charAge, charFaction, charRank, charLogin) 
                    else 
                    outputDebugString("its no ped") 
                    end 
                end 
            end 
            )    
         
         
    end 
  
end 
end 
end 
  
  
  
  
addEvent("createPeds", true) 
addEventHandler("createPeds", getRootElement(), createPeds) 
  

Client Side:

  
  
local windowsData = {} 
windowsData["pedName"] = {} 
windowsData["pedAge"] = {} 
windowsData["pedFaction"] = {} 
windowsData["pedFactionRank"] = {} 
windowsData["pedLastLogin"] = {} 
windowsData["pedArea"] = {} 
windowsData["pedPlayB"] = {} 
  
function selectPedWindow(element, abX, abY, charName, charSkin, charCKed, charArea, charAge, charFaction, charRank, charLogin) 
            local x = abX - 75 
            local y = abY/4.5 
            local pedWin = guiCreateWindow(x, y,159,228,"",false) 
            guiSetAlpha(pedWin,.70) 
            guiWindowSetMovable(pedWin,false) 
            guiWindowSetSizable(pedWin,false) 
            guiSetVisible (pedWin, false) 
            --skinPicture = guiCreateStaticImage(0.2956,0.114,0.4025,0.1711,"",true,pedWin) 
            windowsData["pedName"][charName] = guiCreateLabel(0.1258,0.3158,0.6792,0.0614,"Name: "..tostring(charName).."",true,pedWin) 
            windowsData["pedAge"][charName] = guiCreateLabel(0.1258,0.3904,0.6792,0.0702,"Age: "..tostring(charAge).."",true,pedWin) 
            windowsData["pedFaction"][charName] = guiCreateLabel(0.1258,0.4561,0.6792,0.0614,"Faction:",true,pedWin) 
            windowsData["pedFactionRank"][charName] = guiCreateLabel(0.1258,0.5219,0.6792,0.0614,"Faction Rank:",true,pedWin) 
            windowsData["pedLastLogin"][charName] = guiCreateLabel(0.1258,0.6623,0.6792,0.0658,"Last Login:",true,pedWin) 
            windowsData["pedArea"][charName] = guiCreateLabel(0.1258,0.5921,0.6792,0.0614,"Last Area:",true,pedWin) 
            windowsData["pedPlayB"][charName] = guiCreateButton(0.2075,0.8158,0.5975,0.1404,"Play!",true,pedWin) 
  
            if guiGetVisible ( pedWin ) then 
            destroyElement(pedWin) 
            outputDebugString("window destroyed") 
            else 
            guiSetVisible(pedWin, true) 
            outputDebugString("window creating") 
            end 
end 
addEvent("selectPedWin", true) 
addEventHandler("selectPedWin", getRootElement(), selectPedWindow) 
  

The same issue is happening as in the ScreenShot I posted. I just don't understand :roll:

Does anyone have any idea how valhalla did it so I could possibly look at it as sort of a cheat sheet to try to complete this script.

Link to comment

Fixed it!

local windowsData = {} 
windowsData["pedWindow"] = {} 
windowsData["pedName"] = {} 
windowsData["pedAge"] = {} 
windowsData["pedFaction"] = {} 
windowsData["pedFactionRank"] = {} 
windowsData["pedLastLogin"] = {} 
windowsData["pedArea"] = {} 
windowsData["pedPlayB"] = {} 
  
function selectPedWindow(element, abX, abY, charName, charSkin, charCKed, charArea, charAge, charFaction, charRank, charLogin) 
            local x = abX - 75 
            local y = abY/4.5 
            windowsData["pedWindow"][charName] = guiCreateWindow(x, y,159,228,"",false) 
            guiSetAlpha(windowsData["pedWindow"][charName],.70) 
            guiWindowSetMovable(windowsData["pedWindow"][charName],false) 
            guiWindowSetSizable(windowsData["pedWindow"][charName],false) 
            guiSetVisible (windowsData["pedWindow"][charName], false) 
            --skinPicture = guiCreateStaticImage(0.2956,0.114,0.4025,0.1711,"",true,pedWin) 
            windowsData["pedName"][charName] = guiCreateLabel(0.1258,0.3158,0.6792,0.0614,"Name: "..tostring(charName).."",true,windowsData["pedWindow"][charName]) 
            windowsData["pedAge"][charName] = guiCreateLabel(0.1258,0.3904,0.6792,0.0702,"Age: "..tostring(charAge).."",true,windowsData["pedWindow"][charName]) 
            windowsData["pedFaction"][charName] = guiCreateLabel(0.1258,0.4561,0.6792,0.0614,"Faction:",true,windowsData["pedWindow"][charName]) 
            windowsData["pedFactionRank"][charName] = guiCreateLabel(0.1258,0.5219,0.6792,0.0614,"Faction Rank:",true,windowsData["pedWindow"][charName]) 
            windowsData["pedLastLogin"][charName] = guiCreateLabel(0.1258,0.6623,0.6792,0.0658,"Last Login:",true,windowsData["pedWindow"][charName]) 
            windowsData["pedArea"][charName] = guiCreateLabel(0.1258,0.5921,0.6792,0.0614,"Last Area: ",true,windowsData["pedWindow"][charName]) 
            windowsData["pedPlayB"][charName] = guiCreateButton(0.2075,0.8158,0.5975,0.1404,"Play!",true,windowsData["pedWindow"][charName]) 
  
            if guiGetVisible ( windowsData["pedWindow"][charName] ) then 
            destroyElement(windowsData["pedWindow"][charName]) 
            outputDebugString("window destroyed") 
            else 
            guiSetVisible(windowsData["pedWindow"][charName], true) 
            outputDebugString("window creating") 
            end 
end 
addEvent("selectPedWin", true) 
addEventHandler("selectPedWin", getRootElement(), selectPedWindow) 

I'd this to test:

addEventHandler("onClientClick",root,function (button,state,absoluteX,absoluteY,posX,posY,posZ,entity) 
if entity and getElementType(entity) == "ped" then 
selectPedWindow(entity,absoluteX,absoluteY,tostring(getElementData(entity,"name")),46,nil,nil,tostring(getElementData(entity,"age")),nil,nil,nil) 
  end 
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...