Jump to content

New to scripting =) [Solved]


Baingo

Recommended Posts

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

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

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

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

Try This :D

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) 

:wink:

Link to comment
Try This :D
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) 

:wink:

DevPoint he said outputConsole , not outputChatBox... -.-"

Link to comment
  • 2 weeks later...

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

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

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

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