The Killer Posted November 12, 2013 Share Posted November 12, 2013 hello everyone i have a little problem that when i do the trigger in this code: guiGridListSetItemText (mgrid, row, money, triggerServerEvent("money", getLocalPlayer(), player), false, false ) it is not happend server : addEvent("money", true) addEventHandler("money", root, function (player) getPlayerMoney(player) end ) Edit: and this code too function PlayerList ( ) if ( Players ) then for id, player in ipairs ( getElementsByType ( "player" ) ) do local row = guiGridListAddRow ( gridd ) guiGridListSetItemText ( gridd, row, Players, getPlayerName ( player ), false, false ) guiGridListSetItemColor ( gridd, row, Players, 255, 255, 30 ) end end end addEventHandler ( "onClientResourceStart", resourceRoot, PlayerList ) addEventHandler("onClientGUIClick", root, function () if (source == row) then local row2 = guiGridListAddRow ( mgrid ) local select2 = guiGridListGetItemText(mgrid, row2, money) if selectt and selectt ~= "" then local player = getPlayerFromName(select2) if player then guiGridListSetItemText (mgrid, row2, money, getPlayerMoney(player), false, false ) end end end end ) i want when someone select the row one in 'gridd' then the other grid 'mgrid' show his money Link to comment
tosfera Posted November 12, 2013 Share Posted November 12, 2013 You should store your variable first and then trigger it. It's a nicer way and easier to see what's wrong; local money = getPlayerMoney ( getLocalPlayer() ) -- can be triggered client sided, just don't change it! guiGridListSetItemText (mgrid, row, money, money, false, false ); Also, the second error is because you created a local row. Which can't be seen out of his own function, remove the local and it will work. You might want to add the 'local row = nil;' on top of your document. Link to comment
The Killer Posted November 12, 2013 Author Share Posted November 12, 2013 thank you but i should fix the 2nd code first to test the first code Link to comment
The Killer Posted November 12, 2013 Author Share Posted November 12, 2013 little help in this code: function PlayerList ( ) if ( Players ) then for id, player in ipairs ( getElementsByType ( "player" ) ) do local row = guiGridListAddRow ( gridd ) guiGridListSetItemText ( gridd, row, Players, getPlayerName ( player ), false, false ) guiGridListSetItemColor ( gridd, row, Players, 255, 255, 30 ) end end end addEventHandler ( "onClientResourceStart", resourceRoot, PlayerList ) addEventHandler("onClientGUIClick", root, function () if (source == row) then local row2 = guiGridListAddRow ( mgrid ) local select2 = guiGridListGetItemText(mgrid, row2, money) if selectt and selectt ~= "" then local player = getPlayerFromName(select2) if player then guiGridListSetItemText (mgrid, row2, money, getPlayerMoney(player), false, false ) end end end end ) i want when someone select the row one in 'gridd' then the other grid 'mgrid' show his money Link to comment
Castillo Posted November 12, 2013 Share Posted November 12, 2013 getPlayerMoney client side only returns the money of the local player. Link to comment
The Killer Posted November 12, 2013 Author Share Posted November 12, 2013 Hmm... do you mean like this ? function PlayerList ( ) if ( Players ) then for id, player in ipairs ( getElementsByType ( "player" ) ) do local row = guiGridListAddRow ( gridd ) guiGridListSetItemText ( gridd, row, Players, getPlayerName ( player ), false, false ) guiGridListSetItemColor ( gridd, row, Players, 255, 255, 30 ) end end end addEventHandler ( "onClientResourceStart", resourceRoot, PlayerList ) addEventHandler("onClientGUIClick", root, function () if (source == row) then local row2 = guiGridListAddRow ( mgrid ) local select2 = guiGridListGetItemText(mgrid, row2, money) if selectt and selectt ~= "" then local player = getPlayerFromName(select2) if player then local playerMoney = getPlayerMoney(player) guiGridListSetItemText (mgrid, row2, money, playerMoney, false, false ) end end end end ) Link to comment
Gallardo9944 Posted November 12, 2013 Share Posted November 12, 2013 what has changed? --CLIENTSIDE local playerMoney = getPlayerMoney(player) -- WON'T WORK. It will return the money of your player, so everyone in the gridlist will have your amount of money shown local playerMoney = getPlayerMoney() -- THIS IS THE SAME AS THE PREVIOUS ONE. No differences, at all. Basically, you have to write your money serverside into the element data of each user. Add a function to "refreshCash" and write element data of a user with a value of his money amount. And use element data clientside, it will work. Or you can trigger client from server with user data and then build the gridlist rows and stuff. Link to comment
The Killer Posted November 12, 2013 Author Share Posted November 12, 2013 function createPlayerList( ) if ( Players ) then for id, player in ipairs ( getElementsByType ( "player" ) ) do row3 = guiGridListAddRow ( gridd ) guiGridListSetItemText ( gridd, row3, Players, getPlayerName ( player ), false, false ) guiGridListSetItemColor ( gridd, row3, Players, 255, 255, 30 ) end end end addEventHandler ( "onClientResourceStart", resourceRoot, createPlayerList) addEventHandler("onClientGUIClick", root, function () if (source == row3) then row2 = guiGridListAddRow ( mgrid ) selectt = guiGridListGetItemText(gridd, row3, Players) if selectt and selectt ~= "" then player = getPlayerFromName(selectt) if player then playerMoney = triggerServerEvent("money", getLocalPlayer(), player) guiGridListSetItemText (mgrid, row2, money, playerMoney, false, false ) end end end end ) it doesn't show the money when i select a player it should show his money in the other grid so i try it by using 'triggerServerEvent' same problem. if you want the server side: addEvent("money", true) addEventHandler("money", root, function (player) getPlayerMoney(player) end ) Link to comment
Gallardo9944 Posted November 12, 2013 Share Posted November 12, 2013 (edited) the logic should go like this: 1. --SERVERSIDE setElementData(player,"money",getPlayerMoney(player)) -- Each time player money changes. Yes, each time you write your player money. 2. --CLIENTSIDE playerMoney = getElementData(player,"money") -- This is what we read. So it equals to your player's money if you set that correctly. guiGridListSetItemText (mgrid, row2, money, playerMoney, false, false ) -- Add the value to the grid Edited November 12, 2013 by Guest Link to comment
Castillo Posted November 12, 2013 Share Posted November 12, 2013 Instead of using element data, he can trigger a server side event to get the money, then trigger it back to set it on the grid list. Link to comment
Gallardo9944 Posted November 12, 2013 Share Posted November 12, 2013 Yes, I already mentioned that as an option. Element data is usually easier to understand and it's fully mta-wide so it can be used in further developments without any additional triggers or anything. Link to comment
The Killer Posted November 13, 2013 Author Share Posted November 13, 2013 so i did what you say but nothing happend, the code: function createPlayerList( ) if ( Players ) then for id, player in ipairs ( getElementsByType ( "player" ) ) do row3 = guiGridListAddRow ( gridd ) guiGridListSetItemText ( gridd, row3, Players, getPlayerName ( player ), false, false ) guiGridListSetItemColor ( gridd, row3, Players, 255, 255, 30 ) end end end addEventHandler ( "onClientResourceStart", resourceRoot, createPlayerList) addEventHandler("onClientGUIClick", root, function () if (source == row3) then row2 = guiGridListAddRow ( mgrid ) selectt = guiGridListGetItemText(gridd, row3, Players) if selectt and selectt ~= "" then player = getPlayerFromName(selectt) if player then playerMoney = getElementData(player,"money") guiGridListSetItemText (mgrid, row2, money, playerMoney, false, false ) end end end end ) Link to comment
Gallardo9944 Posted November 13, 2013 Share Posted November 13, 2013 Are you sure you have set the player's element data correctly? Link to comment
The Killer Posted November 13, 2013 Author Share Posted November 13, 2013 do you mean in server ? if you mean it then [server] : setElementData(player,"money",getPlayerMoney(player)) Link to comment
The Killer Posted November 13, 2013 Author Share Posted November 13, 2013 will i try so hard it work when i put "getPlayerMoney" in client side it work but when i do 'trigger' it doesn't work the code after changes : addEventHandler("onClientGUIClick",root, function () if source == gridd then row2 = guiGridListAddRow ( mgrid ) name = guiGridListGetItemText ( gridd, guiGridListGetSelectedItem (gridd), 1 ) if name and name ~= "" then playerMoney = triggerServerEvent("PlayerMoney", getLocalPlayer ()) guiGridListSetItemText (mgrid, row2, money, playerMoney, false, false ) guiGridListSetItemColor (mgird,row2,money, 0, 255, 0 ) elseif name and name == "" then guiGridListClear(mgrid) end end end ) it work if i put "getPlayerMoney" in client side else no Link to comment
The Killer Posted November 13, 2013 Author Share Posted November 13, 2013 do you mean in the trigger ? Link to comment
The Killer Posted November 13, 2013 Author Share Posted November 13, 2013 little help please. Link to comment
فاّرس Posted November 13, 2013 Share Posted November 13, 2013 I'm don't know what do you want. Link to comment
The Killer Posted November 13, 2013 Author Share Posted November 13, 2013 (edited) ok, i want when someone select a player in the grid list 'gridd' then his money show in the other grid 'mgrid' this code it work only if i put 'getPlayerMoney' client side, if i put it in the server by using trigger it doesn't work else if i select a player and repeat select, the money show again and againg and again when i select a player and click the name that i selected before it show my money whenever i click, i want it show the money one time and if i change the selected player i mean if i select another player then the player that i selected before his money remove and show the new one. the code : addEventHandler("onClientGUIClick",root, function () if source == gridd then row2 = guiGridListAddRow ( mgrid ) name = guiGridListGetItemText ( gridd, guiGridListGetSelectedItem (gridd), 1 ) if name and name ~= "" then playerMoney = triggerServerEvent("PlayerMoney", getLocalPlayer ()) guiGridListSetItemText (mgrid, row2, money, playerMoney, false, false ) guiGridListSetItemColor (mgird,row2,money, 0, 255, 0 ) elseif name and name == "" then guiGridListClear(mgrid) end end end ) Edited November 14, 2013 by Guest Link to comment
فاّرس Posted November 13, 2013 Share Posted November 13, 2013 Use : triggerServerEvent when clicked the button. And get the player money from the server-side, and trigger to client and sets the value. And you can use timer to refresh. Link to comment
The Killer Posted November 14, 2013 Author Share Posted November 14, 2013 is this code right ? : addEventHandler("onClientGUIClick",root, function () if source == gridd then row2 = guiGridListAddRow ( mgrid ) name = guiGridListGetItemText ( gridd, guiGridListGetSelectedItem (gridd), 1 ) if name and name ~= "" then triggerServerEvent("PlayerMoney", localPlayer) elseif name and name == "" then guiGridListClear(mgrid) end end end ) addEvent("AddRow", true) addEventHandler("AddRow", root, function () guiGridListSetItemText (mgrid, row2, money, false, false ) guiGridListSetItemColor (mgird,row2,money, 0, 255, 0 ) end ) Server# addEvent("PlayerMoney", true) addEventHandler("PlayerMoney", root, function (player) money = getPlayerMoney (client) if money then triggerClientEvent("AddRow", client) end end ) Link to comment
The Killer Posted November 14, 2013 Author Share Posted November 14, 2013 help please. Link to comment
فاّرس Posted November 14, 2013 Share Posted November 14, 2013 Trigger when clicked then button : triggerServerEvent('GetMoney',localPlayer) and tigger in server-side : addEvent('GetMoney',true) addEventHandler('GetMoney',root,function() triggerClientEvent(source,'_setPlayerMoney',source,getPlayerMoney(source)) end ) source = if you want send to source. Now add trigger in client-side : addEvent('_setPlayerMoney',true) addEventHandler('_setPlayerMoney',root,function(Money) guiGridListSetItemText (mgrid, guiGridListAddRow(mgrid),1, Money, false, false ) guiGridListSetItemColor (mgrid,guiGridListAddRow(mgrid),1, 0, 255, 0 ) end ) ^ I think this you want. Link to comment
The Killer Posted November 14, 2013 Author Share Posted November 14, 2013 Hmm... the same problem that when i select a player nothing happend it should show his money but no. 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