Jump to content

Why don't work?


drk

Recommended Posts

Hey, i've made a point system for my race server but it gives me a error:

ERROR: server.lua:14: function arguments expected near ')'

The code is:

function database:SQLTable() 
    local gRR_Element = getResourceRootElement(getThisResource()) 
    executeSQLCreateTable ( 'Money', 'player_serial STRING, money INT' ) 
    executeSQLCreateTable ( 'Points', 'player_serial STRING, points INT' ) 
end 
addEventHandler('onResourceStart', gRR_Element, database:SQLTable ) 

Link to comment

I'm not sure,try whit this:

function database:SQLTable() 
    executeSQLCreateTable ( 'Money', 'player_serial STRING, money INT' ) 
    executeSQLCreateTable ( 'Points', 'player_serial STRING, points INT' ) 
end 
addEventHandler('onResourceStart', getResourceRootElement(getThisResource()), database:SQLTable ) 

Then, more you can simplify your script ,better.

PD:To a very very sure to we can fix script you need to post complete code.

Link to comment

I've tried first getResourceRootElement and don't work. Thanks for trying to help.

The complete code is:

--[[ 
        -- made by Shick 
        -- credits to -------- for helping 
        -- 22/12/2011 
--]] 
  
-- getResourceRootElement 
local gRR_Element = getResourceRootElement(getThisResource()) 
  
-- SQL Database 
function database:SQLTable() 
    executeSQLCreateTable ( 'Money', 'player_serial STRING, money INT' ) 
    executeSQLCreateTable ( 'Points', 'player_serial STRING, points INT' ) 
addEventHandler('onResourceStart', gRR_Element, database:SQLTable ) 
  
-- Dx Scoreboard 
function scoreboard:addAColumn() 
    call(getResourceFromName('dxscoreboard'), "addScoreboardColumn", "Money") 
    call(getResourceFromName('dxscoreboard'), "addScoreboardColumn", "Points") 
end 
addEventHandler('onResourceStart', gRR_Element, scoreboard:addAColumn ) 

Link to comment

In the first script version you showed us, you had a problem with the rootElement stuff.

Script always runs the non-functions first, then functions. The local was inside the function, so the event cannot reach the data because it's triggered after the event is started. It outputs an error.

Here you hadn't specified the 'database:' and 'scoreboard:'. That's why you need to put tables for it.

--[[ 
        -- made by Shick 
        -- credits to -------- for helping 
        -- 22/12/2011 
--]] 
  
-- getResourceRootElement 
local gRR_Element = getResourceRootElement(getThisResource()) 
local database = { } 
local scoreboard = { } 
  
-- SQL Database 
function database:SQLTable() 
    executeSQLCreateTable ( 'Money', 'player_serial STRING, money INT' ) 
    executeSQLCreateTable ( 'Points', 'player_serial STRING, points INT' ) 
addEventHandler('onResourceStart', gRR_Element, database:SQLTable ) 
  
-- Dx Scoreboard 
function scoreboard:addAColumn() 
    call(getResourceFromName('dxscoreboard'), "addScoreboardColumn", "Money") 
    call(getResourceFromName('dxscoreboard'), "addScoreboardColumn", "Points") 
end 
addEventHandler('onResourceStart', gRR_Element, scoreboard:addAColumn ) 

Edited by Guest
Link to comment
-- money / points reward 
function reward() 
    getPlayerWithSerial = executeSQLSelect( 'Money', 'player_serial', 'player_serial = "' .. getPlayerSerial() ..'"' ) 
      if ( type (getPlayerWithSerial) == 'table' and #getPlayerWithSerial == 0 ) or not getPlayerWithSerial then 
        setElementData ( source, 'Money', "0" ) 
      else 
        getMoneyFromPlayer = executeSQLSelect ( 'Money', 'money', 'money = "' .. getMoneyFromThePlayer .. '"' ) 
          if ( type (getMoneyFromPlayer) == 'table' and #getMoneyFromPlayer == 1 ) then 
            setElementData ( source, 'Money', getMoneyFromThePlayer ) 
            end 
        end 
    end 
end 

'' expected near 'end'. I don't know why it gives me this. I have the four end's to close if, else and the function.

Link to comment

Now, I get this error: ERROR: server.lua:8: attempt to call global 'getThisResource' (a nil value)

In debug I get: stack traceback:

server.lua:8: in main chunk

[C]: ?

quitting debugger

Line 8 is

local gRR_Element = getResourceRootElement(getThisResource()) 

Link to comment

Anyone can help and say to me if this code is correct:

function getAliveCount () 
  aliveAmount = 0 
  for i,v in ipairs (getAlivePlayers()) do 
    aliveAmount = aliveAmount +1 
  end 
  return aliveAmount 
end 
  
function rewardIfWin(source) 
    local alive = getAliveCount() 
    local money = getElementData ( source, 'Money' ) 
    if ( isPedDead(source) ~= false ) and ( alive == 1 ) then 
        grana = math.random ( 100, 2000 ) 
        setElementData ( source, 'Money', money+#grana ) 
        outputChatBox ( "#ABCDEF* #ffffffYou gain #00ff00" .. tostring(grana) .. "$ for winning the deathmatch !", source, 255, 255, 255, true ) 
    end 
end 
  
function ifPlayerQuitSaveTheMoney(source) 
    saveTheMoney = executeSQLInsert ( 'Money', getElementData ( source, 'Money' ) ) 
    if ( type (saveTheMoney) == 'table' and #saveTheMoney == 1 ) then 
        outputDebugString (getPlayerName(source) .. " money saved in SQL database.") 
    end 
end 
addEventHandler ( "onPlayerQuit", getRootElement(), ifPlayerQuitSaveTheMoney ) 
  

Link to comment
function getAliveCount () 
  local aliveAmount = 0 
  for i,v in ipairs (getAlivePlayers()) do 
    aliveAmount = aliveAmount +1 
  end 
  return aliveAmount 
end 
  
function rewardIfWin(source) 
    local alive = getAliveCount() 
    local money = getElementData ( source, 'Money' ) 
    if ( isPedDead(source) ~= false ) and ( alive == 1 ) then 
        local grana = math.random ( 100, 2000 ) 
        setElementData ( source, 'Money', money+grana ) 
        outputChatBox ( "#ABCDEF* #ffffffYou gain #00ff00" .. tostring(grana) .. "$ for winning the deathmatch !", source, 255, 255, 255, true ) 
    end 
end 
  
function ifPlayerQuitSaveTheMoney(source) 
    saveTheMoney = executeSQLInsert ( 'Money', getElementData ( source, 'Money' ) ) 
    if ( type (saveTheMoney) == 'table' and #saveTheMoney == 1 ) then 
        outputDebugString (getPlayerName(source) .. " money saved in SQL database.") 
    end 
end 
addEventHandler ( "onPlayerQuit", getRootElement(), ifPlayerQuitSaveTheMoney ) 

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