Kaufmancab51
07-01-2009, 12:51 PM
Hello there, i was wondering if it was possible to make a command in VLE where a player enters a checkpoint and it will assign them to a random vehicle, e.g a bus driver walks into a marker, and it automatically teleports them next to a bus. How can that be done using VLE?
[NoN]Bruno
07-01-2009, 06:43 PM
You could do that in a simple VCO Function...
Knucis
07-02-2009, 07:14 AM
Well, You need the callback "onPlayerEnterGlobalMarker(PlayerID, MarkerID, MarkerType)" its a VCO Function, but I am sure you can manage it.
just do:
function onPlayerEnterGlobalMarker(PlayerID, MarkerID, MarkerType)
if MarkerID == [here your Checkpoint/Corona ID] then
function
return end
end
Kaufmancab51
07-03-2009, 10:21 AM
Im still a noob at this and i can't figure it out. What exactly must i do in plain simple english?
Well VLE 1.04 doesn't support the feature to 'do something' when a player/vehicle enters a marker, but 1.05 will have the ability to assign commands to when a player enters a marker.
But even when 1.05 is released, this may still not be possible to do with an ingame command. As there is no command to teleport a player to a random vehicle, but there is a command to teleport a player to a certain vehicle ID.
But this could also be a problem, as vehicle IDs may change when the server restarts.
However this could be done using scripting, as Bruno & Knucis said.
The following code should really be added as a plugin to VLE, but seeing as the plugin system is removed in 1.05, there's not much point.
Instead, we can simply put it in the 'Callbacks.lua' file, located at 'VLE Extensions/'.
So yeah, open that file with notepad (or notepad++ if you have it), and go to the far bottom of the file (line 146)
Put the blinking cursor at the end of the line, and press enter to add a new line, then add all of the code below.
Then look at this line:
if MarkerID == 0 then
change the 0 to the marker ID that you are told after you use /addcp
then save the file, and if the server is running then restart it.
Btw, you will need to update the MarkerID number (currently 0) if the marker ID changes, which may happen when the server restarts.
If you want it to work on all checkpoints in there server, then change this:
if MarkerID == 0 then
to this:
if MarkerType == "CP" then
Here's the code to add:
function onPlayerEnterGlobalMarker(PlayerID, MarkerID, MarkerType)
if MarkerID == 0 then
-- step 1 - load all the vehicle IDs from the file into a table
local Path = VLEGetFilePath("Vehicles")
local a = 1
local VehicleIDs = {}
for Line in io.lines(Path) do
if Line ~= "TOPLINE" then
VehicleIDs[a] = tonumber(VLEGetToken(Line, 1, " "))
end
end
-- step 2 - find a random vehicle ID within the limits of the vehicle IDs in the server
local Pos = random(1, a)
local VehicleID = VehicleIDs[Pos]
-- step 3 - teleport the player to the random vehicle ID
local X, Y, Z, ZAngle = GetXYInFrontOfVehicle(VehicleID, 3)
ZAngle = ZAngle + 180
local PlayerVehicleID = getPlayerVehicleID(PlayerID)
if PlayerVehicleID == 0 then
setPlayerPos(PlayerID, X, Y, Z)
setPlayerAngle(PlayerID, ZAngle)
else
setVehiclePos(PlayerVehicleID, X, Y, Z)
setVehicleAngle(PlayerVehicleID, ZAngle)
end
end
end
I might turn that into a nifty self-contained function, including a check on vehicle name. Usage would go something like:
spawnPlayerToRandomVehicle(PlayerID,VehicleName,Me ssageOnSuccess,MessageOnFail)
MessageOnSuccess would be shown to the player if a free car was found and they were spawned to it.
MessageOnFail would be shown if there were no free cars.
Alternatively someone else could do it for me :)
Meh, I'll just throw it together.