Jump to content

Not working


Drakath

Recommended Posts

triggerClientEvent always returns a boolean value (true if the event was triggered successfully, false otherwise).

If you want to retrieve the passcode from the client, the client has to trigger the value back to the server.

But it would make more sense to trigger the passcode only from the client to the server to save 1 triggered event like you do it already.

triggerServerEvent("checkcode",getRootElement(),getLocalPlayer(), thecode) 

==> The second parameter contains the passcode

function verify (player, passcode) 
    if passcode == "A4F8G0T1D5XP5" then 
        givePlayerMoney(source, 100) 
    else 
        outputChatBox("No!", source, 255, 0, 0, true) 
    end 
end 
addEvent("checkcode",true) 
addEventHandler("checkcode",getRootElement(),verify) 

Edit: Furthermore 'source' (in the scope of the verify function) contains the root element, not the player. If you want to output the message to the client who triggered the event, you can also use the global variable 'client' (behaves similar to source) or, as an alternative, you can pass localPlayer instead of "getRootElement()" to your triggerServerEvent call (but due to security issues it's better to use client).

Link to comment

Thanks and also I tried to make something that won't let use the code twice.

function verify (player, thecode) 
if thecode ~= "used" and thecode == "A4F8G0T1D5XP5" then 
givePlayerMoney(source, 100) 
thecode = "used" 
else 
outputChatBox("No!", source, 255, 0, 0, true) 
end 
end 
addEvent("checkcode",true) 
addEventHandler("checkcode",getRootElement(),verify) 

But it didn't work.

Link to comment
local codeUsed = { } 
  
function verify ( player, thecode ) 
    if ( thecode == "A4F8G0T1D5XP5" ) and ( not codeUsed [ thecode ] ) then 
        givePlayerMoney ( source, 100 ) 
        codeUsed [ thecode ] = true 
    else 
        outputChatBox ( "No!", source, 255, 0, 0, true ) 
    end 
end 
addEvent ( "checkcode", true ) 
addEventHandler ( "checkcode", getRootElement(), verify ) 

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