Jump to content

[HELP]setElementData


Recommended Posts

Hi,

Im learning how to use:

setElementData

getElementData

So me & my friend created a delivery man job.

the purpose of setElementData in this script is that the player can only spawn 1 van.

If he tries to spawn another 1 the old 1 will be destroyed and there will be a new Van spawned.

But i have 1 problem.

When i step in the marker

there will be no van spawned and i get this message: [DELIVERY MAN]Your old van is succesfully destroyed and there is a new Van spawned!

This is my code:

DJmarker = createMarker ( 83.796, -149.400, 1.684, "cylinder", 1, 255, 0, 0, 100, getRootElement() ) 
  DJblip = createBlip ( 83.796, -149.400, 1.584, 51 ) 
  
function startMission (player) 
    blip0 = createBlip ( 269.329, -220.570, 0.427, 41 ) 
    blip1 = createBlip ( 215.279, 32.975, 1.462, 41 ) 
    blip2 = createBlip ( -60.394, 83.554, 2.136, 41 ) 
    blip3 = createBlip ( -116.719, -319.788, 0.171, 41 ) 
    blip4 = createBlip ( 867.670, -31.795, 62.195, 41 ) 
    setTimer(setElementPosition, 2200, 1, player, 94.952682495117, -162.39546203613, 2.59375 ) 
    setTimer(setElementRotation, 2200, 1, player, 0, 0, 173.87872314453 ) 
      fadeCamera ( player, false, 1.0, 0, 0, 0 )          
      setTimer ( fadeCamera, 2500, 1, player, true, 1.0 )    
    TheDV = createVehicle ( 440, 93.857, -164.925, 2.806 ) 
    setElementRotation( TheDV, 0, 0, 270 ) 
local dlvan = getElementData(player, "got.van" ) 
        if ( dlvan == false ) then 
setElementData(player,"got.van", TheDV) 
    outputChatBox ( "[DELIVERY MAN]You are now a Delivery man!", player, 0, 255, 0, true ) 
    outputChatBox ( "[DELIVERY MAN]Drive trough the markers to deliver the crates, And earn money.", player, 255, 255, 0, true ) 
    outputChatBox ( "[DELIVERY MAN]Use /quitjob to quit this job.", player, 255, 255, 0, true ) 
end 
end 
addEventHandler( "onMarkerHit", DJmarker, startMission ) 
  
function stopjobCommand ( player ) 
          setTimer(setElementPosition, 1000, 1, player, 85.138, -149.441, 2.583 ) 
                      setTimer(setElementRotation, 1000, 1, player, 0, 0, 270 ) 
                      fadeCamera ( player, false, 1.0, 0, 0, 0 )          
              setTimer ( fadeCamera, 1100, 1, player, true, 1.0 )   
    outputChatBox ( "[DELIVERY MAN]You are no longer Delivery man.", player, 255, 0, 0, true ) 
    setTimer(destroyElement, 100, 1, TheDV) 
    destroyElement(blip0) 
    destroyElement(blip1) 
    destroyElement(blip2) 
    destroyElement(blip3) 
    destroyElement(blip4) 
end 
addCommandHandler ("quitjob", stopjobCommand) 
  
  
  
function checkVan (player,matchingDimension) 
    local dlvan = getElementData( player, "got.van" ) 
    if ( dlvan ) then 
        setElementData (player, "got.van", false ) 
  destroyElement(TheDV) 
    destroyElement(blip0) 
    destroyElement(blip1) 
    destroyElement(blip2) 
    destroyElement(blip3) 
    destroyElement(blip4) 
  outputChatBox("[DELIVERY MAN]Your old van is succesfully destroyed and there is a new Van spawned!",player,0,255,0) 
  
 end 
end 
addEventHandler( "onMarkerHit", DJmarker, checkVan ) 
  

Can someone help me?

Regards,

Jesseunit

Link to comment
  • Moderators

It's very simple, at this line you get the Van:

local dlvan = getElementData( player, "got.van" ) 

So the van to destroy is dlvan yeah ?

So why you try to destroy TheDV ? :mrgreen: :

destroyElement(TheDV) 

replace by this:

destroyElement(dlvan) 

Be careful with the name of your variables :wink:

Link to comment
  • Moderators

You have 2 addEventHandler( "onMarkerHit", ...., .... ) for 2 functions so I think that he creates the new van and setElementData(player,"got.van", TheDV) before the destroyElement( dlvan ) of the second function, so he creates the new van and he destroys it immediatly.

Try to make only one function for this system

EDIT:

Like this:

function startMission (player) 
    local dlvan = getElementData( player, "got.van" ) 
    if ( dlvan ) then 
        setElementData (player, "got.van", false ) 
        destroyElement(dlvan) 
        destroyElement(blip0) 
        destroyElement(blip1) 
        destroyElement(blip2) 
        destroyElement(blip3) 
        destroyElement(blip4) 
        outputChatBox("[DELIVERY MAN]Your old van is succesfully destroyed and there is a new Van spawned!",player,0,255,0) 
    end 
    blip0 = createBlip ( 269.329, -220.570, 0.427, 41 ) 
    blip1 = createBlip ( 215.279, 32.975, 1.462, 41 ) 
    blip2 = createBlip ( -60.394, 83.554, 2.136, 41 ) 
    blip3 = createBlip ( -116.719, -319.788, 0.171, 41 ) 
    blip4 = createBlip ( 867.670, -31.795, 62.195, 41 ) 
    setTimer(setElementPosition, 2200, 1, player, 94.952682495117, -162.39546203613, 2.59375 ) 
    setTimer(setElementRotation, 2200, 1, player, 0, 0, 173.87872314453 ) 
    fadeCamera ( player, false, 1.0, 0, 0, 0 )         
    setTimer ( fadeCamera, 2500, 1, player, true, 1.0 )   
    local TheDV = createVehicle ( 440, 93.857, -164.925, 2.806 ) 
    setElementRotation( TheDV, 0, 0, 270 ) 
    local dlvan = getElementData(player, "got.van" ) 
    if ( dlvan == false ) then 
        setElementData(player,"got.van", TheDV)  
        outputChatBox ( "[DELIVERY MAN]You are now a Delivery man!", player, 0, 255, 0, true ) 
        outputChatBox ( "[DELIVERY MAN]Drive trough the markers to deliver the crates, And earn money.", player, 255, 255, 0, true ) 
        outputChatBox ( "[DELIVERY MAN]Use /quitjob to quit this job.", player, 255, 255, 0, true ) 
    end 
end 
addEventHandler( "onMarkerHit", DJmarker, startMission ) 

Link to comment

Mhhh maybe i know the error:

There is an error in the "onMarkerHit", the maker don't be getted just in the setted coords: in the x and y setteds yes, but not just in the "Z" coord setted, but in all Z (vertical)...

Idk if somone get me xD

Link to comment
  • Moderators
Mhhh maybe i know the error:

There is an error in the "onMarkerHit", the maker don't be getted just in the setted coords: in the x and y setteds yes, but not just in the "Z" coord setted, but in all Z (vertical)...

Idk if somone get me xD

Sorry but the problem is already solved :|

Link to comment
Mhhh maybe i know the error:

There is an error in the "onMarkerHit", the maker don't be getted just in the setted coords: in the x and y setteds yes, but not just in the "Z" coord setted, but in all Z (vertical)...

Idk if somone get me xD

Sorry but the problem is already solved :|

:o When?

Link to comment
You have 2 addEventHandler( "onMarkerHit", ...., .... ) for 2 functions so I think that he creates the new van and setElementData(player,"got.van", TheDV) before the destroyElement( dlvan ) of the second function, so he creates the new van and he destroys it immediatly.

Try to make only one function for this system

EDIT:

Like this:

function startMission (player) 
    local dlvan = getElementData( player, "got.van" ) 
    if ( dlvan ) then 
        setElementData (player, "got.van", false ) 
        destroyElement(dlvan) 
        destroyElement(blip0) 
        destroyElement(blip1) 
        destroyElement(blip2) 
        destroyElement(blip3) 
        destroyElement(blip4) 
        outputChatBox("[DELIVERY MAN]Your old van is succesfully destroyed and there is a new Van spawned!",player,0,255,0) 
    end 
    blip0 = createBlip ( 269.329, -220.570, 0.427, 41 ) 
    blip1 = createBlip ( 215.279, 32.975, 1.462, 41 ) 
    blip2 = createBlip ( -60.394, 83.554, 2.136, 41 ) 
    blip3 = createBlip ( -116.719, -319.788, 0.171, 41 ) 
    blip4 = createBlip ( 867.670, -31.795, 62.195, 41 ) 
    setTimer(setElementPosition, 2200, 1, player, 94.952682495117, -162.39546203613, 2.59375 ) 
    setTimer(setElementRotation, 2200, 1, player, 0, 0, 173.87872314453 ) 
    fadeCamera ( player, false, 1.0, 0, 0, 0 )         
    setTimer ( fadeCamera, 2500, 1, player, true, 1.0 )   
    local TheDV = createVehicle ( 440, 93.857, -164.925, 2.806 ) 
    setElementRotation( TheDV, 0, 0, 270 ) 
    local dlvan = getElementData(player, "got.van" ) 
    if ( dlvan == false ) then 
        setElementData(player,"got.van", TheDV)  
        outputChatBox ( "[DELIVERY MAN]You are now a Delivery man!", player, 0, 255, 0, true ) 
        outputChatBox ( "[DELIVERY MAN]Drive trough the markers to deliver the crates, And earn money.", player, 255, 255, 0, true ) 
        outputChatBox ( "[DELIVERY MAN]Use /quitjob to quit this job.", player, 255, 255, 0, true ) 
    end 
end 
addEventHandler( "onMarkerHit", DJmarker, startMission ) 

Here =)

Link to comment
You have 2 addEventHandler( "onMarkerHit", ...., .... ) for 2 functions so I think that he creates the new van and setElementData(player,"got.van", TheDV) before the destroyElement( dlvan ) of the second function, so he creates the new van and he destroys it immediatly.

Try to make only one function for this system

EDIT:

Like this:

function startMission (player) 
    local dlvan = getElementData( player, "got.van" ) 
    if ( dlvan ) then 
        setElementData (player, "got.van", false ) 
        destroyElement(dlvan) 
        destroyElement(blip0) 
        destroyElement(blip1) 
        destroyElement(blip2) 
        destroyElement(blip3) 
        destroyElement(blip4) 
        outputChatBox("[DELIVERY MAN]Your old van is succesfully destroyed and there is a new Van spawned!",player,0,255,0) 
    end 
    blip0 = createBlip ( 269.329, -220.570, 0.427, 41 ) 
    blip1 = createBlip ( 215.279, 32.975, 1.462, 41 ) 
    blip2 = createBlip ( -60.394, 83.554, 2.136, 41 ) 
    blip3 = createBlip ( -116.719, -319.788, 0.171, 41 ) 
    blip4 = createBlip ( 867.670, -31.795, 62.195, 41 ) 
    setTimer(setElementPosition, 2200, 1, player, 94.952682495117, -162.39546203613, 2.59375 ) 
    setTimer(setElementRotation, 2200, 1, player, 0, 0, 173.87872314453 ) 
    fadeCamera ( player, false, 1.0, 0, 0, 0 )         
    setTimer ( fadeCamera, 2500, 1, player, true, 1.0 )   
    local TheDV = createVehicle ( 440, 93.857, -164.925, 2.806 ) 
    setElementRotation( TheDV, 0, 0, 270 ) 
    local dlvan = getElementData(player, "got.van" ) 
    if ( dlvan == false ) then 
        setElementData(player,"got.van", TheDV)  
        outputChatBox ( "[DELIVERY MAN]You are now a Delivery man!", player, 0, 255, 0, true ) 
        outputChatBox ( "[DELIVERY MAN]Drive trough the markers to deliver the crates, And earn money.", player, 255, 255, 0, true ) 
        outputChatBox ( "[DELIVERY MAN]Use /quitjob to quit this job.", player, 255, 255, 0, true ) 
    end 
end 
addEventHandler( "onMarkerHit", DJmarker, startMission ) 

Here =)

Thanks :D

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