-
Posts
297 -
Joined
-
Last visited
Everything posted by Bonus
-
The best way is to create a colshape with createColRectangle and use onColShapeHit & onColShapeLeave.
-
setElementPosition vehicle is an element too
-
I didn't understand getTickCount() at the beginning too And I still don't understand what getTickCount() is clientsided. getTickCount() clientsided could be the time your CPU is running (have read it somewhere). Not sure, never tested.
-
addEventHandler ( "onPlayerQuit", root, function ( ) local acc = getPlayerAccount ( source ) if acc and not isGuestAccount ( acc ) then local alldata = getAllElementData ( source ) if alldata then for key, value in pairs ( alldata ) do setAccountData ( acc, key, value ) end end end end ) addEventHandler ( "onPlayerLogin", root, function ( _, acc ) local alldata = getAllAccountData ( acc ) if alldata then for key, value in pairs ( alldata ) do setElementData ( source, key, value ) end end end )
-
Jusonex, some LUA-Tutorial-Websites and I tested it myself. This website is pretty good: https://springrts.com/wiki/Lua_Performa ... _for-loops
-
@-Doc- Absolutely wrong. The index is a string, not integer, ipairs won't work. The best way to handle this is: local ranks = { ["Fireman"] = { {"Level1", 1}, {"Level2", 2}, {"Level3", 3}, {"Level4", 4} } } function rankSet() for faction, array in pairs ( ranks ) do -- index is string, so for i=1, #ranks or ipairs won't work here -- faction is "Fireman" here --- for i=1, #array do -- that's way faster than ipairs -- array[i][1] is "Level1", array[i][2] is 1 in the first loop -- end end end The difference between ipairs and for i=1, #array are: ipairs is slow and stops when the index isnt going from i=1 to n without space like: "1, 2, 3, 5, 6, 7, 8" ipairs will stop at 3. for i=1, #array is faster, but doesnt stop. "1, 2, 3, 5, 6, 7, 8" It will give out an error because there is no array[4]. But you can handle it by asking: if array[i] then and it's still faster than ipairs. Some guys use ipairs with getElementsByType: DON'T DO THAT Thats stupid, it's slow and useless. Use that: local players = getElementsByType ( "player" ) for i=1, #players do -- players[i] is the player end That's faster
-
getTickCount() is the time in ms your system is running. When your system is running for 12356 ms: local lastChat = {} if not lastChat[source] or lastChat[source] + 3000 <= getTickCount() then lastChat[source] = getTickCount() else cancelEvent() end Is nearly like: -- 1. Time Chat -- local lastChat = {} -- lastChat[source] is nil if not nil or nil + 3000 <= 12356 then -- getTickCount() | its true cause "not nil" lastChat[source] = 12356 -- getTickCount() else cancelEvent() end -- 2. Chat after 2000 ms -- -- lastChat[source] is 12356 because of 1. chat if not 12356 or 12356 + 3000 <= 14356 then -- its false lastChat[source] = 14356 else <-- because 12356 + 3000 > 14356 cancelEvent() end -- 3. Chat after 3000 ms -- -- lastChat[source] is 12356 because of 1. chat if not 12356 or 12356 + 3000 <= 15356 then -- its true because 12356 + 3000 = 15356 lastChat[source] = 15356 <-- else cancelEvent() end I hope you understand that.
-
What is so complicated about that? Perhaps you need to use removeCamHandler() before setCameraTarget.
-
setCameraTarget (localPlayer)
-
How to get player's screen and use it as a picture ?
Bonus replied to OnlineCheater's topic in Scripting
https://wiki.multitheftauto.com/wiki/OnPlayerScreenShot -
If the player didnt use the chat before or did it 3000 ms before, the last time the player used the chat will be saved with getTickCount(). If the player used the chat within 3000 ms then the event gets canceled.
-
Thats a really bad way to handle this. You create too many timers. Better use getTickCount(): local antiChatSpam = {} addEventHandler ( "onPlayerChat", root, function () if not antiChatSpam[source] or antiChatSpam[source] + 3000 <= getTickCount() then antiChatSpam[source] = getTickCount() else cancelEvent() outputChatBox ( "Don't spam little fa*got.", source, 200 ) end end )
-
dxDrawMaterialLine3D Change the arguments here.
-
Try this function startMiningSpot(hitPlayer) if (hitPlayer == getLocalPlayer()) then triggerServerEvent("syncMiningAnim", hitPlayer, source) end end addEventHandler( "onClientMarkerHit", miningSpot, startMiningSpot) function syncMining(marker) exports.global:applyAnimation(client, "chainsaw", "CSAW_1", -1, true, false, false) setElementPosition(client, getElementPosition(marker)) setPedRotation(client, getElementData(marker, "msRotation")) outputChatBox("Don't show", client) end addEvent("syncMiningAnim", true) addEventHandler("syncMiningAnim", getRootElement(), syncMining)
-
Put it in an array: local chatNick = {} addEventHandler ( "onPlayerJoin", root, function ( ) chatNick[source] = getPlayerName(source) end ) addEventHandler ( "onPlayerQuit", root, function ( ) chatNick[source] = nil end ) addCommandHandler ( "whatever", function ( player, cmd, newname ) chatNick[player] = newname end ) outputChatBox ( chatNick[source] ... )
-
If the 1. player is in the team and the 2. player not it will get spamed. A setTimer with 50 ms is a bad idea, specifically with for ipairs getElementsByType.
-
What is atiranovendedor? Use setPedTarget to let the ped shoot at the attacker.
-
The for-part doesn't make sense. getCurrentFPS only gives the FPS of the local player. Also don't use ipairs in a code like that! I see that s*it everywhere ... guys, ipairs is SLOW. Use for i=1, #players (fastest) or pairs instead, but don't use ipairs when the order doesn't matter (and here it clearly doesn't matter)
-
Increase +1 in what? X? Y? Z? fZ+1 increases the height of the spawn.
-
The first time it's going well, but statusfunctions gets changed by that line: statusfunctions[i] = getElementData(localPlayer,statusfunctions[i]) or "Disabled" getElementData gives true back - atleast one of them. And you cant use getElementData ( localPlayer, true ). You should use local status = getElementData(localPlayer,statusfunctions[i]) or "Disabled" dxDrawText(functionleft[i].." - "..status,sX/2-sizeX/2+fontMaHei,(sY/2-sizeY/2+fontMaHei)+fontMaHei*2*i,0,0,tocolor(40,40,40,255),1,fontManager,"left","top",false,false,false,false) Edit: Oh, he was faster
-
You can use getVehicleComponentPosition. Then maybe ask the position to know if the component is on left, right, front or rear side. Or get another way to set the camera matrix outside the car.
-
That code makes no sense. You let nemesis attack everyone at once who gets targeted by a player. How can it attack everyone at once? Why attack a targeted player? Better create a colshape on nemesis with radius 10-20. Then get all the players with getElementsWithinColShape, put them in an array. Use math.random ( 1, #array ) to get a random number and let nemesis attack array[rndnumber] - a random player near nemesis.
-
First at all I don't understand why you dont use local there. Why make the variables global? You compare the distance between the player and ... the player! That makes no sense. Bonsai wrote it, its hard to hit exactly 100. Well, I dont even know when this function gets called. You should look if the distance is >= 100 and < 1000. If so add math.floor ( distance / 100 ) to ElementData "M". If distance >= 1000 then add math.floor ( distance / 1000 ) to "KM". You should really learn the basics Or learn to read the code ...
-
Can you put the code in the lua-function?
-
Sorry, but both of your posts were wrong. In the 1. post you put root in - thats stupid. Then you put wp as 1. argument - but 1. argument in onClientPlayerDamage is attacker, not weapon. In your 2. post you use onPlayerDamage. You can't cancel onPlayerDamage, only onClientPlayerDamage. Then you do the same mistake with wp and 1. argument again.