Jump to content

Need help with these house icons!


Null

Recommended Posts

Hello all and thank you for taking the time and patience to read this, i am modifying DaKillas house script (Not removing copyright, just modifying slightly)

The original system uses markers and images, i changed the markers to 0 transparency so onMarkerHit function still works, but i want house icons to appear in the center (Green for for sale, blue for sold)

I managed to get it to kinda work, but DestroyElement and createPickup doesn't seem to be working right

SERVER (updated)

local sql = { Query = executeSQLQuery }; 
 
addEventHandler( 'onResourceStart', resourceRoot, function()
  sql.Query( "CREATE TABLE IF NOT EXISTS house_data (\
   ID INTEGER, en_X REAL, en_Y REAL, en_Z REAL,\
   en_tX REAL, en_tY REAL, en_tZ REAL,\
   ex_X REAL, ex_Y REAL, ex_Z REAL,\
   ex_tX REAL, ex_tY REAL, ex_tZ REAL,\
   int INTEGER, dim INTEGER, cost INTEGER, owner TEXT, key TEXT )"
  );
  for i, v in ipairs( getElementsByType( 'player' ) ) do
    setElementData( v, 'k_len', tonumber( get( 'keyLength' ) ) );
    local acc = getPlayerAccount( v );
    if not isGuestAccount( acc ) then
      setElementData( v, 'HS_accountName', getAccountName( acc ) );
    end;
    setElementData( v, 'mrk_in', nil );
  end;
  local hr = sql.Query( "SELECT * FROM house_data" );
  for i = 1, #hr do
    createHouse( false, hr[i].ID, hr[i].owner, hr[i].key, hr[i].en_X, hr[i].en_Y, hr[i].en_Z, hr[i].en_tX, hr[i].en_tY, hr[i].en_tZ, hr[i].ex_X, hr[i].ex_Y, hr[i].ex_Z, hr[i].ex_tX, hr[i].ex_tY, hr[i].ex_tZ, hr[i].int, hr[i].dim, hr[i].cost );
  end;
end );
 
addEventHandler( 'onResourceStop', resourceRoot, function()
  for i, v in ipairs( getElementsByType( 'player' ) ) do
    setElementData( v, 'k_len', nil );
    setElementData( v, 'HS_accountName', nil );
  end;
end );
 
addEventHandler( 'onPlayerJoin', root, function()
  setElementData( source, 'k_len', tonumber( get( 'keyLength' ) ) );
end );
 
addEventHandler( 'onPlayerLogin', root, function( _, acc )
  setElementData( source, 'HS_accountName', getAccountName( acc ) );
end );
 
addEventHandler( 'onPlayerLoout', root, function( _, acc )
  setElementData( source, 'HS_accountName', nil );
end );
 
addCommandHandler( 'hpanel', function( player )
  if isObjectInACLGroup( 'user.'..getAccountName( getPlayerAccount( player ) ), aclGetGroup( 'Admin' ) ) or hasObjectPermissionTo( player, 'function.banPlayer', false ) then
    if not getElementData( player, 'HP_Opened' ) and not getElementData( player, 'mrk_in' ) then
      triggerClientEvent( player, 'HP_SetVisible', root, true );
    end;
  else
    outputChatBox( '* Access denied for this command!', player, 255, 36, 51 );
  end;
end );
 
addEvent( 'onPlayerAttemptCreateHouse', true );
addEventHandler( 'onPlayerAttemptCreateHouse', root, function( rt )
  createHouse( true, #sql.Query( "SELECT * FROM house_data" ) + 1, '', '', unpack( rt ) );
  outputChatBox( '* The new house has been created successfully!', client, 255, 255, 0 );
end );
 
function createHouse( add, ID, owner, key, eX, eY, eZ, etX, etY, etZ, exX, exY, exZ, extX, extY, extZ, int, dim, cost )
  if add then
    sql.Query( "INSERT INTO house_data ( ID, en_X, en_Y, en_Z, en_tX, en_tY, en_tZ, ex_X, ex_Y, ex_Z, ex_tX, ex_tY, ex_tZ, int, dim, cost, owner, key ) VALUES ( "..ID..", "..eX..", "..eY..", "..eZ..", "..etX..", "..etY..", "..etZ..", "..exX..", "..exY..", "..exZ..", "..extX..", "..extY..", "..extZ..", "..int..", "..dim..", "..cost..", '', '' )" );
  end;
 
  local m_Enter = createMarker( eX, eY, eZ - 1, 'cylinder', 1.25, 0, 153, 255, 0 );
  greenhouse = createPickup( eX, eY, eZ,3,1273,0)
  setElementData( m_Enter, 'HS_INFO', { etX, etY, etZ, int, dim, cost, owner, key, ID } );
 
  if getElementData( m_Enter, 'HS_INFO' )[7] ~= '' then
    setMarkerColor( m_Enter, 255, 51, 36, 0 );
  end;
 
  addEventHandler( 'onMarkerHit', m_Enter, function( player )
    if getElementType( player ) == 'player' and not getPedOccupiedVehicle( player ) then
      if not getElementData( player, 'HP_Opened' ) then
        if not isGuestAccount( getPlayerAccount( player ) ) then
          setElementData( player, 'mrk_in', getElementData( source, 'HS_INFO' )[9] );
          onPlayerHouseMarkerHit( player, source, true );
          setPedFrozen( player, true );
        else
          outputChatBox( '* You must be logged in to get in this house!', player, 255, 51, 36 );
        end;
      end;
    end;
  end );
 
  addEventHandler( 'onMarkerLeave', m_Enter, function( player )
    if getElementType( player ) == 'player' and not getPedOccupiedVehicle( player ) then
      setElementData( player, 'mrk_in', nil );
    end;
  end );
 
  local m_Exit = createMarker( exX, exY, exZ - 1, 'cylinder', 1.25, 0, 153, 255, 0 );
  setElementData( m_Exit, 'parent', m_Enter );
  setElementInterior( m_Exit, int );
  setElementDimension( m_Exit, dim );
 
  setElementData( m_Exit, 'extX', extX );
  setElementData( m_Exit, 'extY', extY );
  setElementData( m_Exit, 'extZ', extZ );
 
  addEventHandler( 'onMarkerHit', m_Exit, function( player, dim )
    if getElementType( player ) == 'player' and dim then
      toggleAllControls( player, false );
      fadeCamera( player, false );
      setTimer( function( player, mrk )
        if getPedOccupiedVehicle( player ) then removePedFromVehicle( player ); end;
        local x, y, z = getElementData( mrk, 'extX' ), getElementData( mrk, 'extY' ), getElementData( mrk, 'extZ' );
        setElementPosition( player, x, y, z );
        setElementInterior( player, 0 );
        setElementDimension( player, 0 );
        toggleAllControls( player, true );
        fadeCamera( player, true );
      end, 1200, 1, player, source );
    end;
  end );
end;
 
function onPlayerHouseMarkerHit( player, mrk, cursor )
  local acc = getPlayerAccount( player );
  if isGuestAccount( acc ) then
    outputChatBox( '* You must be logged in to get in this house!', player, 255, 51, 36 );
    setElementData( player, 'mrk_in', nil );
    setPedFrozen( player, false );
    return false;
  end;
  local tts = { [1] = true, [2] = false, [3] = false, [4] = true, [5] = false, [6] = false };
  if isObjectInACLGroup( 'user.'..getAccountName( acc ), aclGetGroup( 'Admin' ) ) or hasObjectPermissionTo( player, 'function.banPlayer', false ) then
    tts[6] = true;
  end;
  local owner = getElementData( mrk, 'HS_INFO' )[7];
  local accName = getAccountName( acc );
  if owner == accName then
    tts[1] = false;
    tts[2] = true;
    tts[3] = true;
    tts[4] = true;
    tts[5] = true;
  end;
  if owner ~= accName and owner ~= '' then
    tts[1] = false;
  end;
  if owner == '' then
    if isObjectInACLGroup( 'user.'..getAccountName( acc ), aclGetGroup( 'Admin' ) ) or hasObjectPermissionTo( player, 'function.banPlayer', false ) then
      tts[4] = true;
    else
      tts[4] = false;
    end;
  end;
  tts[7] = getElementData( mrk, 'HS_INFO' )[9];
  tts[8] = getElementData( mrk, 'HS_INFO' )[7];
  tts[9] = getElementData( mrk, 'HS_INFO' )[6];
  triggerClientEvent( player, 'openHouseManagementWnd', root, tts, cursor );
end;
 
addEvent( 'HOUSE_Buy', true );
addEventHandler( 'HOUSE_Buy', root, function( cost, key )
  local accName = getAccountName( getPlayerAccount( client ) );
  local houseCounter = 0;
  for i, v in ipairs( getElementsByType( 'marker', getResourceRootElement() ) ) do
    if getElementData( v, 'HS_INFO' ) then
      local owner = getElementData( v, 'HS_INFO' )[7];
      if owner == accName then
        houseCounter = houseCounter + 1;
      end;
    end;
  end;
  if houseCounter >= tonumber( get( 'playerHouseCounter' ) ) then
    outputChatBox( '* You can not buy more than #00FF00'..get( 'playerHouseCounter' )..' house(-s)#FF3324 at the same time!', client, 255, 51, 36, true );
    setPedFrozen( client, false );
    return false;
  end;
  if getPlayerMoney( client ) >= tonumber( cost ) then
    outputChatBox( '* Key has been set to #00FF00'..key, client, 255, 51, 36, true );
    outputChatBox( '* Congratulations! You have bought a house!', client, 255, 255, 0 );
    sql.Query( "UPDATE house_data SET owner = '"..accName.."', key = '"..key.."' WHERE ID = ?", getElementData( client, 'mrk_in' ) );
    takePlayerMoney( client, cost );
    local mrk = getHouseByID( getElementData( client, 'mrk_in' ) );
    local t = {};
    for i = 1, 6 do
      t[i] = getElementData( mrk, 'HS_INFO' )[i];
    end;
    t[7] = accName;
    t[8] = key;
    t[9] = getElementData( client, 'mrk_in' );
    setElementData( mrk, 'HS_INFO', { t[1], t[2], t[3], t[4], t[5], t[6], t[7], t[8], t[9] } );
    setMarkerColor( mrk, 255, 51, 36, 0 );
    destroyElement(greenhouse);
    destroyElement(bluehouse);
    bluehouse = createPickup(  t[1], t[2], t[3],3,1272,0);
    setTimer( onPlayerHouseMarkerHit, 50, 1, client, mrk, true );
  else
    outputChatBox( '* You do not have enough money!', client, 255, 51, 36 );
    onPlayerHouseMarkerHit( client, getHouseByID( getElementData( client, 'mrk_in' ) ), true );
  end;
end );
 
addEvent( 'HOUSE_Sell', true );
addEventHandler( 'HOUSE_Sell', root, function()
  sql.Query( "UPDATE house_data SET owner = '', key = '' WHERE ID = ?", getElementData( client, 'mrk_in' ) );
    local mrk = getHouseByID( getElementData( client, 'mrk_in' ) );
    givePlayerMoney( client, getElementData( mrk, 'HS_INFO' )[6] / 2 );
    local t = {};
    for i = 1, 6 do
      t[i] = getElementData( mrk, 'HS_INFO' )[i];
    end;
    t[7] = '';
    t[8] = '';
    t[9] = getElementData( client, 'mrk_in' );
    setElementData( mrk, 'HS_INFO', { t[1], t[2], t[3], t[4], t[5], t[6], t[7], t[8], t[9] } );
    setMarkerColor( mrk, 0, 153, 255, 0 );
    destroyElement(greenhouse);
    destroyElement(bluehouse);
    greenhouse = createPickup(  t[1], t[2], t[3],3,1273,0);
    setTimer( onPlayerHouseMarkerHit, 50, 1, client, mrk, false );
  end
);
 
addEvent( 'HOUSE_Enter', true );
addEventHandler( 'HOUSE_Enter', root, function()
  setPedFrozen( client, false );
  local mrk = getHouseByID( getElementData( client, 'mrk_in' ) );
  local t = {};
  for i = 1, 5 do
    t[i] = getElementData( mrk, 'HS_INFO' )[i];
  end;
  fadeCamera( client, false );
  toggleAllControls( client, false );
  setTimer( function( player, t )
    if getPedOccupiedVehicle( player ) then removePedFromVehicle( player ); end;
    setElementInterior( player, t[4], t[1], t[2], t[3] );
    setElementDimension( player, t[5] );
    toggleAllControls( player, true );
    fadeCamera( player, true );
    setElementData( player, 'mrk_in', nil )
  end, 1200, 1, client, t );
end );
 
addEvent( 'HOUSE_ChangeKey', true );
addEventHandler( 'HOUSE_ChangeKey', root, function( newKey )
  local mrk = getHouseByID( getElementData( client, 'mrk_in' ) );
  sql.Query( "UPDATE house_data SET key = '"..newKey.."' WHERE ID = ?", getElementData( client, 'mrk_in' ) );
  local t = {};
  for i = 1, 6 do
    t[i] = getElementData( mrk, 'HS_INFO' )[i];
  end;
  t[7] = getAccountName( getPlayerAccount( client ) );
  t[8] = newKey;
  t[9] = getElementData( client, 'mrk_in' );
  setElementData( mrk, 'HS_INFO', { t[1], t[2], t[3], t[4], t[5], t[6], t[7], t[8], t[9] } );
end );
 
Edited by Guest
Link to comment
You are assigning the same variable to every pickup.

Now i'd assume this would work

    bluehouse = createPickup( eX, eY, eZ,3,1272,0); 
    destroyElement(greenhouse); 

Creating a bluehouse and destroying the greenhouse?

And it also doesn't recognise eX, eY, eZ when that variable already exists when you create the house

Edited by Guest
Link to comment
dude why are you doing ";"?

It's mostly used to indicate where a block of code ends, but since Lua is a slightly different language - it's not necessary like it is in other languages such as C++.

I think it's good practice to do it anyway in case you'll find yourself doing some C++ later since missing a semi-colon or putting it in the wrong place can break your entire thing.

Link to comment
try to change this : bluehouse = createPickup( eX, eY, eZ,3,1272,0);

to this:

  
bluehouse = createPickup( t[1], t[2], t[3],3,1272,0); 
  

I tried this, everything works except t[1], t[2], t[3] are the teleport locations inside the interior

Is there a way i can attach the house icons to the marker or just make a whole new function to place them in the same postion as the marker

Original marker created here:

function createHouse( add, ID, owner, key, eX, eY, eZ, etX, etY, etZ, exX, exY, exZ, extX, extY, extZ, int, dim, cost ) 
  if add then 
    sql.Query( "INSERT INTO house_data ( ID, en_X, en_Y, en_Z, en_tX, en_tY, en_tZ, ex_X, ex_Y, ex_Z, ex_tX, ex_tY, ex_tZ, int, dim, cost, owner, key ) VALUES ( "..ID..", "..eX..", "..eY..", "..eZ..", "..etX..", "..etY..", "..etZ..", "..exX..", "..exY..", "..exZ..", "..extX..", "..extY..", "..extZ..", "..int..", "..dim..", "..cost..", '', '' )" ); 
  end; 
   
  local m_Enter = createMarker( eX, eY, eZ - 1, 'cylinder', 1.25, 0, 153, 255, 0 ); 
  greenhouse = createPickup( eX, eY, eZ,3,1273,0) 
  setElementData( m_Enter, 'HS_INFO', { etX, etY, etZ, int, dim, cost, owner, key, ID } ); 

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