Lukkaz Posted June 26, 2011 Share Posted June 26, 2011 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
Lukkaz Posted June 26, 2011 Author Share Posted June 26, 2011 bump come one guys there must be some one here who knows. Link to comment
Lukkaz Posted June 27, 2011 Author Share Posted June 27, 2011 *note* when I edit the line until i == 5 To; until i == 2 It creates one ped with all the correct information. Any feedback is appreciated. Link to comment
Lukkaz Posted June 28, 2011 Author Share Posted June 28, 2011 Is this too advanced for this forum? Link to comment
Castillo Posted June 28, 2011 Share Posted June 28, 2011 Maybe nobody understood you? maybe they won't reply because they don't know what are you talking about. Link to comment
JR10 Posted June 28, 2011 Share Posted June 28, 2011 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
Lukkaz Posted June 29, 2011 Author Share Posted June 29, 2011 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.... 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
JR10 Posted June 29, 2011 Share Posted June 29, 2011 Ok i don't know mysql but shouldn't dbSel['skin'] be: dbSel[1]['skin'] --etc etc or dbSel[1][9] 9 is the skin in selecting That is what is explained here: https://wiki.multitheftauto.com/wiki/Mod ... MysqlQuery Link to comment
Lukkaz Posted June 29, 2011 Author Share Posted June 29, 2011 No, I'm sure that works or else the peds wouldn't have the correct skins. I think the issue is with the setElementData, like the element peds keeps getting overwritten if you know what I mean. Link to comment
Castillo Posted June 29, 2011 Share Posted June 29, 2011 Have you tried adding debug outputs? like add a output for the character name and so on (in client side). Link to comment
Lukkaz Posted June 29, 2011 Author Share Posted June 29, 2011 Yes I have and they all are correct and when it loops it will display in the debug the skin ID, the charactername, and the correct age. Link to comment
Castillo Posted June 29, 2011 Share Posted June 29, 2011 So, the problem is when you create the GUI's? if so, could you post the GUI creation part? Link to comment
Lukkaz Posted June 29, 2011 Author Share Posted June 29, 2011 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
Castillo Posted June 29, 2011 Share Posted June 29, 2011 You only have one window here..... you are overwritting the data every time you click a ped? Link to comment
Lukkaz Posted June 29, 2011 Author Share Posted June 29, 2011 Yes how can I fix this? Link to comment
Castillo Posted June 29, 2011 Share Posted June 29, 2011 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
JR10 Posted June 29, 2011 Share Posted June 29, 2011 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
Lukkaz Posted June 30, 2011 Author Share Posted June 30, 2011 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 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
Castillo Posted June 30, 2011 Share Posted June 30, 2011 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
Lukkaz Posted June 30, 2011 Author Share Posted June 30, 2011 EPIC!!!! Thank you so much!!! 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