Jump to content

Trams


Recommended Posts

A simple idea: Bind "enter_exit" to some function, where you detect if the player is in range of the tram, if so attach him to the tram using attachElements and make him invisible. Also make some table where the entered players will be in. If the size of this table is 5, than tthen player can't enter the tram. I would love to make a basic script for you, but I'm unable to do so at the moment, as I'm on my iPhone :(

Link to comment

I'm making a custom-seats resource that does exactly this, the only things you need is attachElements, but you need heavy maths and shit to make justice to getPedOccupiedVehicle, enter_exit keys, killing, and etc. so if you try doing this remember to make a custom getPedOccupiedVehicle and stuff, this way all :S will be good.

Link to comment
  
local playerTram = {} 
local passengers = {} 
  
  
addEventHandler ( "onPlayerJoin", root, 
    function ( ) 
        bindKey ( source, "enter_exit", "down", tramFunc ) 
        playerTram[source] = nil 
    end 
) 
  
function tramFunc ( player ) 
    -- If theres a tram in range and the player should enter the tram 
    local tram = getClosestTram ( player ) 
    if tram and not playerTram[player] then 
        if not passengers[tram] then passengers[tram] = {} end -- If there hasn't been a table assigned to the tram yet 
        if #passengers[tram] < 5 then -- If it's not full (change 5 to whatever you want) 
            passengers[tram][#passengers[tram]+1] = player 
            playerTram[player] = tram 
  
            attachElements ( player, tram ) 
            setElementAlpha ( player, 0 ) 
            setElementFrozen ( player, true ) 
        end 
    else 
        detachElements ( player, playerTram[player] ) 
        setElementAlpha ( player, 255 ) 
        setElementFrozen ( player, false ) 
         
        local x,y,z = getElementPosition ( playerTram[player] ) 
        setElementPosition ( player, x, y, z+2 ) 
  
        table.remove ( passengers[playerTram[player]]] ) 
        playerTram[player] = nil 
    end 
end 
  
function getClosestTram ( player ) 
    local x,y,z = getElementPosition ( player ) 
    local col = createColSphere ( x, y, z, 5 ) -- the 5 argument is the radius, change this if you want so 
    local closest = { 0, nil } 
    for i,v in ipairs ( getElementsWithinColShape ( col ) ) do  
        if getElementType ( v ) == "vehicle" and getElementModel ( v ) == "449" then 
            local a,b,c = getElementPosition ( v ) 
            local distance = getDistanceBetweenPoints3D ( x,y,z,a,b,c ) 
            if closest[1] < distance then closest = { distance, v } end 
        end 
    end 
    return closest[2] 
end 

That's a very basic script. Didn't test it, and using killPed or such stuff will probably result in some problems on respawn. When I have my new monitor, I'll go in my personal server and make something epic for you, as this got my own interest too :P

Also, I don't guarantee this works. It's late at my local time, and I'm pretty sleepy. Did this out of my head either, so the only way to know is to test it :P Let me know.

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