Jump to content

[Help]2 questions


Recommended Posts

Posted

now i am trying to do an arrest system, which when you arrest someone your arrests goes up, i have made the arrest thing ( when you hit someone with night stick he follows you, and you should transport him into a marker ) but idk how to make it count the arrests,, so maybe someone can help me,, btw i am not asking someone to make for me the code i want to learn it myself,, so i am just asking to post which functions should i use,, if i will have to use SQL or smthing else... etc

i have made a transfer money gui,, it's working but i defined 'to_who' the money is going to be sent in client how to define it in server?

for example

client

    local to_who = guiGetText( GUIEditor.edit[2] ) 
  

server

function givemoney (  ) 
    givePlayerMoney ( to_who, amount ) 
    takePlayerMoney ( source, amount ) 
end 
addEvent( "takegive", true ) 
addEventHandler( "takegive", root, givemoney ) 

i tried to trigger it but it's not working

debugscript:

Bad argument @ 'givePlayerMoney'

Bad argument @ 'takePlayerMoney'

as you all know i cannot use those functions (givePlayerMoney, takePlayerMoney ) in client because it got only 1 argument which is the amount

Posted

You can use table.insert and table.remove to store/remove arrested players in a table. Then just count the entires inside that table to see how many players are arrested.

@Money;

You're not retrieving any data, thus the function does not know what to do. I don't know how you trigger it, but you'll need to do something like this;

triggerEvent("takegive", getRootElement(), theGiver, theReceiver, theAmount) 
  
function givemoney(theGiver, theReceiver, theAmount) 
    givePlayerMoney(theGiver, theAmount) 
    takePlayerMoney(theReceiver, theAmount) 
end 
addEvent("takegive", true) 
addEventHandler("takegive", root, givemoney) 

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

Posted

you didn't get what i said about the arrests, example i just arrested and jailed 2 criminals,, how to make someone see how many arrests he got ?

about the money,, so i don't understand, should i triggerServerEvent in the client or leave the server as you wrote with editing "to_who" to "theGiver" ??

edit: i left the serverthe server as you wrote with editing "to_who" to "theGiver" but still not working and still the same debug script errors

Posted

Ah, I see. You'll probably want to use setAccountData if you wanna save their total amount of arrests, kind of like statistics. Right? Then use getAccountData to get their score.

About the money, I'd have to see how you trigger the event "takegive".

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

Posted

So should when the player enter the marker i set his account data to 'setAccountData ( 'definetheacc', "arrests", 'and whatshould be here ??')

about the money here is what you want

function transfer( thePlayer ,button, state, absoluteX, absoluteY) 
if ( source == GUIEditor.button[2] ) then 
guiSetVisible (GUIEditor.window[1], false) 
showCursor (false) 
end 
if  source == GUIEditor.button[1] then 
    local to_who = guiGetText( GUIEditor.edit[2] ) 
    amount = tonumber( guiGetText( GUIEditor.edit[1] ) ) 
if to_who == nil or to_who == false or to_who == "" then 
    outputChatBox( "Please type the player name which you want to transfer the money to" ) 
elseif amount == nil then 
     outputChatBox( "You must type the amount you want to withdraw!" ) 
elseif amount < 0 then 
     outputChatBox( "Please enter a valid number" ) 
else 
    local money = getPlayerMoney(thePlayer)   
    if money < amount then 
    outputChatBox( "You don't have that amount of money" ) 
else 
    local getp = getPlayerFromName ( thePlayer ) 
    outputChatBox(" "..getp.." gave "..to_who.." ".. amount.." ") 
    triggerServerEvent ( "takegive", localPlayer )  
end 
end 
end 
end 
addEventHandler( "onClientGUIClick", GUIEditor.button[1], transfer) 
addEventHandler( "onClientGUIClick", GUIEditor.button[2], transfer) 

Posted

Sorry for the delay, I re-worked your code a bit. Make sure you read it thoroughly and look for comments I added where I made some bigger changes instead of simply pasting it - that way, you'll learn faster! :)

Client-Side:

function transfer() 
    if(source == GUIEditor.button[2]) then 
        guiSetVisible(GUIEditor.window[1], false) 
        showCursor(false) 
    end 
    if(source == GUIEditor.button[1]) then 
        local theReceiver = guiGetText(GUIEditor.edit[2]) 
        local theAmount = tonumber(guiGetText(GUIEditor.edit[1])) 
        if((theReceiver == nil) or (theReceiver == false) or (theReceiver == "")) then 
            outputChatBox("Please type the player name which you want to transfer the money to.") 
        elseif((theAmount == nil) or (theAmount == "")) then 
            outputChatBox("You must type the amount you want to withdraw!") 
        elseif(theAmount <= 0) then 
            outputChatBox("Please enter a valid number") 
        else 
            local theMoney = getPlayerMoney(localPlayer) 
            if(theMoney < theAmount) then 
                outputChatBox("You don't have that amount of money") 
            else 
                -- Since you converted theAmount to an integer, you'll need to re-convert it into a string to use it in chat message. 
                -- You were also trying to get the player ELEMENT, instead of the player NAME (getp) - you don't even need this. Since it's always the localPlayer. 
                -- Also the need of an announcement is not needed other than for debugging - since only YOU will see it. (Hence, client-side) 
                local theReceiverElement = getPlayerFromName(theReceiver) 
                if(getElementType(theReceiverElement) == "player") then 
                    outputChatBox("You have given "..getPlayerName(theReceiverElement).." $"..tostring(theAmount).:".") 
                    triggerServerEvent("takegive", localPlayer, theReceiverElement, theAmount) 
                else 
                    outputChatBox("Invalid player! Make sure you wrote their name correctly. (Including Hex tags!)") 
                end 
            end 
        end 
    end 
end 
addEventHandler("onClientGUIClick", getRootElement(), transfer) 

Server-Side;

function givemoney(theGiver, theReceiver, theAmount) 
    if((theGiver ~= nil) and (theReceiver ~= nil) and (theAmount ~= nil)) then 
        takePlayerMoney(theGiver, theAmount) 
        givePlayerMoney(theReceiver, theAmount) 
        local giverName, receiverName = getPlayerName(theGiver), getPlayerName(theReceiver) 
        outputChatBox(giverName.." has given "..receiverName.." $"..tostring(theAmount)..".", getRootElement()) 
    end 
end 
addEvent("takegive", true) 
addEventHandler("takegive", root, givemoney) 

Also, do note that I have not tested this code whatsoever. Mistakes and typos might happen. However, you should be able to go from here.

Edit:

As for setting account data, it's really simple! For example, if a data has not been set for the specified key already, it will return false. You can do something like this;

Server-Side; (Account Data is always server-side, the data is also permanent. Data used using element data - is not.)

-- This is just an example, you'll have to make the function and event(s) yourself. 
local theData = getAccountData(theAccount, "Test.criminalsJailed") 
if(theData == false) then 
    local setData = setAccountData(theAccount, "Test.criminalsJailed", amountJailed) 
    if(setData ~= false) then 
        outputChatBox("Data successfully set! Amount Jailed: ["..tostring(amountJailed).."]") 
    else 
        outputChatBox("Failed to set data, check debug!") 
    end 
else 
    outputChatBox("Data was already set, old value: ["..tostring(theData).."]") 
    local updateData = setAccountData(theAccount, "Test.criminalsJailed", amountJailed) 
    if(updateData ~= false) then 
        outputChatBox("Successfully updated data! Amount Jailed: ["..tostring(amountJailed).."]") 
    else 
        outputChatBox("Failed to update data, check debug!") 
    end 
end 

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

Posted

Thank you,, you're the best...

Sorry, i am going to fatigue you,,

for the arrest count, i wanted to try your code but i just have a question

function test(thePlayer) 
theAccount = getPlayerAccount ( thePlayer ) 
if not isGuestAccount ( theAccount ) then 
local theData = getAccountData(theAccount, "Test.criminalsJailed") 
if(theData == false) then 
    local setData = setAccountData(theAccount, "Test.criminalsJailed", amountJailed) 
    if(setData ~= false) then 
        outputChatBox("Data successfully set! Amount Jailed: ["..tostring(amountJailed).."]") 
    else 
        outputChatBox("Failed to set data, check debug!") 
    end 
else 
    outputChatBox("Data was already set, old value: ["..tostring(theData).."]") 
    local updateData = setAccountData(theAccount, "Test.criminalsJailed", amountJailed) 
    if(updateData ~= false) then 
        outputChatBox("Successfully updated data! Amount Jailed: ["..tostring(amountJailed).."]") 
    else 
        outputChatBox("Failed to update data, check debug!") 
    end 
end 
end 
end 
addCommandHandler ( "arrests", test ) 
  

everytime i write /arrests, it says

Data successfully set! Amount Jailed: [nil] -- First time

Data was already set, old value: [nil] -- second time

Successfully updated data! Amount Jailed: [nil]

So it was [nil] because he didn't arrest anyone but how to make it grow like if someone writes /seta number

what i have thought but i am quite sure it won't work i am not at home so i can't test it

function seta( thePlayer, arg1 ) 
theAccount = getPlayerAccount ( thePlayer ) 
if not isGuestAccount ( theAccount ) then 
local theData = getAccountData(theAccount, "Test.criminalsJailed") 
if(theData == true) then 
    local setData = setAccountData(theAccount, "Test.criminalsJailed", arg1 ) 
    outputChatBox("Test") 
elseif (theData == false) then 
        outputChatBox("Failed to set your arrests number") 
        end 
end 
end 
addCommandHandler ( "setar", seta ) 

Posted

Where are you defining the variable amountJailed? As far as I can tell, you're not defining it. Thus, it defaults to nil. Thus, it returns nil. :)

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

Posted

Well, i got what you said, but still didn't get what should i write in the script :D

like this ?

function seta( thePlayer, arg1 ) 
theAccount = getPlayerAccount ( thePlayer ) 
if not isGuestAccount ( theAccount ) then 
local theData = getAccountData(theAccount, "Test.criminalsJailed") 
if(theData == true) then 
    local setData = setAccountData(theAccount, "Test.criminalsJailed", amountJailed, arg1 ) 
    outputChatBox("Testsset") 
elseif (theData == false) then 
        outputChatBox("Failed to set your arrests number") 
        end 
end 
end 
addCommandHandler ( "setar", seta ) 

btw it is not working and debug is not showing erros

Posted

In a command handler function, the second argument is the command.

Try this:

function seta( thePlayer, cmd, arg1 ) 
theAccount = getPlayerAccount ( thePlayer ) 
if not isGuestAccount ( theAccount ) then 
local theData = getAccountData(theAccount, "Test.criminalsJailed") 
if(theData == true) then 
    local setData = setAccountData(theAccount, "Test.criminalsJailed", amountJailed, arg1 ) 
    outputChatBox("Testsset") 
elseif (theData == false) then 
        outputChatBox("Failed to set your arrests number") 
        end 
end 
end 
addCommandHandler ( "setar", seta ) 

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

Posted

The variable amountJailed was just an example. You'll have to create and define this variable yourself. If it is not defined, it will be returning nil.

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

Posted

Finally i know now how will i do it,, thank you guys,, :)

now it is working and it outputs the old value and the new one, so i think it works. i will try now to use it in a form of a police computer. :wink:

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