Mikhail Posted October 3, 2018 Share Posted October 3, 2018 (edited) I did this function consoleCreateMarker ( thePlayer, commandName ) if ( thePlayer ) then local x, y, z = getElementPosition ( thePlayer ) -- get the player's position -- create a cylindrical marker next to the player: local marker1 = createMarker ( x, y, z - 1, "cylinder", 1.5, 255, 255, 0, 170 ) if ( theMarker ) then -- check if the marker was created successfully outputConsole ( "El marcador se ha creado correctamente", thePlayer ) else outputConsole ( "Failed to create marker", thePlayer ) end end end addCommandHandler ( "createma", consoleCreateMarker ) function marker11 ( marker11 ) if isElementWithinMarker(thePlayer) then -- checking if player is in a marker destroyElement ( marker ) end end addCommandHandler("deletema", marker11 ) (I'm new in scripting) but this gives me this: Bad argument @ 'isElementWithinMarker' [Expected element at argument 1, got nil] Edited October 3, 2018 by Mikhail Link to comment
Dimos7 Posted October 3, 2018 Share Posted October 3, 2018 (edited) function consoleCreateMarker ( thePlayer, commandName ) if ( thePlayer ) then local x, y, z = getElementPosition ( thePlayer ) -- get the player's position -- create a cylindrical marker next to the player: local marker1 = createMarker ( x, y, z - 1, "cylinder", 1.5, 255, 255, 0, 170 ) if ( marker1 ) then -- check if the marker was created successfully outputConsole ( "El marcador se ha creado correctamente", thePlayer ) else outputConsole ( "Failed to create marker", thePlayer ) end end end addCommandHandler ( "createma", consoleCreateMarker ) function marker11 (thePlayer ) if isElementWithinMarker(thePlayer, marker1) then -- checking if player is in a marker destroyElement ( marker1) end end addCommandHandler("deletema", marker11 ) Edited October 3, 2018 by Dimos7 Link to comment
Mikhail Posted October 3, 2018 Author Share Posted October 3, 2018 (edited) @Dimos7 Bad argument @ 'isElementWithinMarker' [Expected marker at argument 2, got nil] Edited October 3, 2018 by Mikhail Link to comment
Gw8 Posted October 3, 2018 Share Posted October 3, 2018 change marker to a global variable. Link to comment
Dimos7 Posted October 3, 2018 Share Posted October 3, 2018 function consoleCreateMarker ( thePlayer, commandName ) if ( thePlayer ) then local x, y, z = getElementPosition ( thePlayer ) -- get the player's position -- create a cylindrical marker next to the player: marker1 = createMarker ( x, y, z - 1, "cylinder", 1.5, 255, 255, 0, 170 ) if ( marker1 ) then -- check if the marker was created successfully outputConsole ( "El marcador se ha creado correctamente", thePlayer ) else outputConsole ( "Failed to create marker", thePlayer ) end end end addCommandHandler ( "createma", consoleCreateMarker ) function marker11 (thePlayer ) if isElementWithinMarker(thePlayer) then -- checking if player is in a marker destroyElement ( marker1) end end addCommandHandler("deletema", marker11 ) Link to comment
Mikhail Posted October 4, 2018 Author Share Posted October 4, 2018 (edited) 9 hours ago, Gw8 said: change marker to a global variable. how to do it? sorry im new in lua. @Dimos7 Bad argument @ 'isElementWithinMarker' [Expected marker at argument 2, got none] i think the entire destroy function is wrong... is another way to write it? Edited October 4, 2018 by Mikhail Link to comment
Master_MTA Posted October 4, 2018 Share Posted October 4, 2018 function consoleCreateMarker ( thePlayer, commandName ) if ( thePlayer ) then local x, y, z = getElementPosition ( thePlayer ) -- get the player's position -- create a cylindrical marker next to the player: marker1 = createMarker ( x, y, z - 1, "cylinder", 1.5, 255, 255, 0, 170 ) if ( marker1 ) then -- check if the marker was created successfully outputConsole ( "El marcador se ha creado correctamente", thePlayer ) else outputConsole ( "Failed to create marker", thePlayer ) end end end addCommandHandler ( "createma", consoleCreateMarker ) function marker11 (thePlayer ) if isElementWithinMarker(thePlayer,marker1) then -- checking if player is in a marker destroyElement ( marker1) end end addCommandHandler("deletema", marker11 ) enjoy Link to comment
Mikhail Posted October 4, 2018 Author Share Posted October 4, 2018 @Master_MTA ok your script said it: lua:20: unexpected symbol near 'ï' addCommandHandler("deletema", marker11 ) but I rewrote it to: addCommandHandler ( "deletee", marker11) and it worked! but I have a query, could you explain in detail what change you in my script? because obviously you modify something, could you tell me my mistake and what do you modify? So I learn! although I am reading the wiki, we learn from mistakes, and better if you explain it to me .. Link to comment
Master_MTA Posted October 4, 2018 Share Posted October 4, 2018 54 minutes ago, Mikhail said: script am just added the second argument in isElementWithinMarker(thePlayer) to make it like this isElementWithinMarker(thePlayer,marker1) Link to comment
Mikhail Posted October 4, 2018 Author Share Posted October 4, 2018 @Master_MTA oh. ok... im trying to put some more and in the chat dont shows... function marker11 (thePlayer ) if isElementWithinMarker(thePlayer,marker1) then -- checking if player is in a marker destroyElement ( marker1) else outputConsole ( "you should be in the marker to delete it", thePlayer) end end addCommandHandler ( "deletee", marker11) and there are conflicts when I create more than 1 marker and I want to delete them 1 by 1 ... how would the command or the constant to delete all created? this would end the script .. Link to comment
Master_MTA Posted October 4, 2018 Share Posted October 4, 2018 4 minutes ago, Mikhail said: created u better use table+loop Link to comment
Mikhail Posted October 4, 2018 Author Share Posted October 4, 2018 @Master_MTA what is it? Link to comment
Master_MTA Posted October 4, 2018 Share Posted October 4, 2018 Just now, Mikhail said: it http://lua-users.org/wiki/TablesTutorial--------tables https://www.tutorialspoint.com/lua/lua_loops.htm---loops 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