Zuher Laith Posted November 1, 2017 Share Posted November 1, 2017 Hi .. I've made a vending machine mod and I'm trying to make it shows up on marker in XML design, I already took an example of what I need, the bank_system has one what I did is copying the xml server file in that mod and edit it to make it right, well its confusing to me because I'm new at this, Spoiler Client side: g_localPlayer = getLocalPlayer() function show_theWindow() showCursor( true ) guiSetVisible( Bar.Window, true ) guiBringToFront( Bar.Window ); guiSetInputEnabled( true ) end addEvent( "bar_showWnd", true ) addEventHandler( "bar_showWnd", g_localPlayer, show_theWindow ) function hide_theWindow( ) guiSetVisible( Bar.Window, false ) showCursor( false ) guiSetInputEnabled( false ) end addEvent( "bar_hideWnd", true ) addEventHandler( "bar_hideWnd", g_localPlayer, hide_theWindow ) Server side: function playerEnterMarker( marker ) if ( not isPedOnGround ( source ) ) or ( doesPedHaveJetPack ( source ) ) or ( isPedInVehicle ( source ) ) or ( getControlState ( source, "aim_weapon" ) ) then return end for k, v in pairs( banksInfo ) do if marker == banksInfo[ k ].marker then local triggered = triggerEvent( "onPlayerEnterBank", source, banksInfo[ k ].marker, banksInfo[ k ].ATM ) if triggered then setControlState( source, "forwards", false ) setControlState( source, "backwards", false ) setControlState( source, "left", false ) setControlState( source, "right", false ) --outputChatBox( tostring( playersAccount[ source ].balance ) ); local try = triggerClientEvent( source, "bar_showWnd", source, playersAccount[ source ]:accountname(), tostring( playersAccount[ source ].balance ), banksInfo[ k ].name, banksInfo[ k ].marker, banksInfo[ k ].depositAllowed ) if not try then setTimer( triggerClientEvent, 100, 1, source, "bar_showWnd", source, playersAccount[ source ]:accountname(), tostring( playersAccount[ source ].balance ), banksInfo[ k ].name, banksInfo[ k ].marker, banksInfo[ k ].depositAllowed ) end playerInMarker[ source ] = marker end break elseif banksInfo[ k ].entrance and marker == banksInfo[ k ].entrance.marker then fadeCamera( source, false, 1 ) setTimer( setElementInterior, 1100, 1, source, banksInfo[ k ].entrance.teleInterior, banksInfo[ k ].entrance.teleX, banksInfo[ k ].entrance.teleY, banksInfo[ k ].entrance.teleZ ) --setTimer( setPedRotation, 1100, 1, source, 90 ) setTimer( setPedRotation, 1100, 1, source, 90 ) setTimer( fadeCamera, 1100, 1, source, true, 1 ) setTimer( setCameraTarget, 1150, 1, source ); break elseif banksInfo[ k ]._exit and marker == banksInfo[ k ]._exit.marker then fadeCamera( source, false, 1 ) setTimer( setElementInterior, 1100, 1, source, banksInfo[ k ]._exit.teleInterior, banksInfo[ k ]._exit.teleX, banksInfo[ k ]._exit.teleY, banksInfo[ k ]._exit.teleZ ) --setTimer( setPedRotation, 1100, 1, setTimer( setPedRotation, 1100, 1, source, banksInfo[ k ]._exit.teleRot ) setTimer( fadeCamera, 1100, 1, source, true, 1 ) setTimer( setCameraTarget, 1150, 1, source ); break end end end addEventHandler( "onPlayerMarkerHit", root, playerEnterMarker ) function playerLeaveWindow( marker ) if playerInMarker[ source ] then for k, v in ipairs( banksInfo ) do if marker == banksInfo[ k ].marker then triggerEvent( "onPlayerLeaveBank", source, marker, banksInfo[ k ].ATM ) triggerClientEvent( source, "bar_hideWnd", source ) playerInMarker[ source ] = false break end end end end addEventHandler( "onPlayerMarkerLeave", root, playerLeaveWindow ) Xml server: --[[ Resource: bank (written by 50p) Version: 2.3 Filename: bank.xml.server.lua ]] banksInfo = { } function bankInit( ) local xml_root = xmlLoadFile( "bar.locations.xml" ) local banks = 0 while( xmlFindChild( xml_root, "bank", banks ) ) do local markerSize local tempID = banks+1 banksInfo[ tempID ] = { } local bank_node = xmlFindChild( xml_root, "bank", banks ) banksInfo[ tempID ].name = xmlNodeGetAttribute( bank_node, "name" ) banksInfo[ tempID ].useBlip = xmlNodeGetAttribute( bank_node, "blip" ) or true local bank_loc = xmlFindChild( bank_node, "location", 0 ) banksInfo[ tempID ].posX = tonumber( xmlNodeGetAttribute( bank_loc, "posX" ) ) banksInfo[ tempID ].posY = tonumber( xmlNodeGetAttribute( bank_loc, "posY" ) ) banksInfo[ tempID ].posZ = tonumber( xmlNodeGetAttribute( bank_loc, "posZ" ) ) banksInfo[ tempID ].interior = tonumber( xmlNodeGetAttribute( bank_loc, "interior" ) ) or 0; markerSize = tonumber( xmlNodeGetAttribute( bank_loc, "markerSize" ) ) or 2 banksInfo[ tempID ].marker = createMarker( banksInfo[ tempID ].posX, banksInfo[ tempID ].posY, banksInfo[ tempID ].posZ-.9, "cylinder", markerSize, 250, 0, 0, 100 ) setElementInterior( banksInfo[ tempID ].marker, banksInfo[ tempID ].interior ); if xmlNodeGetAttribute( bank_loc, "ATM" ) == "true" then local rot = tonumber( xmlNodeGetAttribute( bank_loc, "ATMRot" ) ) or 0.0 local x, y, z = banksInfo[ tempID ].posX, banksInfo[ tempID ].posY, banksInfo[ tempID ].posZ x = x + math.sin( math.rad( rot ) ) * .6 y = y + math.cos( math.rad( rot ) ) * .6 banksInfo[ tempID ].ATM = createObject( 2942, x, y, z-.35, 0, 0, (360-rot) ) setElementInterior( banksInfo[ tempID ].ATM, tonumber( xmlNodeGetAttribute( bank_loc, "interior" ) ) or 0 ) setElementParent( banksInfo[ tempID ].ATM, banksInfo[ tempID ].marker ) end -- more options if xmlFindChild( bank_node, "entrance", 0 ) then banksInfo[ tempID ].entrance = { } local entrance_node = xmlFindChild( bank_node, "entrance", 0 ) banksInfo[ tempID ].entrance.posX = xmlNodeGetAttribute( entrance_node, "posX" ) banksInfo[ tempID ].entrance.posY = xmlNodeGetAttribute( entrance_node, "posY" ) banksInfo[ tempID ].entrance.posZ = xmlNodeGetAttribute( entrance_node, "posZ" ) banksInfo[ tempID ].entrance.interior = tonumber( xmlNodeGetAttribute( entrance_node, "interior" ) ) or 0; banksInfo[ tempID ].entrance.teleX = xmlNodeGetAttribute( entrance_node, "teleX" ) banksInfo[ tempID ].entrance.teleY = xmlNodeGetAttribute( entrance_node, "teleY" ) banksInfo[ tempID ].entrance.teleZ = xmlNodeGetAttribute( entrance_node, "teleZ" ) banksInfo[ tempID ].entrance.teleRot = xmlNodeGetAttribute( entrance_node, "teleRot" ) banksInfo[ tempID ].entrance.teleInterior = xmlNodeGetAttribute( entrance_node, "teleInterior" ) banksInfo[ tempID ].entrance.marker = createMarker( banksInfo[ tempID ].entrance.posX, banksInfo[ tempID ].entrance.posY, banksInfo[ tempID ].entrance.posZ-1, "cylinder", 1.5, 250, 250, 0, 100 ) --local blip = createBlipAttachedTo( banksInfo[ tempID ].entrance.marker, 52 ) local col = createColTube( banksInfo[ tempID ].entrance.posX, banksInfo[ tempID ].entrance.posY, banksInfo[ tempID ].entrance.posZ-180, 150, 360 ) setElementParent( banksInfo[ tempID ].entrance.marker, col ) setElementInterior( banksInfo[ tempID ].entrance.marker, banksInfo[ tempID ].entrance.interior ); elseif ( type( banksInfo[ tempID ].useBlip ) == "boolean" and banksInfo[ tempID ].useBlip == true ) or ( type( banksInfo[ tempID ].useBlip ) == "string" and banksInfo[ tempID ].useBlip == "true" ) then local col = createColTube( banksInfo[ tempID ].posX, banksInfo[ tempID ].posY, banksInfo[ tempID ].posZ-180, 150, 360 ) setElementParent( banksInfo[ tempID ].marker, col ) end if xmlFindChild( bank_node, "exit", 0 ) and banksInfo[ tempID ].entrance then banksInfo[ tempID ]._exit = { } local exit_node = xmlFindChild( bank_node, "exit", 0 ) banksInfo[ tempID ]._exit.posX = xmlNodeGetAttribute( exit_node, "posX" ) banksInfo[ tempID ]._exit.posY = xmlNodeGetAttribute( exit_node, "posY" ) banksInfo[ tempID ]._exit.posZ = xmlNodeGetAttribute( exit_node, "posZ" ) banksInfo[ tempID ]._exit.interior = tonumber( xmlNodeGetAttribute( exit_node, "interior" ) ) or 0; banksInfo[ tempID ]._exit.teleX = xmlNodeGetAttribute( exit_node, "teleX" ) banksInfo[ tempID ]._exit.teleY = xmlNodeGetAttribute( exit_node, "teleY" ) banksInfo[ tempID ]._exit.teleZ = xmlNodeGetAttribute( exit_node, "teleZ" ) banksInfo[ tempID ]._exit.teleRot = xmlNodeGetAttribute( exit_node, "teleRot" ) banksInfo[ tempID ]._exit.teleInterior = xmlNodeGetAttribute( exit_node, "teleInterior" ) banksInfo[ tempID ]._exit.marker = createMarker( banksInfo[ tempID ]._exit.posX, banksInfo[ tempID ]._exit.posY, banksInfo[ tempID ]._exit.posZ-1, "cylinder", 1.5, 250, 250, 0, 100 ) setElementInterior( banksInfo[ tempID ]._exit.marker, banksInfo[ tempID ]._exit.interior ); end banks = banks + 1 end end The XML itself: <banks> <bank name="Western Onion" blip="true"> <location posX="361.8298" posY="173.6187" posZ="1008.3828" ATM="false" ATMRot="0.0" interior="3" /> <entrance posX="2412.7126" posY="1123.8426" posZ="10.8203" teleX="387.8428" teleY="173.6187" teleZ="1008.3828" teleRot="90" teleInterior="3" /> <exit posX="389.8428" posY="173.6187" posZ="1008.3828" teleX="2414.7126" teleY="1123.0426" teleZ="10.8203" teleRot="270" teleInterior="0" interior="3" /> </bank> <bank name="Western Onion ATM #1" blip="true" > <location posX="360.07577514648" posY="188.58430175781" posZ="1008.3828125" ATM="true" interior="3" ATMRot="0.0" markerSize="1" /> </bank> <bank name="Western Onion ATM #2" blip="true" ATMInterior="3" > <location posX="364.07577514648" posY="188.58430175781" posZ="1008.3828125" ATM="true" interior="3" ATMRot="0.0" markerSize="1" /> </bank> <!-- <bank name="Bank name here" blip="true" > <location posX="0.0" posY="0.0" posZ="0.0" ATM="false" ATMRot="0.0" markerSize="2" interior="0" /> <entrance posX="0.0" posY="0.0" posZ="0.0" teleX="0.0" teleY="0.0" teleZ="0.0" teleRot="0.0" teleInterior="0" /> <exit posX="0.0" posY="0.0" posZ="0.0" teleX="0.0" teleY="0.0" teleZ="0.0" teleRot="0.0" teleInterior="0" interior="0" /> </bank> --> </banks> I pasted the whole code just in case, The problem is might be in Xmlserver.lua, exactly right here: function bankInit( ) local xml_root = xmlLoadFile( "bar.locations.xml" ) local banks = 0 while( xmlFindChild( xml_root, "bank", banks ) ) do local markerSize local tempID = banks+1 banksInfo[ tempID ] = { } local bank_node = xmlFindChild( xml_root, "bank", banks ) banksInfo[ tempID ].name = xmlNodeGetAttribute( bank_node, "name" ) banksInfo[ tempID ].useBlip = xmlNodeGetAttribute( bank_node, "blip" ) or true local bank_loc = xmlFindChild( bank_node, "location", 0 ) banksInfo[ tempID ].posX = tonumber( xmlNodeGetAttribute( bank_loc, "posX" ) ) banksInfo[ tempID ].posY = tonumber( xmlNodeGetAttribute( bank_loc, "posY" ) ) banksInfo[ tempID ].posZ = tonumber( xmlNodeGetAttribute( bank_loc, "posZ" ) ) banksInfo[ tempID ].interior = tonumber( xmlNodeGetAttribute( bank_loc, "interior" ) ) or 0; markerSize = tonumber( xmlNodeGetAttribute( bank_loc, "markerSize" ) ) or 2 banksInfo[ tempID ].marker = createMarker( banksInfo[ tempID ].posX, banksInfo[ tempID ].posY, banksInfo[ tempID ].posZ-.9, "cylinder", markerSize, 250, 0, 0, 100 ) setElementInterior( banksInfo[ tempID ].marker, banksInfo[ tempID ].interior ); if xmlNodeGetAttribute( bank_loc, "ATM" ) == "true" then local rot = tonumber( xmlNodeGetAttribute( bank_loc, "ATMRot" ) ) or 0.0 local x, y, z = banksInfo[ tempID ].posX, banksInfo[ tempID ].posY, banksInfo[ tempID ].posZ x = x + math.sin( math.rad( rot ) ) * .6 y = y + math.cos( math.rad( rot ) ) * .6 banksInfo[ tempID ].ATM = createObject( 2942, x, y, z-.35, 0, 0, (360-rot) ) setElementInterior( banksInfo[ tempID ].ATM, tonumber( xmlNodeGetAttribute( bank_loc, "interior" ) ) or 0 ) setElementParent( banksInfo[ tempID ].ATM, banksInfo[ tempID ].marker ) end banks = banks + 1 end <banks> <bank name="Western Onion ATM" > <location posX="2630.6667480469" posY="1655.393046875" posZ="11.0234375" ATM="true" interior="0" ATMRot="180.0" markerSize="1" /> </bank> </banks> I did a few small edits to make it work, but I actually can't detect the problem and why this is not working, Any help is appreciated . Link to comment
Zuher Laith Posted November 2, 2017 Author Share Posted November 2, 2017 Up .. anyone ? Link to comment
quindo Posted November 2, 2017 Share Posted November 2, 2017 Do you get any errors when you enable /debugscript 3 ? Link to comment
Zuher Laith Posted November 2, 2017 Author Share Posted November 2, 2017 (edited) 1 hour ago, quindo said: Do you get any errors when you enable /debugscript 3 ? No I'm not getting any errors, Its like the code is not running, but everything else in code works . but at first, the objects in map doesn't show up, so its possible the problem is from Xmlserver.lua Edited November 2, 2017 by Zuher Laith Link to comment
Moderators IIYAMA Posted November 2, 2017 Moderators Share Posted November 2, 2017 Please start active debugging your code if viewing errors/warnings isn't enough. Link to comment
Zuher Laith Posted November 2, 2017 Author Share Posted November 2, 2017 (edited) 1 hour ago, IIYAMA said: Please start active debugging your code if viewing errors/warnings isn't enough. It shocked me when the "bankInit" function in Xmlserver.lua was not running at all, so I did the following: -- client.lua: addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource( ) ), function( ) triggerServerEvent( "bankInit", resourceRoot ); end ) -- Xmlserver.lua: function bankInit () -- code and stuff end addEvent( "bankInit", true ) addEventHandler( "bankInit", resourceRoot, bankInit ) and the code worked correctly !, but still.. I'm having a problem with hiding the cursor from client.lua when the onPlayerMarkerLeave event in server side (which is the solution for the problem) Spoiler -- server.lua : function playerEnterMarker( marker ) if ( not isPedOnGround ( source ) ) or ( doesPedHaveJetPack ( source ) ) or ( isPedInVehicle ( source ) ) or ( getControlState ( source, "aim_weapon" ) ) then return end for k, v in pairs( banksInfo ) do if marker == banksInfo[ k ].marker then local triggered = triggerEvent( "onPlayerEnterBank", source, banksInfo[ k ].marker, banksInfo[ k ].ATM ) if triggered then setControlState( source, "forwards", false ) setControlState( source, "backwards", false ) setControlState( source, "left", false ) setControlState( source, "right", false ) local try = triggerClientEvent( source, "bar_showWnd", source ) if not try then setTimer( triggerClientEvent, 100, 1, source, "bar_showWnd", source ) end playerInMarker[ source ] = marker end break elseif banksInfo[ k ].entrance and marker == banksInfo[ k ].entrance.marker then fadeCamera( source, false, 1 ) setTimer( setElementInterior, 1100, 1, source, banksInfo[ k ].entrance.teleInterior, banksInfo[ k ].entrance.teleX, banksInfo[ k ].entrance.teleY, banksInfo[ k ].entrance.teleZ ) --setTimer( setPedRotation, 1100, 1, source, 90 ) setTimer( setPedRotation, 1100, 1, source, 90 ) setTimer( fadeCamera, 1100, 1, source, true, 1 ) setTimer( setCameraTarget, 1150, 1, source ); break elseif banksInfo[ k ]._exit and marker == banksInfo[ k ]._exit.marker then fadeCamera( source, false, 1 ) setTimer( setElementInterior, 1100, 1, source, banksInfo[ k ]._exit.teleInterior, banksInfo[ k ]._exit.teleX, banksInfo[ k ]._exit.teleY, banksInfo[ k ]._exit.teleZ ) --setTimer( setPedRotation, 1100, 1, setTimer( setPedRotation, 1100, 1, source, banksInfo[ k ]._exit.teleRot ) setTimer( fadeCamera, 1100, 1, source, true, 1 ) setTimer( setCameraTarget, 1150, 1, source ); break end end end addEventHandler( "onPlayerMarkerHit", root, playerEnterMarker ) function playerLeaveBank( marker ) if playerInMarker[ source ] then for k, v in ipairs( banksInfo ) do if marker == banksInfo[ k ].marker then triggerEvent( "onPlayerLeaveBank", source, marker, banksInfo[ k ].ATM ) triggerClientEvent( source, "bar_hideWnd", source ) playerInMarker[ source ] = false break end end end end addEventHandler( "onPlayerMarkerLeave", root, playerLeaveBank ) I need to trigger "playerLeaveBank" event from the client side, because If I make showCursor (false) in client side, it won't work for some unknown reason .. but this function make it work . Edited November 2, 2017 by Zuher Laith Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now