selam Posted January 25, 2020 Share Posted January 25, 2020 (edited) Hello, the boat doesn't get spawned when I get in the marker, nothing happens. Someone please help me. Code; Spoiler function buyFish(satinAlim) local money = getPlayerMoney(localPlayer) if (money >= 300) then triggerServerEvent("buyFish", resourceRoot) outputChatBox("You have bought a fish food.") takePlayerMoney( 300 ) marker2 = createMarker (1631.6253662109, 576.00537109375, 0.7578125, "cylinder", 1.2, 600, 600, 900, 1000 ) else outputChatBox("You do not have enough amount of money.") end end addEventHandler("onClientMarkerHit", marker2, botGetir) function botGetir(botdeniz) botarac = createVehicle(473, 1633.3326416016, 563.24768066406, -0.55000001192093) end Edited January 25, 2020 by selam Link to comment
Moderators IIYAMA Posted January 25, 2020 Moderators Share Posted January 25, 2020 32 minutes ago, selam said: nothing happens Attaching a non existing marker to an addEventHandler. You would have received an error of that... local markerParent = createElement("marker-parent") --[[ markerParent = parent marker = child marker = child marker = child addEventHandler listening to: markerParent marker marker marker ]] function buyFish(satinAlim) local money = getPlayerMoney(localPlayer) if (money >= 300) then triggerServerEvent("buyFish", resourceRoot) outputChatBox("You have bought a fish food.") takePlayerMoney( 300 ) local marker2 = createMarker (1631.6253662109, 576.00537109375, 0.7578125, "cylinder", 1.2, 600, 600, 900, 1000 ) setElementParent(marker2, markerParent) else outputChatBox("You do not have enough amount of money.") end end function botGetir(botdeniz) botarac = createVehicle(473, 1633.3326416016, 563.24768066406, -0.55000001192093) end addEventHandler("onClientMarkerHit", markerParent, botGetir) Link to comment
selam Posted January 25, 2020 Author Share Posted January 25, 2020 @IIYAMA Thanks, it worked. 1 Link to comment
selam Posted January 26, 2020 Author Share Posted January 26, 2020 @IIYAMA Hello, when I spawn a boat or a random vehicle, they are spawning as two. And I cannot get in the vehicles, why? Link to comment
Moderators IIYAMA Posted January 26, 2020 Moderators Share Posted January 26, 2020 24 minutes ago, selam said: And I cannot get in the vehicles, Because you created them clientside. They are not synchronised with serverside, therefore it would cause desync if you could drive them. To solve that, create the vehicle serverside. 26 minutes ago, selam said: they are spawning as two. You probably hit the marker while driving a vehicle? The event is triggered for the vehicle as well as the player. To solve that, check if the hit element is the localPlayer. if botdeniz == localPlayer then end Link to comment
selam Posted January 26, 2020 Author Share Posted January 26, 2020 (edited) @IIYAMA I added "createvehicle" in serverside but still same, I cannot drive boat. Also I am having this error since long time, maybe it has something to do with it? "Error client selam triggered serverside event buyFish but event is not added serverside" Edited January 26, 2020 by selam Link to comment
Moderators IIYAMA Posted January 26, 2020 Moderators Share Posted January 26, 2020 21 minutes ago, selam said: @IIYAMA I added "createvehicle" in serverside but still same, I cannot drive boat. Also I am having this error since long time, maybe it has something to do with it? "Error client selam triggered serverside event buyFish but event is not added serverside" It looks like your serverside script is running clientside. So yes those are probably related. Link to comment
selam Posted January 27, 2020 Author Share Posted January 27, 2020 (edited) 13 hours ago, IIYAMA said: It looks like your serverside script is running clientside. So yes those are probably related. So now I changed the "triggerserverevent" command to "triggerevent" as it is client side. Now I am not getting the error I said above. But I still cannot drive vehicles. (createvehicle is on server side still) Full code; local markerParent = createElement("marker-parent") --[[ markerParent = parent marker = child marker = child marker = child addEventHandler listening to: markerParent marker marker marker ]] function buyFish(satinAlim) local money = getPlayerMoney(localPlayer) if (money >= 300) then triggerEvent("buyFish", resourceRoot) outputChatBox("You have bought a fish food.") takePlayerMoney( 300 ) local marker2 = createMarker (1631.6253662109, 576.00537109375, 0.7578125, "cylinder", 1.2, 600, 600, 900, 1000 ) setElementParent(marker2, markerParent) else outputChatBox("You do not have enough amount of money.") end end function botGetir(botdeniz) botarac = createVehicle(473, 1633.3326416016, 563.24768066406, -0.55000001192093) -- server end addEventHandler("onClientMarkerHit", markerParent, botGetir) -- 473, 1633.3326416016, 563.24768066406, -0.55000001192093 Edited January 27, 2020 by selam Link to comment
Moderators IIYAMA Posted January 27, 2020 Moderators Share Posted January 27, 2020 1 hour ago, selam said: But I still cannot drive vehicles. How are you even creating that vehicle when the event "onClientMarketHit" only triggers clientside? If you used that code serverside, there wouldn't be any vehicle in the first place. Link to comment
selam Posted January 30, 2020 Author Share Posted January 30, 2020 @IIYAMA I still didn't fix it, do you know the solution? Link to comment
Moderators IIYAMA Posted January 30, 2020 Moderators Share Posted January 30, 2020 3 hours ago, selam said: @IIYAMA I still didn't fix it, do you know the solution? Show me your meta.xml Link to comment
selam Posted January 30, 2020 Author Share Posted January 30, 2020 3 hours ago, IIYAMA said: Show me your meta.xml I have fish.Lua file and meta.xml meta.xml; <meta> <script src="fish.Lua" type="client"/> <script src="fish.Lua" type="server"/> </meta> Link to comment
Moderators IIYAMA Posted January 30, 2020 Moderators Share Posted January 30, 2020 10 minutes ago, selam said: I have fish.Lua file and meta.xml meta.xml; <meta> <script src="fish.Lua" type="client"/> <script src="fish.Lua" type="server"/> </meta> You are now loading the fish script 2x. 1 version serverside and 1 version clientside. That is not going to work. You need to separate those sides. So: 1 script/file serverside, with serverside code. (Running in the server application) 1 script/file clientside, with clientside code. (Running on each player his computer in the MTA game itself) 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