Jump to content

Any way changed?


manve1

Recommended Posts

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

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

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 by Guest
Link to comment

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

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

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