Jump to content

MySQL houses - /enter command


Recommended Posts

Hey,

I'm actually trying to import my houses system from SA:MP to MTA and I encounter a problem with the /enter command.

He's is the script that load the houses from the database (server-side):

  
HouseID = { } 
HouseElement = { } 
  
addEventHandler("onResourceStart", resourceRoot, 
    function() 
        -- Houses 
        local houses = mysql_query(database ,"SELECT id FROM `house` WHERE `id` >= '1' ORDER BY id DESC LIMIT 1") 
        local rowhouses= mysql_fetch_assoc(houses) 
        for i = 1, rowhouses.id, 1 do 
            MAX_HOUSES = rowhouses.id 
            local result = mysql_query(database ,"SELECT * FROM `house` WHERE `id` = '"..i.."'") 
            local row = mysql_fetch_assoc(result) 
            local pickup = createPickup(row.Entrancex, row.Entrancey, row.Entrancez, 3, 1318, 0) 
            HouseID[row.id] = pickup 
            HouseElement[pickup] = row.id 
            setElementData(pickup, "hEntrancex", row.Entrancex) 
            setElementData(pickup, "hEntrancey", row.Entrancey) 
            setElementData(pickup, "hEntrancez", row.Entrancez) 
            setElementData(pickup, "hExitx", row.Exitx) 
            setElementData(pickup, "hExity", row.Exity) 
            setElementData(pickup, "hExitz", row.Exitz) 
            outputDebugString ("House ID: "..i.." created.") 
        end 
    end 
) 
  

And the /enter command (server-side):

  
function Command(player,_) 
    for i = 1, MAX_HOUSES, 1 do 
        local x, y, z = getElementPosition(player) 
        local hx, hy, hz = getElementPosition(HouseID[i]) -- line 8 
        local distance = getDistanceBetweenPoints3D(x, y, z, hx, hy, hz) 
        if distance <= 5 then 
            setElementPos(player, GetHVar(HouseID[i], "hExitx"), GetHVar(HouseID[i], "hExity"), GetHVar(HouseID[i], "hExitz")) 
            setElementInterior(player, GetHVar(HouseID[i], "hInt")) 
            setElementDimension(player, i) 
            return 1 
        end 
    end  
end 
addCommandHandler("enter", Command, false, false) 
  

I tried from different ways, but it never works.

It returns my these errors:

[2013-06-15 16:20:44] WARNING: [gamemodes]\gm\Commands.lua:8: Bad argument @ 'getElementPosition' [Expected element at argument 1, got nil]

[2013-06-15 16:20:44] WARNING: [gamemodes]\gm\Commands.lua:9: Bad argument @ 'getDistanceBetweenPoints3D'

[2013-06-15 16:20:44] ERROR: [gamemodes]\gm\Commands.lua:10: attempt to compare boolean with number

Thanks in advance.

PS:

  
function GetHVar(maison, variable) 
    return tonumber(getElementData(maison, variable)) 
end 
  

Link to comment

The thing is that I'm using the same system for the vehicles:

  
addEventHandler("onResourceStart", resourceRoot, 
    function() 
        -- vehicles 
        local veh = mysql_query(database ,"SELECT id FROM `cars` WHERE `id` >= '1' ORDER BY id DESC LIMIT 1") 
        local rowveh = mysql_fetch_assoc(veh) 
        for i = 1, rowveh.id, 1 do 
            repeat 
                if i < 823 and i > 819 then 
                    break 
                end  
                local result = mysql_query ( database ,"SELECT * FROM `cars` WHERE `id` = '"..i.."'") 
                local row = mysql_fetch_assoc(result) 
                local vehid = createVehicle ( row.Model, row.Locationx, row.Locationy, row.Locationz, 0, 0, row.Angle, row.License) 
                VehicleID[row.id] = vehid 
                VehicleElement[vehid] = row.id 
            until true   
        end 
    end 
) 
  

And it works, for exemple to respawn a vehicle:

  
function Command(player,_,id) 
    if GetAdminLevel(player) >= 1 then 
        if id then 
            if VehicleID[id] ~= nil then 
                respawnVehicle(VehicleID[id]) 
            else 
                MessageError(player, "This vehicle does not exist.") 
            end  
        else 
            Syntax(player, "/rcid [id]") 
        end 
    else 
        MessageError(player, "You're not an admin.") 
    end  
end 
addCommandHandler("rcid", Command, false, false) 
  

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