Jump to content

Need help about element data


Dazee

Recommended Posts

Posted (edited)

Okay so I was attempting to create a function where I can create a blip on the map which I successfully accomplish then I wanted to either use the same command to make the marker and remove it but I failed miserably here is my result can someone explain me on how to do things like that btw here is the code I came up with in the end that doesen't work

function createPartyBlip ( thePlayer, commandName )  
     if ( thePlayer ) then    
     local x,y,z = getElementPosition (thePlayer) 
     local theBlip = createBlip( x, y, z, 49, 0, 0, 0, 255) 
     local theBlip0 = setElementData( thePlayer, "tempdata.party", theBlip ) 
     local theBlip2 = setElementData ( thePlayer, "tempdata.partyblip", 1 ) 
     local theBlip3 = setElementData ( thePlayer, "tempdata.partyblippy", x ) 
     local theBlip4 = setElementData ( thePlayer, "tempdata.partyblippy", y ) 
     local theBlip5 = setElementData ( thePlayer, "tempdata.partyblippy", z ) 
     if ( theBlip ) then 
        outputChatBox("Marker created successfully", thePlayer) 
     else 
        outputChatBox("Failed to create a marker", thePlayer) 
       end 
    end 
    addCommandHandler( "party", createPartyBlip ) 
function removePartyBlip ( thePlayer, commandName )  
    if ( getElementData(thePlayer, "tempdata.partyblip", 1 ) ) then 
    local blippe=getElementData(thePlayer, "tempdata.party" ) 
    local blippy2=getElementData(thePlayer, "tempdata.partyblippy") 
    local blippy3=getElementData(thePlayer, "tempdata.partyblippy") 
    local blippy4=getElementData(thePlayer, "tempdata.partyblippy")  
    setElementData(thePlayer, "tempdata.partyblip", 0) 
    destroyElement(blippe, blippy2, blippy3, blippy4) 
    outputChatBox("Blip has been removed", thePlayer ) 
 end 
end 
end 
addCommandHandler( "partyremove", removePartyBlip ) 
  

If someone could correct this it would be a great learning experience for me since I learn from wiki and other scripts

Edited by Guest
Posted

You don't need to do e.g. local abcd = setElementData.

Just use setElementData since you don't check the result anyway.

Also, I'm not sure but setElementData and getElementData probably require a boolean value (true/false) instead of 1 and 0.

About the destroying, only 1 argument allowed. destroyElement(element)

And you only need one anyway.

Posted

Ok i have come up with this

function createPartyBlip ( thePlayer, commandName ) 
     local x,y,z = getElementPosition (thePlayer) 
     if ( thePlayer ) then    
     theBlip = createBlip( x, y, z, 49, 0, 0, 0, 255) 
     setElementData( thePlayer, "tempdata.party", theBlip ) 
     setElementData( thePlayer, "tempdata.patee", true ) 
     if ( theBlip ) then 
        outputChatBox("Marker created successfully", thePlayer) 
     else 
        outputChatBox("Failed to create a marker", thePlayer) 
       end 
    end 
    addCommandHandler( "party", createPartyBlip ) 
function removePartyBlip (thePlayer)  
    if ( getElementData(thePlayer, "tempdata.patee", true ) ) then 
    destroyElement(getElementData(thePlayer,"tempdata.party", theBlip)) 
    outputChatBox("Blip has been removed", thePlayer ) 
    setElementData( thePlayer, "tempdata.patee", false ) 
 end 
end 
end 
addCommandHandler( "partyremove", removePartyBlip ) 

but i dont understand why does it say the error all the time

[2014-09-05 00:44:33] WARNING: scoreboardupdated\basiccommands.lua:22: Bad argument @ 'addCommandHandler' [Expected function at argument 2, got nil] 

Posted

I think you screwed up on ending functions.

  
function createPartyBlip ( thePlayer, commandName ) 
     local x,y,z = getElementPosition (thePlayer) 
     if ( thePlayer ) then    
        theBlip = createBlip( x, y, z, 49, 0, 0, 0, 255) 
        setElementData( thePlayer, "tempdata.party", theBlip ) 
        setElementData( thePlayer, "tempdata.patee", true ) 
        if ( theBlip ) then 
           outputChatBox("Marker created successfully", thePlayer) 
        else 
           outputChatBox("Failed to create a marker", thePlayer) 
         end 
     end 
end 
addCommandHandler( "party", createPartyBlip ) 
  
function removePartyBlip (thePlayer) 
    if ( getElementData(thePlayer, "tempdata.patee", true ) ) then 
       destroyElement(getElementData(thePlayer,"tempdata.party", theBlip)) 
       outputChatBox("Blip has been removed", thePlayer ) 
       setElementData( thePlayer, "tempdata.patee", false ) 
    end 
end 
addCommandHandler( "partyremove", removePartyBlip ) 
  

Posted

It creates the blip correctly and everything, but when I try to remove the blip it displays the text saying that "The blip has been removed" but the blip still stays on the radar.

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