Jump to content

[Help] Colshape Detection


Syntrax#

Recommended Posts

Hello,

I've a question regarding detection of which colshape has been hit.I'm currently working on a mysql Housing script but the problem right now is that i don't know how to know which colshape has been hit since it's multiple colshapes with the same name due the fact it's done with ipairs from the mysql results.

function getConnection()
connection = dbConnect( "mysql", "dbname=fghousing;host=localhost", "root", "", "share=1" )
if ( connection ) then -- The connection failed
outputDebugString("Connected to the MySQL server")
local data = dbQuery(connection, "SELECT * FROM housing" )
result = dbPoll( data, -1 )
if result then
outputDebugString("Results has been given")
for i, v in ipairs(result) do
if tonumber(v['Property']) == 1 then
     houseIcon = createPickup(v['Ix'], v['Iy'], v['Iz'], 3, 1272, 0)
     houseCol = createColCircle ( v['Ix'], v['Iy'], 2 )   
setElementID ( houseCol, v['Adress'] ) 
    setElementData(houseCol, "Adress", v['Adress'])
    setElementData(houseCol, "Tax", v['Tax'])
    setElementData(houseCol, "Price", v['Price'])
    setElementData(houseCol, "City", v['City'])
    setElementData(houseCol, "BuyDate", v['BuyDate'])
    setElementData(houseCol, "Owner", v['Owner'])
    addEventHandler ( "onColShapeHit", houseCol, onHousingPick )
elseif tonumber(v['Property']) == 2 then
     appartmentIcon = createPickup(v['Ix'], v['Iy'], v['Iz'], 3, 1273, 0)
     appartmentCol = createColCircle ( v['Ix'], v['Iy'], 2 )    
    addEventHandler ( "onColShapeHit", appartmentCol, onHousingPick )
elseif tonumber(v['Property']) == 3 then
     headquarterIcon = createPickup(v['Ix'], v['Iy'], v['Iz'], 3, 1274, 0)
     headquarterCol = createColCircle ( v['Ix'], v['Iy'], 2 )    
    addEventHandler ( "onColShapeHit", headquarterCol, onHousingPick )
elseif tonumber(v['Property']) == 4 then
     bussinessIcon = createPickup(v['Ix'], v['Iy'], v['Iz'], 3, 1275, 0)
     bussinessCol = createColCircle ( v['Ix'], v['Iy'], 2 )    
    addEventHandler ( "onColShapeHit", bussinessCol, onHousingPick )
elseif tonumber(v['Property']) == 5 then
     garageIcon = createPickup(v['Ix'], v['Iy'], v['Iz'], 3, 1276, 0)
     garageCol = createColCircle ( v['Ix'], v['Iy'], 2 )    
    addEventHandler ( "onColShapeHit", garageCol, onHousingPick )
    end
    if tonumber(v['Interior']) == 1 then
    --interiorMarker = createMarker(v['Mx'], v['My'], v['Mz'], "cylinder", 1, 180, 0, 0, 255)
    elseif tonumber(v['Interior']) ~= 1 then
    interiorMarker = createMarker(v['Mx'], v['My'], v['Mz'], "cylinder", 1, 0, 204, 102, 255)
    end
    if tonumber(v['Garage']) == 1 then
    
    elseif tonumber(v['Garage']) ~= 1 then
    interiorMarker = createMarker(v['Gx'], v['Gy'], v['Gz'] + 1.5, "arrow", 1, 0, 204, 102, 255)
    end
    end
else
outputDebugString("Unable to connect to the MySQL server")
end
end
end
addEventHandler("onResourceStart",resourceRoot,getConnection)

function insertValue(Adress,Owner,BuyDate,Price,Tax,City,Property,Interior,Garage,Ix,Iy,Iz,Mx,My,Mz,Gx,Gy,Gz)
if connection then
dbExec( connection, "INSERT INTO Housing VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", Adress, Owner, BuyDate, Price, Tax, City, Property, Interior, Garage, Ix, Iy, Iz, Mx, My, Mz, Gx, Gy, Gz )
end
end
addEvent("onHousingCreate", true)
addEventHandler("onHousingCreate", root, insertValue)

function onHousingPick(thePlayer)
name = getElementData(houseCol, "Adress")
owner = getElementData(houseCol, "Owner")
price = getElementData(houseCol, "Price")
tax = getElementData(houseCol, "Tax")
city = getElementData(houseCol, "City")
BuyDate = getElementData(houseCol, "BuyDate")
outputDebugString(name.. ", "..owner.." ,"..price.." ,"..tax.." ,"..city..", "..BuyDate.."")
--triggerClientEvent(thePlayer, "onHousingPickup", localPlayer, name, owner, price, tax, city, buyDate)
end

 

Edited by Syntrax#
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...