benwilkins Posted July 7, 2011 Share Posted July 7, 2011 Hey, I want to put the trams into action on an RP server. At the moment no passengers can enter them. Is there any scripts avaliable to solve this problem and let around 5 passengers on board? Link to comment
Jaysds1 Posted July 7, 2011 Share Posted July 7, 2011 SAES has the script but it'll take sometime to make a script for that. Link to comment
Deltanic Posted July 7, 2011 Share Posted July 7, 2011 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
benwilkins Posted July 8, 2011 Author Share Posted July 8, 2011 Ah cool, if you would like to gimme some help when your at your PC then would be more than appreciated dude. Link to comment
qaisjp Posted July 8, 2011 Share Posted July 8, 2011 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 will be good. Link to comment
Deltanic Posted July 8, 2011 Share Posted July 8, 2011 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 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 Let me know. Link to comment
benwilkins Posted July 11, 2011 Author Share Posted July 11, 2011 Tried it, and can not enter as a passenger. Also had to remove a ] from line 34, as there was one too many. Any help anyone? 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