Jump to content

Problem with addEventHandler function


Recommended Posts

function avvertilogin(thePlayer)
outputChatBox("** Login or register for ranking system and save money", getRootElement(), 100, 255, 0)
end
addEventHandler("onPlayerJoin",thePlayer,avvertilogin)

function registrazionedb(thePlayer)
local account = getAccountName(getPlayerAccount(thePlayer))
if(account) then
executeSQLSelect("Giocatori", "Giocatore", "Giocatore = '" ..account.. "'")
if (type(result) == "table" and #result == 0) or not result then
outputChatBox("** One moment while your account is registered in Database ", getRootElement(), 100, 255, 0)
executeSQLInsert("Giocatori","'"..account.."',0,0,0")
outputChatBox("** Ok, Account succesfuly registered ! ", getRootElement(), 100, 255, 0)
end
outputChatBox("** Ok, Account succesfuly loaded from Database ! ", getRootElement(), 100, 255, 0)
local datiaccount = executeSQLSelect("Giocatori", "Soldi, Kill, Morti", "Giocatore = '" ..account.. "'")
setPlayerMoney(thePlayer,datiaccount[1]['Soldi'])
textCreateTextItem("Kill :", 0.8, 0.35, "medium", 255, 255, 0)
textCreateTextItem("Death :", 0.8, 0.4, "medium", 255, 255, 0)
textCreateTextItem("Ratio :", 0.8, 0.4, "medium", 255, 255, 0)	
end
end
addEventHandler("onPlayerLogin",thePlayer,registrazionedb)

When i start the resource mta server give me 2 warning :

Bad Argument @ 'AddEventHandler' string defined function

Bad Argument @ 'AddEventHandler' string defined function

Link to comment

On your script, which one is client, which one is server? If it's client, don't give "theplayer", or any kind like that on every part of the script.

the addEventHandler is having a wrong argument on the second argument.

So the correct addEventHandler should be:

addEventHandler("onPlayerJoin", getRootElement(), avvertilogin)

It's easy, change "theplayer" in addEventHandler to "getRootElement()".

Here's the example: (Also fixed the typos in your writing)

function registrazionedb(thePlayer)
local account = getAccountName(getPlayerAccount(thePlayer))
if(account) then
executeSQLSelect("Giocatori", "Giocatore", "Giocatore = '" ..account.. "'")
if (type(result) == "table" and #result == 0) or not result then
outputChatBox("** Please wait while your account is being registered in the database... ", getRootElement(), 100, 255, 0) -- Proper english output fix by me!
executeSQLInsert("Giocatori","'"..account.."',0,0,0")
outputChatBox("**Account succesfuly registered! ", getRootElement(), 100, 255, 0) --Proper english output fix again by me!
end
outputChatBox("** Account sucessfully loaded! ", getRootElement(), 100, 255, 0) --Proper english output fix again by me!
local datiaccount = executeSQLSelect("Giocatori", "Soldi, Kill, Morti", "Giocatore = '" ..account.. "'")
setPlayerMoney(thePlayer,datiaccount[1]['Soldi'])
textCreateTextItem("Kill :", 0.8, 0.35, "medium", 255, 255, 0)
textCreateTextItem("Death :", 0.8, 0.4, "medium", 255, 255, 0)
textCreateTextItem("Ratio :", 0.8, 0.4, "medium", 255, 255, 0)   
end
end
addEventHandler("onPlayerLogin",getRootElement(),registrazionedb) -- Changed "theplayer" to "getRootElement()" in this line.

PS: You must be -RoCk-Emalegend, right? You must be doing this for the -RoCk- clan server. I can help you fix some problems.

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