Jump to content

Remove of a argument.


Recommended Posts

Posted

Hello,

i just started scripting again and i'm having a problem:

Im passing a argument to a syntax, but the argument is i.e iwant2 .

i want to remove the iwant before i pass it to the syntax, how?

Thanks

Posted

Let's say someone enters "GNR45" in a chatbox or something ( not really chat, just example ) it should instead of giving GNR45 only give 45. So GNR cut off :)

Posted

I will try that, but it is a variable i want to change, like

A = getPlayerName

and then -remove something from A- were A is a variable ofcourse.

EDIT: It gives a unexpected symbol near return, my code:

B = getElementPosition ( player ) 
A = return string.gsub ( "B", "GNR", "" ) 

This is just an example because there is no GNR in a position ;)

Posted

If I understood you correct:

addEventHandler ( 'onPlayerChat', root,  
    function ( message, messageType ) 
        if ( messageType ) == 0 then 
            if ( message ) == 'GNR45' then 
                cancelEvent ( ) 
                outputChatBox ( message:gsub ( 'GNR', '' ) ) 
                outputServerLog( "CHAT: " .. getPlayerName ( source ).. ": " .. message ) 
            end 
        end 
    end 
) 
  

I didn't tested yet.

Posted

Almost, it isnt chat tough, let me explain better :) I have a gridlist in a GUI were you can select thing's it retrieves what you selected fine and call that V ( v = etc. ) Then i need to remove "row" from V, im sure it contains row, and it needs to call the V without "row" ID, that id is then passed to serverside. I got some stuff from what you just gave me: id = v:gsub ( 'row', '' )

This gives me Attempt to index global v ( a number value ) on the the line v:gsub.

Posted

Sorry, I don't get you quite well with that.. but the error you are getting is because the variable you are using in string.gsub is a number value not a string value.

Maybe it's better if you can post your code here?

Posted

( im a noob at LUA ) can you explain me what this does? And how it works?

EDIT: Looked something up, it converts it right? What if i use tostring, remove "row" and then use tonumber?

EDIT2: That doesnt work :( It should become a id of a vehicle.

Posted
function create_veh ( playerSource ) 
v = guiGridListGetSelectedItem ( list_vehicles ) 
id1 = tostring(v) 
id2 = id1:gsub ( 'row', '') 
id = tonumber(id2) 
x, y, z = getElementPosition ( getLocalPlayer () ) 
showCursor ( false ) 
guiSetVisible ( Main_Window, false ) 
outputChatBox(". " .. id1 .. " ! and " .. id2 .. "  !" ) 
createVehicle ( id, x + 2, y + 1, z + 1.5 ) 
triggerServerEvent ( spawn, getLocalPlayer (), id ) 
end 

I have found a alternative solution, but i would like to learn it.

Posted

Oh now I finally know what you want. The problem is that guiGridListGetSelectedItem will not return the text, but the index of the selected row and column in the gridlist. You then have to use that with guiGridListGetItemText, which will grab the text from your gridlist :)

This should do what you want:

function create_veh ( playerSource ) 
    local row,column = guiGridListGetSelectedItem ( list_vehicles ) 
    id = guiGridListGetItemText(row,column) 
    x, y, z = getElementPosition ( getLocalPlayer () ) 
    showCursor ( false ) 
    guiSetVisible ( Main_Window, false ) 
    createVehicle ( id, x + 2, y + 1, z + 1.5 ) 
    triggerServerEvent ( spawn, getLocalPlayer (), id ) 
end 

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