Jump to content

Help..


Krayzee

Recommended Posts

So I'm using the script from the wiki page that just allows you to spawn in Los Santos and create a vehicle but when I start the resource for the server nothing happens, it just shows a black screen.

function joinHandler() 
    local x = 1959.55 
    local y = -1714.46 
    local z = 10 
    spawnPlayer(source, x, y, z) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
    outputChatBox("Script Testing", source) 
end 
addEventHandler("onPlayerJoin", getRootElement(), joinHandler) 
  
function createVehicleForPlayer(thePlayer, command, vehicleModel) 
    local x,y,z = getElementPosition(thePlayer) -- get the position of the player 
    x = x + 5 -- add 5 units to the x position 
    local createdVehicle = createVehicle(tonumber(vehicleModel),x,y,z) 
    -- check if the return value was ''false'' 
    if (createdVehicle == false) then 
        -- if so, output a message to the chatbox, but only to this player. 
        outputChatBox("Your vehicle wasn't created.",thePlayer) 
    end 
end 
addCommandHandler("createvehicle", createVehicleForPlayer) 

How can I fix it? I want to get good at scripting so that I can script for a race server.

Link to comment
function joinHandler() 
    local x = 1658 
    local y = -2288 
    local z = -1 
    spawnPlayer(source, x, y, z) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
    outPutChatBox("Script Testing", source) 
end 
addEventHandler("onPlayerJoin", getRootElement(), joinHandler) 
  
function createVehicleForPlayer(thePlayer, command, vehicleModel) 
    local x,y,z = getElementPosition(thePlayer)  
    x = x + 3  
    local createdVehicle = createVehicle(tonumber(vehicleModel),x,y,z) 
    if (createdVehicle == false) then 
        outPutChatBox("Your vehicle was not created.",thePlayer) 
    end 
end 
addCommandHandler("createvehicle", createVehicleForPlayer) 
  

Link to comment

What did you change beside the numbers Axel? ...

@Krayzee, your script will spawn players when they join the server, not when (re)starting the resource. Try this, it will loop through all players and spawn them at that position when the resource starts:

function resStart() 
  local x, y, z = 1959.55, -1714.46, 10 
  for _, player in ipairs( getElementsByType ( 'player' ) ) do 
    spawnPlayer(player, x, y, z) 
    fadeCamera(player, true) 
    setCameraTarget(player, player) 
    outputChatBox("Script Testing", player) 
  end 
end 
addEventHandler("onResourceStart", getResourceRootElement(), resStart) 

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