Jump to content

Client triggered server side event, but event is not added serverside


Recommended Posts

script_c

[..]
function strt()
payment = 50
    if not isElementWithinMarker(localPlayer, work) then return end
        local random = math.random(2, #places)
          local target = createMarker(places[random][1], places[random][2], places[random][3]-1.0, "cylinder", 1.0, 255, 0, 0)
        local blip = createBlipAttachedTo(cel, 12)
        
        addEventHandler("onClientMarkerHit", cel, function(el, md)
            if not md or getElementType(el) ~= "player" then return end
            if el ~= localPlayer then return end

          

            destroyElement(cel)
            destroyElement(blip)
           setElementFrozen(el, true)
           setPedAnimation ( localPlayer, "CARRY", "crry_prtial", 1,true ) 
            setTimer(function()
                setElementFrozen(el, false)
                setPedAnimation(localPlayer, false)
                setElementData(localPlayer, "delivered", true)
			  triggerServerEvent("getPlayerCredits", getRootElement(), payment) -- HERE

            end, 5000, 1)
        end)
end

script_s

mysql = exports.mysql
addEvent("getPlayerCredits",true) 
addEventHandler("getPlayerCredits", resourceRoot, payment
function (payment) 
if getElementData(plr, "delivered") == true then
		exports.global:giveMoney(thePlayer,payment)
		outputChatBox("OK!",root,0,255,0) 
		return
	end
end) 

Error:

Client triggered server side event getPlayerCredits, but event is not added serverside

 

Link to comment
mysql = exports.mysql
addEvent("getPlayerCredits",true) 
addEventHandler("getPlayerCredits", resourceRoot,
function (payment) 
if getElementData(plr, "delivered") == true then
		exports.global:giveMoney(thePlayer,payment)
		outputChatBox("OK!",root,0,255,0) 
		return
	end
end)

Line 3 script_s

addEventHandler("getPlayerCredits", resourceRoot, payment

should be

addEventHandler("getPlayerCredits", resourceRoot, function(payment)

the reason for the error is because you didnt have a comma after payment which is still wrong syntax btw.

 

TIP:

You should use an editor that shows simple errors in Lua

9Jk8bwM.png

Edited by Mr.Loki
  • Like 1
Link to comment
1 hour ago, Mr.Loki said:

mysql = exports.mysql
addEvent("getPlayerCredits",true) 
addEventHandler("getPlayerCredits", resourceRoot,
function (payment) 
if getElementData(plr, "delivered") == true then
		exports.global:giveMoney(thePlayer,payment)
		outputChatBox("OK!",root,0,255,0) 
		return
	end
end)

Line 3 script_s

addEventHandler("getPlayerCredits", resourceRoot, payment

should be

addEventHandler("getPlayerCredits", resourceRoot, function(payment)

the reason for the error is because you didnt have a comma after payment which is still wrong syntax btw.

 

TIP:

You should use an editor that shows simple errors in Lua

9Jk8bwM.png

Okay, now it's saying: (Line 4 script_s)  bad argument @'getElementData'  [expected element at argument 1, got nil]

Link to comment

You have "plr" and "thePlayer" they are not defined as far as what I can see in the code.

 

Who is plr and who is thePlayer?

I'm guessing that plr = player sending money and thePlayer = player receiving money

If so then you should set the source of the event to the localPlayer by changing getRootElement() to LocalPlayer in line 23

Then add that "el" variable to 1 of the arguments along with payment at line 23 so it would look like: localPlayer, el, payment)

Next in your server event change "plr" to source which will be the localPlayer and add "thePlayer" right before payment in line 3 as a function parameter it would look like:

function(thePlayer,payment)

 

  • Like 1
Link to comment
19 minutes ago, Mr.Loki said:

You have "plr" and "thePlayer" they are not defined as far as what I can see in the code.

 

Who is plr and who is thePlayer?

I'm guessing that plr = player sending money and thePlayer = player receiving money

If so then you should set the source of the event to the localPlayer by changing getRootElement() to LocalPlayer in line 23

Then add that "el" variable to 1 of the arguments along with payment at line 23 so it would look like: localPlayer, el, payment)

Next in your server event change "plr" to source which will be the localPlayer and add "thePlayer" right before payment in line 3 as a function parameter it would look like:

function(thePlayer,payment)

 

No, i just want to give player money from work

Edited by jessiepinkman
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...