Jump to content

Help please " lua:3: <name> expected near ´(´ "


Adde

Recommended Posts

Hello I have problem with a script. The script wont start and it says " lua:3: expected near ´(´ " in debug. I tried to change many different things but could not figure it out. A little help would be nice :)

server side:

exports.scoreboard:addScoreboardColumn('SALA') 
  
function() 
    local playerTeam = getPlayerTeam ( source ) 
    local account = getPlayerAccount(source) 
    local zombiekills = getAccountData(account, "Zombie kills") 
if isObjectInACLGroup ("user."..accName1, aclGetGroup ( "Owner" ) ) then 
setAccountData ( account, "SALA", "Owner" ) 
elseif isObjectInACLGroup ("user."..accName1, aclGetGroup ( "Admin" ) ) then 
setAccountData ( account, "SALA", "Admin" ) 
elseif isObjectInACLGroup ("user."..accName1, aclGetGroup ( "SuperModerator" ) ) then 
setAccountData ( account, "SALA", "SuperModerator" ) 
elseif isObjectInACLGroup ("user."..accName1, aclGetGroup ( "Moderator" ) ) then 
setAccountData ( account, "SALA", "Moderator" ) 
elseif isObjectInACLGroup ("user."..accName1, aclGetGroup ( "TrialModerator" ) ) then 
setAccountData ( account, "SALA", "TrialModerator" ) 
elseif if ( playerTeam(SWAT) ) then    
setAccountData ( account, "SALA", "Player" ) 
elseif if ( playerTeam(Military) ) then    
setAccountData ( account, "SALA", "Player" ) 
elseif if ( playerTeam(Army) ) then    
setAccountData ( account, "SALA", "Player" ) 
end 
end 
) 
  
addEventHandler("onPlayerSpawn",root, 
function () 
    local Guest = getPlayerAccount(source) 
    if isGuestAccount(Guest) then return end 
    local sala = getAccountData(Guest,"SALA") 
    if sala then 
        setElementData(source,"SALA", sala) 
end 
end 
) 

Link to comment

You have to give function a name. You can't define function the way you did it, unless you assign it to a variable.

So, you can change the line 3 to one of the following:

myFunction = function( ) 
-- OR 
function myFunction( ) 

Link to comment

oh, hah ofc -.-´

Now I fixed some other things to but it says " lua:25: unexpected symbol near ´)´ ". When I remove that there´s nothing in debug but it doesn´t work. But when I look for unexpected symbols there I can´t find anything :/

It looks like this now

exports.scoreboard:addScoreboardColumn('SALA') 
  
function thesala() 
    local playerTeam = getPlayerTeam ( source ) 
    local account = getPlayerAccount(source) 
    local zombiekills = getAccountData(account, "Zombie kills") 
if isObjectInACLGroup ("user."..accName1, aclGetGroup ( "Owner" ) ) then 
setAccountData ( account, "SALA", "Owner" ) 
elseif isObjectInACLGroup ("user."..accName1, aclGetGroup ( "Admin" ) ) then 
setAccountData ( account, "SALA", "Admin" ) 
elseif isObjectInACLGroup ("user."..accName1, aclGetGroup ( "SuperModerator" ) ) then 
setAccountData ( account, "SALA", "SuperModerator" ) 
elseif isObjectInACLGroup ("user."..accName1, aclGetGroup ( "Moderator" ) ) then 
setAccountData ( account, "SALA", "Moderator" ) 
elseif isObjectInACLGroup ("user."..accName1, aclGetGroup ( "TrialModerator" ) ) then 
setAccountData ( account, "SALA", "TrialModerator" ) 
elseif ( playerTeam(SWAT) ) then    
setAccountData ( account, "SALA", "Player" ) 
elseif ( playerTeam(Military) ) then    
setAccountData ( account, "SALA", "Player" ) 
elseif ( playerTeam(Army) ) then    
setAccountData ( account, "SALA", "Player" ) 
end 
end 
) 
  
addEventHandler("onPlayerSpawn",root, 
function () 
    local Guest = getPlayerAccount(source) 
    if isGuestAccount(Guest) then return end 
    local sala = getAccountData(Guest,"SALA") 
    if sala then 
        setElementData(source,"SALA", sala) 
end 
end 
) 

Link to comment

Line 17, wtf?

playerTeam is a variable (team element or false) not a function... You can't use variables like if they were functions. You need to get the team's name and compare it with team names. You also need to call thesala function in your onPlayerSpawn callback.

Link to comment

I´ve got "local playerTeam = getPlayerTeam ( source )". This function gets the current team a player is on. Then "if playerTeam(SWAT) then *what to do* ".

I looked through this https://community.multitheftauto.com/index.php?p=resources&s=details&id=5236 and thought that I could make it show the name of the acl group youré in or "player" if the player is not in any acl group. It was a test for myself but when the problems came I decided to talk about it here on forum.

Link to comment

accName1 is not defined.

 exports.scoreboard:addScoreboardColumn('SALA') 
  
function thesala() 
    local playerTeam = getPlayerTeam ( source ) 
    local account = getPlayerAccount(source) 
    local accName1 = getAccountName(account) 
    local zombiekills = getAccountData(account, "Zombie kills") 
if isObjectInACLGroup ("user."..accName1, aclGetGroup ( "Owner" ) ) then 
setAccountData ( account, "SALA", "Owner" ) 
elseif isObjectInACLGroup ("user."..accName1, aclGetGroup ( "Admin" ) ) then 
setAccountData ( account, "SALA", "Admin" ) 
elseif isObjectInACLGroup ("user."..accName1, aclGetGroup ( "SuperModerator" ) ) then 
setAccountData ( account, "SALA", "SuperModerator" ) 
elseif isObjectInACLGroup ("user."..accName1, aclGetGroup ( "Moderator" ) ) then 
setAccountData ( account, "SALA", "Moderator" ) 
elseif isObjectInACLGroup ("user."..accName1, aclGetGroup ( "TrialModerator" ) ) then 
setAccountData ( account, "SALA", "TrialModerator" ) 
elseif ( playerTeam == "SWAT" ) then    
setAccountData ( account, "SALA", "Player" ) 
elseif ( playerTeam == "Military" ) then    
setAccountData ( account, "SALA", "Player" ) 
elseif ( playerTeam == "Army" ) then    
setAccountData ( account, "SALA", "Player" ) 
end 
end 
addEventHandler("onPlayerLogin", getRootElement(), thesala) 
  
addEventHandler("onPlayerLogin",root, 
function () 
    local Guest = getPlayerAccount(source) 
    if isGuestAccount(Guest) then return end 
    local sala = getAccountData(Guest,"SALA") 
    if sala then 
        setElementData(source,"SALA", sala) 
end 
end 
)  

Try this.

Link to comment
ah I see. Now it works :) thx!

But not on Players, just those in acl groups. btw, can remove zombiekillsrow. It´s for nothing.

Yes, of course.

exports.scoreboard:addScoreboardColumn('SALA') 
  
function thesala() 
    local playerTeam = getPlayerTeam ( source ) 
    local account = getPlayerAccount(source) 
    local accName1 = getAccountName(account) 
if isObjectInACLGroup ("user."..accName1, aclGetGroup ( "Owner" ) ) then 
setAccountData ( account, "SALA", "Owner" ) 
elseif isObjectInACLGroup ("user."..accName1, aclGetGroup ( "Admin" ) ) then 
setAccountData ( account, "SALA", "Admin" ) 
elseif isObjectInACLGroup ("user."..accName1, aclGetGroup ( "SuperModerator" ) ) then 
setAccountData ( account, "SALA", "SuperModerator" ) 
elseif isObjectInACLGroup ("user."..accName1, aclGetGroup ( "Moderator" ) ) then 
setAccountData ( account, "SALA", "Moderator" ) 
elseif isObjectInACLGroup ("user."..accName1, aclGetGroup ( "TrialModerator" ) ) then 
setAccountData ( account, "SALA", "TrialModerator" ) 
elseif isObjectInACLGroup ("user."..accName1, aclGetGroup ( "Everyone" ) ) then 
setAccountData ( account, "SALA", "Player" ) 
elseif ( playerTeam == "SWAT" ) then   
setAccountData ( account, "SALA", "Player" ) 
elseif ( playerTeam == "Military" ) then   
setAccountData ( account, "SALA", "Player" ) 
elseif ( playerTeam == "Army" ) then   
setAccountData ( account, "SALA", "Player" ) 
end 
end 
addEventHandler("onPlayerLogin", getRootElement(), thesala) 
  
addEventHandler("onPlayerLogin",root, 
function () 
    local Guest = getPlayerAccount(source) 
    if isGuestAccount(Guest) then return end 
    local sala = getAccountData(Guest,"SALA") 
    if sala then 
        setElementData(source,"SALA", sala) 
end 
end 
) 

Now its works with players too.

Link to comment

People should read more carefully... "playerTeam" will be TEAM ELEMENT not a string representing team's name. You need to get team name to compare it to string. You will get warning messages otherwise. Also, lines from 19 to 25 will never be reached. Every player is in "Everyone" group so this is where the code will ignore other statements.

One more thing, there is no point having 2 different onPlayerLogin handlers, especially when you're setting and getting account data. Event handlers are triggered asynchronously that means the order of the handlers being triggered is not always the same. For example, if you call cancelEvent function in the top handler, this doesn't necessarily mean that the handler below will not be triggered because it may have been triggered before the top one.

https://wiki.multitheftauto.com/wiki/CancelEvent

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