Jump to content

One vehicle for one player


3eBpA

Recommended Posts

Posted
Well, if you do know OOP then you have a lot of points in favor if you plan on using OOP to programm. In MTA 1.4 OOP will be incorporated in the MTA engine functions.

Please let me know if you need any further assistance.

why does skin don't puts on the player ? :o

function TakeJob(hitElement, matchingDimension, thePlayer) 
    local element = getElementType(hitElement); 
    if(getElementType(hitElement) == 'player') and getElementData(hitElement,"trucker") == false 
    and getElementData(hitElement,"vehicle") == false then 
    setPedSkin(source, 206); 
    setElementData(hitElement,"trucker",true); 
    setPlayerTeam(hitElement, truckers); 
    setMarkerColor(marker1, 255, 0, 0, 150); 
    outputChatBox("To end you job stand back on this marker and you will automatically end your job"); 
    elseif getElementData(hitElement,"trucker") == true then 
    outputChatBox("You have ended your job"); 
    setPlayerTeam(hitElement, unemployedteam); 
    setElementData(hitElement,"trucker",false); 
    setMarkerColor(marker1, 255, 0, 0, 0); 
    end 
end 
addEventHandler("onMarkerHit", workmarker, TakeJob); 

Replace it with:

setElementModel(hitElement, 206); 

oh, yep, works, thanks but one question, why I can't change char skin here using setpedskin ? in another function I could use it

Posted

No but you just had a wrong element and the setPedSkin function won't be apply to use it in the future .

This function is deprecated. This means that its use is discouraged and that it might not exist in future versions.

Posted
No but you just had a wrong element and the setPedSkin function won't be apply to use it in the future .

This function is deprecated. This means that its use is discouraged and that it might not exist in future versions.

hmm, okay, thanks, if there'll be more questions, I'll write in this topic

Posted

Ok, a new portion of questions and errors :D

I'm trying to draw a GUI from client script and create markers on server side script (can't create marker from client), when I hit the marker I can't get my gui drawing =\

here, client side :

function MarkerHit( hitElement, matchingDimension ) 
    local elementType = getElementType( hitElement ) 
    if(getElementType(hitElement) == 'player') and getElementData(hitElement,"vehicle") == false 
    and getElementData(hitElement,"trucker") == true then 
    local x,y,z = getElementPosition(hitElement) 
    createVehicle(403, x + 10, y, z, 0 , 0 , 180) 
    setElementData(hitElement,"vehicle",true) 
    elseif getElementData(hitElement,"vehicle") == true then 
    outputChatBox("You have got already a vehicle or you're not a trucker"); 
    end 
end 
addEventHandler("onMarkerHit", marker1, MarkerHit ) 
  
function TruckerGUI() 
    local myWindow = guiCreateWindow ( 0.5, 0.5, 0.5, 0.4, "Trucker Job Menu", true ) 
    local b1X = 0.180; 
    local b1Y = 0.180; 
    local b1Width = 0.15; 
    local b1Height = 0.20; 
    btn1 = guiCreateButton(b1X, b1Y, b1Width, b1Height, "Hire", true, hireWindow); 
    addEventHandler ( "onClientGUIClick", btn1, btn1_Click, false) 
end 
addEventHandler("onMarkerHit", workmarker, TruckerGUI) 
  
function btn1_Click(hitElement, btn1, matchingDimension) 
   local element = getElementType(hitElement); 
   if btn1 == "left" and (getElementType(hitElement) == 'player') and getElementData(hitElement,"trucker") == false 
    and getElementData(hitElement,"vehicle") == false then 
    setElementModel(hitElement, 206); 
    setElementData(hitElement,"trucker",true); 
    setPlayerTeam(hitElement, truckers); 
    setMarkerColor(marker1, 255, 0, 0, 150); 
    else 
    end 
end 

and server script

local truckers = createTeam("Truckers", 222, 153, 25); 
local unemployedteam = createTeam("Unnemployed", 0, 0, 0); 
  
marker1 = createMarker(872, -1208, 16, 'cylinder', 2.0, 255, 0, 0, 0) 
workmarker = createMarker(860, -1208, 16, 'cylinder', 2.0, 0, 255, 0 , 150); 
  

Posted

Obviously not, you are using "onMarkerHit" which is a server side event.

Also, you have other problems in that client side script, such as "setPlayerTeam" which is a server side only function.

Posted
Obviously not, you are using "onMarkerHit" which is a server side event.

Also, you have other problems in that client side script, such as "setPlayerTeam" which is a server side only function.

hmm, can u help noob like me with this code ? =\

  • MTA Team
Posted

Client:

  
function MarkerHit( hitElement, matchingDimension ) 
    local elementType = getElementType( hitElement ) 
    if(getElementType(hitElement) == 'player') and getElementData(hitElement,"vehicle") == false 
    and getElementData(hitElement,"trucker") == true then 
    local x,y,z = getElementPosition(hitElement) 
    createVehicle(403, x + 10, y, z, 0 , 0 , 180) 
    setElementData(hitElement,"vehicle",true) 
    elseif getElementData(hitElement,"vehicle") == true then 
    outputChatBox("You have got already a vehicle or you're not a trucker"); 
    end 
end 
addEventHandler("onClientMarkerHit", marker1, MarkerHit ) 
  
function TruckerGUI() 
    local myWindow = guiCreateWindow ( 0.5, 0.5, 0.5, 0.4, "Trucker Job Menu", true ) 
    local b1X = 0.180; 
    local b1Y = 0.180; 
    local b1Width = 0.15; 
    local b1Height = 0.20; 
    btn1 = guiCreateButton(b1X, b1Y, b1Width, b1Height, "Hire", true, hireWindow); 
    addEventHandler ( "onClientGUIClick", btn1, btn1_Click, false) 
end 
addEventHandler("onClientMarkerHit", workmarker, TruckerGUI) 
  
function btn1_Click(hitElement, btn1, matchingDimension) 
   local element = getElementType(hitElement); 
   if btn1 == "left" and (getElementType(hitElement) == 'player') and getElementData(hitElement,"trucker") == false 
    and getElementData(hitElement,"vehicle") == false then 
    setElementModel(hitElement, 206); 
    setElementData(hitElement,"trucker",true); 
    triggerServerEvent("setteam",localPlayer) 
    setMarkerColor(marker1, 255, 0, 0, 150); 
    else 
    end 
end 

Server:

  
truckers = createTeam("Truckers", 222, 153, 25); 
unemployedteam = createTeam("Unnemployed", 0, 0, 0); 
  
marker1 = createMarker(872, -1208, 16, 'cylinder', 2.0, 255, 0, 0, 0) 
workmarker = createMarker(860, -1208, 16, 'cylinder', 2.0, 0, 255, 0 , 150); 
addEvent("setteam",true) 
addEventHandler("setteam",root, 
function () 
setPlayerTeam(source,truckers) 
end) 

Posted
Client:
  
function MarkerHit( hitElement, matchingDimension ) 
    local elementType = getElementType( hitElement ) 
    if(getElementType(hitElement) == 'player') and getElementData(hitElement,"vehicle") == false 
    and getElementData(hitElement,"trucker") == true then 
    local x,y,z = getElementPosition(hitElement) 
    createVehicle(403, x + 10, y, z, 0 , 0 , 180) 
    setElementData(hitElement,"vehicle",true) 
    elseif getElementData(hitElement,"vehicle") == true then 
    outputChatBox("You have got already a vehicle or you're not a trucker"); 
    end 
end 
addEventHandler("onClientMarkerHit", marker1, MarkerHit ) 
  
function TruckerGUI() 
    local myWindow = guiCreateWindow ( 0.5, 0.5, 0.5, 0.4, "Trucker Job Menu", true ) 
    local b1X = 0.180; 
    local b1Y = 0.180; 
    local b1Width = 0.15; 
    local b1Height = 0.20; 
    btn1 = guiCreateButton(b1X, b1Y, b1Width, b1Height, "Hire", true, hireWindow); 
    addEventHandler ( "onClientGUIClick", btn1, btn1_Click, false) 
end 
addEventHandler("onClientMarkerHit", workmarker, TruckerGUI) 
  
function btn1_Click(hitElement, btn1, matchingDimension) 
   local element = getElementType(hitElement); 
   if btn1 == "left" and (getElementType(hitElement) == 'player') and getElementData(hitElement,"trucker") == false 
    and getElementData(hitElement,"vehicle") == false then 
    setElementModel(hitElement, 206); 
    setElementData(hitElement,"trucker",true); 
    triggerServerEvent("setteam",localPlayer) 
    setMarkerColor(marker1, 255, 0, 0, 150); 
    else 
    end 
end 

Server:

  
truckers = createTeam("Truckers", 222, 153, 25); 
unemployedteam = createTeam("Unnemployed", 0, 0, 0); 
  
marker1 = createMarker(872, -1208, 16, 'cylinder', 2.0, 255, 0, 0, 0) 
workmarker = createMarker(860, -1208, 16, 'cylinder', 2.0, 0, 255, 0 , 150); 
addEvent("setteam",true) 
addEventHandler("setteam",root, 
function () 
setPlayerTeam(source,truckers) 
end) 

oh, thanks man, you're always helping me 8)

  • MTA Team
Posted

No problem.

Tho i'm insisting in the fact that you are creating vehicles client side and these won't be usable.

Posted
No problem.

Tho i'm insisting in the fact that you are creating vehicles client side and these won't be usable.

what do u mean with words "and these won't be usable" ? it's job's car spawner

  • MTA Team
Posted

If you create a vehicle client-side, you won't be able to get inside since it's not syncronized with the server.

Posted
If you create a vehicle client-side, you won't be able to get inside since it's not syncronized with the server.

oh, so I should create vehicle from server-side ? if yes, so, can u show me how to do that ?

Posted
If you create a vehicle client-side, you won't be able to get inside since it's not syncronized with the server.

and also, I've tried, script don't works, even if I'm copypasting it from here

Posted
What doesn't work exactly? Any errors showing up?

no errors, when I'm going to the marker, there's no GUI window but looks like it should appear =\, when I'm hitting marker, there should be used the truckerGUI function, which is creating gui window and button

  • MTA Team
Posted

Try using the event onMarkerHit server-side then triggering a event on the client-side to pop up the gui.

Posted
Try using the event onMarkerHit server-side then triggering a event on the client-side to pop up the gui.

well, can I use a function from the client ?

  • MTA Team
Posted

You're not understaning what i'm saying, change all the events onClientMarkerHit to onMarkerHit and move them to the server-side, then assign them with functions that trigger on that event. In these functions, you should add a trigger to the client-side to open the gui's.

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