WelCome

Trigger + Database

Recommended Posts

Hello, I'm doing a base-system but I have a problem because when triggering from c-side to s-cide it crashes "Error" but the name and password are good

Server

addEvent("Base-System_",true)
addEventHandler("Base-System_",root,function(text1,text2)
if not text1 and text2 then return end
local konto = dbQuery (connect, "SELECT * FROM `Bazy` WHERE `nazwa`=?",text1)
local results = dbPoll(konto,-1)
if (#results == 0) then
outputChatBox("Error",source)
else
for i,v in ipairs(results) do
if text2 == v.haslo then
setElementData(source,v.dim)
outputChatBox("Error",source)
setElementPosition(source,-42.57263, -343.16113, -49)
end
end
end
end)

c-side

addEventHandler("onClientGUIClick",GUIEditor.button[5],function()
if source==GUIEditor.button[5] then
local text1 = guiGetText(GUIEditor.edit[1])
local text2 = guiGetText(GUIEditor.edit[2])
if text1 and text2 then
triggerServerEvent("Base-System_",localPlayer,text1,test2)
end
end
end)

 

Share this post


Link to post

First of all, I'd point out that, regarding line 3, there is a difference between (not text1 and text2) (this one will only evaluate true if text1 is logically false or nil and text2 is logically true or not nil) and (not text1 or not text2) (this one will only evaluate true if one or both of text1 or text2 is logically false or nil). The latter is, I believe, what you intended.

Secondly, you're outputting "Error" even when it succeeds (line 12).

Thirdly, setElementData on line 11 has the wrong syntax - it takes in 3 arguments, not 2 - and it appears you meant setElementDimension rather than setElementData.

Helpful tip: In order to debug this yourself, you should add

iprint(results)

between line 5 and 6, and open /debugscript 3 in game to see what the database query returns.

Edited by MrTasty

Share this post


Link to post

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.