Jump to content

[HELP] Timer / Command


ViRuZGamiing

Recommended Posts

Hi,

I want to make people use this command /gift once every 24 Hours to get something out of table.

/gift > 1,2 or 3 out of the table and then you'll need to wait 1 day till command is back available.

This is what I got;

giftTable = { 
['1'] = givePlayerMoney( source, 2000 ), 
['2'] = outputChatBox( "Too bad you've won nothing today", source ), 
['3'] = giveWeapon ( source, 31, 200 ) 
} 
  
function getGift 
    math.random( #giftTable ) 
end 
  
    if getGift then 
        setTimer( getGift, "86400000" ) 
        else 
                outputChatBox( "You can only use this command once a day!", source ) 
    end 
  
addCommandHandler( "gift", getGift ) 

Link to comment

So this should work?

giftTable = { 
['1'] = givePlayerMoney(source, 2000), 
['2'] = outputChatBox( "Too bad you've won nothing today", source ), 
['3'] = giveWeapon ( source, 31, 200 ), 
['4'] = addPedClothes ( source, 9 ), 
['5'] = removePedClothes ( source, 9 ) 
} 
  
function getGift 
    math.random(#giftTable) 
end 
  
setTimer ( getGift, 86400000, 1, source ) 
  
addCommandHandler("gift", getGift) 

Testing it now and i'll reply if it works in 2-3 Minutes

Link to comment

Now I have;

Client

function ReplaceHat ( ) 
outputConsole ( "> replacing the Captruck!" ) 
  
txd = engineLoadTXD ( "models/txd/captruck.txd" ) 
engineImportTXD ( txd, 9 ) 
dff = engineLoadDFF ( "models/dff/captruck.dff", 9 ) 
engineReplaceModel ( dff, 9 ) 
end 
  
addEvent ( "replaceHat", true ) 
addEventHandler ( "replaceHat", getRootElement(), ReplaceHat ) 

Server

giftTable = { 
['1'] = givePlayerMoney(source, 2000), 
['2'] = outputChatBox( "Too bad you've won nothing today", source ), 
['3'] = giveWeapon ( source, 31, 200 ), 
['4'] = addPedClothes ( source, 9 ), 
['5'] = removePedClothes ( source, 9 ) 
} 
  
function getGift 
    math.random(#giftTable) 
end 
  
setTimer ( getGift, 86400000, 1, source ) 
  
addCommandHandler("gift", getGift) 

Link to comment
getRealTime 
-- You will need: < to make sure the timestamp bigger than the timestamp + a day timestamp. 

getPlayerAccount 

setAccountData 

getAccountData 

You don't need a timer and table.

Instead of the table you should do this:

function getGift(player) 
    local num = math.random(1, 5) 
    if num == 1 then 
        givePlayerMoney(player, 2000) 
    elseif num == 2 then 
        outputChatBox("Too bad you've won nothing today", player) 
    elseif num == 3 then 
        giveWeapon(player, 31, 200) 
    elseif num == 4 then 
        addPedClothes(player, 9) 
    elseif num == 5 then 
        removePedClothes(player, 9) 
    end 
end 
addCommandHandler("gift", getGift) 

Link to comment
Now I have;

Client

function ReplaceHat ( ) 
outputConsole ( "> replacing the Captruck!" ) 
  
txd = engineLoadTXD ( "models/txd/captruck.txd" ) 
engineImportTXD ( txd, 9 ) 
dff = engineLoadDFF ( "models/dff/captruck.dff", 9 ) 
engineReplaceModel ( dff, 9 ) 
end 
  
addEvent ( "replaceHat", true ) 
addEventHandler ( "replaceHat", getRootElement(), ReplaceHat ) 

has some error? or working?

Server

giftTable = { 
['1'] = givePlayerMoney(source, 2000), 
['2'] = outputChatBox( "Too bad you've won nothing today", source ), 
['3'] = giveWeapon ( source, 31, 200 ), 
['4'] = addPedClothes ( source, 9 ), 
['5'] = removePedClothes ( source, 9 ) 
} 
  
function getGift 
    math.random(#giftTable) 
end 
  
setTimer ( getGift, 86400000, 1, source ) 
  
addCommandHandler("gift", getGift) 

Link to comment

Now i've made this;

function getGift(player) 
    local num = math.random(1, 5) 
    if num == 1 then 
        givePlayerMoney(player, 2000) 
    elseif num == 2 then 
        outputChatBox("Too bad you've won nothing today!", player) 
    elseif num == 3 then 
        giveWeapon(player, 31, 200) 
    elseif num == 4 then 
        addPedClothes(player, 9) 
        outputChatBox("You've won a Christmas Hat!", player) 
    elseif num == 5 then 
        removePedClothes(player, 9) 
        outputChatBox("Too bad, you lost your Christmas Hat!", player) 
    else 
        local time = getRealTime() 
        local hours = time.hour 
        local minutes = time.minute 
        outputChatBox ( "Wait "..hours..":"..minutes.. "till you can use the gift command") 
    end 
end 
  
addCommandHandler("gift", getGift) 
  
--test 
function getAccount 
    local account = getPlayerAccount(thePlayer) 
    if account then 
        getAccountData(time) 
    end 
end 
  
function setAccount 
    local account = getPlayerAccount(thePlayer) 
    if account then 
        setAccountData(time) 
    end 
end 
  
addEventHandler("onPlayerQuit", getAccount) 
addEventHandler("onPlayerJoin", setAccount) 

@Rex didn't test it because TA-PL told it was wrong

Link to comment
function getAccount 
    local account = getPlayerAccount(thePlayer) 
    if account then 
        getAccountData(time) 
    end 
end 
  
function setAccount 
    local account = getPlayerAccount(thePlayer) 
    if account then 
        setAccountData(time) 
    end 
end 
  
addEventHandler("onPlayerQuit", getAccount) 
addEventHandler("onPlayerJoin", setAccount) 

---------------------

Does this make sense for you?

You get the current time and output it if the random number wasn't 1, 2, 3, 4, 5. make sense? no?

Though i told you to use timestamp not hours and minutes.

local time = getRealTime() 
local hours = time.hour 
local minutes = time.minute 
outputChatBox ( "Wait "..hours..":"..minutes.. "till you can use the gift command") 

Where is the brackets here?

function getAccount 

function setAccount 

And getAccount is mta native function name, you can't use it.

Where is thePlayer defined?

local account = getPlayerAccount(thePlayer) 

where time is defined?

Where is the rest of the arguments of the function getAccountData (2 arguments required).

getAccountData(time) 

where time is defined?

Where is the rest of the arguments of the function setAccountData (3 arguments required).

setAccountData(time) 

Where is the rest of the arguments of the function addEventHandler (3 arguments required).

And why you did put these event, you don't even need them.

addEventHandler("onPlayerQuit", getAccount) 
addEventHandler("onPlayerJoin", setAccount) 

No logical here, you didn't save the time and you didn't get it and you didn't compare it.

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