# novo

Members

325

1. ## How to sort a table by value

local players = getElementsByType('player') table.sort( players, function(a, b) return getPlayerMoney(a) > getPlayerMoney(b) end )
2. ## Hunter Camera Problem

ShowPlayerHudComponent
3. ## getCursorMoveOn

First error is caused by the function getCursorMoveOn, as it does not return any value in case isCursorShowing() returns false at line 2. Second error is because outputChatBox only accepts a player as second argument server-side (visibleTo), whilst client does not and thus expects a number (r).
4. ## [Solved] Table inside of a table

You get that error because number is an undefined variable, and thus equals to nil. Now, you can do table.test with alphabetical keys only - you have to do table[123] for numbers. local table = { test = 'a', ['something'] = 'b', [1] = 'c', ['test2'] = 'd', } print(table.test) -- a print(table.something) -- b print(table[1]) -- c print(table['test2']) -- d ---------------------------- local players = {} local player = getRandomPlayer() players[player] = { name = getPlayerName(player), } print(players[player].name)
5. ## Short lua question

Only predefined variables are these, and thus what you are trying to achieve is not possible.
6. ## Help with Collision calculator

It indeed does not check if given projectile has a target, but still does work with static elements. Now, you might instead do a per-frame check and find out whether an element interferes with the projectile, or through loop as in your code. I would do some sort of sight check around the projectile and check if there is any nearby approaching element that might end up colliding given its velocity within a certain distance. Also, I had a few issues calculating what the final position is going to be and dividing by 10 worked just fine there for testing, though you might want to replace this with proper calculations.
7. ## setElementVelocity backwards

local vx, vy, vz = getElementVelocity(veh) setElementVelocity( veh, -vx, -vy, vz )
8. ## Help with Collision calculator

function collision (projectile) local time = projectile.counter / 10 local velocity = projectile.velocity velocity = velocity * time -- local position = projectile.position + velocity local sight, x, y, z = processLineOfSight( projectile.position, position, true, true, true, true, true, true, true, false, nil, true ) position = (sight and Vector3(x, y, z)) or position -- Marker( position, 'corona', 3 ) end addEventHandler( 'onClientProjectileCreation', root, function() collision(source) end )
9. ## table.sort problem

toptimes = { {32423,"nickname"}, {12313,"nickname"}, }; table.sort(toptimes, function(a, b) return a[1] < b[1] end ) table.sort basically needs minimum two values inside the input table, toptimes in this case, and then does compare these values and thus determines their order. We have got two sub-tables inside toptimes, and those tables are the ones being compared through table.sort. This is why [1] is used, we retrieve those table's index 1 value and then check which one is smaller/bigger. However, here is a similar thing I found you may have a look at.
10. ## Anti teamkill

addEventHandler("onClientVehicleDamage", root, function(attacker) if getElementModel(source) ~= 432 then return end -- avoid this function from executing in case the vehicle that is being damaged is not a tank(?) if getElementModel(getPedOccupiedVehicle(attacker)) == 432 then -- in case attacker's model is equal to 432 if attacker == localPlayer then -- in case the attacker tank's driver is the localPlayer outputChatBox("Don't attack friendly tanks!", 255, 0, 0) -- a warning message is output end cancelEvent() end end ) What about this? You could've either way tried to modify the code on your own, lol.

I do not know, you probably ran those resources before. Err.. either way I did not check it out for a long while, they probably implemented it - quite a big security hole though.

That is what I meant, you can not manipulate files outside a resource itself.

Are those files even being written/created? I am not sure it is possible to actually write into a different resource location from where you are running the functions.
14. ## Anti teamkill

It is not working because you are using onClientVehicleDamage's arguments in a wrong way. Either way, you are using attacter at isPedInVehicle - a non-defined variable. addEventHandler("onClientVehicleDamage", root, function(attacker) if getElementModel(source) ~= 432 then return end -- avoid this function from executing in case the vehicle that is being damaged is not a tank(?) if getElementModel(attacker) == 432 then -- in case attacker's model is equal to 432 if getVehicleController(attacker) == localPlayer then -- in case the attacker tank's driver is the localPlayer outputChatBox("Don't attack friendly tanks!", 255, 0, 0) -- a warning message is output end cancelEvent() end end )

Well, you can this way avoid loaded scripts from executing your actual wrappered functions. Which means that if you have set a wrapper to _triggerServerEvent and not using an environment, it can be called from inside the loaded script. And you are avoiding this by using an own environment.
16. ## Why this error?

Indeed, it is in fact working fine here. So yeah, perhaps it is not a string. What is the debug error either way?

You can either go through events and trigger a client-sided event from server-side or, create a client-sided command and execute it from server-side. Both examples: -- #1 -- Server addCommandHandler("kazandik", function(player, command, ...) triggerClientEvent(root, "kazandik_music", root) -- trigger this event for every player belonging to the root element, which should trigger for everyone in case you did not change any player's parent element end ) -- Client / Add the snippet bellow into your code addEvent("kazandik_music", true) addEventHandler("kazandik_music", root, function() startMusic() -- calling and executing startMusic end ) ----------------- -- #2 -- Server addCommandHandler("kazandik_all", -- As both, server and client sided commands, can not be named the same - we are using a different one function(player, command, ...) executeCommandHandler("kazandik", root) -- not sure if root can be used here instead of a player element directly / executing 'kazandik', your client-sided command that does the thing -- and in case that does not work for _, v in ipairs(getElementsByType("player")) do -- we iterate over a table returned by 'getElementsByType' that contains all players and executeCommandHandler("kazandik", v) -- execute the command for each one of them end end )

destroyElement is not working there cause when stopSound is executed, (...) the sound element is also destroyed. Also, may you provide us the full code you're running? I do not see any mistake over here.

That basically is what you should do in order to avoid most security issues and in case you want to run all the functions attached to onClientResourceStart, simply set another event name for the handler that you can afterwards manually-trigger in order to execute all those functions simultaneously (without actually triggering onClientResourceStart).

Though there are many security-issues related to loading code that way, the one-issue you're going through on your last post is you are not triggering onClientResourceStart, event responsible of executing startMusic function (as, this way, you are not running a resource on its own and thus such event is not being run).
23. ## [HELP] guiCreateEdit color

You may otherwise have a look at guiSetProperty.

25. ## dwDraw Moviment

You can use interpolateBetween or either change the position values manually. Here's an example.
×

• #### Social Media

×
• Create New...