
t3wz
Members-
Posts
149 -
Joined
-
Last visited
Everything posted by t3wz
-
What about an anti flood or something like?
-
Well i don't know much about Dayz but you can try this: addEventHandler ( "onElementDataChange", root, function ( name, oldValue ) if name == "blood" then setElementData ( source, name, oldValue ) end end ) (serverside)
-
[quote name=..&G:..]May I ask why you did "result = result * amount"? Just curious If the player wants to convert 20 EURs to x USDs for example, result return how much is 1 USD, then we need to do that math to convert 1 USD to 20 USDs
-
[quote name=..&G:..]I tried to use "client" as I saw on wiki, but it doesn't work, it says "String expected got nil" or something like that.. This is because client isn't defined (he 'appears' in the serverside when you use triggerServerEvent) this should work: triggerClientEvent ( thePlayer, "showConversionResult", thePlayer, from, to, tonumber ( amount ), results["rates"][to] )
-
[quote name=..&G:..]The thing is that I want to set the default currency from a window, so I want to make a command to set it. Something like that? Server: local validCurrencies = { ["AUD"] = true, ["BGN"] = true, ["BRL"] = true, ["CAD"] = true, ["CHF"] = true, ["CNY"] = true, ["CZK"] = true, ["DKK"] = true, ["GBP"] = true, ["HKD"] = true, ["HRK"] = true, ["HUF"] = true, ["IDR"] = true, ["ILS"] = true, ["INR"] = true, ["JPY"] = true, ["KRW"] = true, ["MXN"] = true, ["MYR"] = true, ["NOK"] = true, ["NZD"] = true, ["PHP"] = true, ["PLN"] = true, ["RON"] = true, ["RUB"] = true, ["SEK"] = true, ["SGD"] = true, ["THB"] = true, ["TRY"] = true, ["USD"] = true, ["ZAR"] = true, ["EUR"] = true } function convert ( thePlayer, cmd, from, to, amount ) if from and to and amount and tonumber(amount) and tonumber(amount) > 0 then if validCurrencies[from] then if validCurrencies[to] then fetchRemote ( "http://api.fixer.io/latest?base="..from, function ( response, error ) if error == 0 then local results = fromJSON ( response ) triggerClientEvent ( thePlayer, "onResponse", thePlayer, from, to, tonumber ( amount ), results["rates"][to] ); else outputChatBox ( "Error "..error.." when getting the currency, contact an admin", thePlayer, 255, 0, 0 ) end end ) else outputChatBox ( "Invalid currency (to)", thePlayer, 255, 0, 0 ) end else outputChatBox ( "Invalid currency (from)", thePlayer, 255, 0, 0 ) end else outputChatBox ( "Syntax: /convert [FROM] [TO] [AMOUNT]", thePlayer, 255, 0, 0 ) end end addCommandHandler ( "convert", convert ) Client: function onResponse ( from, to, amount, result ) result = result * amount outputChatBox ( "results sucesfully passed to the client. ("..result..")" ) --[[ here you use guiSetText or something like that. parameters: @ from = A currency (string), ex: EUR @ to = A currency (string), ex: USD @ amount = How much the player want to calculate (int), ex: 2 @ result = How much 'to' is 'from' (int), ex: $1.2 (without the $) --]] end addEvent ( "onResponse", true ) addEventHandler ( "onResponse", root, onResponse ) of course you need to edit it (add the guis, remove the command if you want etc)
-
change if ( getElementInerior(challanger) == 11 ) then to if ( getElementInterior(challanger) == 11 ) then i'd suggest you to look at the code before creating a new topic, this is a small mistake that can be fixed quickly..
-
updateCurrencies function only gets the currencies from the site, it does not return anything useful. you've to do something like this: currencies = {} function updateCurrencies ( ) fetchRemote ( "http://api.fixer.io/latest?base=USD", -- se, i'veh changed the url... function ( response, error ) if error == 0 then local decode = fromJSON ( response ) currencies = decode["rates"] else print ( "error "..error.." when getting the currency." ) end end ) return true end updateCurrencies() setTimer ( updateCurrencies, 1 * 3600000, 0 ) function convertCommand ( thePlayer, cmd, currency, number ) if currency and number and tonumber(number) and tonumber(number) > 0 then if currencies[currency] then local number = tonumber ( number ) local result = currencies[currency] * number outputChatBox ( number.." USD == "..result.." "..currency, thePlayer, 0, 255, 0 ) -- changing EUR to USD doesn't change anything on the script, it's just a string... else outputChatBox ( "Invalid currency", thePlayer, 255, 0, 0 ) end else outputChatBox ( "Syntax: /convert [currency] [number]", thePlayer, 255, 0, 0 ) end end addCommandHandler ( "convert", convertCommand ) about fetchRemote, if you go to the wiki you'll see the parameters of this function, the second parameter (ignoring the optional) has to be an function (which will receive the 'results' of the fetch) sorry if my explications is confusing you, my english does not help
-
what event ?, i don't understood what you mean. maybe guiSetEnabled (as the title says) ?
-
as written in the page: and what you don't understood in updateCurrencies function?
-
in triggerServerEvent the second parameter must be a string ("spawm").
-
in the line 3 you define a function called createPed and in the line 8 you call createPed(...), this cause an infinite loop. you could do something like this: defaultCreatePed = createPed function createPed() for i=1,#ped do if (isElement(worker[i])) then destroyElement(worker[i]) else worker[i] = defaultCreatePed (ped[i][5], ped[i][1], ped[i][2], ped[i][3], ped[i][4]) end end end
-
[quote name=..&G:..]And how do I use that? I never used a fetchRemote function before... Like, how do I make a command like "/checkexchange 1 eur" ? fetchRemote gets the 'text' of a site (in this case http://api.fixer.io/latest) and send it as parameter of the function defined in the second parameter. the response is something like that: { "base": "EUR", "date": "2015-08-14", "rates": { "AUD": 1.5122, "BGN": 1.9558, "BRL": 3.91, "CAD": 1.4571, "CHF": 1.0875, "CNY": 7.1396, "CZK": 27.028, "DKK": 7.4633, "GBP": 0.7145, "HKD": 8.664, "HRK": 7.5435, "HUF": 310.69, "IDR": 15387.8, "ILS": 4.2187, "INR": 72.62, "JPY": 138.7, "KRW": 1314.78, "MXN": 18.326, "MYR": 4.5583, "NOK": 9.1375, "NZD": 1.7033, "PHP": 51.557, "PLN": 4.1862, "RON": 4.4257, "RUB": 72.452, "SEK": 9.4308, "SGD": 1.5667, "THB": 39.322, "TRY": 3.1652, "USD": 1.1171, "ZAR": 14.293 } } ... in JSON format, then we use fromJSON and convert it to Lua tables. table = { ["base"] = "EUR", ["date"] = "2015-08-14", ["rates"] = { ["AUD"] = = 1.5122, ["BGN"] = = 1.9558 ["BRL"] = 3.91, ["CAD"] = 1.4571, ["CHF"] = 1.0875, ["CNY"] = 7.1396, ["CZK"] = 27.028, ["DKK"] = 7.4633, ["GBP"] = 0.7145, ["HKD"] = 8.664, ["HRK"] = 7.5435, ["HUF"] = 310.69, ["IDR"] = 15387.8, ["ILS"] = 4.2187, ["INR"] = 72.62, ["JPY"] = 138.7, ["KRW"] = 1314.78, ["MXN"] = 18.326, ["MYR"] = 4.5583, ["NOK"] = 9.1375, ["NZD"] = 1.7033, ["PHP"] = 51.557, ["PLN"] = 4.1862, ["RON"] = 4.4257, ["RUB"] = 72.452, ["SEK"] = 9.4308, ["SGD"] = 1.5667, ["THB"] = 39.322, ["TRY"] = 3.1652, ["USD"] = 1.1171, ["ZAR"] = 14.293 } } with the table we can convert 1 EUR to 1 USD for example with table["rates"]["USD"] and make a command like this: currencies = {} -- table that will store all the currencies. function updateCurrencies ( ) -- function that will get the currencies from the site and update him at the table fetchRemote ( "http://api.fixer.io/latest", function ( response, error ) if error == 0 then local decode = fromJSON ( response ) currencies = decode["rates"] --set the currencies table equal to the response of the fetchRemote function else print ( "error "..error.." when getting the currency." ) end end ) return true end updateCurrencies() -- call the function for the first time setTimer ( updateCurrencies, 1 * 3600000, 0 ) -- update the values (call the function again) every one hour. function convertCommand ( thePlayer, cmd, currency, number ) -- command: /convert [currency] [number] (ex: /convert USD 2 will convert 2 EURs to 2 USDs) if currency and number and tonumber(number) and tonumber(number) > 0 then if currencies[currency] then -- if is a valid currency local number = tonumber ( number ) local result = currencies[currency] * number outputChatBox ( number.." EUR == "..result.." "..currency, thePlayer, 0, 255, 0 ) else outputChatBox ( "Invalid currency", thePlayer, 255, 0, 0 ) end else outputChatBox ( "Syntax: /convert [currency] [number]", thePlayer, 255, 0, 0 ) end end addCommandHandler ( "convert", convertCommand ) hope u understand. obs: the values (in the site) are updated daily (so there's no need to use fetchRemote every hour, that's just an example..)
-
can any one help as fast as possible in simple script
t3wz replied to nasserdfdd's topic in Scripting
This isn't working because client isn't defined, if you go to the onPlayerJoin page on wiki you will see that there is a source, which is the player who joined. you should have used this instead of client. also in line 3, you are checking if getPlayerTeam (a function) is equal to an empty string, this never will true... -
if getElementDimension ( element ) == 4 then -- end also you've to edit the freeroam resource.
-
local x, y = guiGetScreenSize() local rx, ry = (x/1400), (y/900) local rendering function createDx ( ) dxDrawImage(rx*398, ry*410, rx*300, ry*300, 'up.png') end bindKey("F10","down",function () if rendering then removeEventHandler("onClientRender",root,createDx) showCursor ( false ) else addEventHandler("onClientRender",root,createDx) showCursor ( true ) end rendering = not rendering end ) i just forgot an ) ...
-
IIYAMA already answered you. The first code will add a new event called "onPlayerTeamChange" and the second will make the blip visible/invisible, just add them to your current code ...
-
The 'problem' is caused when you check if the element who is entering the area is different than a player (in line 13) just make other check (elseif) to know if it is a vehicle.
-
[quote name=..&G:..]Those are API's and I have to make a website for that, which I don't really want to atm, I want something simple I found this https://www.google.com/finance/converter , But I don't know how to call it so I can select the currencies and amount in-game, and also display only the result of the conversion.. you don't need to create a website... fetchRemote ( "http://api.fixer.io/latest", function ( response, error ) if error == 0 then response = fromJSON ( response ) -- the response is encoded in json, then we need to use fromJSON print ( "1 EUR == "..response["rates"]["BRL"].." BRL" ) else print ( "error "..error.." when getting the currency." ) end end )
-
Use getPedOccupiedVehicle with setVehicleDamageProof and when the player leaves the area (onColShapeLeave) you use setVehicleDamageProof again...
-
You can use a site that provides the currency exchange in an api, something like this or this.
-
lines 9~10, you remove the event and then remove it again, what? (also you forget the then). local x, y = guiGetScreenSize() local rx, ry = (x/1400), (y/900) local rendering function createDx ( ) dxDrawImage(rx*398, ry*410, rx*300, ry*300, 'images/up.png') end bindKey("F10","down",function () if rendering then removeEventHandler("onClientRender",root,createDx) showCursor ( false ) else addEventHandler("onClientRender",root,createDx) showCursor ( true ) end rendering = not rendering end
-
state will always be a string (up or down) then you can't compare a string with an element, also you have to use injectBrowserMouseMove.
-
You're trying to inject clicks in the browser? if so... injectBrowserMouseMove injectBrowserMouseDown injectBrowserMouseUp