malu2000 Posted January 23, 2023 Share Posted January 23, 2023 Hello i'm new here and i need help with a script, if you type /getgift it's says that you have recived $1000 but i didn't.. help me please local lastUsed = {} function giveMoney() local player = source local playerName = getPlayerName(player) local currentTime = getRealTime().timestamp if lastUsed[playerName] then local lastUsedTime = lastUsed[playerName] local timePassed = currentTime - lastUsedTime if timePassed < 86400 then outputChatBox("You can only use this command once per day.", player) return end end givePlayerMoney(player, 1000) outputChatBox("You have received $1000.", player) lastUsed[playerName] = currentTime end addCommandHandler("getgift", giveMoney) Link to comment
Shady1 Posted January 23, 2023 Share Posted January 23, 2023 (edited) 1 hour ago, malu2000 said: Hello i'm new here and i need help with a script, if you type /getgift it's says that you have recived $1000 but i didn't.. help me please local lastUsed = {} function giveMoney() local player = source local playerName = getPlayerName(player) local currentTime = getRealTime().timestamp if lastUsed[playerName] then local lastUsedTime = lastUsed[playerName] local timePassed = currentTime - lastUsedTime if timePassed < 86400 then outputChatBox("You can only use this command once per day.", player) return end end givePlayerMoney(player, 1000) outputChatBox("You have received $1000.", player) lastUsed[playerName] = currentTime end addCommandHandler("getgift", giveMoney) hello welcome to the forum,The code you provided appears to be a script that gives a player $1000 in-game money, but only allows them to use the command once per day. It appears to be functional, however, there are a few things that can be improved: 1- The variable `currentTime` is not being defined, you should use `getRealTime().timestamp` to get the current timestamp. 2-The `lastUsed` table is defined at the top of the script, but it is not being reset, so players who use the command once will not be able to use it again until the script is restarted. To fix this, you can add a line at the top of the `giveMoney` function to check if the current day is different from the last time the player used the command and reset the `lastUsed` table if it is. 3-The output message should be improved, it is better to use `outputChatBox("You can only use this command once per day. Wait "..timePassed.." seconds.", player)` instead of just "You can only use this command once per day.". This way the player will know when they can use the command again. local lastUsed = {} local lastDay = 0 function giveMoney() local player = source local playerName = getPlayerName(player) local currentTime = getRealTime().timestamp local currentDay = getRealTime().monthday if currentDay ~= lastDay then lastUsed = {} lastDay = currentDay end if lastUsed[playerName] then local lastUsedTime = lastUsed[playerName] local timePassed = 86400 - (currentTime - lastUsedTime) if timePassed > 0 then outputChatBox("You can only use this command once per day. Wait "..timePassed.." seconds.", player) return end end givePlayerMoney(player, 1000) outputChatBox("You have received $1000.", player) lastUsed[playerName] = currentTime end addCommandHandler("getgift", giveMoney) I want to try this code, hope it will work for you Edited January 23, 2023 by Shady1 Link to comment
malu2000 Posted January 23, 2023 Author Share Posted January 23, 2023 Unfortunately, your script has the same problem, doesn't give me the money, but i have another script that works, i'm gonna use that because i think it's more complex. I don't even know why i did this topic because as i said i have another script that works. I guess i was curious why it didn't work.. Link to comment
Shady1 Posted January 24, 2023 Share Posted January 24, 2023 8 hours ago, malu2000 said: Unfortunately, your script has the same problem, doesn't give me the money, but i have another script that works, i'm gonna use that because i think it's more complex. I don't even know why i did this topic because as i said i have another script that works. I guess i was curious why it didn't work.. change function : function giveMoney(player) Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now