LabiVila Posted September 3, 2014 Posted September 3, 2014 Hey guys, can you help me how to pass the two arguments betted and amount? And a small explanation would do the job (check line 75 and down at client side) (check line 55 at server side) --client side local x,y = guiGetScreenSize () function betplaced () dxDrawRectangle (x/1.6, y/3.125, x/3.25, y/15, tocolor (0, 0, 0, 150)) dxDrawText ("You have already placed a bet.", x/1.525, y/2.95, x, y, tocolor (255, 255, 255), 1, "clear") end addEvent ("alreadyPlaced", true) addEventHandler ("alreadyPlaced", root, function () addEventHandler ("onClientRender", root, betplaced) setTimer ( function () removeEventHandler ("onClientRender", root, betplaced) end , 5000, 1 ) end ) function Mnumber () dxDrawRectangle (x/1.6, y/3.125, x/3.25, y/15, tocolor (0, 0, 0, 150)) dxDrawText ("The value must be a number.", x/1.525, y/2.95, x, y, tocolor (255, 255, 255), 1, "clear") end addEvent ("number", true) addEventHandler ("number", root, function () addEventHandler ("onClientRender", root, Mnumber) setTimer ( function () removeEventHandler ("onClientRender", root, Mnumber) end , 5000, 1 ) end ) function moneymissing () dxDrawRectangle (x/1.6, y/3.125, x/3.25, y/15, tocolor (0, 0, 0, 150)) dxDrawText ("You don't have enough money.", x/1.525, y/2.95, x, y, tocolor (255, 255, 255), 1, "clear") end addEvent ("noMoney", true) addEventHandler ("noMoney", root, function () addEventHandler ("onClientRender", root, moneymissing) setTimer ( function () removeEventHandler ("onClientRender", root, moneymissing) end , 5000, 1 ) end ) function notfound () dxDrawRectangle (x/1.6, y/3.125, x/3.25, y/15, tocolor (0, 0, 0, 150)) dxDrawText ("The player wasn't found.", x/1.525, y/2.95, x, y, tocolor (255, 255, 255), 1, "clear") end addEvent ("noFound", true) addEventHandler ("noFound", root, function () addEventHandler ("onClientRender", root, notfound) setTimer ( function () removeEventHandler ("onClientRender", root, notfound) end , 5000, 1 ) end ) function text (betted, amount) dxDrawText ("asd", x/3, y/3, x, y, tocolor (255, 255, 255)) end addEvent ("betPlaced", true) addEventHandler ("betPlaced", root, function () addEventHandler ("onClientRender", root, text) setTimer ( function () removeEventHandler ("onClientRender", root, text) end , 5000, 1 ) end ) --server side function onPlayerQuit () local playeraccount = getPlayerAccount (source) if (playeraccount) and not isGuestAccount (playeraccount) then local playermoney = getPlayerMoney (source) setAccountData (playeraccount, "piraterpg.money", playermoney) end end addEventHandler ("onPlayerQuit", getRootElement(), onPlayerQuit) function onPlayerLogin (_, playeraccount) if (playeraccount) then local playermoney = getAccountData (playeraccount, "piraterpg.money") if (playermoney) then setPlayerMoney (source, playermoney) end end end addEventHandler ("onPlayerLogin", getRootElement(), onPlayerLogin) function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end end end bets = {} function bet (source, cmd, betted, amount) local a = tonumber (amount) local betted = getPlayerFromPartialName (betted) if (bets [source]) then return triggerClientEvent (source, "alreadyPlaced", source) -- bet already placed end if (not a) then return triggerClientEvent (source, "number", source) -- must be number end if (getPlayerMoney (source) < a ) then return triggerClientEvent (source, "noMoney", source) -- insufficient money amount end if (not betted) then return triggerClientEvent (source, "noFound", source) -- player wasn't found end bets [source] = {player = betted,amount = amount} triggerClientEvent (source, "betPlaced", source, betted, amount) takePlayerMoney (source, amount) end function removeCmd (state) if (state == "Running") then outputChatBox ("[bET] Bets have been closed!", getRootElement(), 255, 255, 255) removeCommandHandler ("bet", bet) end end addEvent ("onRaceStateChanging") addEventHandler ("onRaceStateChanging", getRootElement(), removeCmd) function addCmd () local alivePlayers = getAlivePlayers () if #alivePlayers >= 1 then outputChatBox ("[bET] Place bets now by typing /bet [playername] [money]", getRootElement(), 255, 255, 255) addCommandHandler ("bet", bet) else outputChatBox ("[bET] At least 5 players are needed to use bet.", getRootElement(), 255, 255, 255) removeEventHandler ("onRaceStateChanging", getRootElement(), removeCmd) end end addEvent ( "onGamemodeMapStart", true ) addEventHandler ("onGamemodeMapStart", getRootElement(), addCmd) function winner () for i, v in pairs ( bets ) do if ( isElement ( i ) ) then if ( source == v.player ) then givePlayerMoney ( i, v.amount * 2 ) outputChatBox ("[bET] "..getPlayerName (localPlayer).." won a bet on "..getPlayerName (source)..".", getRootElement(), 255, 255, 255, i) else outputChatBox ("[bET] You lost your bet on"..getPlayerName (source).."!", source, 255, 255, 255) end end end bets = {} end addEvent ("onPlayerWinDD", true) addEventHandler ("onPlayerWinDD", getRootElement(), winner)
Arsilex Posted September 3, 2014 Posted September 3, 2014 local betted, amount = 0, 0 function text () dxDrawText ("asd", x/3, y/3, x, y, tocolor (255, 255, 255)) end addEvent ("betPlaced", true) addEventHandler ("betPlaced", root, function (b, a) betted, amount = b, a addEventHandler ("onClientRender", root, text) setTimer ( function () removeEventHandler ("onClientRender", root, text) betted, amount = 0, 0 end , 5000, 1 ) end )
LabiVila Posted September 4, 2014 Author Posted September 4, 2014 I actually don't need to set them as zero because I already have them at the server-side as arguments but just can't put them like: function text (betted, amount) dxDrawText ("asd"..betted, x/3... end I wanna make it like this
Saml1er Posted September 4, 2014 Posted September 4, 2014 dxDrawText (betted.." / "..amount, x/3, y/3, x, y, tocolor (255, 255, 255))
Et-win Posted September 4, 2014 Posted September 4, 2014 dxDrawText (tostring(betted).." / "..tostring(amount), x/3, y/3, x, y, tocolor (255, 255, 255)) You forgot using 'tostring'
Moderators IIYAMA Posted September 4, 2014 Moderators Posted September 4, 2014 @Et-win Doesn't matter, if the values are something else then numbers/strings, it should not render in the first place. (checked with tonumber) If the argument is a number it will automatic be transferred to a string, while using ".." actually don't need to set them as zero because I already have them at the server-side as arguments @LabiVila Server-side arguments are useless to client-side.
LabiVila Posted September 4, 2014 Author Posted September 4, 2014 Tried that already Sam but didn't work, Ilyama, how can manage to create those in client-side then? or is it possible any other way of passing those two arguments to client side?
Moderators IIYAMA Posted September 4, 2014 Moderators Posted September 4, 2014 triggerClientEvent setElementData
LabiVila Posted September 4, 2014 Author Posted September 4, 2014 I know I'm looking for too much already but would you mind doing a small preview of it? I actually can't use proper setElementData nor getElementData..
Moderators IIYAMA Posted September 4, 2014 Moderators Posted September 4, 2014 --server addEventHandler("onResourceStart",resourceRoot, function () local variable = "lol" setElementData(resourceRoot,"thisIsFunny",variable) end) --client addEventHandler("onClientResourceStart",resourceRoot, function() variable = getElementData(resourceRoot,"thisIsFunny") end)
Saml1er Posted September 5, 2014 Posted September 5, 2014 Don't worry. It takes time to learn basics. You can find online tutorials for more info and also try to read the same text again and again until you understand it completely ( if you don't then feel free to ask here ) and also run script and read about elements, variables ( global and local and how you access them) on wiki. MTA has predefined variables ( like resourceRoot, root and localPlayer ).
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