Fabio(GNR) Posted May 7, 2011 Share Posted May 7, 2011 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 Link to comment
NeXTreme Posted May 7, 2011 Share Posted May 7, 2011 I'm not sure what exactly you want to do. Link to comment
Fabio(GNR) Posted May 7, 2011 Author Share Posted May 7, 2011 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 Link to comment
proracer Posted May 7, 2011 Share Posted May 7, 2011 You can use (return string.gsub) , right? Link to comment
Fabio(GNR) Posted May 7, 2011 Author Share Posted May 7, 2011 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 Link to comment
proracer Posted May 7, 2011 Share Posted May 7, 2011 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. Link to comment
Fabio(GNR) Posted May 7, 2011 Author Share Posted May 7, 2011 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. Link to comment
proracer Posted May 7, 2011 Share Posted May 7, 2011 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? Link to comment
Fabio(GNR) Posted May 7, 2011 Author Share Posted May 7, 2011 My code is pretty big, maybe i can help you with this info: the variable is row(NUMBER) were (NUMBER) is ofcourse a number. Link to comment
Fabio(GNR) Posted May 7, 2011 Author Share Posted May 7, 2011 ( 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. Link to comment
proracer Posted May 7, 2011 Share Posted May 7, 2011 Can you please post just the important part of the code what it doesn't work? Link to comment
Fabio(GNR) Posted May 7, 2011 Author Share Posted May 7, 2011 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. Link to comment
NeXTreme Posted May 8, 2011 Share Posted May 8, 2011 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 Link to comment
Fabio(GNR) Posted May 8, 2011 Author Share Posted May 8, 2011 Thanks I figured that out yesterday with some help of someone else but thanks for replying My resource is done you can take a a look at it if you wish: https://community.multitheftauto.com/index.php?p= ... ls&id=2134 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