Jump to content
  • 0

Scripting help


Legenden

Question

Hello, I'd like a hand for my first script. I'm a total rookie. So according to MTA wiki I had to write this:

     "YourName" type="gamemode" name="My Server" description="My first MTA DM server" /> 
     

But as I loaded the resource in my server it said:

[04:22:15] SCRIPT ERROR: myserver/newb.lua:9: '' expected near 'end'

Help please.

Link to comment

10 answers to this question

Recommended Posts

  • 0

This is the wrong place to post this but i'll help...

The meta.xml file should have everything that is included in your resource,

so if you create another file, it should be put in the meta.xml as:

<script src="newb.lua" /> 

Moderator, Can you move this to the scripting section please

Link to comment
  • 0
This is the wrong place to post this but i'll help...

The meta.xml file should have everything that is included in your resource,

so if you create another file, it should be put in the meta.xml as:

<script src="newb.lua" /> 

Moderator, Can you move this to the scripting section please

I did that at the first time, I just copied the example from wiki.

Link to comment
  • 0
This is the wrong place to post this but i'll help...

The meta.xml file should have everything that is included in your resource,

so if you create another file, it should be put in the meta.xml as:

<script src="newb.lua" /> 

Moderator, Can you move this to the scripting section please

I did that at the first time, I just copied the example from wiki.

This is the wrong board to put the thread, however, I'd like to see the lines from 0-10.

Link to comment
  • 0
 The newb.lua file: 
local spawnX, spawnY, spawnZ = 386, -1926, 1 
function joinHandler() 
    spawnPlayer(source, spawnX, spawnY, spawnZ) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
    outputChatBox("Welcome to My Server", source) 
end 
addEventHandler("onPlayerJoin", getRootElement(), joinHandler) 
end 
function createVehicleForPlayer(thePlayer, spawn, 468) 
local x,y,z = getElementPosition(thePlayer)  
x = x + 5  
local createdVehicle = createVehicle(tonumber(468),x,y,z) 
if (createdVehicle == false) then 
        outputChatBox("fail",thePlayer) 
    end 
end 
addCommandHandler ("createvehicle", createVehicleForPlayer) 
   

 The meta.xml file: 

     "Legenden" type="gamemode" name="My Server" description="First attempt in scripting" /> 
     

(thePlayer, spawn, 468) - if you wonder what this means:

-- create the function the command handler calls, with the arguments: thePlayer, command, vehicleModel

function createVehicleForPlayer(thePlayer, command, vehicleModel)

-- create a vehicle and stuff

end

-- create a command handler

addCommandHandler("createvehicle", createVehicleForPlayer)

Link to comment
  • 0

this is it:

local spawnX, spawnY, spawnZ = 386, -1926, 1 
function joinHandler() 
    spawnPlayer(source, spawnX, spawnY, spawnZ) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
    outputChatBox("Welcome to My Server", source) 
end 
addEventHandler("onPlayerJoin", getRootElement(), joinHandler) 
  
function createVehicleForPlayer(thePlayer, spawn, 468) 
local x,y,z = getElementPosition(thePlayer) 
x = x + 5 
local createdVehicle = createVehicle(tonumber(468),x,y,z) 
if (createdVehicle == false) then 
        outputChatBox("fail",thePlayer) 
    end 
end 
addCommandHandler ("createvehicle", createVehicleForPlayer) 

I only remove the 'end' after

addEventHandler("onPlayerJoin", getRootElement(), joinHandler) 

Link to comment
  • 0
this is it:
local spawnX, spawnY, spawnZ = 386, -1926, 1 
function joinHandler() 
    spawnPlayer(source, spawnX, spawnY, spawnZ) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
    outputChatBox("Welcome to My Server", source) 
end 
addEventHandler("onPlayerJoin", getRootElement(), joinHandler) 
  
function createVehicleForPlayer(thePlayer, spawn, 468) 
local x,y,z = getElementPosition(thePlayer) 
x = x + 5 
local createdVehicle = createVehicle(tonumber(468),x,y,z) 
if (createdVehicle == false) then 
        outputChatBox("fail",thePlayer) 
    end 
end 
addCommandHandler ("createvehicle", createVehicleForPlayer) 

I only remove the 'end' after

addEventHandler("onPlayerJoin", getRootElement(), joinHandler) 

Like this it says:

[00:49:32] Script error: myserver\newb.lua:9: or "...." expected near '468'

Thanks anyway.

Link to comment
  • 0

This is it:

local spawnX, spawnY, spawnZ = 386, -1926, 1 
function joinHandler() 
    spawnPlayer(source, spawnX, spawnY, spawnZ) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
    outputChatBox("Welcome to My Server", source) 
end 
addEventHandler("onPlayerJoin", getRootElement(), joinHandler) 
    
function createVehicleForPlayer(thePlayer, spawn) 
    local x,y,z = getElementPosition(thePlayer) 
    x = x + 5 
    local createdVehicle = createVehicle(tonumber(468),x,y,z) 
    if (createdVehicle == false) then 
        outputChatBox("fail",thePlayer) 
    end 
end 
addCommandHandler ("createvehicle", createVehicleForPlayer) 

I test it in my local server and it's working.

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