Tex Ranflas Posted March 12, 2016 Share Posted March 12, 2016 Hello, guys. Well, I just got to Lua straight from PAWN (SA:MP) and there's a little question I want to share with you. I'm about to create vehicle for player after player joined to the server. Okay, this ain't no problem. The thing is, I just wanna create some kinda ID to that and stick it with player that I would be able to do some action with certain player's vehicle. In PAWN, it may look like this, that's simple: new pVehicle[MAX_PLAYERS]; //create dimensional array (is there different name for that in Lua?) which will contain vehicle ID for every player //somwhere in some global function which contains playerid parameter (ability to get player id, ain't got no place in MTA by default from what I know, here's the point) pVehicle[playerid] = CreateVehicle(..); //and then, we can do anything we want with player's vehicle - not all or the last created one SetVehiclePos(pVehicle[playerid], ...); Is it supposed to be client-side script which is calling just for one player? Explain, please. Thanx for any help. Link to comment
Dimos7 Posted March 12, 2016 Share Posted March 12, 2016 If understand correctly you want create vehicle for each player join the server? if yes its different Link to comment
DakiLLa Posted March 12, 2016 Share Posted March 12, 2016 Something like this I guess: local pVehicle = {} ... somePlayer = getPlayerFromName( "Mike" ) -- Idk how you get your player, but lets just pick one named Mike for our case pVehicle[ somePlayer ] = createVehicle( ... ) setElementPosition( pVehicle[ somePlayer ], ... ) Link to comment
pro-mos Posted March 12, 2016 Share Posted March 12, 2016 it would look like this, and server sided, because you want other players to see your vehicle not only you. local pVehicles = {} function createVehicleForPlayer(source) if not pVehicles[source] then -- If the player doesnt have a vehicle, and source means whoever triggered the "onPlayerJoin" event local x,y,z = getElementPosition(source) -- get the player position vehicleCreated = createVehicle(model, x + 5, y, z + 0.5) -- Create a vehicle near the player if vehicleCreated then pVehicles[source] = true end else -- if the player has a vehicle already -- warp the player to the vehicle or do something else end end addEventHandler("onPlayerJoin", root, createVehicleForPlayer) note that when the script restarts the array would be lost, you better use a data base. 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