Jump to content

whiskeyzulu

Members
  • Posts

    10
  • Joined

  • Last visited

Recent Profile Visitors

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

whiskeyzulu's Achievements

Member

Member (5/54)

0

Reputation

  1. Hi, I'm struggling to debug my busted cut scene event. I want to be able to type "bust" into the server console and force the client into busted state. I think I'm confusing source/root/etc in my event handlers. server: function buster() --print("SERVER BUST") triggerClientEvent("onBusted",source) end addCommandHandler("bust",buster) client: bustedText = dxCreateTexture("busted.png") function busted() outputChatBox("Busted") print("Busted") if getPlayerName(localPlayer) == "bandit" then --get bandit position local bx,by,bz = getElementPosition(localPlayer) --get table of all vehicles local vehicles = getElementsByType("vehicle") for i, vehicle in ipairs (vehicles) do --find out if other players are nearby local px,py,pz = getElementPosition(vehicle) local distance = getDistanceBetweenPoints3D(bx,by,bz,px,py,pz) if distance < 5 and getElementModel(vehicle) == 596 then createExplosion(bx,by,bz,10) --10 means tank grenade style print ("BOOM") outputChatBox("BOOM!") local screenWidth,screenHeight = guiGetScreenSize() local angle = 0 for i=1,10 do for j=1,360 do angle = math.sin(j) * 80 dxDrawImage(screenWidth / 2 - 50, 0, 100, 240, bustedText, angle, 0, 0) end end for i=1,100 do dxDrawImage(screenWidth / 2 - 50, 0, 100, 240, bustedText, angle, 0, 0) end triggerServerEvent("onWarp",getRootElement()) end end end end addEvent("onBusted",true) addEventHandler("onBusted",root,busted) addEventHandler("onClientVehicleCollision",getRootElement(),busted)
  2. It appears that my problem was due to the fact that I was loading an old version of my map file that did not have any markers placed inside it! I need to work on my version control. My function now works properly and reliably. It is a bit clunkier than I would like so any tips or comments as to how I may be able to clean it up a little would be most greatly appreciated. I still couldn't access a table of markers by indexing directly with a math.random call within square brackets (i.e. randomMarker = marker[math.random(1,#marker)]). I ended up using a for loop to iterate through ipairs as usual. function warper() local player = getPlayerName(source) local vehicleID = 0 local x,y,z = 0 if player == "pilot" then --pilot gets a police maverick helicopter vehicleID = 497 elseif player == "patrol1" or player == "patrol2" then --patrolmen get a police car vehicleID = 596 else --bandits get a taxi vehicleID = 438 end local markers = getElementsByType("marker") local randomIndex = math.random(1,#markers) for i, marker in ipairs (markers) do if player == "pilot" and i == 26 then x,y,z = getElementPosition(marker) elseif player ~= "pilot" and i == randomIndex then x,y,z = getElementPosition(marker) end --make all markers invisible setElementVisibleTo(marker,root,false) end z = z + 0.5 --make sure vehicle is created above ground local newVehicle = createVehicle ( vehicleID, x, y, z) --only bandits can be damaged if player ~= "bandit" then setVehicleDamageProof(newVehicle,true) end spawnPlayer(source,x,y,z+20) warpPedIntoVehicle(source,newVehicle) fadeCamera(source,true) end addEvent("onWarp",true) addEventHandler("onWarp",getRootElement(),warper) addEventHandler("onPlayerJoin",getRootElement(),warper)
  3. so I should enter a while loop until "markers" are true then build the table. Why are the markers I have placed on the map in the map editor not showing up when i start my server? I had this working yesterday!! LOL
  4. spoke too soon! Problem still happens sporadically. #markers is sometimes throwing out nil when I restart my resource.
  5. that would give me the coordinates of each marker. It still doesn't solve how to pick one of those markers to spawn at or whatever. I solved the problem. I included a minimum random argument along with a maximum argument. I believe my original code above would sometimes randomly throw out a zero and cause the code to break. I replaced the code with this: local markers = getElementsByType("marker") local x,y,z = getElementPosition(markers[math.random(1,#markers)]) all is fine! I randomly spawn at any one of my 27 markers! Thanks for trying to help. Big love.
  6. can any of you brainics tell me why this script doesn't give me the coordinates of a random marker?? local markers = getElementsByType("marker") local x,y,z = getElementPosition(markers[math.random(#markers)]) debug tells me that the argument passed to random is nil. There are definitely 27 markers on the map (created with map editor). Maybe I am calling getElementsByType before the map objects have loaded??
  7. Hi, I'm still trying to export game data to a logging program running on a separate machine on my local network. I have written the following code which I hope is sending TCP packets to each player containing everyone's location and a serverTick. How can I tell if the packets are being sent? I set up my receiving program to listen to the port I know the script is writing to but am not receiving any data. I think I have my port forwarded correctly, when I create a port forwarding service on my router should the service use the sender's IP or the receiver's? During debugging I am running both programs on one machine but still receive no data, Is port forwarding required for localhost communication? Do I need to set up some sort of TCP server/client handshake?!? At the moment I create a socket from the player's IP address and assign a port number such as 54321 for player one, on my receiver at that IP address I listen to port 54321 but don't hear anything. Anyway, as you can see I'm a little bit lost! Any tips and guidance is much appreciated. Here is my script: --****************************************************************** --this function requires the ml_sockets library. Download ml_sockets --and place inside MTA San Andreas/server/mods/deathmatch/modules. --Add the following line to your mtaserver configuration file: -- --****************************************************************** --****************************************************************** --ALL PLAYERS MUST HAVE JOINED THE SERVER BEFORE CALLING THIS SCRIPT --****************************************************************** -- this script sends a datagram to each player's IP -- address containing all player's speed and location function broadcast() local players = getElementsByType("player") local playerData = {} local sockets = {} local port = {} --create 2D array which will contain each player's --respective IP address, game map location and serverTick count for i, player in ipairs(players) do --assign a different port number for each player i.e. --player one port = 54321, player two port = 54322, etc.... port[i] = 54320 + i --create array of transmission sockets sockets[i] = {} --create first dimension of data array playerData[i] = {} --create second dimension of data array containing 9 elements --5 for data entries and 4 for delimiting symbols --i.e. {[iPAddress][*][posX][*][posY][*][posZ][*][tick]} for j=1, 9 do playerData[i][j] = '*' end end --get all player's IP address and open socket to that address --on the player's assigned port number for i, player in ipairs(players) do playerData[i][1] = getPlayerIP(player) sockets[i] = sockOpen(playerData[i][1],port[i]) end --broadcast each player's locations and speed to --each player's respective IP address and port for i, player in ipairs (players) do --start datagram with symbol sockWrite(sockets[i],"<") --local car = getPedOccupiedVehicle(player) local tick = getTickCount() local posx,posy,posz = getElementPosition(player) playerData[i][3] = posx playerData[i][5] = posy playerData[i][7] = posz playerData[i][9] = tick for j=1, 9 do sockWrite(sockets[i], tostring(playerData[i][j])) --***DEBUG*** print what was sent to console print(playerData[i][j]) --***END DEBUG*** end --end datagram with symbol sockWrite(sockets[i],">") end end setTimer(broadcast,1000,0)
  8. I realise that. I would like some help in deciding whether I can read the characters from the console window using some Windows API functions or do I need to implement some sort of network sharing. I am trying to read the console directly as this seemed the most straight forward approach. I am currently writing a little test script to discover if I can GetConsoleInput. If someone can let me know if I'm wasting my time and speed up my progress I would be eternally grateful!
  9. I think I may need to implement some UDP functions.....
  10. Does anyone know how I may be able to read player locations and speed from another program? I thought I could print the locations to the MTA Server console window and use some Windows API functions to read the data into an array but this approach is a lot more difficult than I thought (I'm not a very advanced programmer!). Can I make the server window a child of my main C++ program and then just call std io functions? If I monitor key presses to the console window will I see the server "typing" to the console? Thanks, Whiskey
×
×
  • Create New...