Jump to content

[HELP] Boat doesn't get spawned when I get in marker


selam

Recommended Posts

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 by selam
Link to comment
  • Moderators
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
  • Moderators
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

@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 by selam
Link to comment
  • Moderators
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
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 by selam
Link to comment
  • Moderators
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
  • Moderators
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

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