Jump to content

Problem


IIYAMA

Recommended Posts

  • Moderators
  
local myPlayerData = {} 
local weaponObjectsVeh = {} 
local weaponvehicles = {[476]=true} 
  
function make_vehicle_weapon(vehicle, seat, jacked) 
    local player = source; 
    --local vehicle = getPedOccupiedVehicle (player) 
    if vehicle then 
        outputDebugString("vehicle found, IIYAMA is inside a vehicle",source) 
    else 
        outputDebugString("there is no vehicle, so I IIYAMA return this.",source) 
        return 
    end 
    if weaponvehicles[getElementModel(vehicle)] then 
        if not weaponObjectsVeh[vehicle] then 
            outputChatBox("not in table, new vehicle",source) 
            weaponObjectsVeh[vehicle]={} --<--<--< store my data 
            for k, players in pairs (getElementsByType ( "player" )) do 
                if myPlayerData[player]["load"] then 
                    outputChatBox("trigger") 
                    triggerClientEvent(players,"addtotable",getRootElement(),vehicle) 
                end 
            end 
        end 
    end  
end 
--addCommandHandler ("adds", make_vehicle_weapon) 
addEventHandler ("onPlayerVehicleEnter", getRootElement(), make_vehicle_weapon) 
  
  
function filterTableVeh() 
    outputChatBox(#weaponObjectsVeh) 
    for c, vehicle in pairs (weaponObjectsVeh) do 
        if vehicle then 
            outputChatBox ("it does work") -- output works 
        else 
            return 
        end 
        if not isElement( vehicle ) then  --<--<--< check  
            weaponObjectsVeh[vehicle]= nil 
            outputChatBox("not element")) 
        end 
    end 
    outputChatBox(#weaponObjectsVeh) 
end 
  
setTimer (filterTableVeh, 1000,0) 
  
  
  

I check if my tabledata and check if it is an element, but since I add it in the table it isn't a vehicle any more......... how can I turn it back to normal element/user data?

and If I check with "#" it will always awsers 0, but it is there.... :?

Link to comment

Simply pass the element like if you passed an integer:

myTable[ p_Element ] = true; -- you can change 'true' by any other thing as long as it is not null 
  
--or 
  
myTable[ SOME_VALUE ] = p_Element; 

How can I make a table that stores every new object at the next open place?

What do you mean?

Link to comment
  • Moderators

I have now this:

  
function make_vehicle_weapon(vehicle, seat, jacked) 
    local player = source; 
    --local vehicle = getPedOccupiedVehicle (player) 
    if vehicle then 
        outputDebugString("vehicle found, IIYAMA is inside a vehicle",source) 
    else 
        outputDebugString("there is no vehicle, so I IIYAMA return this.",source) 
        return 
    end 
    if weaponvehicles[getElementModel(vehicle)] then 
        if not weaponObjectsVeh[vehicle] then 
            outputChatBox("not in table, new vehicle",source) 
            weaponObjectsVeh[#weaponObjectsVeh+1]=vehicle 
            outputChatBox(#weaponObjectsVeh .. "wtf?") 
            for k, players in pairs (getElementsByType ( "player" )) do 
                if myPlayerData[player]["load"] then 
                    outputChatBox("trigger") 
                    triggerClientEvent(players,"addtotable",getRootElement(),vehicle) 
                end 
            end 
        end 
    end  
end 
--addCommandHandler ("adds", make_vehicle_weapon) 
addEventHandler ("onPlayerVehicleEnter", getRootElement(), make_vehicle_weapon) 

But how can I get the position when I know only the element that is inside?

I have no idea what position this vehicle should be, at the moment I try to remove it, can't find it at the lua tutorial site.

function filterTableVeh() 
    outputChatBox(#weaponObjectsVeh) 
    vehicleInTheWorld = getElementsByType ( "vehicle" ) 
    for c, vehicle in pairs (weaponObjectsVeh) do 
        if vehicle then 
            outputChatBox ("it does work") -- output works 
        else 
            return 
        end 
        --if not isElement( vehicle ) then 
        --outputChatBox(getElementModel(vehicle)) 
        if not vehicleInTheWorld[vehicle] then 
            --weaponObjectsVeh[vehicle] 
            table.remove(weaponObjectsVeh,) 
             
            outputChatBox("not element" .. c) 
        else 
            outputChatBox("there is") 
        end 
    end 
    outputChatBox(#weaponObjectsVeh) 
end 

Link to comment

Since "vehicleInTheWorld" uses elements as indexes, you can't use "table.remove". You should set "vehicle" var index in "vehicleInTheWorld" to false instead.

Another thing I noticed is that you first check in a if statement if you find "vehicle" element index in "weaponObjectsVeh" but later you create a new index using numbers as indexes and element in value which is wrong for two reasons:

1. Your array must only be in one way.

2. Already told you that you can't use "#" for getting length of a non number-indexed table.

Link to comment
  • Moderators
Since "vehicleInTheWorld" uses elements as indexes, you can't use "table.remove". You should set "vehicle" var index in "vehicleInTheWorld" to false instead.

If I do that, it means it is still inside the table. I probally confused you with "vehicleInTheWorld", it was just a testhing to help with removing those vehicles. If I set the Vehicle to nil, will it then be out of the table?

Another thing I noticed is that you first check in a if statement if you find "vehicle" element index in "weaponObjectsVeh" but later you create a new index using numbers as indexes and element in value which is wrong for two reasons:

1. Your array must only be in one way.

2. Already told you that you can't use "#" for getting length of a non number-indexed table.

I getting little bit confused, code is let we say inefficient, but it almost works.

  
--local removeNumberClient = {} 
local weaponObjectsVeh = {} 
  
function filterTableVeh() 
    outputChatBox(#weaponObjectsVeh)--now I can do that... it works. 
    for c, vehicle in pairs (weaponObjectsVeh) do 
        if not vehicle then 
        return 
        end 
        if not isElement( vehicle ) then 
            outputChatBox ("a object is gone")  
           -- local rangeVeh = #weaponObjectsVeh 
            local removeNumber = nil 
            for i=0,#weaponObjectsVeh,1 do  
                if vehicle == weaponObjectsVeh[i] then 
                removeNumber = i 
                end 
            end 
            if removeNumber then 
            --removeNumberClient[removeNumber]= {}-- update for the client table, no index needed 
            outputChatBox(removeNumber) 
            table.remove(weaponObjectsVeh,removeNumber) 
            table.sort(weaponObjectsVeh) 
            end 
        else 
            outputChatBox("spams for all existed vehicles") 
        end 
    end 
    ----uit 
end 

function make_vehicle_weapon(vehicle, seat, jacked) 
    local player = source; 
    --local vehicle = getPedOccupiedVehicle (player) 
    if vehicle then 
        outputDebugString("vehicle found, IIYAMA is inside a vehicle",source) 
    else 
        outputDebugString("there is no vehicle, so I IIYAMA return this.",source) 
        return 
    end 
    if weaponvehicles[getElementModel(vehicle)] then 
        local tableVeh = weaponObjectsVeh[vehicle] 
        local beReturn = false 
        for k, picVeh in pairs (weaponObjectsVeh) do 
            if vehicle == picVeh then 
            beReturn = true 
            outputChatBox("return") 
            end 
        end 
        if beReturn == true then 
            return 
        end 
        --table.insert(weaponObjectsVeh, vehicle) 
        table.sort(weaponObjectsVeh) 
        weaponObjectsVeh[#weaponObjectsVeh+1] = vehicle 
        outputChatBox("not in table, new vehicle ",source) 
  
        for k, players in pairs (getElementsByType ( "player" )) do 
            if myPlayerData[player]["load"] then 
                outputChatBox("trigger") 
                triggerClientEvent(players,"addtotable",getRootElement(),vehicle) 
            end 
        end 
    end  
end 
--addCommandHandler ("adds", make_vehicle_weapon) 
addEventHandler ("onPlayerVehicleEnter", getRootElement(), make_vehicle_weapon) 

finnaly it is working... and now I have too much headache to improve it -_-"

Edited by Guest
Link to comment
Since "vehicleInTheWorld" uses elements as indexes, you can't use "table.remove". You should set "vehicle" var index in "vehicleInTheWorld" to false instead.

If I do that, it means it is still inside the table. I probally confused you with "vehicleInTheWorld", it was just a testhing to help with removing those vehicles. If I set the Vehicle to nil, will it then be out of the table?

It will still be there. But it will ever return false if you try to use it since its value is false.

Cannot see the rest today, I'll look at what you wrote tomorrow.

Link to comment
  • Moderators

I think it is half/fixed now, because the result is "ok"

Not sure if it will lagg to much when I executed every 1 min.

Thank you, for keep an eye on the mistakes I made, maybe they are still there.

yes, take a look at it pls.

  
Is table.sort() needed? 

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