Jump to content

Need help with scripting.


Ernis456

Recommended Posts

Posted (edited)

What lua code to make gates on my own ?

Another question.

How to make payday ? e.g. Every 20 minutes player gets 3 000 $

How to do car reserved to job. e.g. Only cops can drive Police car.

Edited by Guest
Posted

Thanx.

Another question.

How to make payday ? e.g. Every 20 minutes player gets 3 000 $

How to do car reserved to job. e.g. Only cops can drive Police car.

Posted
function payDay(money)
local players = getElementsByType ( "player" )
for theKey,thePlayer in ipairs(players) do
givePlayerMoney(thePlayer, tonumber(money))
end
end

Simply use a Timer with the payDay Function.

Posted
Another question.

I see two questions:P

How to make payday ? e.g. Every 20 minutes player gets 3 000 $
setTimer
getElementsByType("player")
givePlayerMoney

but payday script is on community

How to do car reserved to job. e.g. Only cops can drive Police car.
-- use event onVehicleStartEnter with
addEventHandler
-- and in handler function get the vehicle model id
getElementModel
-- and check if the id is one of police cars
-- if yes, check if the player model id
getElementModel
-- is the cop id
-- if NOT do
cancelEvent()

and now, FANFARES :D

edit:

of course before cancelling the event you can output something to the players chatbox, so players won't get confused, why enter key isn't working :P

Posted

I have problem.

When I run my script Payday:

function PayDay ( text )
givePlayerMoney (thePlayer, 3000 )
end
setTimer ( PayDay, 3000, 1, "PayDay 3 000 $ ! " )

I getting error in console :

WARNING: payday.lua: Bad argument @ 'givePlayerMoney' - Line: 2

Posted
-- func -- time  -- repeat -- money
setTimer ( PayDay, 3000, 1, 3000 )
 
function payDay(money)
local players = getElementsByType ( "player" )
for theKey,thePlayer in ipairs(players) do
givePlayerMoney(thePlayer, tonumber(money))
outputChatBox("It's your payday, you've received 3000$",thePlayer,255,255,0)
end
end

should work

Posted
I have problem.

When I run my script Payday:

function PayDay ( text )
givePlayerMoney (thePlayer, 3000 )
end
setTimer ( PayDay, 3000, 1, "PayDay 3 000 $ ! " )

I getting error in console :

WARNING: payday.lua: Bad argument @ 'givePlayerMoney' - Line: 2

your script.. its totally random!

you just ignored

getElementsByType("player")

(i told you about that)

and you are passing text that you dont use, and you are using unexisting variables (thePlayer)

here's the code (hope you will think on it, not just copy and paste)

function PayDay(howMuch)
local playerList = getElementsByType("player") -- we are getting all players
for key,val in ipairs(playersList) do -- we are looping through all players
-- val is one of the players
givePlayerMoney(val, howMuch) -- we give howMuch variable, passed in setTimer
end
outputChatBox("Payday: $"..howMuch) -- we are outputting chatbox message to everyone on the server
end
local mins = 30 -- every X minutes payday will be done
local howMuch = 1000 -- we are setting variable defining the money to give
-- we are setting timer (check: [url=https://wiki.multitheftauto.com/wiki/SetTimer]https://wiki.multitheftauto.com/wiki/SetTimer[/url])
setTimer(PayDay, mins*60*1000, 0, howMuch) -- function | time (in ms!, that why its multiplied by 1000 and 60 (1000ms = 1 sec, 1 sec*60 = 1 min, and mins(30)*1 min = 30mins) | infinite repeating | how much money to give

Posted
setTimer ( PayDay, 3000, 1, 3000 )
-- CUT

should work

yea, but it will be giving it every 3 secs in that one :P i think author confused time and money in setting timer

Posted

function PayDay(howMuch)
         local playerList = getElementsByType("player") 
         for key,val in ipairs(playersList) do 
             givePlayerMoney(val, howMuch)
         end
         outputChatBox("Payday: $"..howMuch) 
     end
     local mins = 1 
     local howMuch = 3000 
     setTimer(PayDay, mins*60*1000, 0, howMuch)

error : payday.lua:3: bad argument #1 to 'ipairs' (table expected, got nil)

How can I fix it ?

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