Jump to content

Bilal135

Members
  • Posts

    843
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Bilal135

  1. The code down below is taken from Bubble chat resource from the community. (https://community.multitheftauto.com/index.php?p=resources&s=details&id=12008). I was trying to figure out a way to create a bubble that says "Typing..." when a person is typing in chat box. I considered 'IsChatboxInputActive' and tried a few methods, but it did not work. I'd appreciate if someone could guide me as to how it could be done. Thanks. -- client local selfVisible = true -- Want to see your own message? local messages = {} -- {text, player, lastTick, alpha, yPos} local textures = {} local timeVisible = 8500 local distanceVisible = 30 local bubble = true -- Rounded rectangle(true) or not(false) function addBubble(text, player, tick) if (not messages[player]) then messages[player] = {} end local width = dxGetTextWidth(text:gsub("#%x%x%x%x%x%x", ""), 1, "default-bold") local _texture = dxCreateRoundedTexture(width+16,20,100) table.insert(messages[player], {["text"] = text, ["player"] = player, ["tick"] = tick, ["endTime"] = tick + 2000, ["alpha"] = 0, ["texture"] = _texture}) end function removeBubble() table.remove(messages) end addEvent("onChatIncome", true) addEventHandler("onChatIncome", root, function(message, messagetype) if source ~= localPlayer then addBubble(message, source, getTickCount()) elseif selfVisible then addBubble(message, source, getTickCount()) end end ) -- outElastic | Got from https://github.com/EmmanuelOga/easing/blob/master/lib/easing.Lua local pi = math.pi function outElastic(t, b, c, d, a, p) if t == 0 then return b end t = t / d if t == 1 then return b + c end if not p then p = d * 0.3 end local s if not a or a < math.abs(c) then a = c s = p / 4 else s = p / (2 * pi) * math.asin(c/a) end return a * math.pow(2, -10 * t) * math.sin((t * d - s) * (2 * pi) / p) + c + b end addEventHandler("onClientRender", root, function() local tick = getTickCount() local x, y, z = getElementPosition(localPlayer) for _, pMessage in pairs(messages) do for i, v in ipairs(pMessage) do if isElement(v.player) then if tick-v.tick < timeVisible then local px, py, pz = getElementPosition(v.player) if getDistanceBetweenPoints3D(x, y, z, px, py, pz) < distanceVisible and isLineOfSightClear ( x, y, z, px, py, pz, true, not isPedInVehicle(v.player), false, true) then v.alpha = v.alpha < 200 and v.alpha + 5 or v.alpha bx, by, bz = getPedBonePosition(v.player, 6) sx, sy = getScreenFromWorldPosition(bx, by, bz+0.2) elapsedTime = tick - v.tick duration = v.endTime - v.tick progress = elapsedTime / duration if sx and sy then if not v.yPos then v.yPos = sy end local width = dxGetTextWidth(v.text:gsub("#%x%x%x%x%x%x", ""), 1, "default-bold") --local yPos = interpolateBetween ( v.yPos, 0, 0, sy - 22*i, 0, 0, progress, "OutElastic") local yPos = outElastic(elapsedTime, v.yPos, ( sy - 22*i ) - v.yPos, duration, 5) if bubble then dxDrawImage ( sx-width/2-10, yPos - 16, width+16, 20, v.texture, nil, nil, tocolor(0, 0, 0, v.alpha) ) else dxDrawRectangle(sx-width/2-10, yPos - 16, width+16, 20, tocolor(0, 0, 0, v.alpha)) end dxDrawText(v.text, sx-width/2-2, yPos - 14, width, 20, tocolor( 255, 255, 255, v.alpha+50), 1, "default-bold", "left", "top", false, false, false, true) end end else table.remove(messages[v.player], i) end else table.remove(messages[v.player], i) end end end end )
  2. Thank you @stPatrick. The first method did work, but the method you said was much more simpler, did not work. No errors in debug. Thanks @IIYAMA. But I thought I had assigned a value to it here, addEvent("getClientTarekElement", true) function getClientTarekElement_func(s_tarek) c_tarek = s_tarek end addEventHandler("getClientTarekElement", root, getClientTarekElement_func) I still don't understand why c_tarek would not be recognised in any other function.
  3. I created a ped in server side (variable name: tarek), and exported it to client side via triggers, because i wanted to make a name tag specifically for this ped. I was able to successfully export the variable to client side, but the problem is, that variable is only recognized within that function and outside that function it isn't being recognized. I tried to make it global but it didn't work. Please see the code below. Any help would be appreciated. -- server addEvent("serverCallback", true) function getClientTarekElement_func_s() local playerAsking = source local s_tarek = tarek triggerClientEvent(playerAsking, "getClientTarekElement", playerAsking, s_tarek) end addEventHandler("serverCallback", root, getClientTarekElement_func_s) -- client addEvent("getClientTarekElement", true) function getClientTarekElement_func(s_tarek) c_tarek = s_tarek end addEventHandler("getClientTarekElement", root, getClientTarekElement_func) addEventHandler("onClientResourceStart", resourceRoot, function() triggerEvent("s_callback", localPlayer) end) addEvent("s_callback", true) addEventHandler("s_callback", root, function() triggerServerEvent("serverCallback", localPlayer, s_tarek) end) -- nametag for ped addEventHandler( "onClientRender",root, function( ) local px, py, pz, tx, ty, tz, dist px, py, pz = getCameraMatrix( ) tx, ty, tz = getElementPosition( c_tarek ) dist = math.sqrt( ( px - tx ) ^ 2 + ( py - ty ) ^ 2 + ( pz - tz ) ^ 2 ) if dist < 30.0 then if isLineOfSightClear( px, py, pz, tx, ty, tz, true, false, false, true, false, false, false,localPlayer ) then local sx, sy, sz = getPedBonePosition( c_tarek, 5 ) local x,y = getScreenFromWorldPosition( sx, sy, sz + 0.4 ) if x then dxDrawText( "Tarek", x, y, x, y, tocolor(255, 188, 116), 1.0 + ( 15 - dist ) * 0.02, "clear-normal", "center", "center" ) end end end end)
  4. local weaponTable = { -- [weap_id] = { torso, ass, left_arm, right_arm, left_leg, right_leg, head } [24] = { 45, 35, 30, 30, 25, 25, 70 }, } addEventHandler("onPlayerDamage", getRootElement(), function (attacker, weapon, bodypart, loss) if getElementType(attacker) == "player" and getPlayerWeapon(attacker) and weaponTable[ getPlayerWeapon(attacker) ] then setElementHealth(source, getElementHealth(source) - weaponTable[ getPlayerWeapon(attacker) ] [ bodyPart - 2] + loss) end end ) This is supposed to set the damage for each weapon according to the body parts, but for some reason, the code isnt working and the only error im getting is this: Attempt to perform arithmetic on 'bodyPart' (a nil value). Any help would be appreciated.
  5. Thanks a lot, @Patrick. Got the general concept as to how they can be implemented.
  6. I just found out that there's a way to store multiple values in a table. So, I planned to make a custom punish system with it. Stored three values in the table, a rule id, a description for what it is, and it's punishment. I'd like to know how can I implement these, for example, if i typed /punish [player] [id], it should automatically derive it's description and punishment from the table, and punish the player. (and output description in the chat) rules = { {["ruleID"] = "1", ["description"] = "Trash talking", ["punishment"] = "kick"} } Thanks.
  7. The code is written to mute the player upon spamming, which works fine, except that if a player quits the game, changes his nick, and joins again, he does get muted, but won't get unmuted. Also, if the player quits after being muted, and waits some time before joining back, he'll be forever muted again and won't get unmuted. Can't think of a way to fix this. Any help would be appreciated. mutedPlayerSerials = {} interval = 20000 addEvent("mutePlayer", true) addEventHandler("mutePlayer", root, function() local mutedPlayer = getPlayerName(source) local serial = getPlayerSerial(source) outputChatBox(mutedPlayer.." has been muted by console for spamming.", root, 255, 100, 100) table.insert(mutedPlayerSerials, serial) setPlayerMuted(source, true) setTimer(function() local serial = nil mutedPlayerSerials = {} local player = getPlayerFromName(mutedPlayer) if player then setPlayerMuted(player, false) outputChatBox(mutedPlayer.." has been unmuted by console.", root, 100, 255, 100) end end, interval, 1) end) mutedPlayer = false addEventHandler("onPlayerJoin", root, function() local serial = getPlayerSerial(source) for _, v in pairs(mutedPlayerSerials) do if serial == v then mutedPlayer = true break end end if mutedPlayer == true then local mutedPlayerName = getPlayerName(source) local mutedPlayer = getPlayerFromName(mutedPlayerName) setPlayerMuted(mutedPlayer, true) outputChatBox(mutedPlayerName.." has been muted by console.", root, 255, 100, 100) end end)
  8. There's no such argument as 'immortal' in createPed. ped createPed ( int modelid, float x, float y, float z [, float rot = 0.0, bool synced = true ] ) It must be something else in your code which is making your ped invincible. Or it could be this issue, https://bugs.mtasa.com/view.php?id=8790.
  9. Thank you once again @IIYAMA. Was really easy to understand this time. Solved.
  10. I made three tables, local insults = {":O you", ":O off", "cry", "suck my :O", "pussy", ":O", "idiot", "whore", "dickhead", "mother:Oer", "your mom sucks", "bitch", ":Oer", "virgin", "peace of :~", "piece of :~", ":~ of peace", ":~ of piece", "retard", "gay :O", ":O", "gay :O", "gay", "dicksucker", "coward", "angry german kid", "kid", "agk", "asshole"} local answers = {"oki", "stfu", "kid", "tenks", "lol", "kiddy", "wow", "pff", "lmao", "noob", "omg"} local random = {"if i die tell my mom i love she", "omg my heart", "i miss you"} and stored some string values (insults) in it. Then, looped through them to find if a player said one of those in chat. It is supposed to work like this, if he said one of those in chat, then it would trigger functionA, but if he did not, that would trigger functionB. addEventHandler("onPlayerChat", root, function(message, messageType) if not messageType == 0 then return end if not isElementWithinColShape(source, colArea) then return end if not getElementData(tarek, "alive") == true then return end if getElementData(tarek, "rage") == true then return end for _, sMessage in pairs(insults) do if message == sMessage then functionA() else functionB() return end end end) But in this case, it triggered both functionA and function B. What each of these functions do, functionA: Checks if the player insulted the ped a certain number of times, and outputs ped's reaction according to that. (tarek = ped) If the player has not yet insulted a set number of times (end_time_value) then, it outputs something else. functionB: If the player did not say any value from the 'insults' table, then a random value from 'random' table will be outputed. function functionA() setTimer(function() local end_limit_value = 5 if getElementData(tarek, "limit_value") == tonumber(end_limit_value) then setElementData(tarek, "rage", true) setPedAnimation(tarek, "graveyard", "mrnf_loop") outputChatBox("#FFBC74Tarek: #FFFFFFgtfo kiddy", source, 255, 255, 255, true) playAgkRageSound() setTimer(function() outputChatBox("#FFBC74Tarek: #FFFFFFgod get a pussy you virgin :~ of peace", source, 255, 255, 255, true) end, 3000, 1) setTimer(function() outputChatBox("#FFBC74Tarek: #FFFFFFmother:Oer you mom dont want you", source, 255, 255, 255, true) setTimer(function() local x, y, z = getElementPosition(tarek) createExplosion(x, y, z, 6) createExplosion(x, y, z, 6) createExplosion(x, y, z, 6) killPed(tarek) setElementData(tarek, "alive", false) outputChatBox("Angry German Kid has exploded and killed you!", source, 255, 100, 100) setTimer(function() destroyElement(tarek) reviveTarek() setElementData(tarek, "rage", false) end, 20000, 1) end, 6000, 1) end, 2000, 1) return end outputChatBox("#FFBC74Tarek: #FFFFFF"..table.random(answers).."", source, 255, 255, 255, true) index = index + (index_value and 1 or -1) setElementData(tarek, "limit_value", tonumber(index)) end, 3000, 1) end function functionB() outputChatBox("#FFBC74Tarek: #FFFFFF"..table.random(random).."", source, 255, 255, 255, true) end Complete code; https://pastebin.com/hHQs3qZR The problem is with the loop, it does not output what is required, but outputs both of the functions at the same time. (Btw, this script is an *attempt* to create a clone of my friend. Pretty lame, but that's what it is) Any help regarding this would be really appreciated.
  11. So, if I derive values from a certain table and use those values to do something, they will always be case sensitive. How can I remove that? I don't want the values of the table to be case sensitive, For example, local values = {"Hi", "Hello", "Hey"} And if I detect if a player said one of these in chat by looping through them, it will work but only if the player typed the first letter capital. addEventHandler("onPlayerChat", root, function(message, messageType) if not messageType == 0 then return end for _, msg in pairs(values) do if message == msg then outputChatBox("Console: Hey!", source, 255, 100, 100) else return end end end) I heard string.gsub can do this but I'm not sure how to use that. Any help regarding this would be appreciated.
  12. It worked like a charm @IIYAMA. Thank you. (Still figuring out how you did it)
  13. So, i created two buttons in a gui, '>' for 'next skin' and '<' for previous skin. But unfortunately, the code doesn't seem to work very well. Any help regarding this would be really appreciated. skin_btn_next = guiCreateButton(96, 273, 33, 16, ">", false, window) skin_btn_previous = guiCreateButton(58, 273, 33, 16, "<", false, window) function isSkinValid(skinid) local allSkins = getValidPedModels() for _, skin in ipairs(allSkins) do if skin == tonumber(skinid) then return true else return false end end end ped = createPed(0, -2614.0212402344, 1451.1651611328, 7.1875, 180) local skin = getElementModel(ped) local new_skin = skin + 1 local previous_skin = new_skin - 1 if source == skin_btn_next then if isSkinValid(new_skin) then setElementModel(ped, new_skin) else setElementModel(ped, new_skin + 1) end end if source == skin_btn_previous then setElementModel(ped, previous_skin) end (These are just the relevant parts of the script) Entire script; https://pastebin.com/aYydg3TX
  14. Thank you very much @Mahlukat. Problem is fixed.
  15. Wanted to fill up a grid list with locations that are specified in a table, based on a team that was selected in another grid list, but I can't seem to get it right. No errors in the debug. Any help regarding this would be appreciated. Thanks. addEventHandler("onClientGUIClick", resourceRoot, function(button, state) if button == "left" and state == "up" then local LALocations = {"LA Test 1", "LA Test 2", "LA Test 3"} local IFLocations = {"IF Test 1", "IF Test 2", "IF Test 3"} local row, col = guiGridListGetSelectedItem(team_gridlist) if row and col and row ~= -1 and col ~= -1 then local team = guiGridListGetItemText(team_gridlist, row, col) if team == "Liberation Army" then outputChatBox("Test successful", 100, 255, 100) for _, locations_LA in ipairs(LALocations) do local location_row_LA = guiGridListAddRow(location_gridlist) guiGridListSetItemText(location_gridlist, location_row_LA, location_col, locations_LA, false, false) end if team == "Imperial Forces" then for _, locations_IF in ipairs(IFLocations) do local location_row_IF = guiGridListAddRow(location_gridlist) guiGridListSetItemText(location_gridlist, location_row_IF, location_col, locations_IF, false, false) end end end end end end) Here's the complete client sided code; https://pastebin.com/NL7YfyZ4
  16. Thank you, the problem was resolved. I guess toggleControl can block bindKey.
  17. I wanted to shoot missiles with intervals of 5 seconds between them. Tried the following code, but it only works for the first or second time when shooting missiles, then it shoots like normal (no interval). Tried different ways but couldn't fix it. Any help regarding this? armedVehicles = {[425]=true, [520]=true, [476]=true, [447]=true, [430]=true, [432]=true, [464]=true, [407]=true, [601]=true} function vehicleWeaponFire(thePresser, key, keyState, vehicleFireType) local vehModel = getElementModel(getPedOccupiedVehicle(thePresser)) if (armedVehicles[vehModel]) then triggerEvent("onVehicleWeaponFire", thePresser, vehicleFireType, vehModel) end end function bindOnJoin() bindKey(source, "vehicle_fire", "down", vehicleWeaponFire, "primary") bindKey(source, "vehicle_secondary_fire", "down", vehicleWeaponFire, "secondary") end addEventHandler("onPlayerJoin", root, bindOnJoin) function bindOnStart() for index, thePlayer in pairs(getElementsByType("player")) do bindKey(thePlayer, "vehicle_fire", "down", vehicleWeaponFire, "primary") bindKey(thePlayer, "vehicle_secondary_fire", "down", vehicleWeaponFire, "secondary") end end addEventHandler("onResourceStart", getResourceRootElement(), bindOnStart) function stopMissileSpam() player = source toggleControl(player, "vehicle_secondary_fire", false) toggleControl(player, "vehicle_fire", false) setTimer(function() toggleControl(player, "vehicle_secondary_fire", true) toggleControl(player, "vehicle_fire", true) end, 5000, 1) end addEvent("onVehicleWeaponFire", true) addEventHandler("onVehicleWeaponFire", root, stopMissileSpam)
  18. function giveMoney(sender,command,name,amount) if not name or not amount then outputChatBox("Usage: #FFFFFF/givemoney [player name] [amount]",sender,255,0,0,true) return end local receiver = getPlayerFromName(name) if not receiver then outputChatBox("Couldn't find a player with the name #FFFFFF("..name..").",sender,255,0,0,true) return end local receiver = getPlayerFromName(name) if receiver == sender then outputChatBox("You can't give money to yourself.",sender,255,0,0) return end if not tonumber(amount) then outputChatBox("Please enter a valid value.",sender,255,0,0) return end local receiver = getPlayerFromName(name) local receivername = getPlayerName(receiver) local sendername = getPlayerName(sender) local sendermoney = getPlayerMoney(sender) if receiver and tonumber(amount) <= sendermoney then if (amount < 0) then return outputChatBox("Please select a positive number to send.", sender, 255, 0, 0) end takePlayerMoney(sender,amount) givePlayerMoney(receiver,amount) outputChatBox("You gave #FFFFFF"..receivername.." #00FF00$"..tonumber(amount)..".",sender,0,255,0,true) outputChatBox(""..sendername.." #00FF00gave you $"..tonumber(amount)..".",receiver,255,255,255,true) else outputChatBox("You don't have $"..tonumber(amount)..".",sender,255,0,0,true) end end addCommandHandler("givemoney",giveMoney)
  19. Same problem persisting, muted player is muted if he reconnects, but doesn't get unmuted even after 'unmuted' message shows up. ('unmuted' message shows up twice as well).
  20. if reason == "1" then if isPlayerMuted(target) then return outputChatBox("Player is already muted.", player, 255, 0, 0) end if not ( playeraccount ) and isGuestAccount ( playeraccount ) then return end setPlayerMuted(target, true) setAccountData(playeraccount, "mutedfor30secs", true) outputChatBox("* "..name.." has been muted by "..plrname.."!", root, 13, 107, 39, true) setTimer(function() local quitacc = getAccountData(playeraccount, "quit") if (quitacc) then return end setPlayerMuted(target, false) setAccountData(playeraccount, "mutedfor30secs", false) outputChatBox("* "..name.." has been unmuted by Console.", root, 13, 107, 39, true) end, 30000, 1) end function muteOnLogin(_, playeraccount) if not ( playeraccount ) and isGuestAccount ( playeraccount ) then return end local muted = getAccountData(playeraccount, "mutedfor30secs") if not (muted) then return end setPlayerMuted(source, true) outputChatBox("muted", root) setTimer(function() setPlayerMuted(source, false) outputChatBox("unmuted", root) setAccountData(playeraccount, "mutedfor30secs", false) end, 30000, 1) end addEventHandler("onPlayerLogin", root, muteOnLogin) addEventHandler("onPlayerQuit", root, function(_, playeraccount) if not muted then return end if not (playeraccount) and isGuestAccount(playeraccount) then return end local muted = getAccountData(playeraccount, "mutedfor30secs") setAccountData(playeraccount, "quit", true) end) Didn't work, am I doing something wrong here? It mutes the muted player if he reconnects but doesn't unmute, and "Player has been unmuted by console" appears before "unmuted".
  21. I created a custom mute system, and when a player is muted, it's all good as he gets unmuted after the mute time has passed, but if he reconnects, he's no more muted and can still talk, whereas the script thinks he is muted and attempts to unmute an already unmuted player. I tried using setElementData and getElementData when a muted player quits and then joins before the mute time has passed, but it didn't work out so I've no idea now. (Not included in the code below). Have a look at the code. Any help regarding this will be appreciated. if reason == "1" then if isPlayerMuted(target) then return outputChatBox("Player is already muted.", player, 255, 0, 0) end setPlayerMuted(target, true) outputChatBox("* "..name.." has been muted by "..plrname.."!", root, 13, 107, 39, true) setTimer(function() setPlayerMuted(target, false) outputChatBox("* "..name.." has been unmuted by Console.", root, 13, 107, 39, true) end, 30000, 1) end Thanks.
  22. This is the code taken from 'onPlayerChat' event's wiki page (1st example). It is supposed to convert main chat to local chat, so it disables whatever we write by pressing T and instead makes it appear for nearby players in a new message. But it is making both appear. Any help regarding this? -- define our chat radius local chatRadius = 20 --units -- define a handler that will distribute the message to all nearby players function sendMessageToNearbyPlayers( message, messageType ) -- we will only send normal chat messages, action and team types will be ignored if messageType == 0 then -- get the chatting player's position local posX, posY, posZ = getElementPosition( source ) -- create a sphere of the specified radius in that position local chatSphere = createColSphere( posX, posY, posZ, chatRadius ) -- get a table all player elements inside it local nearbyPlayers = getElementsWithinColShape( chatSphere, "player" ) -- and destroy the sphere, since we're done with it destroyElement( chatSphere ) -- deliver the message to each player in that table for index, nearbyPlayer in ipairs( nearbyPlayers ) do outputChatBox( message, nearbyPlayer ) end end end -- attach our new chat handler to onPlayerChat addEventHandler( "onPlayerChat", getRootElement(), sendMessageToNearbyPlayers ) -- define another handler function that cancels the event so that the message won't be delivered through the function blockChatMessage() cancelEvent() end -- attach it as a handler to onPlayerChat addEventHandler( "onPlayerChat", getRootElement(), blockChatMessage )
  23. Anybody knows where can default chat (/say) be found? - which script exactly. Wanted to edit it.
  24. Tried this, still the same error. GUIEditor.memo[1] = guiCreateMemo(0.46, 0.10, 0.48, 0.81, "Welcome to Ultimatium English Freeroam!\n\nBefore getting started, all new players must go through the rules listed below, created to keepthe server clean of disturbers.\n\n#1. Speak English only. As this is an English server, we can't tolerate any other language in public chats. However, if you wish to talk to someone in your own language, then you may use private messages.\nSyntax: /pm [player name] [message].\n\n#2. Do not disturb staff members. Pretty straight forward rule. Do not roam around / make noises near busy staff members, which can be identified by 'L1', 'L2', 'L3', 'L4'\nor 'L5' icon on their names.\n\n#3. Do not insult or provoke anyone. We tend to keep a nice atmosphere here. Any insult against any player will not be tolerated, no matter what. Some insults inclue, 'Bitch', 'Mother:Oer, ':Oer', 'Asshole' etc.\n\n#4. No racism. Calling someone names or anything basede on someone's real life complexion is strictly forbidden. In extreme cases, you might get a ban for it.\n\n#5. Do not lie to staff members. If any staff member questions you about any server relat\nreport (not personal), you must answer honestly. If you lie, you'll eventually be caught and punished.\n\n#6. Do not insult the server. Non-constructive criticism against the server can get you permanently banned in extreme cases.\n\nThat's it for now. Enjoy playing!", true, GUIEditor.window[1])
×
×
  • Create New...