Jump to content

truck = createvehicle(...)


DexoTronic

Recommended Posts

Posted

Hi,

i create a vehicle with truck = createvehicle (..).

now in OnPlayerEnterVehicle

i want to check if player enters the "truck".

is it possible in mta? in the wiki it can only make a diffenrence between the vehicle ids.

i didnt find a example in the net. please help me

Posted

simple enough:

truck = createVehicle( ... )
addEventHandler( 'onPlayerVehicleEnter', getRootElement(),
function( theVehicle, seat )
if theVehicle == truck then  --if variable 'truck' is the vehicle, that somebody has got in
outputChatBox( 'You have got into the truck :D', source, 0, 255, 0 )
end
end
)

Posted

i use the ID 455 as a truck it hasnt a trailer ;)

next question:

if i enter the maker TruckerStartMarker it should make an chat output:

function starttruckmission_func ()
 
TruckerStartMarker = createMarker (-360.84088134766, 1190.403076171, 18.342208862305, "cylinder", 6, 255, 0, 0, 150 )
TruckerEndeMarker = createMarker (834.25341796875, 866.51782226563, 11.092173576355, "cylinder", 6, 255, 0, 0, 150 )
 
end
addEvent ( "starttruckmission", true )
addEventHandler ( "starttruckmission", getRootElement(), starttruckmission_func )
 
function MarkerHit( hitElement, matchingDimension )
if hitElement==getLocalPlayer() then
	outputChatBox( "in the marker TruckerStartMarker" )
end
end
addEventHandler( "onClientMarkerHit", TruckerStartMarker, MarkerHit )

function starttruckmission_func () works, it creates the marker after the server calls that function. but it doesnt react if i enter this marker :/

Posted

the element which hits the marker is probably the truck, not the player

function starttruckmission_func ()
 
TruckerStartMarker = createMarker (-360.84088134766, 1190.403076171, 18.342208862305, "cylinder", 6, 255, 0, 0, 150 )
TruckerEndeMarker = createMarker (834.25341796875, 866.51782226563, 11.092173576355, "cylinder", 6, 255, 0, 0, 150 )
 
end
addEvent ( "starttruckmission", true )
addEventHandler ( "starttruckmission", getRootElement(), starttruckmission_func )
 
function MarkerHit( hitElement, matchingDimension )
if hitElement==getPedOccupiedVehicle(getLocalPlayer()) then -- the vehicle of the local player
outputChatBox( "in the marker TruckerStartMarker" )
end
end
addEventHandler( "onClientMarkerHit", TruckerStartMarker, MarkerHit )

Posted

yes its clientside.

here i call the starttruckmission_func:

Server script:

function enterVehicle ( theVehicle, seat, jacked )

if ( theVehicle == truck) then

if ( PlayerJob[source] == 2 ) then

triggerClientEvent( source, "starttruckmission", getRootElement())

else

removePedFromVehicle ( source )

outputChatBox( "Trucker: Nur unsere Angestellten können dieses Fahrzeug benutzen!", source, 255, 0, 0 )

end

end

end

and its works... the markers are created after entering "truck".

but if i enter the marker nothing happens

addEventHandler ( "onPlayerVehicleEnter", getRootElement(), enterVehicle )

Posted

I got a question what is this line? what it checks, i mean where is the truck called "truck"?

if ( theVehicle == truck) then

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
truck = createVehicle( 455, -138.103515625, 1084.078125, 20.312187194824)

i dont get what you mean^^

i mean that line wasnt in code, im wrong?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

it doesnt matter if the player is in the truck or not.

for example this code works:

function MarkerHit( hitElement, matchingDimension )
if hitElement==getLocalPlayer() then
	guiSetVisible ( TruckWindow , true )
	guiBringToFront ( TruckWindow )
	showCursor ( true )
end
end
addEventHandler( "onClientMarkerHit", TruckMarker, MarkerHit )

this doesnt work:

function MarkerHit( hitElement, matchingDimension )
if hitElement== getLocalPlayer() then
	outputChatBox( "in the marker TruckerStartMarker" )
end
end
addEventHandler( "onClientMarkerHit", TruckerStartMarker, MarkerHit )

and i dont get why

Posted

ok, i fixed your code now it works i ve tested it 10 times, here is code:

client-side

function starttruckmission_func ()
  TruckerStartMarker = createMarker (-360.84088134766, 1190.403076171, 18.342208862305, "cylinder", 6, 255, 0, 0, 150 )
  TruckerEndeMarker = createMarker (834.25341796875, 866.51782226563, 11.092173576355, "cylinder", 6, 255, 0, 0, 150 )
end
addEvent ( "starttruckmission", true )
addEventHandler ( "starttruckmission", getRootElement(), starttruckmission_func )
 
function MarkerHit( hitElement, matchingDimension )
if hitElement== getLocalPlayer() then
outputChatBox( "in the marker TruckerStartMarker" )
end
end
addEventHandler( "onClientMarkerHit", getRootElement(), MarkerHit )

server-side

truck = createVehicle( 455, -138.103515625, 1084.078125, 20.312187194824)
addEventHandler( 'onPlayerVehicleEnter', getRootElement(),
function ( theVehicle, seat, jacked )
if ( theVehicle == truck) then
if ( PlayerJob[source] == 2 ) then
triggerClientEvent( source, "starttruckmission", getRootElement())
else
removePedFromVehicle ( source )
outputChatBox( "Trucker: Nur unsere Angestellten können dieses Fahrzeug benutzen!", source, 255, 0, 0 )
end
end
end)

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
yes it works.... xD

but it should only react if im in "TruckerStartMarker".

your version reacts in all markers :P

well i think this event is only server-side:

addEventHandler( "onMarkerHit", TruckerStartMarker, MarkerHit )

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

ok.. i have now:

function MarkerHit( hitElement, matchingDimension )
if hitElement== source then
	outputChatBox( "in the marker TruckerStartMarker" )
end
end
addEventHandler( "onMarkerHit", TruckerStartMarker, MarkerHit )

in the server script. but it reacts at all markes again :/

EDIT:

Here whole client script...:

TruckWindow = guiCreateWindow(389,354,497,222,"",false)
guiSetAlpha(TruckWindow ,1)
TruckMann  = guiCreateStaticImage(11,24,112,136,"images/truck.jpg",false,TruckWindow )
guiSetAlpha(TruckMann  ,1)
TruckText = guiCreateLabel(130,28,346,130,"Willkommen bei unserer Spedition.\nDu verdienst ihr Geld,\nindem du Waren von A nach B transportierst.\nWenn du willst kannst du gleich loslegen,\nwir suchen noch Leute.\nAlles was du brauchst ist ein Fuehrerschein.",false,TruckWindow )
guiSetAlpha(TruckText ,1)
guiLabelSetColor(TruckText ,255,120,0)
guiLabelSetVerticalAlign(TruckText ,"top")
guiLabelSetHorizontalAlign(TruckText ,"left",false)
TruckAnnehmenBtn = guiCreateButton(9,171,243,42,"Job annehmen",false,TruckWindow )
guiSetAlpha(TruckAnnehmenBtn ,1)
TruckAblehnenBtn = guiCreateButton(255,171,233,42,"Job ablehnen/kuendigen",false,TruckWindow )
guiSetAlpha(TruckAblehnenBtn ,1)
guiSetVisible ( TruckWindow , false )
 
 
 
 
local TruckMarker = createMarker( -144.73950195313, 1078.8743896484, 19.492191314697, 'cylinder', 1.0, 255, 0, 0, 150 )
function TruckMarkerHit( hitElement, matchingDimension )
if hitElement==getLocalPlayer() and matchingDimension==true then
	if source==TruckerStartMarker then
		guiSetVisible ( TruckWindow , true )
		guiBringToFront ( TruckWindow )
		showCursor ( true )
	end
end
end
addEventHandler( "onClientMarkerHit", TruckMarker, TruckMarkerHit )
local localPlayer = getLocalPlayer ( )
 
--function windowHandler( )
--	guiSetVisible ( TruckWindow , true )
--	guiBringToFront ( TruckWindow )
--	showCursor ( true )
--end
 
function onClickBtn ( button, state )
if (button == "left" and state == "up") then
	if (source == TruckAnnehmenBtn ) then
		guiSetInputEnabled(false)
		guiSetVisible ( TruckWindow , false )
		showCursor ( false )
		triggerServerEvent (  "truckerannehmen", getRootElement())
 
	end
end
end
 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), windowHandler )
addEventHandler ( "onClientGUIClick", TruckAnnehmenBtn, onClickBtn, false )
 
function onClickBtn ( button, state )
if (button == "left" and state == "up") then
	if (source == TruckAblehnenBtn ) then
		guiSetInputEnabled(false)
		guiSetVisible ( TruckWindow , false )
		showCursor ( false )
		triggerServerEvent (  "truckerablehnen", getRootElement())
	end
end
end
 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), windowHandler )
addEventHandler ( "onClientGUIClick", TruckAblehnenBtn, onClickBtn, false )
 
function starttruckmission_func ()
TruckerStartMarker = createMarker (-360.84088134766, 1190.403076171, 18.742208862305, "cylinder", 6, 255, 0, 0, 150 )
TruckerEndeMarker = createMarker (834.25341796875, 866.51782226563, 11.492173576355, "cylinder", 6, 255, 0, 0, 150 )
end
addEvent ( "starttruckmission", true )
addEventHandler ( "starttruckmission", getRootElement(), starttruckmission_func )
 
function MarkerHit( hitElement, matchingDimension )
if hitElement== getLocalPlayer() and matchingDimension==true then
	if source==TruckerStartMarker then
		outputChatBox( "in the marker TruckerStartMarker" )
	elseif source==TruckerEndeMarker then
		outputChatBox( "in the marker TruckerEndeMarker" )
		removeEventHandler( "onClientMarkerHit", TruckerStartMarker, MarkerHit )
		removeEventHandler( "onClientMarkerHit", TruckerEndeMarker, MarkerHit )
		destroyElement(TruckerStartMarker)
		destroyElement(TruckerEndeMarker)
		TruckerStartMarker, TruckerEndeMarker = nil
	end
end
end
addEventHandler( "onClientMarkerHit", TruckerStartMarker, MarkerHit )
addEventHandler( "onClientMarkerHit", TruckerEndeMarker, MarkerHit )

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