Jump to content

Help with Vehicle Spawning


csontih

Recommended Posts

function startJob()
    outputChatBox("Teszt Munka", 0, 255, 0)
local vehMark = createMarker(1617.6962890625, 2368.6525878906, 10.8203125,"cylinder")
  function vehicleSpawner(hitElement,matchingDimension)

    if getElementType(hitElement) == "player" then
        if getPedOccupiedVehicle(hitElement) == false then
        local x,y,z = getElementPosition(hitElement)
            local veh = createVehicle(578, 255, 255, 255)
            warpPedIntoVehicle(hitElement,veh)
        end
    end 
end 
addEventHandler("onMarkerHit",vehMark,vehicleSpawner)

When i go into the Marker, nothing happens, can someone help?

Link to comment
2 hours ago, csontih said:

When i go into the Marker, nothing happens, can someone help?

Hello csontih,

have you tried looking into your scripting debug console? You can open it up by logging in as admin into your MTA server and executing

/debugscript 3

Your startJob function is missing an end tag. Try placing one after the call to oututChatBox, like...

function startJob()
    outputChatBox("Teszt Munka", root, 0, 255, 0)
end

Your call to outputChatBox is missing the visibleTo parameter. I "fixed" it in the above script.

Link to comment
2 minutes ago, csontih said:

Still not working..

What is the debug console output? Could you please either execute the "/debugscript 3" command or look for the debug script log file inside of your MTA server folder? Is your code running serverside or clientside? Please put the contents of your meta.xml file.

Edited by The_GTA
Link to comment
2 minutes ago, csontih said:

 - The code i posted is sourceC.lua

The code you posted is supposed to go into sourceS.lua because it does use server-side functions and events (warpPedIntoVehicle and onMarkerHit). Since you are executing warpPedIntoVehicle on players and players are synchronized-with-the-server elements, this function usage is designated for server-side only.

Edited by The_GTA
Link to comment

It's  a container delivery job, i want the marker to spawn, when i start the job.

 

function startJob()
    outputChatBox("You started the job!", 255, 255, 255)
    
    destroyElement(pickupMarker)
    pickupMarker = createMarker(pickupPos[1], pickupPos[2], pickupPos[3] - 3.7, "cylinder", 4, 255, 162, 0, 200)

    destroyElement(pickupBlip)
    pickupBlip = createBlip(pickupPos[1], pickupPos[2], pickupPos[3] - 3.7, 0, 2, 255, 162, 0)

    Roboto = dxCreateFont("Roboto.ttf", 12)

    addEventHandler("onClientRender", root, renderMarkerInfo)
    addEventHandler("onClientMarkerHit", root, markerHandler)

How could i do that in SourceS?

Link to comment
2 minutes ago, csontih said:

How could i do that in SourceS?

You have not yet defined the classification of said job. How should the server and client know that a player has the job? You have got two options:

  • use ACL along with internal MTA server accounts
  • use a custom Lua table based job registry

After doing the classification, you can spawn markers according to job synchronization data between server and client.

Link to comment
-- SERVER
local job_registry = {}

local function _get_player_jobinfo(player)
    local info = job_registry[player];
    
    if (info) then return info; end;
    
    info = {};
    info.current_job = false;
    job_registry[player] = info;
    return info;
end

addEventHandler("onPlayerQuit", root,
    function()
        job_registry[source] = nil;
    end
);

function setPlayerJob(player, jobname)
    local jobinfo = _get_player_jobinfo(player);
    
    if (jobinfo.current_job == jobname) then
        return;
    end
  
    jobinfo.current_job = jobname;

    outputDebugString("* Set job: " .. getPlayerName(player) .. " -> " .. tostring(jobname));
    
    triggerClientEvent(player, "onClientPlayerSetJob", player, jobname);
end

-- CLIENT
local current_job = false;

local pickupMarker = false;
local pickupBlip = false;



addEvent("onClientPlayerSetJob", true);
addEventHandler("onClientPlayerSetJob", root,
    function(jobname)
        if not (source == localPlayer) then return; end;
        
        if (jobname) then
            outputChatBox("* Job changed to " .. jobname .. "!");
        else
            outputChatBox("* You are now job-less.");
        end
        
        if (current_job) then
            if (pickupMarker) then
                destroyElement(pickupMarker);
                pickupMarker = false;
            end
            if (pickupBlip) then
                destroyElement(pickupBlip);
                pickupBlip = false;
            end
        end
        
        current_job = jobname;
        
        if (jobname == "container delivery") then
            pickupMarker = createMarker( --[[ TODO ]] );
            pickupBlip = createBlip( --[[ TODO ]] );
            
            addEventHandler("onClientMarkerHit", pickupMarker,
                function(hitElement)
                    if not (hitElement == localPlayer) then return; end;
                    
                    -- TODO: do some jobby stuff, synchronize with the server using events.
                end
            );
        end
    end
);

Hope this helps! Use it as general idea and extend the script.

EDIT: fixed a bug in _get_player_jobinfo (21.11.2021 13:14 GMT+1)

Edited by The_GTA
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...