manve1 Posted September 17, 2012 Share Posted September 17, 2012 hi, is there a possibility some one could change my code, so only on grid list selected player's vehicle gets fixed, blown? addEventHandler("onClientGUIClick", fix, function() if (source == fix) then vehicles = getElementsByType ( "vehicle" ) for vehicleKey, vehicleValue in ipairs(vehicles) do fixVehicle ( vehicleValue ) end end end ) addEventHandler("onClientGUIClick", blow, function() if (source == blow) then vehicles = getElementsByType ( "vehicle" ) for vehicleKey, vehicleValue in ipairs(vehicles) do blowVehicle ( vehicleValue ) end end end ) /\ these are both of them Link to comment
Callum Posted September 17, 2012 Share Posted September 17, 2012 Well iterating every vehicle to perform the operation isn't the best method - perhaps a bit more information would be helpful. Can you tell us exactly how you store the vehicle data? Link to comment
Castillo Posted September 17, 2012 Share Posted September 17, 2012 -- client side: addEventHandler ( "onClientGUIClick", root, function ( ) if ( source == fix or source == blow ) then local row, col = guiGridListGetSelectedItem ( Grid ) if ( row and col and row ~= -1 and col ~= -1 ) then local playerName = guiGridListGetItemText ( Grid, row, 1 ) local player = getPlayerFromName ( playerName ) if ( not player ) then return end triggerServerEvent ( "doVehicleAction", localPlayer, player, ( source == fix and "fix" or source == blow and "blow" ) ) end end end ) -- server side: addEvent ( "doVehicleAction", true ) addEventHandler ( "doVehicleAction", root, function ( player, action ) local vehicle = getPedOccupiedVehicle ( player ) if ( vehicle ) then if ( action == "fix" ) then fixVehicle ( vehicle ) elseif ( action == "blow" ) then blowVehicle ( vehicle ) end end end ) Link to comment
manve1 Posted September 17, 2012 Author Share Posted September 17, 2012 blow's all cars still, i need only for the person chosen on the gridList Link to comment
Jaysds1 Posted September 17, 2012 Share Posted September 17, 2012 Can you post a full code pls, or give us the gridlist variable? Link to comment
Castillo Posted September 17, 2012 Share Posted September 17, 2012 blow's all cars still, i need only for the person chosen on the gridList My script will only fix/blow the selected player's vehicle, what you are saying is just not possible. Link to comment
Jaysds1 Posted September 17, 2012 Share Posted September 17, 2012 (edited) try this: addEventHandler ( "onClientGUIClick", guiRoot, function ( ) local fixit = (source == fix) local blowit = (source == blow) if fixit or blowit then local row = guiGridListGetSelectedItem ( Grid ) if row== -1 then return end local playerName = guiGridListGetItemText ( Grid, row, 1 ) local player = getPlayerFromName ( playerName ) if ( not player ) then return end triggerServerEvent ( "doVehicleAction", localPlayer, player,fixit,blowit) end end ) addEvent ( "doVehicleAction", true ) addEventHandler ( "doVehicleAction", root, function ( player, fix,blow ) if isPedInVehicle(player) then local vehicle = getPedOccupiedVehicle ( player ) if fix then fixVehicle ( vehicle ) elseif blow then blowVehicle ( vehicle ) else outputChatBox(fit.." and "..blow,client) end end end ) Edited September 18, 2012 by Guest Link to comment
manve1 Posted September 18, 2012 Author Share Posted September 18, 2012 EDIT: Jay your script didn't work EDIT2: Some how solidsnake14 ur script decided to do absolutely nothing Link to comment
TAPL Posted September 18, 2012 Share Posted September 18, 2012 I gusse that because you're removing the hex code from the player name, and function getPlayerFromName must fit the name. Link to comment
Castillo Posted September 18, 2012 Share Posted September 18, 2012 That's right TAPL, I guess with the useful function: getPlayerFromNamePart it could work. addEventHandler ( "onClientGUIClick", root, function ( ) if ( source == fix or source == blow ) then local row, col = guiGridListGetSelectedItem ( Grid ) if ( row and col and row ~= -1 and col ~= -1 ) then local playerName = guiGridListGetItemText ( Grid, row, 1 ) local player = getPlayerFromNamePart ( playerName ) if ( not player ) then return end triggerServerEvent ( "doVehicleAction", localPlayer, player, ( source == fix and "fix" or source == blow and "blow" ) ) end end end ) function getPlayerFromNamePart(name) if name then for i, player in ipairs(getElementsByType("player")) do if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then return player end end end return false end Link to comment
manve1 Posted September 18, 2012 Author Share Posted September 18, 2012 The script actually does nothing if i press blow or fix, i selected my self, and got in car, tried to blow my self and nothing. Link to comment
Castillo Posted September 18, 2012 Share Posted September 18, 2012 addEventHandler ( "onClientGUIClick", root, function ( ) if ( source == fix or source == blow ) then local row, col = guiGridListGetSelectedItem ( Grid ) if ( row and col and row ~= -1 and col ~= -1 ) then local playerName = guiGridListGetItemText ( Grid, row, 1 ) outputChatBox ( "Selected player name: ".. playerName ) local player = getPlayerFromNamePart ( playerName ) if ( not player ) then return outputChatBox ( "Invalid player.", 255, 0, 0 ) end triggerServerEvent ( "doVehicleAction", localPlayer, player, ( source == fix and "fix" or source == blow and "blow" ) ) end end end ) function getPlayerFromNamePart(name) if name then for i, player in ipairs(getElementsByType("player")) do if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then return player end end end return false end Try with that and see what does it output. Link to comment
manve1 Posted September 18, 2012 Author Share Posted September 18, 2012 It output's invalid player Link to comment
Castillo Posted September 18, 2012 Share Posted September 18, 2012 That's what I though. Copy the code again and tell me what does it output now. Link to comment
manve1 Posted September 18, 2012 Author Share Posted September 18, 2012 the selected player and invalid player Link to comment
TAPL Posted September 18, 2012 Share Posted September 18, 2012 I have idea You can store the Player name with the hex code with this https://wiki.multitheftauto.com/wiki/GuiGridListSetItemData and then get the data with this https://wiki.multitheftauto.com/wiki/GuiGridListGetItemData Link to comment
Castillo Posted September 18, 2012 Share Posted September 18, 2012 addEventHandler ( "onClientGUIClick", root, function ( ) if ( source == fix or source == blow ) then local row, col = guiGridListGetSelectedItem ( Grid ) if ( row and col and row ~= -1 and col ~= -1 ) then local playerName = guiGridListGetItemText ( Grid, row, 1 ) local player = getPlayerFromNamePart ( playerName ) if ( not player ) then return outputChatBox ( "Invalid player.", 255, 0, 0 ) end triggerServerEvent ( "doVehicleAction", localPlayer, player, ( source == fix and "fix" or source == blow and "blow" ) ) end end end ) function getPlayerFromNamePart ( name ) if ( name ) then for _, player in ipairs ( getElementsByType ( "player" ) ) do local playerName = getPlayerName ( playerName ):gsub ( "#%x%x%x%x%x%x", "" ) if ( playerName:find ( tostring ( name ):lower ( ), 1, true ) ) then return player end end end return false end Try that. Link to comment
manve1 Posted September 18, 2012 Author Share Posted September 18, 2012 addEventHandler ( "onClientGUIClick", root, function ( ) if ( source == fix or source == blow ) then local row, col = guiGridListGetSelectedItem ( Grid ) if ( row and col and row ~= -1 and col ~= -1 ) then local playerName = guiGridListGetItemText ( Grid, row, 1 ) local player = getPlayerFromNamePart ( playerName ) if ( not player ) then return outputChatBox ( "Invalid player.", 255, 0, 0 ) end triggerServerEvent ( "doVehicleAction", localPlayer, player, ( source == fix and "fix" or source == blow and "blow" ) ) end end end ) function getPlayerFromNamePart ( name ) if ( name ) then for _, player in ipairs ( getElementsByType ( "player" ) ) do local playerName = getPlayerName ( playerName ):gsub ( "#%x%x%x%x%x%x", "" ) if ( playerName:find ( tostring ( name ):lower ( ), 1, true ) ) then return player end end end return false end Try that. this is client right? if yes, then it doesn't do anything. Link to comment
Castillo Posted September 19, 2012 Share Posted September 19, 2012 Post your entire code, including grid list and so on. Link to comment
manve1 Posted September 19, 2012 Author Share Posted September 19, 2012 (edited) deleted so no one gonna try stealing it, i know lots of people do this. Edited September 19, 2012 by Guest Link to comment
TAPL Posted September 19, 2012 Share Posted September 19, 2012 Change this function getPlayerFromNamePart ( name ) if ( name ) then for _, player in ipairs ( getElementsByType ( "player" ) ) do local playerName = getPlayerName ( player ):gsub ( "#%x%x%x%x%x%x", "" ) if ( playerName:find ( tostring ( name ), 1, true ) ) then return player end end end return false end to function getPlayerFromNamePart ( name ) if ( name ) then for _, player in ipairs (getElementsByType("player")) do local playerName = getPlayerName(player):gsub("#%x%x%x%x%x%x", "") if (playerName:find(tostring(name), 1, true)) then return player end end end return false end and this if guiGridListGetItemText(Grid, i, Column) == old then guiGridListSetItemText(Grid, i, Column, new, false, false) to if guiGridListGetItemText(Grid, i, Column) == old:gsub("#%x%x%x%x%x%x", "") then guiGridListSetItemText(Grid, i, Column, new:gsub("#%x%x%x%x%x%x", ""), false, false) 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