Jump to content

Saml1er

Retired Staff
  • Posts

    1,058
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Saml1er

  1. Port forwarding is for incoming connections, not outgoing. The API server already has the necessary ports open, and therefore connection should work (unless there's firewall the outgoing server) I wonder why callRemote was not working for me when my ports were not open? Hmmm I think it was an year ago.
  2. Because you need to do port forwarding. Execute "openports" in your server console and it will you whether your ports are open or no. If no then do port forwarding.
  3. Because count is not defined. I accidently removed it. function checkHouseForPercentage() checkTimer = nil outputChatBox("1") if houserobBlip then count = 0 -- this line needs to be added outputChatBox("2")
  4. Yes, 1LoL1 is right. count = count +1 wl = getElementData(robber, "wanted") +1 if wl > 36 then wl = 36 exports.RPGPolice:setWantedLevel(robber, wl) end end end-- you just needed to add this
  5. getElementHealth returns an int with range ( 0-100) so... function getHealth() if (getElementHealth(localPlayer)) == 100 then --Checks if the player has full HP takePlayerMoney(localPlayer, 1000) elseif (getElementHealth(localPlayer)) => 80 then --Checks if the player has more than or equal 80 health ...
  6. add debugs and you will find out which line is causing it. Do it like this: function checkHouseForPercentage() checkTimer = nil outputChatBox("1") if houserobBlip then outputChatBox("2") for i, robber in ipairs (getElementsWithinColShape(houserobCircle, "player")) do if not isPedDead(robber) and robberTeams[getTeamName(getPlayerTeam(robber))] then count = count +1 wl = getElementData(robber, "wanted") +1 if wl > 36 then wl = 36 exports.RPGPolice:setWantedLevel(robber, wl) end end if not firstTime then outputChatBox("3") firstTime = 0 for i, robber in pairs (getElementsWithinColShape(houserobCircle, "player")) do if not isPedDead(robber) and robberTeams[getTeamName(getPlayerTeam(robber))] then showProcess(robber) end end outputChatBox("4") if count > 0 then outputChatBox("5") local percent = getElementData(houserobMarker, "percent") local percent = percent + (count*ppP) if percent > 0 then triggerClientEvent("showHouserobBlip", getRootElement(), 2, houserob[houserobNumber][1],houserob[houserobNumber][2],houserob[houserobNumber][3]) outputChatBox("7") else if percent > 100 then setElementData(houserobMarker, "percent", 100) nextStep() else setElementData(houserobMarker, "percent", percent) outputChatBox("8") end end outputChatBox("Last") checkTimer = setTimer(checkHouseForPercentage, 5000, 1) end end
  7. You have to be logged in and you need to be an admin then do /debugscript 3 in chat. Your code is way too long for anyone to read. Please copy-paste in pastebin.com
  8. Just use tables and do everything server side since you definitely don't want to bomb yourself lol. You are placing a bomb so it can explode other players, right? So do it sever side. local bombs = {} addCommandHandler ("bomb", function ( p, cmd ) if not bombs[getPlayerSerial (p) ] then local x, y, z = getElementPosition(p) local colShape = createColSphere ( x, y, z, 1 ) bombs[getPlayerSerial (p) ] = colShape -- save the xyz else -- bomb is already planted for current player end end ) addCommandHandler ("explode", function ( p, cmd ) if bombs[getPlayerSerial (p) ]) then local x, y, z = getElementPosition ( bombs[getPlayerSerial (p) ] ) destroyElement (bombs[getPlayerSerial (p) ]) bombs[getPlayerSerial (p) ] = nil createExplosion ( x, y, z,8 ) end ) addEventHandler ( "onColShapeHit", resourceRoot, -- resourceRoot will only allow this event handler to get triggered if colshape is created by this resource where this script is currently running function ( elem ) if getElementType(elem) == "player" then -- source of this event is the colshape local x, y, z = getElementPosition ( source ) createExplosion ( x, y, z, 8 ) destroyElement ( source ) end end ) serial is always good to use because it won't change even if player reconnects but if you want to remove bomb when player disconnects from server then set this same thing to nil, for example, addEventHandler("onPlayerQuit", root, function () if bombs[getPlayerSerial (source) ]) then destroyElement (bombs[getPlayerSerial (source) ]) bombs[getPlayerSerial (source) ] = nil end --this (nil) will remove the entry completely from the table. Don't use false use nil if you want to remove it and save memory just like I did end) I wrote this script from mobile. If you find any errors then fix it on your own.
  9. Saml1er

    [HELP] Marker

    Can you explain what are you trying to do?
  10. This example is wrong. You are not converting string to number. r = tonumber(r) g = tonumber(g) b = tonumber(g) Not critisizing but I'm sure many new newbies will try to learn something from this code but they will find that it doesn't work.
  11. Saml1er

    [HELP] Marker

    local markersCreated = 0 function www (source) local w = createMarker( -2805.87890625,1318.779296875,7.1015625, "cylinder", 1.5, 255, 255, 0, 170 ) if not w then return -- stop the function by returning nothing end if markersCreated > 1 then outputChatBox("Marker is created", source, 255, 255, 255, true) else markersCreated = markersCreated + 1 end end addCommandHandler("markerr", www) cancelEvent() is used to cancel events not command handlers.
  12. You are doing it wrong. local duration = 8 -- lets say 8 seconds function startCounter ( ) end Ctimer = setTimer(startCounter,duration*1000,1) ms, _, _= getTimerDetails ( Ctimer ) s = ms/1000 m = ms/60 Also I'm sure a while loop in a thread is used for getTimerDetails since for a custom timer you will need to check every instance how much time has passed. You are getting wrong time because your code is wrong but since we already have getTimerDetails function so you definitely don't need to waste time writing a new one. EDIT: use isTimer( TimerVariable ) to check if timer still exists because timer is not set to nil and also don't check like this: if s == 60 then Instead do it like this: if s >= 60 then -- greater than or equal to
  13. Saml1er

    solved shader

    Check my answer here: viewtopic.php?f=91&t=93901 If you did everything I said there then it should work perfectly.
  14. That usually happens when you call DFF functions before TXD. Do it in this way: txd = engineLoadTXD ( "data/euros.txd" ) engineImportTXD ( txd, 587 ) dff = engineLoadDFF ( "data/euros.dff" ) engineReplaceModel ( dff, 587 ) Source: mta wiki
  15. Did you check Dealman's post? He posted full code and he explained each and every line and more importantly its related to what you want. I never used interpolate functions because they suck pretty much. I can write my own code which is easier to understand for anyone. Anyhow getTickCount doesn't return 0 when its called @Aristates. getTickCount returns time. Lets say you want to know the execution time of a code. local start = getTickCount() -- the return value will be different at different time depending on date like year, month, minute, second etc for i= 1, 40000 do -- this loop will repeat 40 k times end local ms = start - getTickCount() -- milliseconds now local seconds = ms/1000 -- seconds local minutes = seconds/60 -- minutes outputChatBox ( minutes .. " minutes ".. seconds .." seconds " ..ms.." milliseconds passed ") -- this will tell you how much time passed I'm on phone and thats all I can explain for now
  16. Because event is triggered before event handler is added. Its your meta.xml. You are loading client file before server side and that's why it happens. Do it like this:
  17. I wrote a simple script which loads txd and replaces textures using shaders. Right now I'm going to sleep, in morning I'll post it here. Here it is: addEventHandler( "onClientResourceStart", resourceRoot, function() local txd = engineLoadTXD ( "main.txd" ) engineImportTXD ( txd, 12990) t_shader, tec = dxCreateShader ( "uv_scripted.fx" ) -- Create texture and add to shader if t_shader then local myTexture = dxCreateTexture ( "example.png" ); dxSetShaderValue ( t_shader, "CUSTOMTEX0", myTexture ); else return outputChatBox ("Failed to create shader!") end local x,y,z = getElementPosition ( localPlayer ) local obj = createObject (12990,x+5,y+5,z ) -- create the object engineApplyShaderToWorldTexture ( t_shader, "wall2", obj ) end ) NOTE: This is just an example. I didn't include the dff file which is a custom object and it has a texture named "wall2". This example won't work because I have not included the dff file so replace this: engineApplyShaderToWorldTexture ( t_shader, "wall2", obj ) to engineApplyShaderToWorldTexture ( t_shader, "sw_jetty", obj ) -- this is the default txd name of this object If you're wondering if that's the case then you won't be able to use a txd file? the answer is no, YOU CAN USE IT only if you use the same TXD name for the image as default ones. If default txd name of the object is sw_jetty then you must name it to sw_jetty in txd file which you will create in TXD workshop. Remember wall2 is the texture name I used in the main.txd file If you're not loading a custom txd file but you simply want to replace the texture with a png or jpg texture then check objects ide ( txd and dff names) here: https://wiki.multitheftauto.com/wiki/IDE_List If you want try without using the main.txd file then simply remove wall2 form second arguement replace it with this: sw_jetty This is how it should look like: engineApplyShaderToWorldTexture ( t_shader, "sw_jetty", obj ) Also remember that image you are going to insert in txd file, its size should be 256x256 or 512x512 otherwise txd file will not work You can make your own txd file using TXD workshop, I bet you will find lots of tutorials in youtube for TXD workshop especially for MTA I uploaded the resource to mediafire. You can download it here: http://www.mediafire.com/download/ox08p ... tatest.rar EDIT: I forgot to add these lines in the resource but I hope you understand how it works. local txd = engineLoadTXD ( "main.txd" ) engineImportTXD ( txd, 12990)
  18. But why are you updating a column which doesn't even exist? In your first post you are updating 2 columns ( area and data ) This??? dbExec(DB_connection, "UPDATE `world` SET `data` = ? WHERE `area` = ?", area, data) Anyway if you want to add a column named "value" then simply use alter. dbExec(DB_connection, "ALTER TABLE world ADD value TEXT")
  19. addEventHandler ( "onColShapeHit", GreenZone, function (thePlayer,matchingDimension ) if matchingDimension and isElement(thePlayer) then if getElementType(thePlayer) == "player" then toggleControl ( thePlayer, "fire", false ) toggleControl ( thePlayer, "next_weapon", false ) toggleControl ( thePlayer, "previous_weapon", false ) outputChatBox( "Biztonsági zóna: Beléptél a biztonsági zónába itt nem lőhetsz.",thePlayer, r,g,b) elseif getElementType(thePlayer) == "ped" and getElementData(thePlayer, "zombie") then destroyElement( thePlayer ) -- destroy the ped since you don't want zombies in safe zone end end end)
  20. Its never hard to google: https://forum.multitheftauto.com/viewtopic.php?f=91&t=68541
  21. Instead of wasting time on learning "How to decompile?", you should rather look for "How to code?" because decompilers for luac files are usually written in c++ and there's usually nothing special in compiled lua code. You will be disappointed after decompiling because soon you will realise that it was never difficult to write something exactly samw. Even if you get the source code, can you make it to work without programming knowledge?
  22. Well you can simply set cache to false in meta.xml for client side scripts. Clients will not download lua file, code will be executed directly. Altho someone with advanced programming knowledge can get the code from RAM and convert it from bytes to lua again but still not much people would like to go through this for stealing your code but still its possible.
  23. I'm not sure how MTA team coded sync stuff but since this is a projectile so its important to sync it. I guess they used TCP to send message to all clients for creating and shooting projectile due to which ping matters a lot in this case. If client is lagging then its a problem but hey that doesn't mean that you cannot make this script. You can code it. I'm on mobile phone. I will write a simple script tomorrow
  24. Well if you are ready to go through trouble then you can write a simple UDP server and client script to send and receive data in C or C++. I guess you can compile it (DLL) and use it in MTA for your server. I wrote a very simple working script for my test multiplayer game. Server side code for linux ( Since most servers are running on linux ) in C: #include <stdio.h> #include <time.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #define PORT 28009 // Choose a free port #define MAX_CLIENTS 250 // sync between clients int compareAddress ( struct sockaddr_in *a1, struct sockaddr_in *a2) // useful function { int Match = 0; if ( sizeof (a1) == sizeof ( a2 ) && (a1->sin_family == a2->sin_family) && (a1->sin_addr.s_addr == a2->sin_addr.s_addr) && (a1->sin_port == a2->sin_port) ) { Match++; } return Match; } // for now we will not use this function void sendQuitMessagetoAll (int listener, struct sockaddr_in cli_addr[], struct sockaddr_in *cli_source ) { char niceArray [] = "One of the player has quit the game."; int clients = sizeof ( cli_addr ); int i; for ( i=0; i<clients; i++){ int len = sizeof(niceArray); int total = 0; // how many bytes we've sent int bytesleft = len; // how many we have left to send int n; while(total < len) { n = sendto(listener, niceArray+total, bytesleft, 0, (struct sockaddr*)&cli_addr[i], sizeof (cli_addr[i]) ); if (n == -1) { break; } total += n; bytesleft -= n; } len = total; // return number actually sent here } } int main(void) { fd_set master; // master file descriptor list int clients, client_addrSize[MAX_CLIENTS], listener, retval, nbytes, i, c, j, newLoopPos, bytesSent; int len, total, bytesleft, n, clientRemoved; clients = 0; // 0 connected clients socklen_t slen_temp; time_t last_update[MAX_CLIENTS]; // checking disconnection or time out double diff_t; struct sockaddr_in myaddr, cli_addr[MAX_CLIENTS], cli_temp; ; /* our address and client address*/ socklen_t addrlen = sizeof(myaddr); /* length of addresses */ memset((char *)&myaddr, 0, sizeof(myaddr)); myaddr.sin_family = AF_INET; myaddr.sin_addr.s_addr = htonl(INADDR_ANY); myaddr.sin_port = htons(PORT); /* create a UDP socket */ if ((listener = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { perror("cannot create socket\n"); return 0; } /* bind the socket to any valid IP address and a specific port */ if (bind(listener, (struct sockaddr *)&myaddr, sizeof(myaddr)) < 0) { perror("bind failed"); return 0; } // main loop for( ; ; ) { FD_ZERO(&master); FD_SET(listener, &master); retval = select(listener+1, &master, NULL, NULL, NULL) ; if (retval == -1) { perror("select"); exit(4); } else if ( retval ) { printf (" data available\n "); // run through the existing connections looking for data to read if (FD_ISSET(listener, &master)) { // we got one!! char buf[1024]; // buffer for client data // handle data from a client if ((n = recvfrom(listener, buf, sizeof(buf), 0, (struct sockaddr*)&cli_temp, &slen_temp)) <= 0) { // got error or connection closed by client if (nbytes == 0) // connection closed printf("selectserver: socket %d hung up\n", listener); else perror("ERROR: recvfrom"); } else { char niceArray[n]; for(i = 0; i < n; i++) niceArray[i] = buf[i]; j = 0; // j wil act as bool for checking if client address is already stored in array or no int this_length = sizeof ( (struct sockaddr*)&cli_temp); if (clients < MAX_CLIENTS) { for(i = 0; i < clients; i++) { // struct sockaddr*)&cli_addr[i] if ( compareAddress(&cli_addr[i], &cli_temp) > 0 ) { j++; } } } if ( j == 0 ) { // so yeah client doesn't exist so we store the address and last update time cli_addr[clients] = cli_temp; last_update[clients] = time(NULL); clients++; printf("\n Client Added. \n"); } newLoopPos = 0; // start loop from 0 do { clientRemoved = 0; for(i = newLoopPos; i < clients; i++) { diff_t = difftime( time(NULL), last_update[i] ); if ( diff_t >= 15 ) { // client has time out or disconnect if ( (i+1) == clients) { // we don't need to DO the do-while loop AGAIN if we are removing the last element // nothing here <!-- s;) --><img src=\"{SMILIES_PATH}/icon_wink.gif\" alt=\";)\" title=\"Wink\" /><!-- s;) --> } else clientRemoved++; newLoopPos = i; clients--; struct sockaddr_in cli_source; cli_source = cli_addr[i]; // client that got disconnected for ( c = i - 1 ; c < MAX_CLIENTS - 1 ; c++ ) { // then its better to remove him from array cli_addr[c] = cli_addr[c+1]; last_update[c] = last_update[c+1]; } // we surely don't want to display disconnection messages from past 10 hours or so <!-- s;) --><img src=\"{SMILIES_PATH}/icon_wink.gif\" alt=\";)\" title=\"Wink\" /><!-- s;) --> if ( diff_t < 60 ) { /* //lets disable quit message for a while until we add support in client side for reading sendQuitMessagetoAll ( listener, cli_addr, &cli_source ); */ } break; // it's important to break for loop now since we don't need to loop again wee } /* DEBUG PURPOSE printf("(%d) LOOP and (%d) clients variable.\n", i, clients); */
×
×
  • Create New...