Jump to content

destroyElement..


itHyperoX

Recommended Posts

Hello, i'm working on a vehicle system, and again got some problem....

 

destroyElement - expected element at argument 1.

Code:

addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),function()
    targetSpawnedVeh = getElementData(source,"vehSpawned")
    if targetSpawnedVeh then
        destroyElement(targetSpawnedVeh)
        removeElementData(source,"vehSpawned")
        outputChatBox("success1")
    else
        outputChatBox("error")    
    end
end)

addEventHandler("onResourceStop",resourceRoot,function()
    targetSpawnedVeh = getElementData(source,"vehSpawned")
    if targetSpawnedVeh then
        destroyElement(targetSpawnedVeh)
        removeElementData(source,"vehSpawned")
        outputChatBox("success2")
    else
        outputChatBox("error")    
    end
end)

Always returning to "error"

Edited by TheMOG
Link to comment
                  if #playercar == 1 then
                       local x,y,z = getElementPosition(source)
                       local vehicle = createVehicle(playercar[1].vehID,x + 5,y +2,z)
                    setElementData(vehicle,"vehicle:Owner","vehicleSpawned")
                       setElementData(vehicle,"vehicleSpawned",getPlayerName(source))
                       setElementData(source, "vehicleSpawned", vehicle)
                    setElementData(vehicle,"VehOwner",getPlayerName(source))
                       vehicleSpawnMessage(1)
                   else
                    noVehicleOnSlot(1)
                end

 

I checked with a command, and its working.

 

addCommandHandler("test",function(source,cmd)
    veh = getElementData(source,"myVehicle1")
    isInVeh = getPedOccupiedVehicle ( source )
    if isInVeh then    
        if isElement(veh) then
            outputChatBox("The vehicle is spawned",source)
        else
            outputChatBox("The vehicle is not spawned",source)    
        end
    else
        outputChatBox("Not in veh")    
    end    
end)

 

Edited by TheMOG
Link to comment
13 minutes ago, pa3ck said:

You're using the events onResourceStart and onResourceStop with "source" --> source is never going to be a player, it will always be the resource. What you should do is, when a resource starts, use a for loop to loop through every player. 

Niice thank you buddy. Working perfect

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