Baingo Posted October 29, 2011 Share Posted October 29, 2011 (edited) Hi guys I'm new to scripting and i just cant quite get my head around it not sure how long it should take =S so im starting with something real basic, just creating markers but id like to do it so the person can just type a command and bam new marker without having to put in coords everytime i wanna make a marker if it can even be done. or do i just make them on map editor? this is what i got Script.lua function createMarker (ThePlayer, commandName) if (thePlayer) then local x,y,z = getElementPosition (thePlayer) local theMarker = createMarker ( x,y,z, "arrow", 1.5, 255, 255, 0, 255, visibleTo = getRootElement) if (theMarker) then outputConsole ("Entry Marker Created", thePlayer) else outputConsole ("Failed to Create Marker", thePlayer) end end end addCommandHandler ("createentrymarker", consoleCreateMarker) it says there is a problem with line 4 about > expected near = Meta.xml Hope its not too noob =P I got no idea how to assign the marker with the interior next lesson i guess. Edited November 10, 2011 by Guest Link to comment
Aibo Posted October 29, 2011 Share Posted October 29, 2011 1. you're redefining createMarker function. use some other name 2. thePlayer and ThePlayer will be different variables, Lua is case-sensitive 3. visibleTo is the parameter name, you dont need it, just put the element (getRootElement() or root in this case) there 4. you're adding consoleCreateMarker function as a command handler, but your function is called createMarker (see 1) Link to comment
Al3grab Posted October 29, 2011 Share Posted October 29, 2011 here is where i edited : function cMarker (thePlayer, commandName) -- here if (thePlayer) then local x,y,z = getElementPosition (thePlayer) local theMarker = createMarker ( x,y,z, "arrow", 1.5, 255, 255, 0, 255,getRootElement()) -- here if (theMarker) then outputConsole ("Entry Marker Created", thePlayer) else outputConsole ("Failed to Create Marker", thePlayer) end end end addCommandHandler ("createentrymarker", cMarker ) -- here Link to comment
Baingo Posted October 29, 2011 Author Share Posted October 29, 2011 Thanks guys that helped alot, except the only problem is that the marker will appear for a quick second then disappear and doesnt output a console message. this is what i changed on it function cMarker (thePlayer, commandName) if (thePlayer) then local x,y,z = getElementPosition (thePlayer) local theMarker = createMarker ( x,y,z, "arrow", 1.5, 255, 255, 0, 255, getRootElement()) if (theMarker) then outputConsole ("Entry Marker Created", thePlayer) else outputConsole ("Failed to Create Marker", thePlayer) end end end addCommandHandler ("createentrymarker", cMarker) Link to comment
^Dev-PoinT^ Posted October 30, 2011 Share Posted October 30, 2011 Try This function cMarker (thePlayer, commandName) if (thePlayer) then local x,y,z = getElementPosition (thePlayer) local theMarker = createMarker ( x,y,z, "arrow", 1.5, 255, 255, 0, 255, getRootElement()) if (theMarker) then outputChatBox ("Entry Marker Created", thePlayer) else outputChatBox ("Failed to Create Marker", thePlayer) end end end addCommandHandler ("createentrymarker", cMarker) Link to comment
Al3grab Posted October 30, 2011 Share Posted October 30, 2011 oh yes , outputConsole should be outputChatBox =D Link to comment
CapY Posted October 30, 2011 Share Posted October 30, 2011 Try This function cMarker (thePlayer, commandName) if (thePlayer) then local x,y,z = getElementPosition (thePlayer) local theMarker = createMarker ( x,y,z, "arrow", 1.5, 255, 255, 0, 255, getRootElement()) if (theMarker) then outputChatBox ("Entry Marker Created", thePlayer) else outputChatBox ("Failed to Create Marker", thePlayer) end end end addCommandHandler ("createentrymarker", cMarker) DevPoint he said outputConsole , not outputChatBox... -.-" Link to comment
Baingo Posted November 8, 2011 Author Share Posted November 8, 2011 Awesome thanks guys, how would I go about Adding a command to remove/destroy the marker Link to comment
Chlorek Posted November 8, 2011 Share Posted November 8, 2011 Removing created marker (simple version with one marker removing only). local theMarker function cMarker (thePlayer, commandName) if (thePlayer) then local x,y,z = getElementPosition (thePlayer) theMarker = createMarker ( x,y,z, "arrow", 1.5, 255, 255, 0, 255, getRootElement()) if (theMarker) then outputChatBox ("Entry Marker Created", thePlayer) else outputChatBox ("Failed to Create Marker", thePlayer) end end end addCommandHandler ("createentrymarker", cMarker) function rMarker (thePlayer, commandName) if (isElement(theMarker) == true) then destroyElement(theMarker) outputChatBox ("Marker has been destroyed!", thePlayer) else outputChatBox ("There is not any entry marker!", thePlayer) end end addCommandHandler ("removemarker", rMarker) Should work. You can write script to creating many entry markers and then removing it, that is not much more lines of code. Link to comment
Baingo Posted November 9, 2011 Author Share Posted November 9, 2011 I create the marker and i go to destroy it but i get there is not an event marker i changed a few names only commands really and i changed it to event marker not entry but nothing that should matter i dont think. function cMarker (thePlayer, commandName) if (thePlayer) then local x,y,z = getElementPosition (thePlayer) local theMarker = createMarker ( x,y,z+0.5, "checkpoint", 4, 0, 255, 0, 0, getRootElement()) ---- ( Type of marker = Checkpoint, 4 = radius, (size), 0 Red, 255 Green, 0 Blue) if (theMarker) then outputChatBox ("Event Marker Created", thePlayer) else outputChatBox ("Failed to Create Marker", thePlayer) end end end addCommandHandler ("createmarker", cMarker) function rMarker (thePlayer, commandName) if (isElement(theMarker) == true) then destroyElement(theMarker) outputChatBox ("Marker has been destroyed!", thePlayer) else outputChatBox ("There is not any Event marker!", thePlayer) end end addCommandHandler ("destroymarker", rMarker) Link to comment
Chlorek Posted November 9, 2011 Share Posted November 9, 2011 (edited) local theMarker function cMarker (thePlayer, commandName) if (thePlayer) then local x,y,z = getElementPosition (thePlayer) theMarker = createMarker ( x,y,z+0.5, "checkpoint", 4, 0, 255, 0, 0, getRootElement()) ---- ( Type of marker = Checkpoint, 4 = radius, (size), 0 Red, 255 Green, 0 Blue) if (theMarker) then outputChatBox ("Event Marker Created", thePlayer) else outputChatBox ("Failed to Create Marker", thePlayer) end end end addCommandHandler ("createmarker", cMarker) function rMarker (thePlayer, commandName) if (isElement(theMarker) == true) then destroyElement(theMarker) outputChatBox ("Marker has been destroyed!", thePlayer) else outputChatBox ("There is not any Event marker!", thePlayer) end end addCommandHandler ("destroymarker", rMarker) Variables defined inside of any functions are available for this function only. They aren't available in every function;] It's really importnat so you should remember that! Edited November 9, 2011 by Guest Link to comment
12p Posted November 9, 2011 Share Posted November 9, 2011 Variables defined inside of any functions are available for this function only. They aren't global ;]It's really importnat so you should remember that! You are saying it wrong - "local" defined variables inside a function block are only available for that function. But if you don't use "local" prefix in variables, those will be global. Link to comment
Chlorek Posted November 9, 2011 Share Posted November 9, 2011 Oh my english isn't too good and sometimes I don't know how to say something But I wanted to say that and thank you for correting me #edit I think my last answer is now corrected Link to comment
Baingo Posted November 10, 2011 Author Share Posted November 10, 2011 Ah ok thanks i see how it works. starting to get a bit better at this thanks to these forums =D sorted out last problem i had using this help u gave me was creatingblipattatched to and tryna work out how to delete the blip i made a variable theBlip = createBlipattachedTo and a local theBlip at top very thankful for your help guys. [sOLVED] 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