Jump to content

Neon Carball DirectX Scripts


MAB

Recommended Posts

To make a minimap like that you'll need to convert their 3D space onto a 2D plane, if you do some Google searches I'm sure you'll find quite a bit of information on how to accomplish this.

As for the replay, I wrote something similar for testing purposes a while ago. Basically, what you need to do is store the position and rotation of the vehicle in a table. You then loop through this table.

You can check out my testing script if you want, do note however that I wrote this a long time ago and never finished it. Nor do I intend to.

Also, this was merely written for testing purposes. As such, this code has not been refactored and is not optimized in any way shape or form. :)

How to use:

1. Start the resource.

2. Start race, and pick whatever map you want.

3. The recording starts once the race state is changed to "running".

4. It records for 15 seconds.

5. Use the command /startreplay to start the replay. (Go back to the starting position first)

Server.lua

function updateRaceState_Handler(newState, oldState) 
    if(newState == "Running") then 
        local allPlayers = getElementsByType("player") 
        for k, v in pairs(allPlayers) do 
            if(isPedDead(v) == false) then 
                triggerClientEvent(v, "updateClientRaceState", resourceRoot, "Running") 
            end 
        end 
    end 
end 
addEvent("onRaceStateChanging", true) 
addEventHandler("onRaceStateChanging", root, updateRaceState_Handler) 

Client.lua

-- Variables 
local mapState = false 
local recordIndex = 0 
  
-- Tables 
local log_VehiclePositionData = {} 
local log_VehicleRotationData = {} 
local log_VehicleVelocityData = {} 
  
function updateClientRaceState_Handler(newState) 
    if(newState == "Running") then 
        outputChatBox("Starting Recording") 
        mapState = "Running" 
        startTick = getTickCount() 
        addEventHandler("onClientRender", root, log_LocalVehicleData_Handler) 
        --collectgarbage("restart") 
    end 
end 
addEvent("updateClientRaceState", true) 
addEventHandler("updateClientRaceState", root, updateClientRaceState_Handler) 
  
function log_LocalVehicleData_Handler() 
    local currentTime = getTickCount() 
    if((currentTime-startTick) <= 15000) then 
        if(isPedDead(localPlayer) == false) then 
            if(isPedInVehicle(localPlayer) == true) then 
                -- Empty The Tables 
                -- Start Recording 
                local theVehicle = getPedOccupiedVehicle(localPlayer) 
                local pX, pY, pZ = getElementPosition(theVehicle);table.insert(log_VehiclePositionData, {pX, pY, pZ}); 
                local rX, rY, rZ = getElementRotation(theVehicle);table.insert(log_VehicleRotationData, {rX, rY, rZ}); 
                local vX, vY, vZ = getElementVelocity(theVehicle);table.insert(log_VehicleVelocityData, {vX, vY, vZ}); 
            end 
        end 
    else 
        outputChatBox("Recording Finished!") 
        removeEventHandler("onClientRender", root, log_LocalVehicleData_Handler) 
        --collectgarbage("collect") 
        --collectgarbage("count") 
        outputChatBox(tostring(gcinfo())) 
    end 
end 
  
function renderReplay_CMD() 
    theReplayVehicle = createVehicle(568, 0, 0, 0) 
    theReplayPed = createPed(0, 0, 0, 0) 
    warpPedIntoVehicle(theReplayPed, theReplayVehicle, 0) 
    replayFrame = 1 
    addEventHandler("onClientRender", root, renderReplay_Handler) 
end 
addCommandHandler("startreplay", renderReplay_CMD) 
  
function renderReplay_Handler() 
    if(replayFrame <= #log_VehiclePositionData) then 
        setElementPosition(theReplayVehicle, log_VehiclePositionData[replayFrame][1], log_VehiclePositionData[replayFrame][2], log_VehiclePositionData[replayFrame][3]) 
        setElementRotation(theReplayVehicle, log_VehicleRotationData[replayFrame][1], log_VehicleRotationData[replayFrame][2], log_VehicleRotationData[replayFrame][3]) 
        setElementVelocity(theReplayVehicle, log_VehicleVelocityData[replayFrame][1], log_VehicleVelocityData[replayFrame][2], log_VehicleVelocityData[replayFrame][3]) 
        replayFrame = replayFrame+1 
    end 
end 

Link to comment
To make a minimap like that you'll need to convert their 3D space onto a 2D plane, if you do some Google searches I'm sure you'll find quite a bit of information on how to accomplish this.

As for the replay, I wrote something similar for testing purposes a while ago. Basically, what you need to do is store the position and rotation of the vehicle in a table. You then loop through this table.

You can check out my testing script if you want, do note however that I wrote this a long time ago and never finished it. Nor do I intend to.

Also, this was merely written for testing purposes. As such, this code has not been refactored and is not optimized in any way shape or form. :)

How to use:

1. Start the resource.

2. Start race, and pick whatever map you want.

3. The recording starts once the race state is changed to "running".

4. It records for 15 seconds.

5. Use the command /startreplay to start the replay. (Go back to the starting position first)

Server.lua

function updateRaceState_Handler(newState, oldState) 
    if(newState == "Running") then 
        local allPlayers = getElementsByType("player") 
        for k, v in pairs(allPlayers) do 
            if(isPedDead(v) == false) then 
                triggerClientEvent(v, "updateClientRaceState", resourceRoot, "Running") 
            end 
        end 
    end 
end 
addEvent("onRaceStateChanging", true) 
addEventHandler("onRaceStateChanging", root, updateRaceState_Handler) 

Client.lua

-- Variables 
local mapState = false 
local recordIndex = 0 
  
-- Tables 
local log_VehiclePositionData = {} 
local log_VehicleRotationData = {} 
local log_VehicleVelocityData = {} 
  
function updateClientRaceState_Handler(newState) 
    if(newState == "Running") then 
        outputChatBox("Starting Recording") 
        mapState = "Running" 
        startTick = getTickCount() 
        addEventHandler("onClientRender", root, log_LocalVehicleData_Handler) 
        --collectgarbage("restart") 
    end 
end 
addEvent("updateClientRaceState", true) 
addEventHandler("updateClientRaceState", root, updateClientRaceState_Handler) 
  
function log_LocalVehicleData_Handler() 
    local currentTime = getTickCount() 
    if((currentTime-startTick) <= 15000) then 
        if(isPedDead(localPlayer) == false) then 
            if(isPedInVehicle(localPlayer) == true) then 
                -- Empty The Tables 
                -- Start Recording 
                local theVehicle = getPedOccupiedVehicle(localPlayer) 
                local pX, pY, pZ = getElementPosition(theVehicle);table.insert(log_VehiclePositionData, {pX, pY, pZ}); 
                local rX, rY, rZ = getElementRotation(theVehicle);table.insert(log_VehicleRotationData, {rX, rY, rZ}); 
                local vX, vY, vZ = getElementVelocity(theVehicle);table.insert(log_VehicleVelocityData, {vX, vY, vZ}); 
            end 
        end 
    else 
        outputChatBox("Recording Finished!") 
        removeEventHandler("onClientRender", root, log_LocalVehicleData_Handler) 
        --collectgarbage("collect") 
        --collectgarbage("count") 
        outputChatBox(tostring(gcinfo())) 
    end 
end 
  
function renderReplay_CMD() 
    theReplayVehicle = createVehicle(568, 0, 0, 0) 
    theReplayPed = createPed(0, 0, 0, 0) 
    warpPedIntoVehicle(theReplayPed, theReplayVehicle, 0) 
    replayFrame = 1 
    addEventHandler("onClientRender", root, renderReplay_Handler) 
end 
addCommandHandler("startreplay", renderReplay_CMD) 
  
function renderReplay_Handler() 
    if(replayFrame <= #log_VehiclePositionData) then 
        setElementPosition(theReplayVehicle, log_VehiclePositionData[replayFrame][1], log_VehiclePositionData[replayFrame][2], log_VehiclePositionData[replayFrame][3]) 
        setElementRotation(theReplayVehicle, log_VehicleRotationData[replayFrame][1], log_VehicleRotationData[replayFrame][2], log_VehicleRotationData[replayFrame][3]) 
        setElementVelocity(theReplayVehicle, log_VehicleVelocityData[replayFrame][1], log_VehicleVelocityData[replayFrame][2], log_VehicleVelocityData[replayFrame][3]) 
        replayFrame = replayFrame+1 
    end 
end 

i need to learn how not to use other scripters resources and i don't understanf your script

Link to comment

I wouldn't necessarily call it wasting my time, I'm sure other readers might find it useful. :)

@Amir:

If you truly wanna learn not to use other people's scripts, you should start searching for information. Programming and scripting isn't much other than trial and error, really.

For example, you need to plan ahead before you start scripting. Use both these forums, the MTA Wiki and Google for inspiration, even if the tutorial you're looking at is written for C++ or whatever language - you can always adapt it for Lua.

For example to make a replay system think of it like this;

1. You need to capture the behaviour of a vehicle;

1a) You'll want to save the position of the vehicle

1b) You'll want to save the rotation of the vehicle

1c) You'll want to save the velocity of the vehicle (may not be necessary)

Okay so you know this so far - position, rotation and velocity. A quick glance at the MTA Wiki and you'll find these functions do exactly what you want;

getElementPosition 
getElementRotation 
getElementVelocity 

2. Now that you have the necessary functions to record the behaviour of a vehicle; how do we go about doing this?

2a) Timers. Would a timer be a logical choice? No, because it has a minimum interval of 50ms - which may result in a choppy replay.

2b) What would the best option be for smooth and accurate capture? Obviously, onClientRender comes to mind since at 60 FPS you'll be executing the code every ~16ms.

So now you know when to capture these values, but where do we store all the values? Obviously inside of a table - you can either use one table or like I did, a separate table for every value(position, rotation and velocity).

How do we store values inside of a table? If we didn't know this, we'd head onto Google and search for "lua insert value table" or something similar - immediately we'd find that this is what we want;

table.insert(theTable, theValue) 

----

This is the kind of way you have to go about doing things. You might also want to write it down, sort of like brainstorming. You'd be surprised how many professional programmers do brainstorming before they go ahead and find a solution that fits their needs. :)

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