Jump to content

adithegman

Members
  • Posts

    32
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

adithegman's Achievements

Rat

Rat (9/54)

0

Reputation

  1. I'm trying to develop the spectating system and ran into this error: When a player dies and the startSpectate event is called from server, there is an error at the setCameraTarget function: bad argument @ 'setCameraTarget' [ Expected Vector 3 at argument 1, got nil] I checked the updatePlayers() function to see whether the players table was formed correctly or not and it is. Thanks for helping!? Client script: local players = {} local index = 1 local function updatePlayers() players = {} local candidates = getElementsByType("player") for k, v in ipairs(candidates) do if getElementData(v, "game.status") == "playing" then table.insert(players, v) end end end local function spectatePrevious() if index == 1 then index = #players else index = index - 1 end setCameraTarget(players[i]) end local function spectateNext() if index == #players then index = 1 else index = index + 1 end setCameraTarget(players[i]) end local function startSpectateHandler() setElementData(localPlayer, "game.status", "spectating") updatePlayers() index = 1 bindKey("arrow_l", "down", spectatePrevious) bindKey("arrow_r", "down", spectateNext) t = players[i] setCameraTarget(t) --- This is the line warning the error occurs end local function stopSpectateHandler() unbindKey("arrow_l", "down", spectatePrevious) unbindKey("arrow_r", "down", spectateNext) setCameraTarget(localPlayer) end addEventHandler("onClientResourceStart", resourceRoot, updatePlayers) addEventHandler("onPlayerJoin", root, updatePlayers) addEventHandler("onPlayerQuit", root, updatePlayers) addEvent("startSpectate", true) addEventHandler("startSpectate", localPlayer, startSpectateHandler) addEvent("stopSpectate", true) addEventHandler("stopSpectate", localPlayer, startSpectateHandler)
  2. Hey guys, need some help with my code, the script works, but it spams me this warning: Code: function onRender( ) if isCursorShowing( ) then vehicles = getElementsByType( "vehicle" ) local px, py, pz = getElementPosition( localPlayer ) for key, vehicle in ipairs(vehicles) do local vx, vy, vz = getElementPosition( vehicle ) local distance = getDistanceBetweenPoints3D ( vx,vy,vz,px,py,pz ) if distance < 30 then local w, h = guiGetScreenSize () local scalex, scaley = w/1920/distance, h/1080/distance local x, y = getScreenFromWorldPosition ( vx, vy, vz + 1 ) dxDrawImage ( x, y, 200 * scalex, 200 * scaley, "steering_wheel.png" ) end end end end addEventHandler( "onClientRender", getRootElement(), onRender ) Update! After a while I got bored and decided to take a ride around LS for some time, and I noticed that when I'm around just one car, it doesn't show me the warning. So i went to the wiki and found out that getScreenFromWorldPosition returns false if the camera does not see the object. Modified the code and now it works perfectly! local x, y = getScreenFromWorldPosition ( vx, vy, vz + 1 ) if x ~= false then dxDrawImage ( x, y, 200 * scalex * 4, 200 * scaley * 4, "steering_wheel.png" ) end
  3. Thanks man, don't know how I missed that
  4. I've tried to make a script that tells you what are you aiming at. For ex, it tells you if you're aiming at a player or a vehicle. But for whatever reason, it doesn't work... The script runs just fine, no warnings/errors. Thanks for the help. function checkAiming( ) if isPedAiming ( getLocalPlayer() ) then local w, h = guiGetScreenSize () local elementType = getElementType ( getPedTarget ( getLocalPlayer ( ) ) ) dxDrawText ( "You are aiming at a(n) " .. elementType .. " now", w/2, h/4) end end addEventHandler( "onPlayerRender", getRootElement(), checkAiming )
  5. Is there any possible way that when the player is in an interior, for example CJ's house, to make the windows transparent and the player to be able to see outside when he looks through them?
  6. Thanks for the example man! I think I got the idea... And BTW, I don't really need a timer for every vehicle, It is something close to that but a bit more complicated to explain so I just asked that question hoping that it will implicitly answer my ohter unknowings and fortunately it did. Thanks for the help!
  7. Hey! I just started scripting in LUA and I need some help... I have a very good knowledge of the C languages (mainly C++) but I'm having trouble understanding a few things. What I want to do is create a timer (x = setTimer(...) ) for every vehicle on the server... and I have no idea how to do it. I know it must be tied to tables, I tried using tables but I failed... I only just started on LUA today so I'm a pretty big noob NOTE: This account is not MINE so disregard my other posts
  8. not working... working just when start the resource
  9. i made another one from scratch so create a new lua file named "server" without quotes witch containes this code: local Criminal = createTeam ( "Criminal", 155, 0, 0 ) function putPlayerInTeam ( player ) if ( isElement ( player ) ) then if ( getPlayerTeam ( player ) == getTeamFromName ( "Criminal" )) then outputChatBox("* You Are Already On The 'Criminal' Team!",player,255,0,0) return end setPlayerTeam ( player , Criminal ) outputChatBox("* You Have Been Joined Into The 'Criminal' Team! ",player,155,0,0) end end addCommandHandler ( "criminal", putPlayerInTeam ) and don't forget to create "meta.xml" file witch contains: <meta> <script src="server.lua" type="server" /> </meta> note: mta.xml must be in the same folder with server.lua hope it helps
  10. adithegman

    help :(

    hello guys, i'm tryng to make a script that every five minutes it cleares the chat, but... it doesn't work pls help This is client-side local cleared = 0 function timer() if ( cleared == 0 ) then setTimer ( clearChat, 60000*5, 1 ) cleared = 1 end end function clearChat() done=0 cleared = 0 while done<=200 do outputChatBox("",0,0,0,false) done = done+1 end setTimer ( timer, 1, 1 ) end addEventHandler ( "onClientResourceStart", getRootElement, timer )
  11. to be honest, my friend asked me to ask the community because on his server it doesn't work, so i don't know if he has permision....
  12. hi guys i have this panel and the maps aren't loading, i hope you guys can find the problem
  13. hello guys, i have a problem with the anti-spam and hope you guys can solve it it outputChatBox well cuz' i see for ex Adithegman has been muted... but it doesn't mute me for 1 min, i can still speak note: this is server-side antiSpam = {} function antiChatSpam() if isTimer(antiSpam[source]) then cancelEvent() outputChatBox("#ffffff"..getPlayerName(source).." has been #ff0000muted #fffffffor for 60 seconds, reason: #ff0000spam", getRootElement(), 255, 255, 0,true) setPlayerMuted ( source, true ) setTimer ( autoUnmute, 60000, 1, source) else antiSpam[source] = setTimer(function(source) antiSpam[source] = nil end, 1000, 1, source) end end addEventHandler("onPlayerChat", root, antiChatSpam) local commandSpam = {} function preventCommandSpam( command ) if command == "say" then if (not commandSpam[source]) then commandSpam[source] = 1 elseif (commandSpam[source] == 5) then cancelEvent() outputChatBox("#ffffff"..getPlayerName(source).." has been #ff0000muted #fffffffor for 60 seconds, reason: #ff0000spam!", getRootElement(), 255, 255, 0,true) setPlayerMuted( source, true ) setTimer ( autoUnmute, 60000, 1, source) else commandSpam[source] = commandSpam[source] + 1 end end end addEventHandler("onPlayerCommand", root, preventCommandSpam) setTimer(function() commandSpam = {} end, 1000, 0) function autoUnmute ( source ) setPlayerMuted ( source, false ) end
×
×
  • Create New...