Jump to content

[Help]Police comp


Recommended Posts

Posted

I have made a police computer to tell me how many arrests i got and to show all criminals online in the server,, problem is that it totally not working, i checked the code many times cannot get the problem..

  
--Client 
function createwindow(theAccount, getdata) 
    if ( guiGetVisible ( window1 ) == false ) then 
    playerTeam = getPlayerTeam ( source ) 
    if getTeamName(playerTeam) == "Police" then  
    guiSetVisible (window1, true) 
    triggerServerEvent ( "setarrests", localPlayer, playerTeam)  
    guiSetText ( arrests_lab2, getdata ) 
else 
    if ( guiGetVisible ( window1 ) == true ) then 
    guiSetVisible (window1, false) 
end 
end 
end 
end 
addCommandHandler ( "pcomp", createwindow ) 

  
--Server 
function getdatas() 
    theAccount = getPlayerAccount ( source ) 
    local getdata = getAccountData(theAccount, "Arrests.count") 
end 
addEvent("setarrests", true) 
addEventHandler("setarrests", root, getdatas) 

There is no shown errors

( i know my code is nasty, i am still learning )

Posted (edited)

If you want to set a text on the client-side, you should be triggering over to the client-side event.

try this:

--Client 
function createwindow() 
    if not guiGetVisible ( window1 ) then 
        local playerTeam = getPlayerTeam ( localPlayer ) 
        if getTeamName(playerTeam) == "Police" then 
            guiSetVisible (window1, true) 
            triggerServerEvent ( "setarrests", localPlayer, playerTeam) 
        end 
    else 
        guiSetVisible (window1, false) 
    end 
end 
addCommandHandler ( "pcomp", createwindow ) 
  
addEvent("getArrestData",true) 
function getArrestData(data) 
    guiSetText ( arrests_lab2, data ) 
end 
addEventHandler("getArrestData",root,getArrestData) 
  
--Server 
function getdatas() 
    local theAccount = getPlayerAccount ( source ) 
    local getdata = getAccountData(theAccount, "Arrests.count") or "0" 
    triggerClientEvent(client,"getArrestData",client,tostring(getdata)) 
end 
addEvent("setarrests", true) 
addEventHandler("setarrests", root, getdatas) 

Edited by Guest
Posted

Try the code above again.

The only reason why you're getting that error is because the Account Data "Arrest.Count" is false, or doesn't exist, so I made the script return either the number of arrests or 0.

Posted

Try this now:

--Client 
function createwindow() 
    if not guiGetVisible ( window1 ) then 
        local playerTeam = getPlayerTeam ( localPlayer ) 
        if getTeamName(playerTeam) == "Police" then 
            guiSetVisible (window1, true) 
            triggerServerEvent ( "setarrests", localPlayer, playerTeam) 
        end 
    else 
        guiSetVisible (window1, false) 
    end 
end 
addCommandHandler ( "pcomp", createwindow ) 
  
addEvent("getArrestData",true) 
function getArrestData(data) 
    guiSetText ( arrests_lab2, data ) 
end 
addEventHandler("getArrestData",root,getArrestData) 
  
--Server 
function getdatas() 
    local theAccount = getPlayerAccount ( source ) 
    local getdata = getAccountData(theAccount, "Arrests.count") or "0" 
    triggerClientEvent(client,"getArrestData",client,tostring(getdata)) 
end 
addEvent("setarrests", true) 
addEventHandler("setarrests", root, getdatas) 

Posted

i am not talking about the data, i am talking about the 'guiSetText', will it change the text to the my data so i only can see it, or it changes the text to everyone ?

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